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

通常我们查看图层服务是否支持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);
      });
    }
  });
});
posted @ 2022-09-20 16:52  槑孒  阅读(525)  评论(0编辑  收藏  举报