# Class WebMercator

java.lang.Object
com.codename1.maps.vector.WebMercator

public final class WebMercator extends Object

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.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final double`
  `MAX_LATITUDE`
  The furthest latitude Web Mercator can represent.
  `static final int`
  `TILE_SIZE`
  The canonical tile edge length in pixels.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `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.
  `static double`
  `clampLatitude(double lat)`
  Confines `lat` to the range the projection can actually represent.
  `static double`
  `latToWorldY(double lat, double zoom)`
  Latitude in degrees to an absolute world-pixel y at `zoom`.
  `static double`
  `lonToWorldX(double lon, double zoom)`
  Longitude in degrees to an absolute world-pixel x at `zoom`.
  `static double`
  `sinh(double x)`
  Hyperbolic sine, absent from the minimal device `Math`.
  `static double`
  `worldSize(double zoom)`
  The world width/height in pixels at `zoom` (may be fractional).
  `static double`
  `worldXToLon(double worldX, double zoom)`
  World-pixel x at `zoom` back to longitude in degrees.
  `static double`
  `worldYToLat(double worldY, double zoom)`
  World-pixel y at `zoom` back to latitude in degrees.

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### TILE_SIZE

    public static final int TILE_SIZE
    The canonical tile edge length in pixels.
    See Also:
      - Constant Field Values

  - ### MAX_LATITUDE

    public static final double MAX_LATITUDE
    The furthest latitude Web Mercator can represent. The projection runs to infinity at the poles, so every slippy map cuts off here, which also makes the world exactly square.
    See Also:
      - Constant Field Values

- ## Method Details

  - ### worldSize

    public static double worldSize(double zoom)
    The world width/height in pixels at `zoom` (may be fractional).

  - ### lonToWorldX

    public static double lonToWorldX(double lon, double zoom)
    Longitude in degrees to an absolute world-pixel x at `zoom`.

  - ### latToWorldY

    public static double latToWorldY(double lat, double zoom)
    Latitude in degrees to an absolute world-pixel y at `zoom`.

  - ### worldXToLon

    public static double worldXToLon(double worldX, double zoom)
    World-pixel x at `zoom` back to longitude in degrees.

  - ### worldYToLat

    public static double worldYToLat(double worldY, double zoom)
    World-pixel y at `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)
    Hyperbolic sine, absent from the minimal device `Math`.