代码之家  ›  专栏  ›  技术社区  ›  asgallant

Esri映射PopupTemplate的内容方法,每个功能只调用一次

  •  4
  • asgallant  · 技术社区  · 7 年前

    PopupTemplate content 方法:

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

    这是很好的,除非在一个给定的点上有多个特性。当用户在这些特性之间循环时,如果他/她返回到已经显示的特性,则不会执行content方法,因此不会发布弹出数据。

    MapView

    mapView.popup.watch('selectedFeature', (graphic: __esri.Graphic) => {
      const layer = ???;
      this.publishPopupData(layer, graphic.attributes);
    });
    

    名义上, graphic.layer 应该包含层引用,但是在我的例子中它总是 null .

    MapView.popup (或者其他我没有考虑过的事情)?

    如果重要的话,弹出窗口是为了 MapImageLayer

    1 回复  |  直到 6 年前
        1
  •  0
  •   Below the Radar    6 年前

    很正常 content popupComponent 每次 函数被调用。相反, this.publishPopupData() 应该返回一些要添加到 .

    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... 
    });