首页 > 其他分享 >arcgis for js 4.x 点击要素高亮显示

arcgis for js 4.x 点击要素高亮显示

时间:2022-09-20 17:02:05浏览次数:56  
标签:显示 graphic 高亮 js arcgis highlight response view

通常我们查看图层服务是否支持popupTemplate,然后设置显示的字段属性。

但是我们不需要显示弹出窗口,只需要高亮显示要素,应该如何操作呢

popupTemplate设置成{}

不行,仍旧会弹出窗口

设置成null,直接不高亮显示了

所以还有什么办法呢

使用highlight()就可以了

// featureLayer就是要高亮显示的图层服务
let highlight;
view.on("click", (event) => {
  view.hitTest(event).then((response) => {
    //   console.log("response:", response);
    if (highlight) highlight.remove();
    if (response.results.length) {
      let graphic = response.results.filter((result) => {
        return result.graphic.layer === featureLayer;
      })[0].graphic;
      view.whenLayerView(graphic.layer).then((layerView) => {
        highlight = layerView.highlight(graphic);
      });
    }
  });
});

标签:显示,graphic,高亮,js,arcgis,highlight,response,view
From: https://www.cnblogs.com/echohye/p/16711660.html

相关文章