ArcGIS JS API 4.24中点击多边形外如何打开Popup?
在ArcGIS Maps SDK for JavaScript 4.24中打开Popup的解决方案
在4.24版本里,view.openPopup()方法尚未推出,而view.popup.open()也不支持直接传入包含title、content的配置对象(这种用法是4.27+版本新增的)。你需要通过直接配置Popup实例的属性来实现弹窗显示,以下是两种可行方案:
方式1:直接设置Popup属性并显示
替换你代码中view.openPopup()的部分为以下代码:
// 配置弹窗标题、内容和位置 view.popup.title = "some title"; view.popup.content = "This location is outside the boundary"; view.popup.location = newPoint; // 显示弹窗 view.popup.visible = true;
方式2:通过临时Graphic绑定PopupTemplate
如果需要更贴合ArcGIS的Popup使用逻辑,可以创建一个带PopupTemplate的临时Graphic,再关联到Popup:
// 创建带弹窗模板的临时图形 const tempGraphic = new Graphic({ geometry: newPoint, popupTemplate: { title: "some title", content: "This location is outside the boundary" } }); // 将图形关联到Popup并显示 view.popup.setFeatures([tempGraphic]); view.popup.location = newPoint; view.popup.visible = true;
注意事项
- 确保
boundaryPolygon和newPoint的空间参考一致,否则geometryEngine.contains的判断可能出错。 - 如果之前有打开的Popup,设置新属性后会自动覆盖原有内容。
内容的提问来源于stack exchange,提问作者user1541219
相关产品推荐
相关产品推荐

