I have a leaflet map with popups bound to polygons. On clicking the polygons the pop up only shows the area of the most recently drawn polygon. I thought this was because of the use of 'draw:created' and changed to 'click' but this stops the popup appearing. Original code is as follows:

var polygons = new L.featureGroup();
map.on('draw:created', function(e) {
         var type = e.layerType,
            layer = e.layer;
         if (type === 'polygon') {
            var seeArea = L.GeometryUtil.geodesicArea(layer.getLatLngs()[0]);
            drawnItems.bindPopup('area is '+ (seeArea*0.000247105).toFixed(2) +' acres');
  • 2
    On each drawn polygon you are binding popup to drawnItems layer instead of newly created layer polygon. It should be layer.bindPopup(.....
    – TomazicM
    Dec 8 '21 at 10:57
  • Many thanks that solves it.
    – williamh
    Dec 9 '21 at 9:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.