javascript - 将地理 WGS 84 转换为 Web 墨卡托 102100

标签 javascript arcgis esri

我正在尝试将地理坐标系转换为 Esri Webmercator,但是当我进行转换时,生成的 x 和 y 的值为 0000003232112222… 和 00000012665321…。 这很奇怪,因为坐标不存在。

var positions = [];
positions.push(x, y);

var g = new esri.geometry.Point(positions);
g = esri.geometry.geographicToWebMercator(g);
x = g.x;
y = g.y;

最佳答案

您应该尝试 esri/geometry/webMercatorUtils 模块中的 geographicToWebMercator 方法。请参阅详细信息 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 + " )");

现场演示:

<!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>

希望对您有所帮助。

关于javascript - 将地理 WGS 84 转换为 Web 墨卡托 102100,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11957538/

相关文章:

javascript - Node.js 使用请求模块从 url 下载图像给出 URI 错误

javascript - 如何设置 dojo combobox 商店

javascript - 如何使用 XY 坐标向 ArcGIS map 添加标记

javascript - ESRI : Failed to parse source map

javascript - 如何将字符串化的 surveyjs 类 JSON 对象转换为实际的 JSON

javascript - 在 foreach 循环中创建具有唯一 ID 的输入字段`

Javascript:将字符串解析为日期作为本地时区

r - R 中 igraph 网络的输出 shapefile

flash - wmode ="opaque"问题和 wmmode ="window"问题

python - 在 Ruby 中解析 ESRI 形状文件