cesium-native  0.41.0
WebMercatorProjection.h
1 #pragma once
2 
3 #include "Ellipsoid.h"
4 #include "GlobeRectangle.h"
5 #include "Library.h"
6 
7 #include <glm/vec2.hpp>
8 #include <glm/vec3.hpp>
9 
10 namespace CesiumGeospatial {
11 
12 class Cartographic;
13 
24 class CESIUMGEOSPATIAL_API WebMercatorProjection final {
25 public:
40  static const double MAXIMUM_LATITUDE;
41 
48 
58  const Ellipsoid& ellipsoid CESIUM_DEFAULT_ELLIPSOID) noexcept {
59  const double value =
60  ellipsoid.getMaximumRadius() * CesiumUtility::Math::OnePi;
61  return CesiumGeometry::Rectangle(-value, -value, value, value);
62  }
63 
70  const Ellipsoid& ellipsoid CESIUM_DEFAULT_ELLIPSOID) noexcept;
71 
75  const Ellipsoid& getEllipsoid() const noexcept { return this->_ellipsoid; }
76 
87  glm::dvec3 project(const Cartographic& cartographic) const noexcept;
88 
98  project(const CesiumGeospatial::GlobeRectangle& rectangle) const noexcept;
99 
111  Cartographic unproject(const glm::dvec2& projectedCoordinates) const noexcept;
112 
124  Cartographic unproject(const glm::dvec3& projectedCoordinates) const noexcept;
125 
135  unproject(const CesiumGeometry::Rectangle& rectangle) const noexcept;
136 
144  static double mercatorAngleToGeodeticLatitude(double mercatorAngle) noexcept;
145 
153  static double geodeticLatitudeToMercatorAngle(double latitude) noexcept;
154 
158  bool operator==(const WebMercatorProjection& rhs) const noexcept {
159  return this->_ellipsoid == rhs._ellipsoid;
160  };
161 
166  bool operator!=(const WebMercatorProjection& rhs) const noexcept {
167  return !(*this == rhs);
168  };
169 
170 private:
171  Ellipsoid _ellipsoid;
172  double _semimajorAxis;
173  double _oneOverSemimajorAxis;
174 };
175 
176 } // namespace CesiumGeospatial
A position defined by longitude, latitude, and height.
Definition: Cartographic.h:12
A quadratic surface defined in Cartesian coordinates.
Definition: Ellipsoid.h:38
A two-dimensional, rectangular region on a globe, specified using longitude and latitude coordinates....
The map projection used by Google Maps, Bing Maps, and most of ArcGIS Online, EPSG:3857.
WebMercatorProjection(const Ellipsoid &ellipsoid CESIUM_DEFAULT_ELLIPSOID) noexcept
Constructs a new instance.
bool operator==(const WebMercatorProjection &rhs) const noexcept
Returns true if two projections (i.e. their ellipsoids) are equal.
static constexpr CesiumGeometry::Rectangle computeMaximumProjectedRectangle(const Ellipsoid &ellipsoid CESIUM_DEFAULT_ELLIPSOID) noexcept
Computes the maximum rectangle that can be covered with this projection.
static const GlobeRectangle MAXIMUM_GLOBE_RECTANGLE
The maximum bounding rectangle of the Web Mercator projection, ranging from -PI to PI radians longitu...
CesiumGeospatial::GlobeRectangle unproject(const CesiumGeometry::Rectangle &rectangle) const noexcept
Unprojects a Web Mercator rectangle to the globe.
CesiumGeometry::Rectangle project(const CesiumGeospatial::GlobeRectangle &rectangle) const noexcept
Projects a globe rectangle to Web Mercator coordinates.
const Ellipsoid & getEllipsoid() const noexcept
Gets the Ellipsoid.
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...
Cartographic unproject(const glm::dvec3 &projectedCoordinates) const noexcept
Converts Web Mercator coordinates to geodetic ellipsoid coordinates.
static const double MAXIMUM_LATITUDE
The maximum latitude (both North and South) supported by a Web Mercator (EPSG:3857) projection.
Cartographic unproject(const glm::dvec2 &projectedCoordinates) const noexcept
Converts Web Mercator coordinates to geodetic ellipsoid coordinates.
bool operator!=(const WebMercatorProjection &rhs) const noexcept
Returns true if two projections (i.e. their ellipsoids) are not equal.
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.
glm::dvec3 project(const Cartographic &cartographic) const noexcept
Converts geodedic ellipsoid coordinates to Web Mercator coordinates.
static constexpr double OnePi
pi
Definition: Math.h:80
Classes for geospatial computations in Cesium.
A 2D rectangle.
Definition: Rectangle.h:14