1
0
forked from MTSR/mapserver
mapserver/coords/tilecoords.go
2019-01-21 13:27:36 +01:00

47 lines
1.2 KiB
Go

package coords
import (
"math"
)
type TileCoords struct {
X, Y int
Zoom int
LayerId int
}
type TileQuadrants struct {
UpperLeft, UpperRight, LowerLeft, LowerRight *TileCoords
}
func NewTileCoords(x, y, zoom int, layerId int) *TileCoords {
return &TileCoords{X: x, Y: y, Zoom: zoom, LayerId: layerId}
}
func (tc *TileCoords) GetZoomedOutTile() *TileCoords {
return &TileCoords{
X: int(math.Floor(float64(tc.X) / 2.0)),
Y: int(math.Floor(float64(tc.Y) / 2.0)),
Zoom: tc.Zoom - 1,
LayerId: tc.LayerId}
}
func (tc *TileCoords) GetZoomedQuadrantsFromTile() TileQuadrants {
nextZoom := tc.Zoom + 1
nextZoomX := tc.X * 2
nextZoomY := tc.Y * 2
upperLeft := &TileCoords{X: nextZoomX, Y: nextZoomY, Zoom: nextZoom, LayerId: tc.LayerId}
upperRight := &TileCoords{X: nextZoomX + 1, Y: nextZoomY, Zoom: nextZoom, LayerId: tc.LayerId}
lowerLeft := &TileCoords{X: nextZoomX, Y: nextZoomY + 1, Zoom: nextZoom, LayerId: tc.LayerId}
lowerRight := &TileCoords{X: nextZoomX + 1, Y: nextZoomY + 1, Zoom: nextZoom, LayerId: tc.LayerId}
return TileQuadrants{
UpperLeft: upperLeft,
UpperRight: upperRight,
LowerLeft: lowerLeft,
LowerRight: lowerRight,
}
}