I have a Leaflet map with a featureGroup, a layerGroup and drawControl however only the featureGroup is editable using the drawControl.
I think its because the layerGroup is separate from the featureGroup rather than a layer within it. Instead of .addTo(map) I have tried new L.layerGroup().addTo(drawnItems) but to no avail.
My html code is:
var LeafIcon = L.Icon.extend({ options: { iconSize: [51.7, 25.3], iconAnchor: [11, 46], } }); var myIcon1 = new LeafIcon({iconUrl: 'images/s1.png'}), myIcon2 = new LeafIcon({iconUrl: 'images/s2.png'}), myIcon3 = new LeafIcon({iconUrl: 'images/s3.png'}), myIcon4 = new LeafIcon({iconUrl: 'images/s4.png'}), myIcon5 = new LeafIcon({iconUrl: 'images/s5.png'}), myIcon6 = new LeafIcon({iconUrl: 'images/s6.png'}), myIcon7 = new LeafIcon({iconUrl: 'images/s7.png'}), myIcon8 = new LeafIcon({iconUrl: 'images/s8.png'}), myIcon9 = new LeafIcon({iconUrl: 'images/s9.png'}), myIcon10 = new LeafIcon({iconUrl: 'images/s10.png'}), myIcon11 = new LeafIcon({iconUrl: 'images/s11.png'}), myIcon12 = new LeafIcon({iconUrl: 'images/s12.png'}), myIcon13 = new LeafIcon({iconUrl: 'images/s13.png'}), myIcon14 = new LeafIcon({iconUrl: 'images/s14.png'}), myIcon15 = new LeafIcon({iconUrl: 'images/s15.png'}); //adds drawn items layer var drawnItems = new L.FeatureGroup().addTo(map); //adds site tags layer var sitetagItems = new L.layerGroup().addTo(map); //add drawing tools to map and default polygons to red once zoomed and circle to default to blue map.drawControl = new L.Control.Draw({ draw: { rectangle: false, polygon: { shapeOptions: { color: 'red' }, allowIntersection: false, drawError: { color: 'orange', timeout: 1000 }, showArea: true, metric: true, repeatMode: true }, circlemarker:{ metric: true, radius: 343, color:'blue', fill:false } }, edit: { featureGroup: drawnItems, layerGroup: sitetagItems, } }); map.addControl(map.drawControl); map.on('draw:created', function(e) { e.layer.addTo(drawnItems); }) function Action1(){var bounds = map.getBounds();var center = bounds.getCenter();L.marker([center.lat,center.lng], {icon: myIcon1}).addTo(sitetagItems);};
layerGroupoption ineditoption ofL.Control.Drawcontrol. You can edit only features from feature group that is specified infeatureGroupoption.