Hide Table of Contents
esri/dijit/util
esri/layer/pixelFilters
esri/process
esri/support
esri/workers
Object: esri/geometry/webMercatorUtils

Description

(Added at v3.8)
Convert Web Mercator coordinates to geographic and vice versa.

When coding legacy (non-AMD) style, there is no need to require the module. All methods and properties are available in the namespace. For example, esri.geometry.geographicToWebMercator().

Samples

Search for samples that use this class.

Methods

NameReturn typeSummary
canProject(source, target)BooleanReturns true if the 'source' can be projected to 'target' by the project() function, or if the 'source' and 'target' is the same spatialReference.
geographicToWebMercator(geometry)GeometryConverts geometry from geographic units to Web Mercator units.
lngLatToXY(long, lat)Number[]Translates the given latitude and longitude values to Web Mercator.
project(geometry, target)ObjectProject the geometry clientside (if possible).
webMercatorToGeographic(geometry, isLinear?)GeometryConverts geometry from Web Mercator units to geographic units.
xyToLngLat(x, y)Number[]Translates the given Web Mercator coordinates to Longitude and Latitude.
Method Details

canProject(source, target)

Returns true if the 'source' can be projected to 'target' by the project() function, or if the 'source' and 'target' is the same spatialReference. (Added at v3.11)
Return type: Boolean
Parameters:
<SpatialReference | Object> source Required An input of type SpatialReference or an object with spatialReference property such as Geometry or Map.
<SpatialReference | Object> target Required The target spatial reference, of type SpatialReference or an object with spatialReference property such as Map.

geographicToWebMercator(geometry)

Converts geometry from geographic units to Web Mercator units.
Return type: Geometry
Parameters:
<Geometry> geometry Required The geometry to convert.
Sample:
var geom = esri.geometry.geographicToWebMercator(candidate.location);

lngLatToXY(long, lat)

Translates the given latitude and longitude values to Web Mercator.
Return type: Number[]
Parameters:
<Number> long Required The longitude value to convert. 
<Number> lat Required The latitude value to convert. 
Sample:
esri.geometry.lngLatToXY(-120, 33);

project(geometry, target)

Project the geometry clientside (if possible). (Added at v3.11)
Return type: Object
Parameters:
<Geometry> geometry Required An input geometry.
<SpatialReference | Object> target Required The target spatial reference, of type SpatialReference or an object with spatialReference property such as Map.

webMercatorToGeographic(geometry, isLinear?)

Converts geometry from Web Mercator units to geographic units.
Return type: Geometry
Parameters:
<Geometry> geometry Required The geometry to convert.
<Boolean> isLinear Optional 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.
Sample:
query.geometry = esri.geometry.webMercatorToGeographic(geometries[0]);

xyToLngLat(x, y)

Translates the given Web Mercator coordinates to Longitude and Latitude. By default the returned longitude is normalized so that it is within -180 and +180.
Return type: Number[]
Parameters:
<Number> x Required The x coordinate value to convert.
<Number> y Required The y coordinate value to convert.
Sample:
var normalizedVal = esri.geometry.xyToLngLat(42215329, 1321748);
console.log(normalizedVal); //returns 19.226, 11.789

var value = esri.geometry.xyToLngLat(42215329, 1321748, true);
console.log(value); // returns 379.22, 11.78
Show Modal