Table of Contents

Class WebMercator

Namespace
LansMap.Core.Geo

Converts between WGS84 degrees and normalized Web Mercator, plus tile addresses.

public static class WebMercator
Inheritance
object
WebMercator

Remarks

All values are double. Latitude is clamped to MercatorMaxLat on the way in. Unwrapped mercator X is not folded here: callers that have crossed the antimeridian should pass through WrapUnit(double) first.

Methods

MercatorToTile(MercatorPoint, ZoomLevel)

Tile address containing a mercator position at a zoom level.

public static TileCoord MercatorToTile(MercatorPoint m, ZoomLevel z)

Parameters

m MercatorPoint

Position in normalized mercator.

z ZoomLevel

Zoom level.

Returns

TileCoord

XYZ address in the canonical world; X and Y are clamped to the grid.

Remarks

Does not wrap: an unwrapped X is clamped onto the canonical grid, not folded onto a neighbouring world copy. Fold with WrapUnit(double) first when wrapping is what you want.

TileToMercatorRect(TileCoord)

Canonical-world footprint of a tile, as a square in normalized mercator.

public static MercatorRect TileToMercatorRect(TileCoord t)

Parameters

t TileCoord

XYZ tile address.

Returns

MercatorRect

Square whose edge is 1 / 2^z of the world, origin at the tile's north-west corner in normalized mercator.

ToLatLon(MercatorPoint)

Inverse projection from normalized Web Mercator to degrees WGS84.

public static LatLon ToLatLon(MercatorPoint m)

Parameters

m MercatorPoint

Position in normalized mercator.

Returns

LatLon

Coordinate in degrees WGS84; longitude is in [-180, 180); +180 becomes -180.

Remarks

An X outside [0, 1) is clamped in longitude, not wrapped, so a point one world to the east becomes the antimeridian rather than a wrapped copy. Fold with WrapUnit(double) first when the input may have unwrapped.

ToMercator(LatLon)

Projects a geographic coordinate into normalized Web Mercator.

public static MercatorPoint ToMercator(LatLon ll)

Parameters

ll LatLon

Coordinate in degrees WGS84.

Returns

MercatorPoint

Position in normalized mercator; Y is clamped to 0 through 1.