mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2025-01-22 22:30:27 +01:00
mtwebmapper: Added scaffold for updating the pyramid tiles. TODO: Implement th actual imaging stuff.
This commit is contained in:
parent
d39a948bd4
commit
33337d5df2
@ -29,10 +29,27 @@ type xz struct {
|
|||||||
Z int16
|
Z int16
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type xzm struct {
|
||||||
|
P xz
|
||||||
|
Mask uint16
|
||||||
|
}
|
||||||
|
|
||||||
func (c xz) quantize() xz {
|
func (c xz) quantize() xz {
|
||||||
return xz{X: (c.X - -1933) / 16, Z: (c.Z - -1933) / 16}
|
return xz{X: (c.X - -1933) / 16, Z: (c.Z - -1933) / 16}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c xz) dequantize() xz {
|
||||||
|
return xz{X: c.X*16 + -1933, Z: c.Z*16 + -1933}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c xz) parent() xzm {
|
||||||
|
xp, xr := c.X>>1, uint16(c.X&1)
|
||||||
|
zp, zr := c.Z>>1, uint16(c.Z&1)
|
||||||
|
return xzm{
|
||||||
|
P: xz{X: xp, Z: zp},
|
||||||
|
Mask: ((1 << xr) << 2) | (1 << zr)}
|
||||||
|
}
|
||||||
|
|
||||||
func newTileUpdater(mapDir, redisAddress string, colors *common.Colors, workers int) *tileUpdater {
|
func newTileUpdater(mapDir, redisAddress string, colors *common.Colors, workers int) *tileUpdater {
|
||||||
tu := tileUpdater{
|
tu := tileUpdater{
|
||||||
mapDir: mapDir,
|
mapDir: mapDir,
|
||||||
@ -95,24 +112,58 @@ func (tu *tileUpdater) doUpdates() {
|
|||||||
go updateBaseTiles(jobs, btc, &done)
|
go updateBaseTiles(jobs, btc, &done)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
parentJobs := make(map[xz]uint16)
|
||||||
|
|
||||||
for c, _ := range changes {
|
for c, _ := range changes {
|
||||||
log.Printf("job: %+v", c)
|
//log.Printf("job: %+v", c)
|
||||||
jobs <- c
|
jobs <- c
|
||||||
|
pxz := c.parent()
|
||||||
|
parentJobs[pxz.P] |= pxz.Mask
|
||||||
}
|
}
|
||||||
|
close(jobs)
|
||||||
done.Wait()
|
done.Wait()
|
||||||
|
|
||||||
|
for level := 7; level >= 0; level-- {
|
||||||
|
pJobs := make(chan xzm)
|
||||||
|
for i, n := 0, min(len(parentJobs), tu.workers); i < n; i++ {
|
||||||
|
done.Add(1)
|
||||||
|
go updatePyramidTiles(level, baseDir, pJobs, &done)
|
||||||
|
}
|
||||||
|
ppJobs := make(map[xz]uint16)
|
||||||
|
for c, mask := range parentJobs {
|
||||||
|
pJobs <- xzm{P: c, Mask: mask}
|
||||||
|
pxz := c.parent()
|
||||||
|
ppJobs[pxz.P] |= pxz.Mask
|
||||||
|
}
|
||||||
|
close(pJobs)
|
||||||
|
done.Wait()
|
||||||
|
parentJobs = ppJobs
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func min(a, b int) int {
|
||||||
|
if a < b {
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func updatePyramidTiles(level int, baseDir string, jobs chan xzm, done *sync.WaitGroup) {
|
||||||
|
defer done.Done()
|
||||||
|
for job := range jobs {
|
||||||
|
_ = job
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateBaseTiles(jobs chan xz, btc *common.BaseTileCreator, done *sync.WaitGroup) {
|
func updateBaseTiles(jobs chan xz, btc *common.BaseTileCreator, done *sync.WaitGroup) {
|
||||||
|
defer btc.Close()
|
||||||
|
defer done.Done()
|
||||||
for job := range jobs {
|
for job := range jobs {
|
||||||
x := job.X*16 + -1933 - 1
|
xz := job.dequantize()
|
||||||
z := job.Z*16 + -1933 - 1
|
//log.Printf("%d/%d %d/%d", x, z, job.X, job.Z)
|
||||||
log.Printf("%d/%d %d/%d", x, z, job.X, job.Z)
|
if err := btc.CreateTile(xz.X-1, xz.Z-1, int(job.X), int(job.Z)); err != nil {
|
||||||
if err := btc.CreateTile(x, z, int(job.X), int(job.Z)); err != nil {
|
|
||||||
log.Printf("WARN: create tile failed: %s", err)
|
log.Printf("WARN: create tile failed: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
btc.Close() // TODO: Keep redis connection open to update the pyramid tiles.
|
|
||||||
done.Done()
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user