繁体   English   中英

Leaflet js实时更改地图弹出内容

[英]Change the content of map pop up real time, Leaflet js

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

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

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

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

我找到了一个更好的答案。在filter函数内调用bindpopup函数将对我有用。

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

territories.bindPopup(poupcontent);

调用territories.bindPopup(newpoupcontent); 在带有新内容的过滤器功能中

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM