Open nmccready opened 8 years ago
From @Martijnvl on March 29, 2014 21:11
I got that same issue, maybe someone can help use out with a working example. Much tnx
From @ninniuz on April 3, 2014 16:9
As a workaround I had to create a L.Control.Draw
in my controller, define options there and add a drawnItems
in my scope.
var drawnItems = new L.FeatureGroup();
var options = { edit: { featureGroup: drawnItems } };
var drawControl = new L.Control.Draw(options);
angular.extend($scope, controls: { custom: [drawControl] });
Then simply add the layer to drawnItems when you get the draw:created
event.
From @Martijnvl on April 7, 2014 21:11
I did they exact same thing but for some reason when I draw a circle for example I don't see it getting painted on the layer...see my ctrl code below. I placed the css files inside my index.html. I can't figure out why this isn't working. I do see that the layer gets added to drawitems but nothing shows on map. Any help would be appreciated.
var drawnItems = new L.FeatureGroup();
var options = {
edit: { featureGroup: drawnItems
},
draw: {
polygon: {
shapeOptions: {
color: 'purple'
}
},
circle: {
shapeOptions: {
stroke: true,
weight: 4,
color: 'blue',
opacity: 0.5,
fill: true,
fillColor: null, //same as color by default
fillOpacity: 0.2,
clickable: true
}
}
},
showRadius: true
};
var drawControl = new L.Control.Draw(options);
angular.extend($scope, {
defaults: {
scrollWheelZoom: false
},
london: {
lat: 51.505,
lng: -0.09,
zoom: 8
},
controls: {
custom: [drawControl]
}
});
leafletData.getMap().then(function (map) {
map.on('draw:created', function (e) {
var type = e.layerType,
layer = e.layer;
if (type === 'circle') {
console.log(JSON.stringify(layer.toGeoJSON()));
}
drawnItems.addLayer(layer);
});
});
From @muenchdo on April 24, 2014 13:23
@Martijnvl Is it possible that you have missed adding the drawnItems
to your map? I did it like this:
leafletData.getMap().then(function(map) {
map.addLayer(drawnItems);
});
Now I can at least add new shapes to the map. But somehow I have some strange issues with the editing functionality. Sometimes I can edit, but after adding a new shape the editing button is suddenly disabled. Then, after adding another shape, editing is suddenly possible again. I haven't been able to track down the reason for this behaviour.
EDIT: I have further investigated my issues and it seems that every time I add a new shape, the editing toolbar is toggled. Does anybody have any ideas what could be causing this?
From @aaronsharper on March 26, 2014 2:33
Trying to get the Leaflet.draw controls to work correctly. I can get the controls to show up on the map, and I can detect when the "draw:created" event is triggered, but when the layer is added to the map, the edit functionality doesn't work. I am guessing this is because I am supposed to add the layer to the "drawnItems" featureGroup, but that doesn't seem available from the directive in my controller. Am I missing something? Is there a way to get the declared "drawnItems" value from the directive from my controller? I am sure this is user error on my part.
Thanks in advance.
Copied from original issue: tombatossals/angular-leaflet-directive#344