简体   繁体   English

从地图外部打开传单弹出窗口吗?

[英]Open popup on leaflet from outside of map?

I am using leaflet maps, when I click on the map the map will open a popup in a set place and center on the location using the following code. 我正在使用传单地图,当我单击地图时,地图将使用以下代码在设置的位置打开一个弹出窗口,并以该位置为中心。

  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);

However I want the above code to work when a set html element is clicked rather than the map. 但是我希望上面的代码在单击设置的html元素而不是地图时起作用。

So I was trying something like 所以我在尝试类似

  $('.lid').click(function() {
 // 
  });

Where .lid is the element to be clicked, but I do not know how to declare the function properly, what would I need to put in the above click function to open the popup as declared in the popup above? .lid是要单击的元素,但是我不知道如何正确地声明该函数,我需要在上述click函数中打开上面的弹出窗口中声明的弹出窗口吗?

Thank you for any help 感谢您的任何帮助

to merge them I just put 合并它们,我只是把

   $('.lid').on('click', onMapClick);

So the query ran when I clicked th div instead of the map 因此,当我单击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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM