boundingBoxOfTile method
Calculates the geographic bounding box for a single tile.
Returns the latitude/longitude boundaries that define the geographic area covered by the specified tile. Includes fixes for dateline crossing.
tile The tile to calculate boundaries for
Returns the BoundingBox in geographic coordinates
Implementation
BoundingBox boundingBoxOfTile(Tile tile) {
double minLatitude = max(Projection.LATITUDE_MIN, tileYToLatitude(tile.tileY + 1));
double minLongitude = max(Projection.LONGITUDE_MIN, tileXToLongitude(tile.tileX));
double maxLatitude = min(Projection.LATITUDE_MAX, tileYToLatitude(tile.tileY));
double maxLongitude = min(Projection.LONGITUDE_MAX, tileXToLongitude(tile.tileX + 1));
if (maxLongitude == -180) {
// fix for dateline crossing, where the right tile starts at -180 and causes an invalid bbox
maxLongitude = 180;
}
return BoundingBox(minLatitude, minLongitude, maxLatitude, maxLongitude);
}