mapserver/server/initialrenderer/job.go

105 lines
2.1 KiB
Go
Raw Normal View History

2019-01-21 11:11:07 +03:00
package initialrenderer
import (
"mapserver/app"
"mapserver/coords"
2019-01-22 15:35:15 +03:00
"strconv"
2019-01-22 15:46:58 +03:00
"time"
2019-01-21 22:13:38 +03:00
"github.com/sirupsen/logrus"
2019-01-21 11:11:07 +03:00
)
2019-01-22 15:35:15 +03:00
func getTileKey(tc *coords.TileCoords) string {
return strconv.Itoa(tc.X) + "/" + strconv.Itoa(tc.Y) + "/" + strconv.Itoa(tc.Zoom)
}
2019-01-21 11:11:07 +03:00
func Job(ctx *app.App) {
fields := logrus.Fields{}
logrus.WithFields(fields).Info("Starting initial rendering")
2019-01-22 15:53:11 +03:00
blockcount := 0
tilecount := 0
2019-01-21 11:11:07 +03:00
2019-01-21 12:53:58 +03:00
rstate := ctx.Config.RenderState
lastcoords := coords.NewMapBlockCoords(rstate.LastX, rstate.LastY, rstate.LastZ)
2019-01-21 11:11:07 +03:00
for true {
2019-01-21 18:27:31 +03:00
start := time.Now()
2019-01-21 16:27:15 +03:00
hasMore, newlastcoords, mblist, err := ctx.BlockAccessor.FindLegacyMapBlocks(lastcoords, ctx.Config.InitialRenderingFetchLimit, ctx.Config.Layers)
2019-01-21 11:11:07 +03:00
if err != nil {
panic(err)
}
2019-01-21 16:27:15 +03:00
if len(mblist) == 0 && !hasMore {
2019-01-22 15:53:11 +03:00
fields = logrus.Fields{
"blocks": blockcount,
2019-01-22 18:36:50 +03:00
"tiles": tilecount,
2019-01-22 15:53:11 +03:00
}
logrus.WithFields(fields).Info("Initial rendering complete")
2019-01-21 12:53:58 +03:00
rstate.InitialRun = false
ctx.Config.Save()
2019-01-21 11:11:07 +03:00
break
}
2019-01-22 15:53:11 +03:00
blockcount += len(mblist)
2019-01-21 13:18:27 +03:00
lastcoords = *newlastcoords
2019-01-22 15:35:15 +03:00
tileRenderedMap := make(map[string]bool)
2019-01-22 14:53:36 +03:00
2019-01-22 15:46:58 +03:00
for i := 12; i >= 1; i-- {
2019-01-22 15:35:15 +03:00
for _, mb := range mblist {
//13
tc := coords.GetTileCoordsFromMapBlock(mb.Pos, ctx.Config.Layers)
2019-01-22 14:53:36 +03:00
2019-01-22 15:46:58 +03:00
//12-1
2019-01-22 15:35:15 +03:00
tc = tc.ZoomOut(13 - i)
key := getTileKey(tc)
if tileRenderedMap[key] {
continue
}
tileRenderedMap[key] = true
2019-01-21 15:27:36 +03:00
fields = logrus.Fields{
2019-01-21 15:45:35 +03:00
"X": tc.X,
"Y": tc.Y,
"Zoom": tc.Zoom,
2019-01-21 15:27:36 +03:00
"LayerId": tc.LayerId,
}
2019-01-22 14:53:36 +03:00
logrus.WithFields(fields).Debug("Dispatching tile rendering (z11-1)")
2019-01-21 13:31:50 +03:00
2019-01-22 15:53:11 +03:00
tilecount++
2019-01-22 14:53:36 +03:00
ctx.Objectdb.RemoveTile(tc)
2019-01-22 23:13:16 +03:00
_, err = ctx.Tilerenderer.Render(tc, 2)
2019-01-21 15:27:36 +03:00
if err != nil {
panic(err)
}
2019-01-21 13:31:50 +03:00
}
}
2019-01-21 11:11:07 +03:00
2019-01-21 12:53:58 +03:00
//Save current positions of initial run
rstate.LastX = lastcoords.X
rstate.LastY = lastcoords.Y
rstate.LastZ = lastcoords.Z
ctx.Config.Save()
2019-01-21 18:27:31 +03:00
t := time.Now()
elapsed := t.Sub(start)
2019-01-21 11:11:07 +03:00
fields = logrus.Fields{
2019-01-21 18:27:31 +03:00
"count": len(mblist),
"X": lastcoords.X,
"Y": lastcoords.Y,
"Z": lastcoords.Z,
"elapsed": elapsed,
2019-01-21 11:11:07 +03:00
}
logrus.WithFields(fields).Info("Initial rendering")
}
}