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

41 lines
851 B
Go
Raw Permalink Normal View History

2019-01-11 18:00:40 +03:00
package coords
2019-01-17 12:04:09 +03:00
import (
2023-12-29 18:00:11 +03:00
"mapserver/types"
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
)
2023-12-29 18:00:11 +03:00
func GetTileCoordsFromMapBlock(mbc *types.MapBlockCoords, layers []*types.Layer) *TileCoords {
2019-01-21 15:27:36 +03:00
tc := TileCoords{X: mbc.X, Y: (mbc.Z + 1) * -1, Zoom: MAX_ZOOM}
2023-12-29 18:00:11 +03:00
currentLayer := types.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
2023-12-29 18:00:11 +03:00
func GetMapBlockRangeFromTile(tc *TileCoords, y int) *types.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
2023-12-29 18:00:11 +03:00
return &types.MapBlockRange{
Pos1: types.NewMapBlockCoords(mapBlockX1, y, mapBlockZ1),
Pos2: types.NewMapBlockCoords(mapBlockX2, y, mapBlockZ2),
2019-01-17 12:04:09 +03:00
}
}