我从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);
答案 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