I am trying to make a selection via drawing a rectangle (or any shape) with leaflet draw. The selected features should be highlighted. I saw that there are various functions within the leaflet source that could help (contains from Bounds class and _containsPoint from Poly) however I keep getting an error saying that layer does not have this function. I have tried putting the draw layer into a new variable by creating a new L.Polygon object and calling _containsPoint(), but this gives a similar error - saying that the function does not exist for that polygon.
var marker1 = L.marker([51.441767, 5.470247],{
draggable: true
}).addTo(map);
var someLayerGroup = L.featureGroup();
marker1.addTo(someLayerGroup);
map.addControl(new L.Control.Draw({
edit: {
featureGroup: drawnItems,
edit: false
},
draw: {
marker: false,
circlemarker: false,
polyline: false,
circle: false,
polygon: {
allowIntersection: false,
showArea: true
}
}
}));
map.on(L.Draw.Event.CREATED, function (event) {
var layer2 = event.layer;
var type = event.layerType;
if(type==='rectangle'){
//do rectangle specific actions
someLayerGroup.eachLayer(function(layer){
if(layer2.contains(layer)){
//set style of the point
layer.setStyle({fillColor: '#CCCC00'});
}
});
}
drawnItems.addLayer(layer2);
});
JsFiddle: http://jsfiddle.net/ve2huzxw/2109/