繁体   English   中英

如何使用href从数据geojson打开传单标记弹出窗口

[英]How to open leaflet marker popup from data geojson with href

我从geojson获得markers和数据popups

我想从href打开一个特定的popup 我需要您使用其ID或其他方式打开弹出窗口。

我看到了这个示例,但是我不知道如何在代码中实现它。

这是我的示例geojson数据

{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Point","coordinates":[-67.9283981,10.1497326]},"properties":{"id":107,"text":"Marker 1"}}

这是我的代码

$.getJSON('get_mapa_getjon.php', function(data) {
    var geojson = L.geoJson(data, {
        onEachFeature: function (feature, layer) {
            layer.bindPopup(feature.properties.id + '<br />' + feature.properties.text);
            }
    });
geojson.addTo(map);

您需要以这种方式geojson层并检查诸如id类的要素属性

geojson.eachLayer(function(feature){ //geojson is the object which have your data

    if(feature.feature.properties.id=='required-id'){ //insert the id in place of 'required-id'
        feature.openPopup(); //open popup for matching ID
    }
    //remove the below line if you have multiple features with same ID
    break;//exit loop once it opens the popup
});

这是一个工作的小提琴

暂无
暂无

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

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