I\'ve draw polyline programmatically (not using leaflet draw) inside polygone using leaflet draw plugin on map, I want to keep only the points of polyline that are inside of pol
I'm working with turfjs to check for overlapping polygones in leaflet.
map.on('draw:created', function (e) {
var intersection = [];
otherPolysLayer.eachLayer(function (layer) {
if (!_.isUndefined(turf.intersect(e.layer.toGeoJSON(), ))) {
intersection.push(layer);
}
})
});
You could change the above so that instead it checks for the entire polygone, you'd check with the difference method.
difference: Finds the difference between two polygons by clipping the second polygon from the first.
I've been looking for a good while for a decent library and looked into leaflet-pip, kevlindev amongst others but I find that turf really just works out of the box.
Update
http://jsfiddle.net/ddce1wh5/ how about this? I used intersect, because that is apparently the part you'd like to keep, I misread, apologies. The following http://jsfiddle.net/mcqL1y90/ we use an array of lines that uses either the intersecting line, or if no intersection is taking place it takes the line itself to draw on the map.