mapserver/coords/tilecoords.go
NatureFreshMilk f8f524013e go fmt
2019-01-18 09:13:37 +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,
}
}