【问题标题】:Change the content of map pop up real time, Leaflet js实时更改地图弹出内容,Leaflet js
【发布时间】:2014-05-27 20:09:28
【问题描述】:

在 Leaflet 中,我显示了一张地图,其中弹出显示有关所选区域的信息。 这是我的代码

L.geoJson(territories, {
    style: function(feature) {
          return {color: "#328CFA"};
    }
}).bindPopup(poupcontent).addTo(map);

变量 poupcontent 具有要在弹出窗口中显示的数据。 我的站点中有一些过滤选项。 现在我需要根据应用的过滤器实时过滤弹出窗口中显示的内容。

【问题讨论】:

    标签: javascript leaflet


    【解决方案1】:

    弹出窗口是一个纯 HTML,它被动态插入到页面中,并且可以包含在例如<div id="popupcontent">...</div> 中。有了它,您可以使用document.getElementById('popupcontent').innerHTML 访问内容并根据需要进行更改。

    【讨论】:

      【解决方案2】:

      我找到了更好的答案。在过滤器函数中调用 bindpopup 函数对我有用。即

      var territories = L.geoJson(territories, {
          style: function(feature) {
                return {color: "#328CFA"};
          }
      }).addTo(map);
      
      territories.bindPopup(poupcontent);
      

      使用新内容在过滤器函数内调用territories.bindPopup(newpoupcontent);

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-11-15
        • 2017-09-05
        • 2017-09-14
        • 1970-01-01
        • 2020-06-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多