import { canProject, project, lngLatToXY, xyToLngLat, geographicToWebMercator } from "@arcgis/core/geometry/support/webMercatorUtils.js";
Since
ArcGIS Maps SDK for JavaScript 4.0

Supports client-side projection workflows between WGS84 and Web Mercator without requiring loading the projectOperator and its dependencies or using a geometry service.

Best suited for relatively simple geometries that do not require the full capabilities of the projectOperator.

Known limitations

  • Geometries with true curves are not supported.
  • Mesh geometries are not supported.
See also

Functions

canProject

Function

Returns true when project() can handle the inputs.

Supported cases are limited to conversions between WGS84 and Web Mercator, or no-op calls where 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 project() can handle the source and target inputs.

project

Function

Projects the geometry client-side when the input and target spatial references are supported by this module.

Use this method when the target spatial reference may vary between WGS84 and Web Mercator, or when needing to handle no-op projections between identical spatial references.

Use canProject() to test whether this function can handle the inputs. If the conversion direction is already known, use geographicToWebMercator() or webMercatorToGeographic(). If this function cannot handle the inputs, use projectOperator 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 input is supported; otherwise returns null.

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 the WGS 84 geographic coordinate system (WKID: 4326) to the Web Mercator coordinate system (WKID: 3857).

This method provides a lightweight, high-performance client-side conversion optimized for this specific transformation. Geometries containing true curves are not supported. Use projectOperator instead.

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 the Web Mercator coordinate system (WKID: 3857) to the WGS 84 geographic coordinate system (WKID: 4326).

This method provides a lightweight, high-performance client-side conversion for this specific transformation. Geometries containing true curves are not supported. Use projectOperator instead.

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

Parameters

ParameterTypeDescriptionRequired
geometry

The input geometry to convert.

isLinear

Indicates whether to preserve continuous coordinate values and skip longitude normalization. By default, this method normalizes output longitude values. Specify true to preserve unnormalized values, such as when working with wrapped world coordinates. Default value is false.

Returns
GeometryUnion

Returns the converted geometry in geographic units.