cesium-native  0.41.0
CesiumGeospatial::WebMercatorProjection Class Referencefinal

The map projection used by Google Maps, Bing Maps, and most of ArcGIS Online, EPSG:3857. More...

#include <CesiumGeospatial/WebMercatorProjection.h>

Public Member Functions

 WebMercatorProjection (const Ellipsoid &ellipsoid CESIUM_DEFAULT_ELLIPSOID) noexcept
 Constructs a new instance. More...
 
const EllipsoidgetEllipsoid () const noexcept
 Gets the Ellipsoid.
 
glm::dvec3 project (const Cartographic &cartographic) const noexcept
 Converts geodedic ellipsoid coordinates to Web Mercator coordinates. More...
 
CesiumGeometry::Rectangle project (const CesiumGeospatial::GlobeRectangle &rectangle) const noexcept
 Projects a globe rectangle to Web Mercator coordinates. More...
 
Cartographic unproject (const glm::dvec2 &projectedCoordinates) const noexcept
 Converts Web Mercator coordinates to geodetic ellipsoid coordinates. More...
 
Cartographic unproject (const glm::dvec3 &projectedCoordinates) const noexcept
 Converts Web Mercator coordinates to geodetic ellipsoid coordinates. More...
 
CesiumGeospatial::GlobeRectangle unproject (const CesiumGeometry::Rectangle &rectangle) const noexcept
 Unprojects a Web Mercator rectangle to the globe. More...
 
bool operator== (const WebMercatorProjection &rhs) const noexcept
 Returns true if two projections (i.e. their ellipsoids) are equal.
 
bool operator!= (const WebMercatorProjection &rhs) const noexcept
 Returns true if two projections (i.e. their ellipsoids) are not equal.
 

Static Public Member Functions

static constexpr CesiumGeometry::Rectangle computeMaximumProjectedRectangle (const Ellipsoid &ellipsoid CESIUM_DEFAULT_ELLIPSOID) noexcept
 Computes the maximum rectangle that can be covered with this projection. More...
 
static double mercatorAngleToGeodeticLatitude (double mercatorAngle) noexcept
 Converts a Mercator angle, in the range -PI to PI, to a geodetic latitude in the range -PI/2 to PI/2. More...
 
static double geodeticLatitudeToMercatorAngle (double latitude) noexcept
 Converts a geodetic latitude in radians, in the range -PI/2 to PI/2, to a Mercator angle in the range -PI to PI. More...
 

Static Public Attributes

static const double MAXIMUM_LATITUDE
 The maximum latitude (both North and South) supported by a Web Mercator (EPSG:3857) projection. More...
 
static const GlobeRectangle MAXIMUM_GLOBE_RECTANGLE
 The maximum bounding rectangle of the Web Mercator projection, ranging from -PI to PI radians longitude and from -MAXIMUM_LATITUDE to +MAXIMUM_LATITUDE.
 

Detailed Description

The map projection used by Google Maps, Bing Maps, and most of ArcGIS Online, EPSG:3857.

This projection uses geodetic longitude and latitude expressed with WGS84 and transforms them to Mercator using the spherical (rather than ellipsoidal) equations.

See also
GeographicProjection

Definition at line 24 of file WebMercatorProjection.h.

Constructor & Destructor Documentation

◆ WebMercatorProjection()

CesiumGeospatial::WebMercatorProjection::WebMercatorProjection ( const Ellipsoid &ellipsoid  CESIUM_DEFAULT_ELLIPSOID)
noexcept

Constructs a new instance.

Parameters
ellipsoidThe Ellipsoid.

Member Function Documentation

◆ computeMaximumProjectedRectangle()

static constexpr CesiumGeometry::Rectangle CesiumGeospatial::WebMercatorProjection::computeMaximumProjectedRectangle ( const Ellipsoid &ellipsoid  CESIUM_DEFAULT_ELLIPSOID)
inlinestaticconstexprnoexcept

Computes the maximum rectangle that can be covered with this projection.

Parameters
ellipsoidThe Ellipsoid. Default value: Ellipsoid::WGS84.
Returns
The rectangle

Definition at line 57 of file WebMercatorProjection.h.

◆ geodeticLatitudeToMercatorAngle()

static double CesiumGeospatial::WebMercatorProjection::geodeticLatitudeToMercatorAngle ( double  latitude)
staticnoexcept

Converts a geodetic latitude in radians, in the range -PI/2 to PI/2, to a Mercator angle in the range -PI to PI.

Parameters
latitudeThe geodetic latitude in radians.
Returns
The Mercator angle.

◆ mercatorAngleToGeodeticLatitude()

static double CesiumGeospatial::WebMercatorProjection::mercatorAngleToGeodeticLatitude ( double  mercatorAngle)
staticnoexcept

Converts a Mercator angle, in the range -PI to PI, to a geodetic latitude in the range -PI/2 to PI/2.

Parameters
mercatorAngleThe angle to convert.
Returns
The geodetic latitude in radians.

◆ project() [1/2]

glm::dvec3 CesiumGeospatial::WebMercatorProjection::project ( const Cartographic cartographic) const
noexcept

Converts geodedic ellipsoid coordinates to Web Mercator coordinates.

Converts geodetic ellipsoid coordinates, in radians, to the equivalent Web Mercator X, Y, Z coordinates expressed in meters. The height is copied unmodified to the z coordinate.

Parameters
cartographicThe geodetic coordinates in radians.
Returns
The equivalent web mercator X, Y, Z coordinates, in meters.

◆ project() [2/2]

CesiumGeometry::Rectangle CesiumGeospatial::WebMercatorProjection::project ( const CesiumGeospatial::GlobeRectangle rectangle) const
noexcept

Projects a globe rectangle to Web Mercator coordinates.

This is done by projecting the southwest and northeast corners.

Parameters
rectangleThe globe rectangle to project.
Returns
The projected rectangle.

◆ unproject() [1/3]

CesiumGeospatial::GlobeRectangle CesiumGeospatial::WebMercatorProjection::unproject ( const CesiumGeometry::Rectangle rectangle) const
noexcept

Unprojects a Web Mercator rectangle to the globe.

This is done by unprojecting the southwest and northeast corners.

Parameters
rectangleThe rectangle to unproject.
Returns
The unprojected rectangle.

◆ unproject() [2/3]

Cartographic CesiumGeospatial::WebMercatorProjection::unproject ( const glm::dvec2 &  projectedCoordinates) const
noexcept

Converts Web Mercator coordinates to geodetic ellipsoid coordinates.

Converts Web Mercator X and Y coordinates, expressed in meters, to a Cartographic containing geodetic ellipsoid coordinates. The height is set to 0.0.

Parameters
projectedCoordinatesThe web mercator projected coordinates to unproject.
Returns
The equivalent cartographic coordinates.

◆ unproject() [3/3]

Cartographic CesiumGeospatial::WebMercatorProjection::unproject ( const glm::dvec3 &  projectedCoordinates) const
noexcept

Converts Web Mercator coordinates to geodetic ellipsoid coordinates.

Converts Web Mercator X, Y coordinates, expressed in meters, to a Cartographic containing geodetic ellipsoid coordinates. The Z coordinate is copied unmodified to the height.

Parameters
projectedCoordinatesThe web mercator projected coordinates to unproject, with height (z) in meters.
Returns
The equivalent cartographic coordinates.

Member Data Documentation

◆ MAXIMUM_LATITUDE

const double CesiumGeospatial::WebMercatorProjection::MAXIMUM_LATITUDE
static

The maximum latitude (both North and South) supported by a Web Mercator (EPSG:3857) projection.

Technically, the Mercator projection is defined for any latitude up to (but not including) 90 degrees, but it makes sense to cut it off sooner because it grows exponentially with increasing latitude. The logic behind this particular cutoff value, which is the one used by Google Maps, Bing Maps, and Esri, is that it makes the projection square. That is, the rectangle is equal in the X and Y directions.

The constant value is computed by calling: CesiumGeospatial::WebMercatorProjection::mercatorAngleToGeodeticLatitude(CesiumUtility::Math::OnePi)

Definition at line 40 of file WebMercatorProjection.h.


The documentation for this class was generated from the following file: