You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ArcGIS JS API 4.27升级后view.popup.watch报错,求替代方案

ArcGIS JavaScript API 4.27 替代弃用的 popup.watch 方法

在ArcGIS JavaScript API 4.27版本中,Popup对象不再继承Accessor类,原watch方法被移除,因此会出现view.popup.watch is not a function的报错。替代方案如下:

原报错代码

view.popup.watch("selectedFeature", (graphic) => {
  // 原有业务逻辑
});

替代实现

使用selected-feature-change事件监听来替代原watch逻辑:

view.popup.on("selected-feature-change", (event) => {
  const graphic = event.selectedFeature;
  // 这里编写原watch回调中的业务逻辑
});

额外说明

  • 事件参数event包含selectedFeature属性,与原watch监听的属性值完全对应
  • 若需要移除该监听,可调用view.popup.removeEventListener("selected-feature-change", 回调函数)

内容的提问来源于stack exchange,提问作者Robert Smith

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 00:37:01