【问题标题】:Converting geographic WGS 84 to Web Mercator 102100将地理 WGS 84 转换为 Web Mercator 102100
【发布时间】:2012-08-11 01:17:32
【问题描述】:

我正在尝试将地理坐标系转换为 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;

【问题讨论】:

  • 第一个坐标几乎看起来像四叉树分解,但第二个不是(大于 3 的数字)。也许只是巧合。
  • 分配空间参考有帮助吗? (developers.arcgis.com/javascript/jsapi/point-amd.html)。对于行 var g = new esri.geometry.Point...
  • 发送到位置数组的 x 和 y 值的确切输入是什么?请包括这些值的确切格式和数据类型。理想情况下,在示例中包含实际设置硬编码 x 和 y 值的代码,以便其他人可以执行问题代码。

标签: javascript arcgis esri


【解决方案1】:

您应该在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>

希望对你有帮助。

【讨论】:

  • 我使用 AMD 风格的 arcgis api for javascript。至于 legacy 风格,主要代码类似。 @Pavlo
【解决方案2】:

您实际上不必转换纬度/经度即可将点添加到 webmercator 中的底图。

您可以通过几种不同的方式直接使用纬度/经度创建点(API 将在内部进行从地理到 webmercator 的转换)。从 3.3 版(2013 年 1 月)开始提供此功能。

var point = new Point(-98, 38); // note that longitude(x) comes 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.com/javascript/3/jsapi/point-amd.html#point4

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-10-30
    • 1970-01-01
    • 1970-01-01
    • 2014-01-24
    • 2021-02-07
    • 2016-09-25
    • 1970-01-01
    相关资源
    最近更新 更多