5

我在 Angular 应用程序中使用 Esri 地图,并将弹出窗口呈现为 Angular 组件,其中包含从PopupTemplate'scontent方法发布的数据:

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.

有没有办法强制弹出窗口始终调用 content 方法,即使它已经为给定的功能执行过?或者,有没有办法从MapView.popup(或我没有考虑过的其他东西)获取功能所属的图层?

如果重要,弹出窗口用于MapImageLayer子层。

4

1 回答 1

0

content当您返回已显示的功能弹出窗口时,不会再次调用该函数是正常的。我认为问题在于popupComponent每次content调用函数时都会覆盖变量。相反,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... 
});
于 2019-02-14T20:11:30.783 回答