[英]Open popup with an external link generated by html
I have created (via html) a list of links with IDs generated from a database via PHP, 我已经创建了(通过html)带有ID的链接列表,这些ID是通过PHP从数据库生成的,
These links are the same data that is generated in the geoJson that is drawn on the map. 这些链接与在地图上绘制的geoJson中生成的数据相同。
var geojson = L.geoJson(geojsonSample, {
pointToLayer: function(feature, latlng) {
var smallIcon = new L.Icon({
iconSize: [50, 50],
iconAnchor: [13, 27],
popupAnchor: [1, -24],
autoPanPadding: [30,30],
iconUrl: feature.properties.icon.iconUrl
});
return L.marker(latlng, {icon: smallIcon });
},
onEachFeature: function(feature, layer) {
layer._leaflet_id = feature.properties.control;
var popupText = feature.properties.description
layer.bindPopup(popupText)
layer.bindTooltip(feature.properties.title).openTooltip();
}
}).addTo(map);
// markers.addLayer(geojsonAux);
var markers = L.markerClusterGroup();
markers.addLayer(geojson).addTo(map);
map.fitBounds(geojson.getBounds().pad(Math.sqrt(2) /4));
/// geojson example /// geojson示例
var geojsonSample = {
"type": "FeatureCollection",
"features": [{"type":"Feature","geometry":{
"type": "Point",
"coordinates": [
-72,
4
]
},"properties":{
"title": "Espacio Akana",
"category": "Chile",
"icon": {
"iconUrl": "https:\/\/tupale.co\/milfs\/images\/secure\/?file=300\/82afc44d9c358234ebb411f848481ea4.png",
"iconSize": [
60
]
},
"localizacion": "-72 4 15 ",
"control": "69c90579b5cbccc80b09df24057ff82b",
"description": "primera descripcion "
}},{"type":"Feature","geometry":{
"type": "Point",
"coordinates": [
-70.3976891,
-23.64939325
]
},"properties":{
"title": "Teatro Pedro de la Barra",
"category": "Chile",
"icon": {
"iconUrl": "https:\/\/tupale.co\/milfs\/images\/secure\/?file=300\/82afc44d9c358234ebb411f848481ea4.png",
"iconSize": [
60
]
},
"localizacion": "-70.3976891 -23.64939325 16 ",
"control": "7850c035cc53ee5719aa8677fb805ea7",
"description": "segunda descripcion "
}} ]};
/// external html link example ///外部html链接示例
<ul class="list-group ">
<li class="list-group-item"><a id="7850c035cc53ee5719aa8677fb805ea7" href="#" > Teatro Pedro de la Barra</a> </li>
<li class="list-group-item"><a id="69c90579b5cbccc80b09df24057ff82b" href="#" > Espacio Akana</a> </li>
</ul>
How can I make the popup open by calling it from the onclik event of each link? 如何通过在每个链接的onclik事件中调用弹出窗口来使其打开? demo in https://jsfiddle.net/humano/s56fz1u9/53/ 演示在https://jsfiddle.net/humano/s56fz1u9/53/
If I'm right you want to open the marker popup based on the id of the clicked <a>
tag's id. 如果我是对的,您想根据单击的<a>
标签ID的ID打开标记弹出窗口。 You could achieve this either by adding a class to all of your <a>
tags and bindind the below function there or by binding the function dynamicaly to each <a>
tag when you create them. 您可以通过将一个类添加到所有<a>
标记并在那里绑定下面的函数,或者在创建它们时将其动态地绑定到每个<a>
标记来实现此目的。 I've done this and it worked perfect but please note that I haven't tested the below code and some adjustments may be needed. 我已经做到了,并且效果很好,但是请注意,我尚未测试以下代码,可能需要进行一些调整。
function openMarkerPopup(e){
const markerID = e.id;
const marker = markers.getLayer(markerID);
marker.openPopup();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.