Skip to content
import { canProject, project, lngLatToXY, xyToLngLat, geographicToWebMercator } from "@arcgis/core/geometry/support/webMercatorUtils.js";
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.

See also

Functions

canProject

Function

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.

See also
Signature
canProject (source: object | SpatialReference | null | undefined, target: object | SpatialReference | null | undefined): boolean
Parameters
ParameterTypeDescriptionRequired
source

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

target

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

Returns
boolean

Returns true if source can be projected to target.

project

Function

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 project() instead.

See also
Signature
project (geometry: GeometryUnion | null | undefined, spatialReference: SpatialReference | null | undefined): GeometryUnion | null | undefined
Parameters
ParameterTypeDescriptionRequired
geometry

The input geometry.

spatialReference

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

Returns
GeometryUnion | null | undefined

Returns the projected geometry if the projection is successful.

lngLatToXY

Function

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

Signature
lngLatToXY (long: number, lat: number): [ number, number ]
Parameters
ParameterTypeDescriptionRequired
long

The longitude value to convert.

lat

The latitude value to convert.

Returns
[ number, number ]

Returns the converted values in an array.

xyToLngLat

Function

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.

Signature
xyToLngLat (x: number, y: number): [ number, number ]
Parameters
ParameterTypeDescriptionRequired
x

The X coordinate value to convert.

y

The Y coordinate value to convert.

Returns
[ number, number ]

Returns the converted values in an array.

geographicToWebMercator

Function

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

Signature
geographicToWebMercator (geometry: GeometryUnion): GeometryUnion
Parameters
ParameterTypeDescriptionRequired
geometry

The input geometry to convert.

Returns
GeometryUnion

Returns the converted geometry in Web Mercator units.

webMercatorToGeographic

Function

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

Signature
webMercatorToGeographic (geometry: GeometryUnion, isLinear?: boolean): GeometryUnion
Parameters
ParameterTypeDescriptionRequired
geometry

The input geometry to convert.

isLinear

= 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
GeometryUnion

Returns the converted geometry in geographic units.