从gps坐标计算Esri地图范围

时间:2016-08-24 12:50:44

标签: esri arcgis-js-api

我在Esri地图上添加了一些标记,并希望在缩放级别显示所有标记都可见的地图。我计算了最小和最大lat-lng并设置了范围。但它不起作用。 给定坐标 lat,lon:41.984440,-87.827278 lat,lon:41.874489,-87.705772

计算的最小 - 最大值: XMAX: “ - 87.827278” XMIN: “ - 87.705772” YMAX: “41.984440” YMIN: “41.874489” 预期结果: enter image description here

> EsriSetMapExtent:function(obj)
>     {
>       var extent = new esri.geometry.Extent(obj.xMin, obj.yMin, obj.xMax, obj.yMax);
>       m.esriMap.setExtent(extent);
>     },

2 个答案:

答案 0 :(得分:1)

xMin和xMax的值相反。只有X轴,请检查执行计算的功能。如果你改变它们就行了。以下是工作样本

<!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>Simple Map</title>
    <link rel="stylesheet" href="https://js.arcgis.com/3.17/esri/css/esri.css">
    <style>
      html, body, #map {
        height: 100%;
        margin: 0;
        padding: 0;
      }
    </style>
    <script src="https://js.arcgis.com/3.17/"></script>
    <script>
      var map;

      require(["esri/map","esri/geometry/Extent", "esri/SpatialReference", "esri/geometry/Point", "esri/symbols/SimpleMarkerSymbol",
  "esri/Color", "esri/graphic", "dojo/domReady!"], function(Map, Extent, SpatialReference, Point, SimpleMarkerSymbol, Color, Graphic) {
        map = new Map("map", {
          basemap: "topo",  //For full list of pre-defined basemaps, navigate to http://arcg.is/1JVo6Wd
          center: [-87.705772, 41.874489], // longitude, latitude
          zoom: 13
        });
        
        map.on('load', function(evt){
          var pt = new Point(-87.705772, 41.874489, new SpatialReference({wkid:4326}))
          var sms = new SimpleMarkerSymbol().setStyle(SimpleMarkerSymbol.STYLE_SQUARE).setColor(
            new Color([255,0,0,0.5]));
          var graphic = new Graphic(pt,sms);
          map.graphics.add(graphic);
          
          pt = new Point(-87.827278, 41.984440, new SpatialReference({wkid:4326}))
          sms = new SimpleMarkerSymbol().setStyle(SimpleMarkerSymbol.STYLE_SQUARE).setColor(
            new Color([0,255,0,0.5]));
          graphic = new Graphic(pt,sms);
          map.graphics.add(graphic);
        })
        
        var extent = new Extent(-87.827278, 41.874489, -87.705772, 41.984440, new SpatialReference({ wkid:4326 }));
        
        map.setExtent(extent, true);
      });
    </script>
  </head>

  <body>
    <div id="map"></div>
  </body>
</html>

答案 1 :(得分:0)

最适合我的解决方案是:

const geoPoint = new Point(Longitude, Latitude);
if (!map.extent.contains(geoPoint)) {
  // point not in view
}