【问题标题】:Get the details of the layer and its details when click on the map in Angular 10在 Angular 10 中单击地图时获取图层的详细信息及其详细信息
【发布时间】:2021-01-20 10:13:57
【问题描述】:

angular 10点击ArcGIS地图时如何获取图层的详细信息。点击事件在地图上触发。例如:显示门牌号码的地图。在地图上单击其中一个门牌号时,我们如何获得门牌号。我必须在我的代码中使用“门牌号”来实现其他功能。

this._view.on('click', function (event) {
    console.log('click working');
    //Need to get the value of clicked layer.
  });

/更新代码/

this._view.on('click', function (event) {
        this._view.hitTest(event).then(function (response) {
          const graphic = response.results.filter(function (result) {
            // return result.graphic.layer === hurricanesLayer;
            return result.graphic.layer;
          })[0].graphic;
          console.log(graphic.attributes);
        });
      });

我收到错误消息, '未捕获的类型错误:无法读取未定义的属性'_view'

【问题讨论】:

标签: angular arcgis arcgis-js-api angular10 esri-loader


【解决方案1】:

这取决于您想要实现的目标。例如,如果您想检索每个“可查询”层的最顶层特征,您可以使用MapView 中的hitTest 方法。此方法将屏幕坐标作为参数。在您的情况下,将是视图上单击事件的结果。

这里的文档, ArcGIS API - MapView hitTest

这里是一个例子, ArcGIS Examples - Access features with pointer events

【讨论】:

  • 看看你添加的代码..我想我把它钉在了箱子里;)
  • 非常感谢您提供的线索。 :) 我已经更新了代码。假设我有一个单层我需要检查'return result.graphic.layer === hurricanesLayer;' ?如果 'hurricanesLayer' 是图层名称。
  • 它是图层对象...如果您的图层是hurricanesLayer(例如let hurricanesLayer = new FeatureLayer(...);),那么它将起作用。不是名称,是层。
  • 好的,知道了。当我使用 this._view 应用 hitTest() 时,我收到错误“未捕获的类型错误:无法读取未定义的属性 '_view'”。 (我已经分配了 this._view = new EsriMapView(mapViewProperties); )
  • 可能是上下文,做这个小技巧,在this._view.on(..) 之前加上let self = this;,里面用self而不是this
猜你喜欢
  • 2010-12-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多