admin管理员组文章数量:1401401
I am trying to convert geographic coordinate system to Esri Webmercator, but when I do the conversion the resulted x and y have values of 0000003232112222… and 00000012665321…. This is very odd since coordinates as those do not exist.
var positions = [];
positions.push(x, y);
var g = new esri.geometry.Point(positions);
g = esri.geometry.geographicToWebMercator(g);
x = g.x;
y = g.y;
I am trying to convert geographic coordinate system to Esri Webmercator, but when I do the conversion the resulted x and y have values of 0000003232112222… and 00000012665321…. This is very odd since coordinates as those do not exist.
var positions = [];
positions.push(x, y);
var g = new esri.geometry.Point(positions);
g = esri.geometry.geographicToWebMercator(g);
x = g.x;
y = g.y;
Share
Improve this question
edited Aug 1, 2016 at 8:42
Pavlo
45k14 gold badges83 silver badges114 bronze badges
asked Aug 14, 2012 at 17:22
user1564511user1564511
3
- The first coordinate almost looks like a quadtree deposition, but the second one doesn't (digits greater than 3). Maybe just coincidence. – John Commented Aug 14, 2012 at 17:25
- would assigning the spatial reference help? (developers.arcgis./javascript/jsapi/point-amd.html). For the line var g = new esri.geometry.Point... – Rob Welan Commented Mar 31, 2016 at 8:08
- What are the exact inputs for your x and y values being sent into the positions array? Please include the exact format and data type of these values. Ideally, include code that actually sets the hardcoded x and y values in your sample so the problem code can be executed by others. – Fitz Commented Aug 3, 2016 at 19:36
2 Answers
Reset to default 1You should try geographicToWebMercator
method in esri/geometry/webMercatorUtils
module.see the detailed documentation.
//a point in GCS_WGS_1984(wkid is 4326)
var point = new Point(-118.15, 33.80, new SpatialReference({
wkid: 4326
}));
var pointWebMercator = webMercatorUtils.geographicToWebMercator(point);
alert("the point in 102100 is ( " + pointWebMercator.x + "," + pointWebMercator.y + " )");
a live demo:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no" />
<title>Converting geographic WGS 84 to Web Mercator 102100</title>
<link rel="stylesheet" href="https://js.arcgis./3.20/esri/css/esri.css">
<style>
html,
body,
#map {
height: 100%;
margin: 0;
padding: 0;
}
</style>
<script src="https://js.arcgis./3.20/"></script>
<script>
var map;
require(["esri/map", "esri/geometry/Point", "esri/SpatialReference", "esri/geometry/webMercatorUtils", "dojo/domReady!"], function (Map, Point, SpatialReference, webMercatorUtils) {
map = new Map("map", {
basemap: "topo", //For full list of pre-defined basemaps, navigate to http://arcg.is/1JVo6Wd
center: [-122.45, 37.75], // longitude, latitude
zoom: 13
});
//a point in GCS_WGS_1984(wkid is 4326)
var point = new Point(-118.15, 33.80, new SpatialReference({
wkid: 4326
}));
var pointWebMercator = webMercatorUtils.geographicToWebMercator(point);
alert("the point in 102100 is ( " + pointWebMercator.x + "," + pointWebMercator.y + " )");
});
</script>
</head>
<body>
<div id="map"></div>
</body>
</html>
Hope it could help you.
You don't actually have to convert the latitide/longitude to add points to a basemap that's in webmercator.
You can create the Point directly using latitude/longitude (and the API will internally do the conversion from geographic to webmercator) in a few different ways. This is available since version 3.3 (January 2013).
var point = new Point(-98, 38); // note that longitude(x) es before the latitude(y).
// or as an array
var point = new Point([-98, 38]);
// or as an object
var point = new Point({latitude: 38, longitude: -98});
https://developers.arcgis./javascript/3/jsapi/point-amd.html#point4
本文标签: javascriptConverting geographic WGS 84 to Web Mercator 102100Stack Overflow
版权声明:本文标题:javascript - Converting geographic WGS 84 to Web Mercator 102100 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744309129a2599945.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论