mapserver/coords/tileconvert.go

30 lines
636 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 (
"math"
)
2019-01-11 18:00:40 +03:00
const (
MAX_ZOOM = 13
)
func GetTileCoordsFromMapBlock(mbc MapBlockCoords) TileCoords {
2019-01-13 18:37:03 +03:00
return TileCoords{X: mbc.X, Y: (mbc.Z + 1) * -1, Zoom: MAX_ZOOM}
2019-01-11 18:00:40 +03:00
}
2019-01-17 12:04:09 +03:00
func GetMapBlockRangeFromTile(tc TileCoords, y int) MapBlockRange {
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),
}
}