1

I am trying to get the layer details of the map which are already overlay on the map. When leaflet draw is created I want to get the layer details (Not the polygon coordinates created by leaflet draw plugin) so that I can use them. I am able to get the coordinates of drawn polygon but that's not what I want.

var draw_layer = new L.FeatureGroup();
mymap.addLayer(draw_layer);
var drawControlFull = new L.Control.Draw({
    draw: {
        polygon: {
          allowIntersection: false, // Restricts shapes to simple polygons
          drawError: {
            color: '#e1e100', // Color the shape will turn when intersects
            message: '<strong>Oh snap!<strong> you can\'t draw that!' // Message that will show when intersect
          },
          shapeOptions: {
            color: '#97009c'
          }
        },
        // disable toolbar item by setting it to false
        polyline: false,
        circle: false,
        rectangle: false,
        marker: false,
        circlemarker: false
        },

    edit: {
        featureGroup: draw_layer,
        remove: true
    }
});
mymap.addControl(drawControlFull);

mymap.on(L.Draw.Event.CREATED, function (e) {
    var type = e.layerType, layer = e.layer;
    
    if(type === 'polygon'){
        var _ajax_cords = [];
        var _coords = layer.getLatLngs()[0];
        $.each(_coords,function(ind,val){
            var _te_co = {x : val.lat, y : val.lng};
            _ajax_cords.push(_te_co);
        });
    }
    
    //if (type === 'polygon') {layer.bindPopup('A popup!');}draw_layer.addLayer(layer);
});

Well I can get the marker detail as I get lot of posts on that but didn't see a post how to get the polygon details.

enter image description here

Any help on this is much appreciable

Saroj
  • 1,343
  • 4
  • 15
  • 31
  • 1
    You can use the more modern Draw Tool [Leaflet-Geoman](https://github.com/geoman-io/leaflet-geoman) and then call `map.pm.getGeomanDrawLayers()` – Falke Design Feb 20 '21 at 18:27
  • @FalkeDesign I tried this, but it halts my page for no reason when I try to overlay some tooltip on the map. – Saroj Feb 22 '21 at 12:35
  • can you create a demo? this is weird ... – Falke Design Feb 22 '21 at 14:45
  • @Saroj did you get any luck on finding the answer for this? – Sunali Bandara Jun 03 '22 at 14:26
  • @SunaliBandara yes I used geoserver for it where I saved block shape file and did some geoserver function to get the intersect of it. Or you can use turf js https://turfjs.org/docs/#pointsWithinPolygon – Saroj Jun 05 '22 at 05:49

0 Answers0