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

How to open leaflet marker popup from data geojson with href

我从 geojson 得到 markers 和数据 popups

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

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

这是我的样本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
});

这是一个有效的 fiddle