diff --git a/app/config.go b/app/config.go index af2c7a3..80cd7db 100644 --- a/app/config.go +++ b/app/config.go @@ -4,6 +4,7 @@ import ( "encoding/json" "io/ioutil" "mapserver/coords" + "mapserver/layer" "os" "sync" ) @@ -15,6 +16,7 @@ type Config struct { Webdev bool `json:"webdev"` WebApi *WebApiConfig `json:"webapi"` RenderState *RenderStateType `json:"renderstate"` + Layers []layer.Layer `json:"layers"` } type WebApiConfig struct { @@ -76,6 +78,15 @@ func ParseConfig(filename string) (*Config, error) { LastMtime: 0, } + layers := []layer.Layer{ + layer.Layer{ + Id: 0, + Name: "Base", + From: -16, + To: 160, + }, + } + cfg := Config{ Port: 8080, EnableInitialRendering: true, @@ -83,6 +94,7 @@ func ParseConfig(filename string) (*Config, error) { Webdev: false, WebApi: &webapi, RenderState: &rstate, + Layers: layers, } info, err := os.Stat(filename) diff --git a/app/setup.go b/app/setup.go index 828a6d2..3ff4dbe 100644 --- a/app/setup.go +++ b/app/setup.go @@ -3,7 +3,6 @@ package app import ( "mapserver/colormapping" "mapserver/db" - "mapserver/layerconfig" "mapserver/mapblockaccessor" "mapserver/mapblockrenderer" "mapserver/params" @@ -22,7 +21,6 @@ func Setup(p params.ParamsType, cfg *Config) (*App, error) { a.Config = cfg //Parse world config - a.Worldconfig = worldconfig.Parse("world.mt") logrus.WithFields(logrus.Fields{"version": Version}).Info("Starting mapserver") @@ -79,7 +77,7 @@ func Setup(p params.ParamsType, cfg *Config) (*App, error) { a.Mapblockrenderer, a.Tiledb, a.Blockdb, - layerconfig.DefaultLayers, + a.Config.Layers, ) return &a, nil diff --git a/layer/layer.go b/layer/layer.go new file mode 100644 index 0000000..2e62fdd --- /dev/null +++ b/layer/layer.go @@ -0,0 +1,8 @@ +package layer + +type Layer struct { + Id int `json:"id"` + Name string `json:"name"` + To int `json:"to"` + From int `json:"from"` +} diff --git a/layerconfig/layerconfig.go b/layerconfig/layerconfig.go deleted file mode 100644 index 08e828b..0000000 --- a/layerconfig/layerconfig.go +++ /dev/null @@ -1,47 +0,0 @@ -package layerconfig - -import ( - "encoding/json" - "io/ioutil" -) - -type LayerContainer struct { - Layers []Layer `json:"layers"` -} - -type Layer struct { - Id int `json:"id"` - Name string `json:"name"` - To int `json:"to"` - From int `json:"from"` -} - -var DefaultLayers []Layer - -func init() { - DefaultLayers = []Layer{ - Layer{ - Id: 0, - Name: "Base", - From: -16, - To: 160, - }, - } -} - -func ParseFile(filename string) ([]Layer, error) { - - data, err := ioutil.ReadFile(filename) - if err != nil { - return nil, err - } - - lc := LayerContainer{} - - err = json.Unmarshal(data, &lc) - if err != nil { - return nil, err - } - - return lc.Layers, nil -} diff --git a/layerconfig/layerconfig_test.go b/layerconfig/layerconfig_test.go deleted file mode 100644 index 57e9416..0000000 --- a/layerconfig/layerconfig_test.go +++ /dev/null @@ -1,26 +0,0 @@ -package layerconfig - -import ( - "testing" -) - -func TestReadJson(t *testing.T) { - layers, err := ParseFile("./testdata/layers.json") - - if err != nil { - t.Fatal(err) - } - - if layers == nil { - t.Fatal("no data") - } - - if len(layers) != 1 { - t.Fatal("length mismatch") - } - - if layers[0].Name != "Base" { - t.Fatal("name mismatch") - } - -} diff --git a/layerconfig/testdata/layers.json b/layerconfig/testdata/layers.json deleted file mode 100644 index 8e405ff..0000000 --- a/layerconfig/testdata/layers.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "layers": [{ - "id": 0, - "name": "Base", - "from": -16, - "to": 160 - }] -} \ No newline at end of file diff --git a/tilerenderer/renderer.go b/tilerenderer/renderer.go index 846410f..602cf10 100644 --- a/tilerenderer/renderer.go +++ b/tilerenderer/renderer.go @@ -8,7 +8,7 @@ import ( "image/png" "mapserver/coords" "mapserver/db" - "mapserver/layerconfig" + "mapserver/layer" "mapserver/mapblockrenderer" "mapserver/tiledb" "time" @@ -19,7 +19,7 @@ import ( type TileRenderer struct { mapblockrenderer *mapblockrenderer.MapBlockRenderer - layers []layerconfig.Layer + layers []layer.Layer tdb tiledb.DBAccessor dba db.DBAccessor } @@ -27,7 +27,7 @@ type TileRenderer struct { func NewTileRenderer(mapblockrenderer *mapblockrenderer.MapBlockRenderer, tdb tiledb.DBAccessor, dba db.DBAccessor, - layers []layerconfig.Layer) *TileRenderer { + layers []layer.Layer) *TileRenderer { return &TileRenderer{ mapblockrenderer: mapblockrenderer, @@ -90,7 +90,7 @@ func (tr *TileRenderer) RenderImage(tc coords.TileCoords) (*image.NRGBA, error) log.WithFields(logrus.Fields{"x": tc.X, "y": tc.Y, "zoom": tc.Zoom}).Debug("RenderImage") - var layer *layerconfig.Layer + var layer *layer.Layer for _, l := range tr.layers { if l.Id == tc.LayerId { diff --git a/tilerenderer/renderer_test.go b/tilerenderer/renderer_test.go index 09c1acb..9251f96 100644 --- a/tilerenderer/renderer_test.go +++ b/tilerenderer/renderer_test.go @@ -7,7 +7,7 @@ import ( "mapserver/colormapping" "mapserver/coords" "mapserver/db" - "mapserver/layerconfig" + "mapserver/layer" "mapserver/mapblockaccessor" "mapserver/mapblockrenderer" "mapserver/testutils" @@ -52,7 +52,16 @@ func TestTileRender(t *testing.T) { tdb, _ := tiledb.NewSqliteAccessor(tiletmpfile.Name()) tdb.Migrate() - tr := NewTileRenderer(r, tdb, a, layerconfig.DefaultLayers) + layers := []layer.Layer{ + layer.Layer{ + Id: 0, + Name: "Base", + From: -16, + To: 160, + }, + } + + tr := NewTileRenderer(r, tdb, a, layers) if tr == nil { panic("no renderer") diff --git a/tileupdate/job.go b/tileupdate/job.go index 0f6602e..3a9d6e6 100644 --- a/tileupdate/job.go +++ b/tileupdate/job.go @@ -7,34 +7,31 @@ import ( ) func Job(ctx *app.App) { - //TODO remember last time run - t := time.Now().Unix() + rstate := ctx.Config.RenderState fields := logrus.Fields{ - "time": t, + "lastmtime": rstate.LastMtime, } logrus.WithFields(fields).Info("Starting incremental update") for true { - mblist, err := ctx.BlockAccessor.FindLatestMapBlocks(t, 1000) + mblist, err := ctx.BlockAccessor.FindLatestMapBlocks(rstate.LastMtime, 1000) if err != nil { panic(err) } for _, mb := range mblist { - if mb.Mtime > t { - t = mb.Mtime + 1 + if mb.Mtime > rstate.LastMtime { + rstate.LastMtime = mb.Mtime + 1 } } - rstate := ctx.Config.RenderState - rstate.LastMtime = t ctx.Config.Save() fields = logrus.Fields{ - "count": len(mblist), - "time": t, + "count": len(mblist), + "lastmtime": rstate.LastMtime, } logrus.WithFields(fields).Info("incremental update")