Leaflet / Leaflet.draw

Vector drawing and editing plugin for Leaflet
https://leaflet.github.io/Leaflet.draw/docs/leaflet-draw-latest.html
MIT License
1.97k stars 992 forks source link

can anyone explain how to create holes inside a polygon using leaflet draw? #452

Open sbharadwaj92 opened 9 years ago

badreal commented 8 years ago

+1

SirenHound commented 8 years ago

This is the easiest way I could think of (drawLayer is my editable layergroup)

//make hole
var makeHole = function(poly1, poly2){
  poly1._holes = poly1._holes || [];
    poly1._holes.push(poly2.getLatLngs());
  return poly1;
};
var cookieCut= function(){
  var layers = drawLayer.getLayers();
  if (layers.length > 1){
    newPoly = makeHole(layers[0], layers[1]);
    newPoly.redraw();
  }
};

jsfiddle here: https://jsfiddle.net/Sirenhound/cqbvgp09/