2019-01-18 15:07:01 +03:00
|
|
|
package tileupdate
|
|
|
|
|
|
|
|
import (
|
2019-01-18 15:50:59 +03:00
|
|
|
"mapserver/app"
|
2019-01-21 15:41:47 +03:00
|
|
|
"mapserver/coords"
|
2019-01-18 15:50:59 +03:00
|
|
|
"time"
|
2019-01-22 23:13:16 +03:00
|
|
|
|
|
|
|
"github.com/sirupsen/logrus"
|
2019-01-18 15:07:01 +03:00
|
|
|
)
|
|
|
|
|
2019-01-18 15:50:59 +03:00
|
|
|
func Job(ctx *app.App) {
|
2019-01-21 13:13:00 +03:00
|
|
|
rstate := ctx.Config.RenderState
|
2019-01-18 15:07:01 +03:00
|
|
|
|
2019-01-18 15:50:59 +03:00
|
|
|
fields := logrus.Fields{
|
2019-01-21 13:13:00 +03:00
|
|
|
"lastmtime": rstate.LastMtime,
|
2019-01-18 15:50:59 +03:00
|
|
|
}
|
|
|
|
logrus.WithFields(fields).Info("Starting incremental update")
|
2019-01-18 15:07:01 +03:00
|
|
|
|
2019-01-18 15:50:59 +03:00
|
|
|
for true {
|
2019-01-21 16:27:15 +03:00
|
|
|
mblist, err := ctx.BlockAccessor.FindLatestMapBlocks(rstate.LastMtime, ctx.Config.UpdateRenderingFetchLimit, ctx.Config.Layers)
|
2019-01-18 15:07:01 +03:00
|
|
|
|
2019-01-18 15:50:59 +03:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2019-01-18 15:07:01 +03:00
|
|
|
|
2019-01-18 15:50:59 +03:00
|
|
|
for _, mb := range mblist {
|
2019-01-21 13:13:00 +03:00
|
|
|
if mb.Mtime > rstate.LastMtime {
|
2019-01-21 15:41:47 +03:00
|
|
|
rstate.LastMtime = mb.Mtime
|
|
|
|
}
|
|
|
|
|
|
|
|
tc := coords.GetTileCoordsFromMapBlock(mb.Pos, ctx.Config.Layers)
|
|
|
|
|
|
|
|
if tc == nil {
|
2019-01-21 17:13:33 +03:00
|
|
|
panic("tile not in any layer")
|
2019-01-21 15:41:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
for tc.Zoom > 1 {
|
|
|
|
tc = tc.GetZoomedOutTile()
|
2019-01-21 17:13:33 +03:00
|
|
|
ctx.Objectdb.RemoveTile(tc)
|
2019-01-21 15:41:47 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Render zoom 12-1
|
2019-01-21 17:13:33 +03:00
|
|
|
for _, mb := range mblist {
|
2019-01-21 15:41:47 +03:00
|
|
|
tc := coords.GetTileCoordsFromMapBlock(mb.Pos, ctx.Config.Layers)
|
|
|
|
for tc.Zoom > 1 {
|
|
|
|
tc = tc.GetZoomedOutTile()
|
|
|
|
|
|
|
|
fields = logrus.Fields{
|
2019-01-21 15:45:35 +03:00
|
|
|
"X": tc.X,
|
|
|
|
"Y": tc.Y,
|
|
|
|
"Zoom": tc.Zoom,
|
2019-01-21 15:41:47 +03:00
|
|
|
"LayerId": tc.LayerId,
|
|
|
|
}
|
|
|
|
logrus.WithFields(fields).Debug("Dispatching tile rendering (update)")
|
|
|
|
|
2019-01-22 14:53:36 +03:00
|
|
|
_, err = ctx.Tilerenderer.Render(tc, 2)
|
2019-01-21 15:41:47 +03:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2019-01-18 15:50:59 +03:00
|
|
|
}
|
|
|
|
}
|
2019-01-18 15:07:01 +03:00
|
|
|
|
2019-01-21 12:53:58 +03:00
|
|
|
ctx.Config.Save()
|
|
|
|
|
2019-01-21 15:41:47 +03:00
|
|
|
if len(mblist) > 0 {
|
|
|
|
fields = logrus.Fields{
|
2019-01-21 18:27:31 +03:00
|
|
|
"count": len(mblist),
|
|
|
|
"lastmtime": rstate.LastMtime,
|
2019-01-21 15:41:47 +03:00
|
|
|
}
|
|
|
|
logrus.WithFields(fields).Info("incremental update")
|
2019-01-18 15:50:59 +03:00
|
|
|
}
|
2019-01-18 15:07:01 +03:00
|
|
|
|
2019-01-18 15:50:59 +03:00
|
|
|
time.Sleep(5 * time.Second)
|
|
|
|
}
|
2019-01-18 15:07:01 +03:00
|
|
|
}
|