1
0
forked from MTSR/mapserver

layer config in default config

This commit is contained in:
NatureFreshMilk 2019-01-21 11:13:00 +01:00
parent 4194a16ee1
commit c9a405f88a
9 changed files with 43 additions and 100 deletions

View File

@ -4,6 +4,7 @@ import (
"encoding/json" "encoding/json"
"io/ioutil" "io/ioutil"
"mapserver/coords" "mapserver/coords"
"mapserver/layer"
"os" "os"
"sync" "sync"
) )
@ -15,6 +16,7 @@ type Config struct {
Webdev bool `json:"webdev"` Webdev bool `json:"webdev"`
WebApi *WebApiConfig `json:"webapi"` WebApi *WebApiConfig `json:"webapi"`
RenderState *RenderStateType `json:"renderstate"` RenderState *RenderStateType `json:"renderstate"`
Layers []layer.Layer `json:"layers"`
} }
type WebApiConfig struct { type WebApiConfig struct {
@ -76,6 +78,15 @@ func ParseConfig(filename string) (*Config, error) {
LastMtime: 0, LastMtime: 0,
} }
layers := []layer.Layer{
layer.Layer{
Id: 0,
Name: "Base",
From: -16,
To: 160,
},
}
cfg := Config{ cfg := Config{
Port: 8080, Port: 8080,
EnableInitialRendering: true, EnableInitialRendering: true,
@ -83,6 +94,7 @@ func ParseConfig(filename string) (*Config, error) {
Webdev: false, Webdev: false,
WebApi: &webapi, WebApi: &webapi,
RenderState: &rstate, RenderState: &rstate,
Layers: layers,
} }
info, err := os.Stat(filename) info, err := os.Stat(filename)

View File

@ -3,7 +3,6 @@ package app
import ( import (
"mapserver/colormapping" "mapserver/colormapping"
"mapserver/db" "mapserver/db"
"mapserver/layerconfig"
"mapserver/mapblockaccessor" "mapserver/mapblockaccessor"
"mapserver/mapblockrenderer" "mapserver/mapblockrenderer"
"mapserver/params" "mapserver/params"
@ -22,7 +21,6 @@ func Setup(p params.ParamsType, cfg *Config) (*App, error) {
a.Config = cfg a.Config = cfg
//Parse world config //Parse world config
a.Worldconfig = worldconfig.Parse("world.mt") a.Worldconfig = worldconfig.Parse("world.mt")
logrus.WithFields(logrus.Fields{"version": Version}).Info("Starting mapserver") 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.Mapblockrenderer,
a.Tiledb, a.Tiledb,
a.Blockdb, a.Blockdb,
layerconfig.DefaultLayers, a.Config.Layers,
) )
return &a, nil return &a, nil

8
layer/layer.go Normal file
View File

@ -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"`
}

View File

@ -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
}

View File

@ -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")
}
}

View File

@ -1,8 +0,0 @@
{
"layers": [{
"id": 0,
"name": "Base",
"from": -16,
"to": 160
}]
}

View File

@ -8,7 +8,7 @@ import (
"image/png" "image/png"
"mapserver/coords" "mapserver/coords"
"mapserver/db" "mapserver/db"
"mapserver/layerconfig" "mapserver/layer"
"mapserver/mapblockrenderer" "mapserver/mapblockrenderer"
"mapserver/tiledb" "mapserver/tiledb"
"time" "time"
@ -19,7 +19,7 @@ import (
type TileRenderer struct { type TileRenderer struct {
mapblockrenderer *mapblockrenderer.MapBlockRenderer mapblockrenderer *mapblockrenderer.MapBlockRenderer
layers []layerconfig.Layer layers []layer.Layer
tdb tiledb.DBAccessor tdb tiledb.DBAccessor
dba db.DBAccessor dba db.DBAccessor
} }
@ -27,7 +27,7 @@ type TileRenderer struct {
func NewTileRenderer(mapblockrenderer *mapblockrenderer.MapBlockRenderer, func NewTileRenderer(mapblockrenderer *mapblockrenderer.MapBlockRenderer,
tdb tiledb.DBAccessor, tdb tiledb.DBAccessor,
dba db.DBAccessor, dba db.DBAccessor,
layers []layerconfig.Layer) *TileRenderer { layers []layer.Layer) *TileRenderer {
return &TileRenderer{ return &TileRenderer{
mapblockrenderer: mapblockrenderer, 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") 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 { for _, l := range tr.layers {
if l.Id == tc.LayerId { if l.Id == tc.LayerId {

View File

@ -7,7 +7,7 @@ import (
"mapserver/colormapping" "mapserver/colormapping"
"mapserver/coords" "mapserver/coords"
"mapserver/db" "mapserver/db"
"mapserver/layerconfig" "mapserver/layer"
"mapserver/mapblockaccessor" "mapserver/mapblockaccessor"
"mapserver/mapblockrenderer" "mapserver/mapblockrenderer"
"mapserver/testutils" "mapserver/testutils"
@ -52,7 +52,16 @@ func TestTileRender(t *testing.T) {
tdb, _ := tiledb.NewSqliteAccessor(tiletmpfile.Name()) tdb, _ := tiledb.NewSqliteAccessor(tiletmpfile.Name())
tdb.Migrate() 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 { if tr == nil {
panic("no renderer") panic("no renderer")

View File

@ -7,34 +7,31 @@ import (
) )
func Job(ctx *app.App) { func Job(ctx *app.App) {
//TODO remember last time run rstate := ctx.Config.RenderState
t := time.Now().Unix()
fields := logrus.Fields{ fields := logrus.Fields{
"time": t, "lastmtime": rstate.LastMtime,
} }
logrus.WithFields(fields).Info("Starting incremental update") logrus.WithFields(fields).Info("Starting incremental update")
for true { for true {
mblist, err := ctx.BlockAccessor.FindLatestMapBlocks(t, 1000) mblist, err := ctx.BlockAccessor.FindLatestMapBlocks(rstate.LastMtime, 1000)
if err != nil { if err != nil {
panic(err) panic(err)
} }
for _, mb := range mblist { for _, mb := range mblist {
if mb.Mtime > t { if mb.Mtime > rstate.LastMtime {
t = mb.Mtime + 1 rstate.LastMtime = mb.Mtime + 1
} }
} }
rstate := ctx.Config.RenderState
rstate.LastMtime = t
ctx.Config.Save() ctx.Config.Save()
fields = logrus.Fields{ fields = logrus.Fields{
"count": len(mblist), "count": len(mblist),
"time": t, "lastmtime": rstate.LastMtime,
} }
logrus.WithFields(fields).Info("incremental update") logrus.WithFields(fields).Info("incremental update")