▾
import { canProject, project, lngLatToXY, xyToLngLat, geographicToWebMercator } from "@arcgis/core/geometry/support/webMercatorUtils.js";const { canProject, project, lngLatToXY, xyToLngLat, geographicToWebMercator } = await $arcgis.import("@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.
Functions
canProject
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
| Parameter | Type | Description | Required |
|---|---|---|---|
| source | object | SpatialReference | null | undefined | The input SpatialReference or an object with
| |
| target | object | SpatialReference | null | undefined | The target SpatialReference or an object with
| |
project
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.
- Signature
-
project (geometry: GeometryUnion | null | undefined, spatialReference: SpatialReference | null | undefined): GeometryUnion | null | undefined
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| geometry | The input geometry. | | |
| spatialReference | The target SpatialReference or an object with
| |
- Returns
- GeometryUnion | null | undefined
Returns the projected geometry if the input is supported; otherwise returns
null.
lngLatToXY
Translates the given latitude and longitude (decimal degree) values to Web Mercator XY values.
- Signature
-
lngLatToXY (long: number, lat: number): [ number, number ]
xyToLngLat
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 ]
geographicToWebMercator
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
| Parameter | Type | Description | Required |
|---|---|---|---|
| geometry | The input geometry to convert. | |
- Returns
- GeometryUnion
Returns the converted geometry in Web Mercator units.
webMercatorToGeographic
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
| Parameter | Type | Description | Required |
|---|---|---|---|
| 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
| |
- Returns
- GeometryUnion
Returns the converted geometry in geographic units.