要素微件 - 从多个图层视图中查询图形

尝试一下在线预览

此示例类似于 侧面板中的要素微件 ,不同之处在于该示例演示了如何处理不同类型的多个图层。 此示例使用三个单独的图层:两个 影像图层 和一个 要素图层 。 此示例使用 Popup's fetchFeatures 方法。 这需要给定的屏幕位置并从多个 LayerViews 中返回要素。 它根据图层的关联 PopupTemplate 显示信息。

首先,监听视图的点击事件并将其传递给  fetchFeatures  方法。

       
1
2
3
4
5
6
7
view.on("click", (event) => {
  ...
  // Call fetchFeatures and pass in the click event location
  view.popup.fetchFeatures(event).then((response) => {
   // Do something
  });
});

接下来,遍历所有返回的要素以访问它们关联的 LayerView图形

     
1
2
3
4
5
 view.popup.fetchFeatures(event).then((response) => {
   response.promisesPerLayerView.forEach((fetchResult) => {
     // Do something
   });
  });

然后,遍历从生成的 LayerViews 返回的 图形 ,并将此图形传递给 要素 微件的 图形 属性。

         
1
2
3
4
5
6
7
8
9
 graphics.forEach((graphic) => {

   const featureChild = new Feature ({
     container: document.createElement("div"),
     graphic: graphic,
     map: view.map,
     spatialReference: view.spatialReference
   });
 });

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.