Esri地图PopupTemplate的content方法每个要素只调用一次。

5

我正在Angular应用程序中使用Esri地图,将我的弹出窗口呈现为使用PopupTemplatecontent方法发布数据的Angular组件:

layer.popupTemplate = new PopupTemplate({
  content: (feature: { graphic: __esri.Graphic }) => {
    this.publishPopupData(layer, feature.graphic.attributes);
    return popupComponent.viewContainerRef.element.nativeElement;
  },
  // other properties... 
});

除了在一个点上有多个要素的情况下,它都能很好地工作。当用户浏览要素时,如果返回到已经显示过的要素,则内容方法不会执行,因此弹出窗口数据不会发布。
我可以访问MapView的弹出窗口上当前选定的要素,但我需要知道该要素来自哪个图层,以便正确地发布数据(每个图层对将ArcGIS数据处理为弹出窗口使用的模型都有独特的要求)。
mapView.popup.watch('selectedFeature', (graphic: __esri.Graphic) => {
  const layer = ???;
  this.publishPopupData(layer, graphic.attributes);
});

通常情况下,graphic.layer应该包含图层引用,但在我的情况下它始终为null

是否有一种方法可以强制弹出窗口总是调用内容方法,即使它已经针对给定要素执行过?或者,是否有一种方法可以从MapView.popup(或其他我未考虑的内容)中获取要素所属的图层?

如果有关系,这些弹出窗口是为MapImageLayer子图层准备的。

1个回答

0

当您返回已经显示过的功能弹出窗口时,content函数不会再次调用是正常的。我认为问题在于每次调用content函数时,您都在覆盖popupComponent变量。相反,this.publishPopupData()应该返回一个您将添加到新的HTML元素中的内容。

我会提供JavaScript答案,因为我不太了解TypeScript:

layer.popupTemplate = new PopupTemplate({
  content: function(graphic) {
    var popupElement = document.createElement("div");
    //use popupElement.innerHTML if this.publishPopupData() returns a string or use popupElement.appendChild() if it's an html element
    popupElement.innerHTML = this.publishPopupData(layer, graphic.attributes); 
    return popupElement;
  },
  // other properties... 
});

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接