Skip to content

Commit

Permalink
add edit-action for clear all layers
Browse files Browse the repository at this point in the history
  • Loading branch information
boeckMt committed Jan 12, 2017
1 parent b57b22c commit 9eded86
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Leaflet.draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ L.drawLocal = {
cancel: {
title: 'Cancel editing, discards all changes.',
text: 'Cancel'
},
clearAll:{
title: 'clear all layers.',
text: 'clearAll'
}
},
buttons: {
Expand Down
14 changes: 14 additions & 0 deletions src/edit/EditToolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ L.EditToolbar = L.Toolbar.extend({
text: L.drawLocal.edit.toolbar.actions.cancel.text,
callback: this.disable,
context: this
},
{
title: L.drawLocal.edit.toolbar.actions.clearAll.title,
text: L.drawLocal.edit.toolbar.actions.clearAll.text,
callback: this._clearAllLayers,
context: this
}
];
},
Expand Down Expand Up @@ -134,6 +140,14 @@ L.EditToolbar = L.Toolbar.extend({
}
},

_clearAllLayers:function(){
//console.log(this._activeMode.handler)
this._activeMode.handler.removeAllLayers();
if (this._activeMode) {
this._activeMode.handler.disable();
}
},

_checkDisabled: function () {
var featureGroup = this.options.featureGroup,
hasLayers = featureGroup.getLayers().length !== 0,
Expand Down
10 changes: 10 additions & 0 deletions src/edit/handler/EditToolbar.Delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ L.EditToolbar.Delete = L.Handler.extend({
this._map.fire(L.Draw.Event.DELETED, { layers: this._deletedLayers });
},

// @method removeAllLayers(): void
// Remove all delateable layers
removeAllLayers: function(){
// Iterate of the delateable layers and add remove them
this._deletableLayers.eachLayer(function (layer) {
this._removeLayer({layer:layer});
}, this);
this.save();
},

_enableLayerDelete: function (e) {
var layer = e.layer || e.target || e;

Expand Down

0 comments on commit 9eded86

Please sign in to comment.