diff --git a/coords/tileconvert.go b/coords/tileconvert.go index 274ba35..f92b101 100644 --- a/coords/tileconvert.go +++ b/coords/tileconvert.go @@ -14,7 +14,7 @@ func GetTileCoordsFromMapBlock(mbc MapBlockCoords, layers []layer.Layer) *TileCo var layerid *int for _, l := range layers { - if mbc.Y > l.From && mbc.Y < l.To { + if (mbc.Y*16) >= l.From && (mbc.Y*16) <= l.To { layerid = &l.Id } } diff --git a/initialrenderer/job.go b/initialrenderer/job.go index 5ee0b01..cf944fe 100644 --- a/initialrenderer/job.go +++ b/initialrenderer/job.go @@ -4,7 +4,6 @@ import ( "github.com/sirupsen/logrus" "mapserver/app" "mapserver/coords" - "mapserver/mapblockparser" ) func Job(ctx *app.App) { @@ -17,13 +16,13 @@ func Job(ctx *app.App) { lastcoords := coords.NewMapBlockCoords(rstate.LastX, rstate.LastY, rstate.LastZ) for true { - newlastcoords, mblist, err := ctx.BlockAccessor.FindLegacyMapBlocks(lastcoords, ctx.Config.InitialRenderingFetchLimit) + hasMore, newlastcoords, mblist, err := ctx.BlockAccessor.FindLegacyMapBlocks(lastcoords, ctx.Config.InitialRenderingFetchLimit, ctx.Config.Layers) if err != nil { panic(err) } - if len(mblist) == 0 { + if len(mblist) == 0 && !hasMore { logrus.Info("Initial rendering complete") rstate.InitialRun = false ctx.Config.Save() @@ -33,19 +32,14 @@ func Job(ctx *app.App) { lastcoords = *newlastcoords - //only mapblocks with valid layer - validmblist := make([]*mapblockparser.MapBlock, 0) - //Invalidate zoom 12-1 for _, mb := range mblist { tc := coords.GetTileCoordsFromMapBlock(mb.Pos, ctx.Config.Layers) if tc == nil { - continue + panic("tile not in any layer") } - validmblist = append(validmblist, mb) - for tc.Zoom > 1 { tc = tc.GetZoomedOutTile() ctx.Tiledb.RemoveTile(tc) @@ -53,7 +47,7 @@ func Job(ctx *app.App) { } //Render zoom 12-1 - for _, mb := range validmblist { + for _, mb := range mblist { tc := coords.GetTileCoordsFromMapBlock(mb.Pos, ctx.Config.Layers) for tc.Zoom > 1 { tc = tc.GetZoomedOutTile() @@ -84,7 +78,6 @@ func Job(ctx *app.App) { "X": lastcoords.X, "Y": lastcoords.Y, "Z": lastcoords.Z, - "validcount": len(validmblist), } logrus.WithFields(fields).Info("Initial rendering") } diff --git a/mapblockaccessor/mapblockaccessor.go b/mapblockaccessor/mapblockaccessor.go index 0d6be51..edac4e6 100644 --- a/mapblockaccessor/mapblockaccessor.go +++ b/mapblockaccessor/mapblockaccessor.go @@ -5,6 +5,7 @@ import ( "mapserver/coords" "mapserver/db" "mapserver/mapblockparser" + "mapserver/layer" "time" cache "github.com/patrickmn/go-cache" @@ -40,18 +41,31 @@ func (a *MapBlockAccessor) Update(pos coords.MapBlockCoords, mb *mapblockparser. a.c.Set(key, mb, cache.DefaultExpiration) } -func (a *MapBlockAccessor) FindLegacyMapBlocks(lastpos coords.MapBlockCoords, limit int) (*coords.MapBlockCoords, []*mapblockparser.MapBlock, error) { +func (a *MapBlockAccessor) FindLegacyMapBlocks(lastpos coords.MapBlockCoords, limit int, layerfilter []layer.Layer) (bool, *coords.MapBlockCoords, []*mapblockparser.MapBlock, error) { blocks, err := a.accessor.FindLegacyBlocks(lastpos, limit) if err != nil { - return nil, nil, err + return false, nil, nil, err } mblist := make([]*mapblockparser.MapBlock, 0) var newlastpos *coords.MapBlockCoords + hasMore := len(blocks) == limit for _, block := range blocks { + newlastpos = &block.Pos + + inLayer := false + for _, l := range layerfilter { + if (block.Pos.Y*16) >= l.From && (block.Pos.Y*16) <= l.To { + inLayer = true + } + } + + if !inLayer { + continue + } fields := logrus.Fields{ "x": block.Pos.X, @@ -64,7 +78,7 @@ func (a *MapBlockAccessor) FindLegacyMapBlocks(lastpos coords.MapBlockCoords, li mapblock, err := mapblockparser.Parse(block.Data, block.Mtime, block.Pos) if err != nil { - return nil, nil, err + return false, nil, nil, err } for _, listener := range a.listeners { @@ -74,13 +88,12 @@ func (a *MapBlockAccessor) FindLegacyMapBlocks(lastpos coords.MapBlockCoords, li a.c.Set(key, mapblock, cache.DefaultExpiration) mblist = append(mblist, mapblock) - newlastpos = &block.Pos } - return newlastpos, mblist, nil + return hasMore, newlastpos, mblist, nil } -func (a *MapBlockAccessor) FindLatestMapBlocks(mintime int64, limit int) ([]*mapblockparser.MapBlock, error) { +func (a *MapBlockAccessor) FindLatestMapBlocks(mintime int64, limit int, layerfilter []layer.Layer) ([]*mapblockparser.MapBlock, error) { blocks, err := a.accessor.FindLatestBlocks(mintime, limit) if err != nil { @@ -91,6 +104,17 @@ func (a *MapBlockAccessor) FindLatestMapBlocks(mintime int64, limit int) ([]*map for _, block := range blocks { + inLayer := false + for _, l := range layerfilter { + if (block.Pos.Y*16) >= l.From && (block.Pos.Y*16) <= l.To { + inLayer = true + } + } + + if !inLayer { + continue + } + fields := logrus.Fields{ "x": block.Pos.X, "y": block.Pos.Y, diff --git a/tileupdate/job.go b/tileupdate/job.go index 16a1085..23e8d59 100644 --- a/tileupdate/job.go +++ b/tileupdate/job.go @@ -17,7 +17,7 @@ func Job(ctx *app.App) { logrus.WithFields(fields).Info("Starting incremental update") for true { - mblist, err := ctx.BlockAccessor.FindLatestMapBlocks(rstate.LastMtime, ctx.Config.UpdateRenderingFetchLimit) + mblist, err := ctx.BlockAccessor.FindLatestMapBlocks(rstate.LastMtime, ctx.Config.UpdateRenderingFetchLimit, ctx.Config.Layers) if err != nil { panic(err)