问题描述
在角度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);
});
});
我遇到了错误, '未捕获的TypeError:无法读取未定义的属性'_view''
解决方法
这取决于您要实现的目标。例如,如果要检索每个“可查询”层的最高功能,则可以使用hitTest
中的MapView
方法。该方法将屏幕坐标作为参数。您的情况将是视图上的click事件的结果。
这里是文档, ArcGIS API - MapView hitTest
这里有一个例子, ArcGIS Examples - Access features with pointer events