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

41 lines
821 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-14 10:50:54 +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}
2019-04-15 09:08:28 +03:00
currentLayer := layer.FindLayerByY(layers, mbc.Y)
2019-01-21 15:27:36 +03:00
2019-04-15 09:08:28 +03:00
if currentLayer == nil {
2019-01-21 15:27:36 +03:00
return nil
}
2019-04-15 09:08:28 +03:00
tc.LayerId = currentLayer.Id
2019-01-21 15:27:36 +03:00
return &tc
2019-01-11 18:00:40 +03:00
}
2019-01-17 12:04:09 +03:00
2019-02-14 16:04:01 +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
2019-02-14 16:04:01 +03:00
return &MapBlockRange{
2019-01-17 12:04:09 +03:00
Pos1: NewMapBlockCoords(mapBlockX1, y, mapBlockZ1),
Pos2: NewMapBlockCoords(mapBlockX2, y, mapBlockZ2),
}
}