L.Popup doesn't fire 'popupclose' event when using multipolygon features
See original GitHub issueNot sure what the logic is, but I have a GeoJSON layer which I switched from a standard polygon dataset to an aggregate (multipart / multipolygon) polygon dataset. I have a listener for popupclose:
popup.on('popupclose', function(e) {
...
});
… which stopped working when I made the switch, and worked fine again when I switched back.
No errors are thrown to the user when it fails, the event just doesn’t get fired.
Firefox / Windows / v0.6 beta (downloaded 8th May), and the problem also occurs in IE8. In 0.5.1 neither works, so I couldn’t create a working demo in JSFiddle, but if you paste the code below into a test website and alternate between the two GeoJSON examples, you should see what I mean:
<link rel="stylesheet" href="libs/leaflet/leaflet.css">
<script src="libs/leaflet/leaflet.js"></script>
<div id="map" style="height: 300px"></div>
<script>
var map = new L.Map("map", {
center: new L.LatLng(1, 1),
zoom: 14
});
var geojson = {"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[1.001,1.001],[1.001,0.999],[0.999,0.999],[0.999,1.001],[1.001,1.001]]]},"properties":{"works": "My close event works fine..."}}]};
//var geojson = {"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"MultiPolygon","coordinates":[[[[1.001,1.001],[1.001,0.999],[0.999,0.999],[0.999,1.001],[1.001,1.001]]]]},"properties":{"works": "Mine doesn't..."}}]};
var lyr = L.geoJson(geojson, {
style: { weight : 1 },
onEachFeature : function(feature, layer) {
var popup = layer.bindPopup(feature.properties.works);
popup.on("popupclose", function(e) {
alert("Hi!");
});
}
}).addTo(map);
</script>
Issue Analytics
- State:
- Created 10 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
Why is my Leaflet popup closing unexpectedly? - Stack Overflow
I believe your animated setView is closing out the popup as part of the moveend event. Instead, try using this code for the...
Read more >Leaflet ignore click event when popup is open
When the popup is closed the props are shown in a fixed tooltip over the polygon. However, the popup always opens and closes...
Read more >Documentation - a JavaScript library for interactive maps
Creates a popup with the specified content and options and opens it in the given point on a map. closePopup(<Popup> popup?) this. Closes...
Read more >L.Polygon - WRLD3D
A class for drawing polygon overlays on a map. Extends Polyline . Note that points you pass when creating a polygon shouldn't have...
Read more >Breaking changes | ArcGIS Maps SDK for JavaScript 4.25
The following classes, methods, properties and events have been ... Popups using a default template will now display attachments as thumbnail images instead ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The event listener is on the map object. Here is what worked for me.
map.on(‘popupclose’, function(e){ console.log(‘popup closed’); });
I am using leaflet 1.7.1 and there is a
remove
event inpopup
s. I’m not sure if this is the same event aspopupclose
but it works for me: