Bạn nên cố gắng geographicToWebMercator
phương pháp trong esri/geometry/webMercatorUtils
module.see các chi tiết 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 + ")");
một bản demo trực tiếp:
<!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.com/3.20/esri/css/esri.css">
<style>
html,
body,
#map {
height: 100%;
margin: 0;
padding: 0;
}
</style>
<script src="https://js.arcgis.com/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>
Hy vọng nó có thể giúp bạn.
Tọa độ đầu tiên gần như trông giống như một phân tách quadtree, nhưng tọa độ thứ hai không (chữ số lớn hơn 3). Có lẽ chỉ là trùng hợp ngẫu nhiên. – John
sẽ chỉ định trợ giúp tham chiếu không gian? (https://developers.arcgis.com/javascript/jsapi/point-amd.html). Đối với dòng var g = new esri.geometry.Point ... –
Đầu vào chính xác cho các giá trị x và y của bạn được gửi vào mảng vị trí là gì? Vui lòng bao gồm định dạng chính xác và loại dữ liệu của các giá trị này. Lý tưởng nhất, bao gồm mã thực sự đặt các giá trị x và y được mã hóa cứng trong mẫu của bạn để mã vấn đề có thể được thực hiện bởi những người khác. – Fitz