1 line
8.5 KiB
Plaintext
1 line
8.5 KiB
Plaintext
|
{"version":3,"file":"WebMercatorProjection-d67afe4b.js","sources":["../../../../Source/Core/WebMercatorProjection.js"],"sourcesContent":["import Cartesian3 from \"./Cartesian3.js\";\nimport Cartographic from \"./Cartographic.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport Ellipsoid from \"./Ellipsoid.js\";\nimport CesiumMath from \"./Math.js\";\n\n/**\n * The map projection used by Google Maps, Bing Maps, and most of ArcGIS Online, EPSG:3857. This\n * projection use longitude and latitude expressed with the WGS84 and transforms them to Mercator using\n * the spherical (rather than ellipsoidal) equations.\n *\n * @alias WebMercatorProjection\n * @constructor\n *\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid.\n *\n * @see GeographicProjection\n */\nfunction WebMercatorProjection(ellipsoid) {\n this._ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84);\n this._semimajorAxis = this._ellipsoid.maximumRadius;\n this._oneOverSemimajorAxis = 1.0 / this._semimajorAxis;\n}\n\nObject.defineProperties(WebMercatorProjection.prototype, {\n /**\n * Gets the {@link Ellipsoid}.\n *\n * @memberof WebMercatorProjection.prototype\n *\n * @type {Ellipsoid}\n * @readonly\n */\n ellipsoid: {\n get: function () {\n return this._ellipsoid;\n },\n },\n});\n\n/**\n * Converts a Mercator angle, in the range -PI to PI, to a geodetic latitude\n * in the range -PI/2 to PI/2.\n *\n * @param {Number} mercatorAngle The angle to convert.\n * @returns {Number} The geodetic latitude in radians.\n */\nWebMercatorProjection.mercatorAngleToGeodeticLatitude = function (\n mercatorAngle\n) {\n return CesiumMath.PI_OVER_TWO - 2.0 * Math.atan(Math.exp(-mercatorAngle));\n};\n\n/**\n * Converts a geodetic latitude in radians, in the range -PI/2 to PI/2, to a Mercator\n * angle in the range -PI to PI.\n *\n * @param {Number} latitude The geodetic latitude in radians.\n * @returns {Number} The Mercator angle.\n */\nWebMercatorProjection.geodeticLatitudeToMercatorAngle = function (latitude) {\n // Clamp the latitude coordinate to the valid Mercator bounds.\n if (latitude > WebMercatorProjection.MaximumLatitude) {\n latitude = WebMercatorProjection.MaximumLatitude;\n } else if (latitude < -WebMercatorProjection.MaximumLatitude) {\n latitude = -WebMercatorProjection.MaximumLatitude;\n }\n const sinLatitude = Math.sin(latitude);\n return 0.5 * Math.log((1.0 + sinLatitude) / (1.0 - sinLatitude));\n};\n\n/**\n * The maximum latitude (both North and South) supported by a Web Mercator\n * (EPSG:3857) projection. Technically, the Mercator projection is defined\n * for any latitude up to (but not including) 90 degrees, but it makes sense\n * to cut it off sooner because it grows exponentially with increasing latitude.\n * The logic behind this particular cutoff value, which is the one used by\n * Google Maps, Bing Maps, and Esri, is that it makes the projection\n * square. That is, the rectangle is equal in the X and Y directions.\n *\n * The constant value is computed by calling:\n * WebMercatorProjection.mercatorAngleToGeodeticLatitude(Math.PI)\n *\n * @type {Number}\n */\nWebMercatorProjection.MaximumLatitude = WebMercatorProjection.mercatorAngleToGeodeticLatitude(\n Math.PI\n);\n\n/**\n * Converts geodetic ellipsoid coordinates, in radians, to the equivalent Web Mercator\n * X, Y, Z coordinates expressed in meters and returned in a {@link Cartesian3}. The height\n * is copied unmodified to the Z coordinate.\n *\n * @param {Cartographic} cartographic The cartographic coordinates in radians.\n * @param {Cartesian3} [result] The instance to which to copy the result, or undefined if a\n * new instance should be created.\n * @returns {Cartesian3} The equivalent web mercator X, Y, Z coordinates, in meters.\n */\nWebMercatorProjection.prototype.project = function (cartographic, result) {\n const semimajorAxis = this._semimajorAxis;\n const x = cartographic.longitude * semimajorAxis;\n const y
|