1
0
forked from MTSR/mapserver
mapserver/server/app/setup.go

84 lines
1.6 KiB
Go
Raw Normal View History

2019-01-18 10:47:38 +03:00
package app
import (
2019-01-18 11:13:37 +03:00
"mapserver/colormapping"
"mapserver/db"
2019-01-28 16:33:32 +03:00
"mapserver/eventbus"
2019-01-18 11:13:37 +03:00
"mapserver/mapblockaccessor"
"mapserver/mapblockrenderer"
2019-01-21 17:13:33 +03:00
"mapserver/mapobjectdb"
2019-01-21 18:27:31 +03:00
"mapserver/params"
2019-01-18 11:13:37 +03:00
"mapserver/tilerenderer"
"mapserver/worldconfig"
"github.com/sirupsen/logrus"
"errors"
2019-01-18 10:47:38 +03:00
)
2019-01-18 11:03:57 +03:00
func Setup(p params.ParamsType, cfg *Config) (*App, error) {
2019-01-18 11:13:37 +03:00
a := App{}
a.Params = p
a.Config = cfg
2019-01-28 16:33:32 +03:00
a.WebEventbus = eventbus.New()
2019-01-18 10:47:38 +03:00
2019-01-18 11:13:37 +03:00
//Parse world config
a.Worldconfig = worldconfig.Parse("world.mt")
logrus.WithFields(logrus.Fields{"version": Version}).Info("Starting mapserver")
2019-01-18 10:47:38 +03:00
2019-01-18 11:13:37 +03:00
var err error
2019-01-25 15:14:49 +03:00
switch a.Worldconfig.Backend {
case worldconfig.BACKEND_SQLITE3:
a.Blockdb, err = db.NewSqliteAccessor("map.sqlite")
if err != nil {
return nil, err
}
default:
return nil, errors.New("map-backend not supported: " + a.Worldconfig.Backend)
2019-01-18 10:47:38 +03:00
}
2019-01-18 11:13:37 +03:00
//migrate block db
2019-01-18 10:47:38 +03:00
err = a.Blockdb.Migrate()
if err != nil {
return nil, err
}
2019-01-18 11:13:37 +03:00
//mapblock accessor
2019-01-18 10:47:38 +03:00
a.BlockAccessor = mapblockaccessor.NewMapBlockAccessor(a.Blockdb)
2019-01-18 11:13:37 +03:00
//color mapping
2019-01-18 10:47:38 +03:00
a.Colormapping = colormapping.NewColorMapping()
err = a.Colormapping.LoadVFSColors(false, "/colors.txt")
if err != nil {
return nil, err
}
2019-01-18 11:13:37 +03:00
//mapblock renderer
a.Mapblockrenderer = mapblockrenderer.NewMapBlockRenderer(a.BlockAccessor, a.Colormapping)
2019-01-18 10:47:38 +03:00
2019-01-18 11:13:37 +03:00
//tile database
2019-01-21 17:13:33 +03:00
a.Objectdb, err = mapobjectdb.NewSqliteAccessor("mapserver.sqlite")
2019-01-18 10:47:38 +03:00
if err != nil {
return nil, err
}
2019-01-18 11:13:37 +03:00
//migrate tile database
2019-01-21 17:13:33 +03:00
err = a.Objectdb.Migrate()
2019-01-18 10:47:38 +03:00
if err != nil {
return nil, err
}
2019-01-18 11:13:37 +03:00
//setup tile renderer
a.Tilerenderer = tilerenderer.NewTileRenderer(
a.Mapblockrenderer,
2019-01-21 17:13:33 +03:00
a.Objectdb,
2019-01-18 11:13:37 +03:00
a.Blockdb,
2019-01-21 13:13:00 +03:00
a.Config.Layers,
2019-01-18 11:13:37 +03:00
)
2019-01-18 10:47:38 +03:00
2019-01-18 11:13:37 +03:00
return &a, nil
2019-01-18 10:47:38 +03:00
}