1
0
forked from MTSR/mapserver
mapserver/server/coords/tileconvert.go

47 lines
886 B
Go
Raw Normal View History

2019-01-11 18:00:40 +03:00
package coords
2019-01-17 12:04:09 +03:00
import (
2019-01-21 15:27:36 +03:00
"mapserver/layer"
2019-01-21 15:45:35 +03:00
"math"
2019-01-17 12:04:09 +03:00
)
2019-01-11 18:00:40 +03:00
const (
MAX_ZOOM = 13
)
2019-02-06 10:38:08 +03:00
func GetTileCoordsFromMapBlock(mbc *MapBlockCoords, layers []layer.Layer) *TileCoords {
2019-01-21 15:27:36 +03:00
tc := TileCoords{X: mbc.X, Y: (mbc.Z + 1) * -1, Zoom: MAX_ZOOM}
var layerid *int
for _, l := range layers {
2019-01-21 16:27:15 +03:00
if (mbc.Y*16) >= l.From && (mbc.Y*16) <= l.To {
2019-01-21 15:27:36 +03:00
layerid = &l.Id
2019-01-22 15:35:15 +03:00
break
2019-01-21 15:27:36 +03:00
}
}
if layerid == nil {
return nil
}
tc.LayerId = *layerid
return &tc
2019-01-11 18:00:40 +03:00
}
2019-01-17 12:04:09 +03:00
2019-01-21 15:27:36 +03:00
func GetMapBlockRangeFromTile(tc *TileCoords, y int) MapBlockRange {
2019-01-17 12:04:09 +03:00
scaleDiff := float64(MAX_ZOOM - tc.Zoom)
scale := int(math.Pow(2, scaleDiff))
mapBlockX1 := tc.X * scale
mapBlockZ1 := (tc.Y * scale * -1) - 1
2019-01-18 11:13:37 +03:00
mapBlockX2 := mapBlockX1 + scale - 1
mapBlockZ2 := (mapBlockZ1 + ((scale - 1) * -1))
2019-01-17 12:04:09 +03:00
return MapBlockRange{
Pos1: NewMapBlockCoords(mapBlockX1, y, mapBlockZ1),
Pos2: NewMapBlockCoords(mapBlockX2, y, mapBlockZ2),
}
}