require(["esri/geometry/support/webMercatorUtils"], (webMercatorUtils) => { /* code goes here */ });
import * as webMercatorUtils from "@arcgis/core/geometry/support/webMercatorUtils.js";
esri/geometry/support/webMercatorUtils
Converts Web Mercator coordinates to geographic coordinates and vice versa.
Known Limitation
Geometry type Mesh is not supported.
Method Overview
Name | Return Type | Summary | Object |
---|---|---|---|
Returns | webMercatorUtils | ||
Converts a geometry from geographic units (wkid: 4326) to Web Mercator units (wkid: 3857). | webMercatorUtils | ||
Translates the given latitude and longitude (decimal degree) values to Web Mercator XY values. | webMercatorUtils | ||
Projects the geometry clientside (if possible). | webMercatorUtils | ||
Converts a geometry from Web Mercator units (wkid: 3857) to geographic units (wkid: 4326). | webMercatorUtils | ||
Translates the given Web Mercator coordinates to Longitude and Latitude values (decimal degrees). | webMercatorUtils |
Method Details
-
canProject
canProject(source, target){Boolean}
-
Returns
true
if thesource
spatial reference can be projected to thetarget
spatial reference with the project() function, or if thesource
andtarget
are the same SpatialReference.Parameterssource SpatialReference|ObjectThe input SpatialReference or an object with
spatialReference
property such as Geometry or Map.target SpatialReference|ObjectThe target SpatialReference or an object with
spatialReference
property such as Geometry or Map.ReturnsType Description Boolean Returns true
ifsource
can be projected totarget
.- See also
-
geographicToWebMercator
geographicToWebMercator(geometry){Geometry}
-
Converts a geometry from geographic units (wkid: 4326) to Web Mercator units (wkid: 3857).
Parametergeometry GeometryThe input geometry to convert.
ReturnsType Description Geometry Returns the converted geometry in Web Mercator units.
-
Translates the given latitude and longitude (decimal degree) values to Web Mercator XY values.
Returns
-
project
project(geometry, spatialReference){Geometry}
-
Projects the geometry clientside (if possible). You should test the input geometry in canProject() prior to using this function. If the result of canProject() is
true
, then proceed to project. If canProject() returnsfalse
, thenproject()
won't return useful results. Use geometryService.project() instead.Parametersgeometry GeometryThe input geometry.
spatialReference SpatialReference|ObjectThe target SpatialReference or an object with
spatialReference
property such as Geometry or Map.ReturnsType Description Geometry Returns the projected geometry if the projection is successful.
-
webMercatorToGeographic
webMercatorToGeographic(geometry, isLinear){Geometry}
-
Converts a geometry from Web Mercator units (wkid: 3857) to geographic units (wkid: 4326).
Parametersgeometry GeometryThe input geometry to convert.
isLinear BooleanoptionalDefault Value: falseIndicates whether to work with linear values, i.e., do not normalize. By default, this conversion method normalizes xmin and xmax values. If this is not desired, specify this value as
true
. Default value isfalse
.ReturnsType Description Geometry Returns the converted geometry in geographic units.
-
Translates the given Web Mercator coordinates to Longitude and Latitude values (decimal degrees). By default the returned longitude is normalized so that it is within -180 and +180.
Returns