require(["esri/geometry/webMercatorUtils"], function(webMercatorUtils) { /* code goes here */ });
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
Method Details
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)
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. |
Sample: var pt = Point(0, 0), // a geographic point.
result;
if (webMercatorUtils.canProject(pt, map)) {
result = webMercatorUtils.project(pt, map);
}
Converts geometry from geographic units to Web Mercator units.
Parameters:
<Geometry > geometry |
Required |
The geometry to convert. |
Sample:
require([
"esri/geometry/webMercatorUtils", ...
], function(webMercatorUtils, ... ) {
var geom = webMercatorUtils.geographicToWebMercator(candidate.location);
...
});
Translates the given latitude and longitude values to Web Mercator.
Parameters:
<Number > long |
Required |
The longitude value to convert. |
<Number > lat |
Required |
The latitude value to convert. |
Sample:
require([
"esri/geometry/webMercatorUtils", ...
], function(webMercatorUtils, ... ) {
webMercatorUtils.lngLatToXY(-120, 33);
...
});
Project the geometry clientside (if possible). (Added at v3.11)
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. |
Sample: var pt = Point(0, 0), // a geographic point.
result;
if (webMercatorUtils.canProject(pt, map)) {
result = webMercatorUtils.project(pt, map);
}
Converts geometry from Web Mercator units to geographic units.
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:
require([
"esri/geometry/webMercatorUtils", ...
], function(webMercatorUtils, ... ) {
query.geometry = webMercatorUtils.webMercatorToGeographic(geometries[0]);
...
});
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.
Parameters:
<Number > x |
Required |
The x coordinate value to convert. |
<Number > y |
Required |
The y coordinate value to convert. |
Sample:
require([
"esri/geometry/webMercatorUtils", ...
], function(webMercatorUtils, ... ) {
var normalizedVal = webMercatorUtils.xyToLngLat(42215329, 1321748);
console.log(normalizedVal); //returns 19.226, 11.789
var value = webMercatorUtils.xyToLngLat(42215329, 1321748, true);
console.log(value); // returns 379.22, 11.78
...
});