webMercatorUtils

AMD: require(["esri/geometry/support/webMercatorUtils"], (webMercatorUtils) => { /* code goes here */ });
ESM: import * as webMercatorUtils from "@arcgis/core/geometry/support/webMercatorUtils.js";
Object: esri/geometry/support/webMercatorUtils
Since: ArcGIS Maps SDK for JavaScript 4.0

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 true if the source spatial reference can be projected to the target spatial reference with the project() function, or if the source and target are the same SpatialReference.

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

Method
canProject(source, target){Boolean}

Returns true if the source spatial reference can be projected to the target spatial reference with the project() function, or if the source and target are the same SpatialReference.

Parameters

The input SpatialReference or an object with spatialReference property such as Geometry or Map.

The target SpatialReference or an object with spatialReference property such as Geometry or Map.

Returns
Type Description
Boolean Returns true if source can be projected to target.
See also

geographicToWebMercator

Method
geographicToWebMercator(geometry){Geometry}

Converts a geometry from geographic units (wkid: 4326) to Web Mercator units (wkid: 3857).

Parameter
geometry Geometry

The input geometry to convert.

Returns
Type Description
Geometry Returns the converted geometry in Web Mercator units.

lngLatToXY

Method
lngLatToXY(long, lat){Number[]}

Translates the given latitude and longitude (decimal degree) values to Web Mercator XY values.

Parameters
long Number

The longitude value to convert.

lat Number

The latitude value to convert.

Returns
Type Description
Number[] Returns the converted values in an array.

project

Method
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() returns false, then project() won't return useful results. Use geometryService.project() instead.

Parameters
geometry Geometry

The input geometry.

spatialReference SpatialReference|Object

The target SpatialReference or an object with spatialReference property such as Geometry or Map.

Returns
Type Description
Geometry Returns the projected geometry if the projection is successful.

webMercatorToGeographic

Method
webMercatorToGeographic(geometry, isLinear){Geometry}

Converts a geometry from Web Mercator units (wkid: 3857) to geographic units (wkid: 4326).

Parameters
geometry Geometry

The input geometry to convert.

isLinear Boolean
optional
Default Value: false

Indicates 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 is false.

Returns
Type Description
Geometry Returns the converted geometry in geographic units.

xyToLngLat

Method
xyToLngLat(x, y){Number[]}

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.

Parameters
x Number

The X coordinate value to convert.

y Number

The Y coordinate value to convert.

Returns
Type Description
Number[] Returns the converted values in an array.

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.