mapserver/tilerendererjob/common.go

88 lines
1.7 KiB
Go
Raw Normal View History

2019-01-24 17:56:37 +03:00
package tilerendererjob
import (
"mapserver/app"
"mapserver/coords"
"mapserver/types"
2019-01-24 17:56:37 +03:00
"strconv"
2019-01-24 22:55:20 +03:00
"github.com/sirupsen/logrus"
2019-01-24 17:56:37 +03:00
)
func getTileKey(tc *coords.TileCoords) string {
2019-02-08 10:11:06 +03:00
return strconv.Itoa(tc.X) + "/" + strconv.Itoa(tc.Y) + "/" +
strconv.Itoa(tc.Zoom) + "/" + strconv.Itoa(tc.LayerId)
2019-01-24 17:56:37 +03:00
}
func renderMapblocks(ctx *app.App, mblist []*types.ParsedMapblock) int {
2019-01-24 17:56:37 +03:00
tileRenderedMap := make(map[string]bool)
tilecount := 0
2019-02-08 16:25:07 +03:00
totalRenderedMapblocks.Add(float64(len(mblist)))
2019-01-24 17:56:37 +03:00
2019-01-26 12:35:33 +03:00
for i := 12; i >= 1; i-- {
2019-02-20 12:10:00 +03:00
//Spin up workers
jobs := make(chan *coords.TileCoords, ctx.Config.RenderingQueue)
done := make(chan bool, 1)
2019-02-20 23:07:33 +03:00
for j := 0; j < ctx.Config.RenderingJobs; j++ {
2019-02-20 12:10:00 +03:00
go worker(ctx, jobs, done)
}
2019-01-26 12:35:33 +03:00
for _, mb := range mblist {
//13
2019-02-14 21:59:35 +03:00
fields := logrus.Fields{
2019-02-20 23:07:33 +03:00
"pos": mb.Pos,
2019-02-19 10:33:38 +03:00
"prefix": "tilerenderjob",
2019-02-14 21:59:35 +03:00
}
2019-02-19 10:33:38 +03:00
logrus.WithFields(fields).Debug("Tile render job mapblock")
2019-02-14 21:59:35 +03:00
2019-01-26 12:35:33 +03:00
tc := coords.GetTileCoordsFromMapBlock(mb.Pos, ctx.Config.Layers)
2019-02-14 21:59:35 +03:00
if tc == nil {
2019-03-01 21:28:55 +03:00
fields := logrus.Fields{
"pos": mb.Pos,
"zoom": i,
}
logrus.WithFields(fields).Error("mapblock outside of layer!")
2019-02-14 21:59:35 +03:00
panic("mapblock outside of layer!")
}
2019-01-26 12:35:33 +03:00
//12-1
tc = tc.ZoomOut(13 - i)
key := getTileKey(tc)
if tileRenderedMap[key] {
continue
}
tileRenderedMap[key] = true
tilecount++
2019-01-24 22:55:20 +03:00
2019-02-19 10:33:38 +03:00
fields = logrus.Fields{
"X": tc.X,
"Y": tc.Y,
"Zoom": tc.Zoom,
"LayerId": tc.LayerId,
2019-02-20 23:07:33 +03:00
"prefix": "tilerenderjob",
2019-02-19 10:33:38 +03:00
}
logrus.WithFields(fields).Debug("Tile render job dispatch tile")
2019-01-24 22:55:20 +03:00
//dispatch re-render
2019-01-24 17:56:37 +03:00
jobs <- tc
}
2019-02-20 12:10:00 +03:00
//spin down worker pool
close(jobs)
2019-02-22 16:18:00 +03:00
2019-02-22 16:10:41 +03:00
for j := 0; j < ctx.Config.RenderingJobs; j++ {
<-done
}
2019-01-24 17:56:37 +03:00
}
return tilecount
}