[英]Open popup on leaflet from outside of map?
我正在使用傳單地圖,當我單擊地圖時,地圖將使用以下代碼在設置的位置打開一個彈出窗口,並以該位置為中心。
var popup = L.popup();
function onMapClick(e) {
popup
.setLatLng([40.737, -73.923])
.setContent("You clicked the map at " + e.latlng.toString())
.openOn(thisLeafletMap);
thisLeafletMap.panTo(new L.LatLng(40.737, -73.923));
}
thisLeafletMap.on('click', onMapClick);
但是我希望上面的代碼在單擊設置的html元素而不是地圖時起作用。
所以我在嘗試類似
$('.lid').click(function() {
//
});
.lid是要單擊的元素,但是我不知道如何正確地聲明該函數,我需要在上述click函數中打開上面的彈出窗口中聲明的彈出窗口嗎?
感謝您的任何幫助
合並它們,我只是把
$('.lid').on('click', onMapClick);
因此,當我單擊div而不是地圖時,查詢就運行了
$('#popupid').click();
然后確保你有
data-rel="popup" in your anchor tag....I just looked at some older code of mine that works, It if that does not do the trick Let me know. I will go find what is missing
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.