Skip to content

Commit

Permalink
Fix #1 by firing draw:edited and draw:deleted events from popup edit …
Browse files Browse the repository at this point in the history
…actions.
  • Loading branch information
justinmanley committed Oct 25, 2017
1 parent 3683213 commit 962edd4
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/edit/popup/actions/EditAction.Popup.Delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ LeafletToolbar.EditAction.Popup.Delete = LeafletToolbar.ToolbarAction.extend({
},

addHooks: function () {
this._map.removeLayer(this._shape);
this._map.removeLayer(this.toolbar);
var map = this._map;

map.removeLayer(this._shape);
map.removeLayer(this.toolbar);

console.log('firing draw:deleted');
map.fire(L.Draw.Event.DELETED, { layers: L.layerGroup([this._shape]) });
}
});
13 changes: 12 additions & 1 deletion src/edit/popup/actions/EditAction.Popup.Edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,18 @@ LeafletToolbar.EditAction.Popup.Edit = LeafletToolbar.ToolbarAction.extend({
map.removeLayer(this.toolbar);

map.on('click', function () {
this.save();
shape.editing.disable();
});
}, this);
},

save: function() {
var map = this._map,
shape = this._shape;

if (shape.edited) {
map.fire(L.Draw.Event.EDITED, { layers: L.layerGroup([shape]) });
}
shape.edited = false;
}
});
28 changes: 28 additions & 0 deletions test/src/EditActionPopupDeleteSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
describe("LeafletToolbar.EditAction.Popup.Delete", function() {
beforeEach(function() {
var container = document.createElement('div');
container.id = 'map';
document.body.appendChild(container);
});

it("Should fire a draw:deleted event when completed.", function(done) {
var map = L.map('map'),
shape = L.circle([0, 0], { radius: 1 }),
deleteAction = new LeafletToolbar.EditAction.Popup.Delete(map, shape);

// Necessary so that the popup delete action can remove its toolbar.
deleteAction.toolbar = new LeafletToolbar();

map.on('draw:deleted', function(evt) {
expect(evt.layers.hasLayer(shape)).to.equal(true);
done();
});

deleteAction.enable();
});

afterEach(function() {
var container = document.getElementById('map');
container.parentNode.removeChild(container);
});
});
30 changes: 30 additions & 0 deletions test/src/EditActionPopupEditSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
describe("LeafletToolbar.EditAction.Popup.Edit", function() {
beforeEach(function() {
var container = document.createElement('div');
container.id = 'map';
document.body.appendChild(container);
});

it("Should fire a draw:edited event when completed.", function(done) {
var map = L.map('map'),
shape = L.circle([0, 0], { radius: 1 }),
editAction = new LeafletToolbar.EditAction.Popup.Edit(map, shape);

// Necessary so that the popup delete action can remove its toolbar.
editAction.toolbar = new LeafletToolbar();

map.on('draw:edited', function(evt) {
expect(evt.layers.hasLayer(shape)).to.equal(true);
done();
});

editAction.enable();
shape.edited = true;
editAction.save();
});

afterEach(function() {
var container = document.getElementById('map');
container.parentNode.removeChild(container);
});
});

0 comments on commit 962edd4

Please sign in to comment.