Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

leaflet popups, setting an on close event

I'm aware you can set an "on popup close" event on the map object in leaflet, is there any way to set that on a per-popup basis?

If I have a layer taken from an event like so...

var layer = event.layer;

var bound = layer.bindPopup(
  "blah",
  {closeButton: false, closeOnClick: false}
);

var popUp = bound.openPopup();

I would like to conditionally set an on-close event for this popup based on a condition. The issue I am facing is that when they draw a shape, I open a popup to allow them to name it. However, if they click on the shape while this popUp is open, it runs the "click" event which opens ANOTHER popup to edit it. I'd like to avoid this and make it so that if they close the first popup without setting a name, it removes the shape entirely.

like image 989
ptr Avatar asked Sep 26 '14 11:09

ptr


1 Answers

There is no an onClose, but there is an onRemove. This is fired when you close the popup:

marker.getPopup().on('remove', function() { //Your code here });

like image 115
Brayan Jaimes Avatar answered Sep 21 '22 12:09

Brayan Jaimes