1

我正在使用 ArcGIS 地图来显示位置并允许用户缩放并拖动到他们的目的地。当他们单击“保存”按钮时,我想保存坐标,并且在我的回发中我想向他们显示相同的缩放位置。我能够保存范围值,但不知道如何在鼠标单击时将其恢复。setExtent 对我不起作用。请参阅以下内容。

 <script type="text/javascript">
  dojo.require("esri.map");
  dojo.require("esri.tasks.locator");

  var map, locator;

  function init() {

      var initExtent = new esri.geometry.Extent({ xmin: -20098296, ymin: -2804413, xmax: 5920428, ymax: 15813776, spatialReference: { wkid: 54032} });
      map = new esri.Map("map", { extent: initExtent });

    var tiledMapServiceLayer = new esri.layers.ArcGISTiledMapServiceLayer("http://maps.dcgis.dc.gov/DCGIS/rest/services/DCGIS_DATA/DC_Basemap_WebMercator/MapServer");
    map.addLayer(tiledMapServiceLayer);

    locator = new esri.tasks.Locator("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Locators/ESRI_Geocode_USA/GeocodeServer");
    dojo.connect(locator, "onAddressToLocationsComplete", showResults);

    dojo.connect(map, "onExtentChange", showExtent);
    dojo.connect(map, "onMouseMove", showCoordinates);
    dojo.connect(map, "onMouseDrag", showCoordinates);


//    setExtent(map, document.getElementById('extent').value);

}
function showCoordinates(evt) {
    //get mapPoint from event
    var mp = evt.mapPoint;
    //display mouse coordinatesLabel1
    dojo.byId("Label1").innerHTML = mp.x + ", " + mp.y;

}


function refreshMap() {       

    setExtent(map, document.getElementById('extent').value);
}

function setExtent(map,ext) {
    //        var startExtent = new esri.geometry.Extent(ext,
    //          new esri.SpatialReference({ wkid: 54032 }));
   debugger
    var coordinate = ext.split(" ");
    var xmin=coordinate[1];        
    var ymin=coordinate[3];
    var xmax=coordinate[5];
    var ymax = coordinate[7];
    var newExtent = new esri.geometry.Extent();
    newExtent.xmin = xmin;
    newExtent.ymin = ymin;
    newExtent.xmax = xmax;
    newExtent.ymax = ymax;
    newExtent.spatialReference = new esri.SpatialReference({ wkid: 31466 });
    map.setExtent(newExtent);
    dojo.connect(locator, "onAddressToLocationsComplete", showResults);
}
function showExtent(ext) {

      var s = "";
      s = "XMin: " + ext.xmin + 
   " YMin: " + ext.ymin +
   " XMax: " + ext.xmax + 
   " YMax: " + ext.ymax;
      var spatialref = ext.spatialReference.wkid;
   dojo.byId("onExtentChangeInfo").innerHTML = s;
   document.getElementById('extent').value = s;          
  }

  function locate() {
    map.graphics.clear();
    var add = dojo.byId("address").value.split(",");
    var address = {
      Address : add[0],
      City: add[1],
      State: add[2],
      Zip: add[3]
    };
    locator.addressToLocations(address,["Loc_name"]);
  }

  function showResults(candidates) {
    var candidate;
    var symbol = new esri.symbol.SimpleMarkerSymbol();
    var infoTemplate = new esri.InfoTemplate("Location", "Address: ${address}<br />Score: ${score}<br />Source locator: ${locatorName}");

    symbol.setStyle(esri.symbol.SimpleMarkerSymbol.STYLE_CIRCLE);
    symbol.setColor(new dojo.Color([255,0,0,0.75]));

    var points =  new esri.geometry.Multipoint(map.spatialReference);

    for (var i=0, il=candidates.length; i<il; i++) {
      candidate = candidates[i];
      if (candidate.score > 70) {
        var attributes = { address: candidate.address, score:candidate.score, locatorName:candidate.attributes.Loc_name };
        var geom = esri.geometry.geographicToWebMercator(candidate.location);
        var graphic = new esri.Graphic(geom, symbol, attributes, infoTemplate);
        map.graphics.add(graphic);
        map.graphics.add(new esri.Graphic(geom, new esri.symbol.TextSymbol(attributes.address).setOffset(0, 8)));
        points.addPoint(geom);
      }
  }
   // map.centerAndZoom(points, 6);

    map.setExtent(points.getExtent().expand(1));
  }

  dojo.addOnLoad(init);
</script>
4

1 回答 1

0

在我的应用程序中,我还在地图中计算和设置范围。它可以工作,但在我的情况下,我不是在使用 arcgis 地图,而是在使用 C# 编码的 ArcMap 上工作,因此在我的示例代码中,方法/类看起来有点不同(例如,我使用 ESRI.ArcGIS.Carto。来自 IMxDocument 的 IActiveView 而不是 esri.map 类来获取/发送范围)但它看起来是一个类似的过程,所以也许这对你也有用。

我认为您唯一缺少的是视图/地图的刷新?代码的相关部分在我的代码中如下所示:

// zoom
activeView.Extent = envelope.Envelope;  // activeView.Extent is of class IEnvelope 
activeView.Refresh();

所以也许你可以使用 map.refresh() 或类似的东西?

于 2011-07-27T23:34:02.870 回答