How to determine if polygons overlap in a flyer
I am using sheet drawing to create polygons. My requirement is when the user draws a polygon, it should not intersect / overlap with existing polygons. I have used a point in the polygon leaflet to determine if the point falls within the polygon and it works, but the problem is I cannot tell if the line intersects other polygons. In this case, the points lie outside the existing polygons, but there is overlap.
The below attached image may give a better picture!
source to share
In the leaflet.draw file, you can pass parameters to individual drawing handlers. One allowIntersection
is a boolean type that "Determines if line segments can intersect."
Your options would look something like this (excerpt from configletletlet.draw ):
var options = {
position: 'topright',
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: '#bada55'
}
},
},
edit: {
featureGroup: editableLayers, //REQUIRED!!
remove: false
}
};
var drawControl = new L.Control.Draw(options);
map.addControl(drawControl);
source to share
Perhaps you can also use Terraformer Core , which is an open source project created by the people at ESRI. You would probably do something like this:
var polygon = new Terraformer.Primitive({ "type": "Polygon", "coordinates": [ [ [ -101.46972656250001, 34.125447565116126 ], [ -100.85449218750001, 33.760882000869195 ], [ -101.09619140625, 33.19273094190692 ], [ -102.12890625000001, 33.137551192346145], [ -102.19482421875, 33.63291573870479 ], [ -101.46972656250001, 34.125447565116126 ] ] ] }); var intersects = polygon.intersects({ "type": "Polygon", "coordinates": [ [ [ -103.32539, 30.58608 ], [ -102.32083, 29.87894 ], [ -103.32539, 30.58608 ] ] ] }); // intersects is a bool.
source to share