mapserver/coords/tilecoords.go

57 lines
1.4 KiB
Go
Raw Permalink Normal View History

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-22 18:36:50 +03:00
X int `json:"x"`
Y int `json:"y"`
Zoom int `json:"zoom"`
LayerId int `json:"layerid"`
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-22 15:35:15 +03:00
func (tc *TileCoords) ZoomOut(n int) *TileCoords {
var nc *TileCoords = tc
2019-01-24 22:55:20 +03:00
for i := 0; i < n; i++ {
2019-01-22 15:35:15 +03:00
nc = nc.GetZoomedOutTile()
}
return nc
}
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
}