[英]How to open leaflet marker popup from data geojson with href
I get markers
and data popups
from geojson
. 我从
geojson
获得markers
和数据popups
。
I want to open a specific popup
from href
. 我想从
href
打开一个特定的popup
。 I need you to open popup using its ID
or another way. 我需要您使用其
ID
或其他方式打开弹出窗口。
I saw this example but I don't know how can I implement it in my code. 我看到了这个示例,但是我不知道如何在代码中实现它。
Here is my sample geojson
data 这是我的示例
geojson
数据
{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Point","coordinates":[-67.9283981,10.1497326]},"properties":{"id":107,"text":"Marker 1"}}
and here is my code 这是我的代码
$.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);
You need to loop over the geojson
layer and check for feature property like id
in our case this way 您需要以这种方式
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.