【问题标题】:How to zoom to feature selection when map and Layer wkid are different?地图和图层 wkid 不同时如何缩放到要素选择?
【发布时间】:2018-01-15 16:21:20
【问题描述】:

我有一个使用 Esri ArcGis Js Api v3.11 的地图服务。

在该地图上,用户可以查询每个 FeatureLayer 并返回一个简单的网格。行点击事件附加了以下处理程序:

_grid.on('dgrid-select', function(event) {
    var data = event.rows[0].data;
    //get the current selected featureLayer
    //build a query against it, using the objectId
    //zoom to position: https://developers.arcgis.com/javascript/3/jssamples/fl_zoomgrid.html
    var layerUrl = dijit.byId("LayerSelectBox").get("value");
    var url = lang.replace(_baseUrl, { layer: layerUrl });
    var fl = new FeatureLayer(url, {
        mode: FeatureLayer.MODE_SELECTION,
        outFields: ["ObjectID"]
    });
    //clear selection
    fl.clearSelection();
    query.objectIds = [data.OBJECTID];
    fl.selectFeatures(query, FeatureLayer.SELECTION_NEW, function(features) {
        //zoom to the selected feature
        var geometryExtent = features[0].geometry.getExtent().expand(5.0);
        _map.setExtent(geometryExtent);
    });
});

虽然查询及其周围的一切工作正常,但放大到结果让我很头疼。该地图的空间参考 Wkid 为 102100,返回的几何图形为 102362。

尝试将地图的范围设置为几何的范围或以某个点为中心会导致以下错误:

地图:几何 (wkid: 102362) 无法转换为空间参考 地图的(wkid:102100)

.selectFeatures (https://developers.arcgis.com/javascript/3/jsapi/featurelayer-amd.html#selectfeatures) 的文档仅提供以下有用信息:

输入查询。查询对象有以下限制 避免图层和地图属性之间的冲突。

  • 查询对象指定的outFields被FeatureLayer构造函数中指定的outFields覆盖。
  • 查询对象指定的returnGeometry值被忽略,使用true。
  • 忽略查询对象设置的outSpatialReference,使用地图的空间参考。

说实话,这让我有点困惑。如何将结果 sr 转换/转换为地图 sr 并将地图居中?通过在地图上单击一个 FeatureLayer 来查询它,会产生一个带有开箱即用的 Zoom to 按钮的小对话框窗口,因此该功能可供抓取。我似乎在做一些根本错误的事情。

【问题讨论】:

    标签: javascript dojo esri-javascript-api


    【解决方案1】:

    最后,GeometryService 拯救了我:

    fl.selectFeatures(query, FeatureLayer.SELECTION_NEW, function(features) {
    
        var gmsvc = new GeometryService("url//to/Geometryservice");
    
        var fooExtent = graphicUtils.graphicsExtent(features);
    
        var projectParams = new ProjectParameters();  
        projectParams.geometries = [fooExtent];  
        projectParams.outSR = map.spatialReference;  
        gmsvc.project(projectParams).then(function(x) {
            map.setExtent(x[0]);
        })
    });
    

    我正在使用 graphicsUtils 从一组几何图形中计算范围。这不是绝对必要的,但由于我的结果可以是任何东西,从一个点到一个多边形,这是一个很好的接触,并节省了一些 switch 语句。

    接下来,我使用我的几何服务将范围投影到地图的空间参考中,一旦完成,我将设置该范围。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-12
      • 1970-01-01
      • 2016-02-27
      • 1970-01-01
      • 1970-01-01
      • 2015-10-09
      • 2019-10-08
      • 2015-01-29
      相关资源
      最近更新 更多