2019-01-11 18:00:40 +03:00
|
|
|
package coords
|
|
|
|
|
|
|
|
import (
|
2019-01-13 18:37:03 +03:00
|
|
|
"math"
|
2019-01-11 18:00:40 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
type TileCoords struct {
|
2019-01-18 11:13:37 +03:00
|
|
|
X, Y int
|
|
|
|
Zoom int
|
2019-01-17 10:53:07 +03:00
|
|
|
LayerId int
|
2019-01-11 18:00:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type TileQuadrants struct {
|
2019-01-21 15:27:36 +03:00
|
|
|
UpperLeft, UpperRight, LowerLeft, LowerRight *TileCoords
|
2019-01-11 18:00:40 +03:00
|
|
|
}
|
|
|
|
|
2019-01-21 15:27:36 +03:00
|
|
|
func NewTileCoords(x, y, zoom int, layerId int) *TileCoords {
|
|
|
|
return &TileCoords{X: x, Y: y, Zoom: zoom, LayerId: layerId}
|
2019-01-11 18:00:40 +03:00
|
|
|
}
|
|
|
|
|
2019-01-21 15:27:36 +03:00
|
|
|
func (tc *TileCoords) GetZoomedOutTile() *TileCoords {
|
|
|
|
return &TileCoords{
|
2019-01-18 11:13:37 +03:00
|
|
|
X: int(math.Floor(float64(tc.X) / 2.0)),
|
|
|
|
Y: int(math.Floor(float64(tc.Y) / 2.0)),
|
|
|
|
Zoom: tc.Zoom - 1,
|
2019-01-17 10:53:07 +03:00
|
|
|
LayerId: tc.LayerId}
|
2019-01-11 18:00:40 +03:00
|
|
|
}
|
|
|
|
|
2019-01-21 15:27:36 +03:00
|
|
|
func (tc *TileCoords) GetZoomedQuadrantsFromTile() TileQuadrants {
|
2019-01-13 18:37:03 +03:00
|
|
|
nextZoom := tc.Zoom + 1
|
|
|
|
|
|
|
|
nextZoomX := tc.X * 2
|
|
|
|
nextZoomY := tc.Y * 2
|
|
|
|
|
2019-01-21 15:27:36 +03:00
|
|
|
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}
|
2019-01-13 18:37:03 +03:00
|
|
|
|
|
|
|
return TileQuadrants{
|
|
|
|
UpperLeft: upperLeft,
|
|
|
|
UpperRight: upperRight,
|
|
|
|
LowerLeft: lowerLeft,
|
|
|
|
LowerRight: lowerRight,
|
|
|
|
}
|
2019-01-11 18:00:40 +03:00
|
|
|
}
|