Leaflet will become even better if you add …

An API function to close a popup. At the moment I'm using `popup._close()`

Perhaps there are better ways entirely around it but here's a hack I'm currently using:

var popup;

popup = L.popup();
map.on('click', function(event) {
popup
.setLatLng(event.latlng)
.setContent($('#wanna-edit').html())
.openOn(map);
$('#map').on('keypress', function(e) {
e.which == 0 && popup._close();
});
});

7 votes
Vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    Peter Bengtsson shared this idea  ·   ·  Admin →

    2 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      Signed in as (Sign out)
      Submitting...
      • Ramadan Alrai commented  · 

        Thanks for this notice: map.closePopup() I 've been looking for this statement, to close the popup window.

      • Chris commented  · 

        I am missing more popup functions too, map.closePopup() is totally worthless when creating multiple popups with popup.addTo(map), also would be nice to overwrite close button function or have an domready event on the popup content... :)

      Feedback and Knowledge Base