1
0
forked from MTSR/mapserver

filter mapblocks without layer

This commit is contained in:
NatureFreshMilk 2019-01-21 14:27:15 +01:00
parent 479a92e7ab
commit 563ea61e67
4 changed files with 36 additions and 19 deletions

View File

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

View File

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

View File

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

View File

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