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

时间:2015-07-06 03:41:42

标签: javascript jquery leaflet mapbox

我从markers获得popups和数据geojson

我想从popup打开一个特定的href。我需要你用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);

1 个答案:

答案 0 :(得分:1)

您需要遍历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