Skip to content

Commit

Permalink
Added PixelRatioForZoom function to replace
Browse files Browse the repository at this point in the history
We had a badly named function called PixelsToNative
that did not do a conversion but returned a ratio.

Renamed and expanded to all any tile dimension.
  • Loading branch information
gdey committed Jul 27, 2024
1 parent 30e670a commit 06c93c1
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions slippy/tile.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,28 @@ func FromBounds(g TileGridder, bounds geom.PtMinMaxer, z Zoom) ([]Tile, error) {

return ret, nil
}

// MvtTileDim is the number of pixels in a tile
const MvtTileDim = 4096.0

// PixelRatioForZoom returns the ratio of pixels to projected units at the given zoom. Multiply this value by
// the pixel count in tile.buffer to get the expected conversion.
//
// if zoom is larger the MaxZoom, it will be set to MaxZoom
// if tileDim is 0, it will be set to MvtTileDim
func PixelRatioForZoom(g TileGridder, zoom Zoom, tileDim uint64) float64 {
if zoom > MaxZoom {
zoom = MaxZoom
}
if tileDim == 0 {
tileDim = MvtTileDim
}
ext, _ := Extent(g, Tile{Z: zoom})
return ext.XSpan() / float64(tileDim)
}

// MvtPixelRationForZoom returns the ratio of pixels to projected units at the given zoom.
// This assumes an MVT tile is being used.
func MvtPixelRationForZoom(g TileGridder, zoom Zoom) float64 {
return PixelRatioForZoom(g, zoom, MvtTileDim)
}

0 comments on commit 06c93c1

Please sign in to comment.