public final class WebMercator
- Object
- WebMercator
Spherical Web Mercator (EPSG:3857) helpers expressed in “world pixels” –
the slippy-map coordinate space where the whole world spans
tileSize * 2^zoom pixels. All of the vector engine’s panning and tile
math is done in this space.
These are the standard OSM tiling formulas; kept here (rather than reusing
the projected Mercator) so the renderer can work in
fractional pixels at fractional zoom without round-tripping through the
legacy Coord projection flag.
Fields
public static final int TILE_SIZE = 256 | The canonical tile edge length in pixels. |
public static final double MAX_LATITUDE = 85.05112878 | The furthest latitude Web Mercator can represent. |
Methods
public static double worldSize(double zoom) | The world width/height in pixels at zoom (may be fractional). |
public static double lonToWorldX(double lon, double zoom) | Longitude in degrees to an absolute world-pixel x at zoom. |
public static double latToWorldY(double lat, double zoom) | Latitude in degrees to an absolute world-pixel y at zoom. |
public static double worldXToLon(double worldX, double zoom) | World-pixel x at zoom back to longitude in degrees. |
public static double worldYToLat(double worldY, double zoom) | World-pixel y at zoom back to latitude in degrees. |
public static double clampLatitude(double lat) | Confines lat to the range the projection can actually represent. |
public static double centerLatitude(double southLat, double northLat) | The latitude that sits visually halfway between southLat and northLat on a Mercator map – the midpoint of their projected y coordinates, converted back. |
public static double sinh(double x) | Hyperbolic sine, absent from the minimal device Math. |
Inherited methods
Field details
TILE_SIZE
public static final int TILE_SIZE = 256MAX_LATITUDE
public static final double MAX_LATITUDE = 85.05112878Method details
worldSize
public static double worldSize(double zoom)zoom (may be fractional).lonToWorldX
public static double lonToWorldX(double lon, double zoom)zoom.latToWorldY
public static double latToWorldY(double lat, double zoom)zoom.worldXToLon
public static double worldXToLon(double worldX, double zoom)zoom back to longitude in degrees.worldYToLat
public static double worldYToLat(double worldY, double zoom)zoom back to latitude in degrees.clampLatitude
public static double clampLatitude(double lat)Confines lat to the range the projection can actually represent.
Projecting a latitude beyond MAX_LATITUDE produces an enormous or
infinite y, and arithmetic on those values quietly yields nonsense:
averaging the projections of -90 and 90 lands on the south pole rather
than the equator. Clamping first keeps every derived camera finite and
sensible.
centerLatitude
public static double centerLatitude(double southLat, double northLat)The latitude that sits visually halfway between southLat and
northLat on a Mercator map – the midpoint of their projected y
coordinates, converted back. Both inputs are clamped to
MAX_LATITUDE first.
This is not the arithmetic mean, because Mercator stretches distances away from the equator. Latitudes 0 and 80 average to 40, but their projected midpoint is about 57; centering a camera on 40 pushes the northern edge of that band well outside a viewport sized to hold it. Anything framing bounds must center this way for the fitted zoom to actually contain them.
sinh
public static double sinh(double x)Math.