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

93 lines
1.8 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"
2019-02-05 15:13:34 +03:00
"mapserver/db/sqlite"
2019-01-28 16:33:32 +03:00
"mapserver/eventbus"
2019-01-18 11:13:37 +03:00
"mapserver/mapblockaccessor"
"mapserver/mapblockrenderer"
2019-02-05 15:25:01 +03:00
sqliteobjdb "mapserver/mapobjectdb/sqlite"
2019-01-21 18:27:31 +03:00
"mapserver/params"
2019-01-18 11:13:37 +03:00
"mapserver/tilerenderer"
"mapserver/worldconfig"
2019-02-07 11:11:11 +03:00
"mapserver/settings"
2019-01-18 11:13:37 +03:00
"github.com/sirupsen/logrus"
"errors"
2019-01-18 10:47:38 +03:00
)
2019-02-01 13:26:57 +03:00
func Setup(p params.ParamsType, cfg *Config) *App {
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:
2019-02-05 15:13:34 +03:00
a.Blockdb, err = sqlite.New("map.sqlite")
2019-01-25 15:14:49 +03:00
if err != nil {
2019-02-01 13:26:57 +03:00
panic(err)
2019-01-25 15:14:49 +03:00
}
default:
2019-02-01 13:26:57 +03:00
panic(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 {
2019-02-01 13:26:57 +03:00
panic(err)
2019-01-18 10:47:38 +03:00
}
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 {
2019-02-01 13:26:57 +03:00
panic(err)
2019-01-18 10:47:38 +03:00
}
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-28 16:47:53 +03:00
//mapserver database
2019-02-06 17:52:34 +03:00
if a.Worldconfig.MapObjectConnection != "" {
2019-01-28 16:47:53 +03:00
//TODO: Psql connection
} else {
2019-02-05 15:25:01 +03:00
a.Objectdb, err = sqliteobjdb.New("mapserver.sqlite")
2019-01-28 16:47:53 +03:00
}
2019-01-18 10:47:38 +03:00
if err != nil {
2019-02-01 13:26:57 +03:00
panic(err)
2019-01-18 10:47:38 +03:00
}
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 {
2019-02-01 13:26:57 +03:00
panic(err)
2019-01-18 10:47:38 +03:00
}
2019-02-07 11:11:11 +03:00
//settings
a.Settings = settings.New(a.Objectdb)
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-02-01 13:26:57 +03:00
return &a
2019-01-18 10:47:38 +03:00
}