Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Edit/delete handler bug. #247

Merged
merged 4 commits into from

2 participants

@manubb

First commit:
When in edit/delete mode, revertLayers has to be called when another handler is clicked on.

To reproduce in http://leaflet.github.io/Leaflet.draw/
-Draw two markers
-Delete one but do not click save/cancel
-Click edit button.

The marker is deleted even though the change was not saved.

Second commit:
-draw:deletestart and draw:deletestop are fired in delete handler instead of draw:editstart and draw:editstop.
-enable and disable functions are reshaped so that a handler cannot be activated while the other is still active.

This is useful when drawLayer has to be updated in some way when entering delete mode and in another way when entering edit mode.

manubb added some commits
@manubb manubb When in edit/delete mode, revertLayers has to be called
when another handler is clicked on.
61c9841
@manubb manubb Reorder code that enable/disable edt/delete handlers.
Add draw:deletestart and draw:deletestop events.
bb4d474
@jacobtoye
Owner

Awesome!

One small issue, could you please pull in the Leaflet.draw upstream to get all changes in the last 3 months so this PR can be automatically merged. There might be conflicts since you fork is out of date.

@jacobtoye jacobtoye merged commit 8ff11e9 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 18, 2013
  1. @manubb

    When in edit/delete mode, revertLayers has to be called

    manubb authored
    when another handler is clicked on.
  2. @manubb

    Reorder code that enable/disable edt/delete handlers.

    manubb authored
    Add draw:deletestart and draw:deletestop events.
  3. @manubb

    Merge remote-tracking branch 'upstream/master'

    manubb authored
    Conflicts:
    	src/edit/EditToolbar.js
  4. @manubb
This page is out of date. Refresh to see the latest.
View
8 src/draw/handler/Draw.Feature.js
@@ -19,11 +19,11 @@ L.Draw.Feature = L.Handler.extend({
enable: function () {
if (this._enabled) { return; }
- L.Handler.prototype.enable.call(this);
-
this.fire('enabled', { handler: this.type });
this._map.fire('draw:drawstart', { layerType: this.type });
+
+ L.Handler.prototype.enable.call(this);
},
disable: function () {
@@ -31,9 +31,9 @@ L.Draw.Feature = L.Handler.extend({
L.Handler.prototype.disable.call(this);
- this.fire('disabled', { handler: this.type });
-
this._map.fire('draw:drawstop', { layerType: this.type });
+
+ this.fire('disabled', { handler: this.type });
},
addHooks: function () {
View
7 src/edit/EditToolbar.js
@@ -107,7 +107,12 @@ L.EditToolbar = L.Toolbar.extend({
this.options.featureGroup.off('layeradd layerremove', this._checkDisabled, this);
},
-
+ _handlerActivated: function (e) {
+ if (this._activeMode && this._activeMode.handler.enabled()) {
+ this._activeMode.handler.revertLayers();
+ }
+ L.Toolbar.prototype._handlerActivated.call(this, e);
+ },
disable: function () {
if (!this.enabled()) { return; }
View
16 src/edit/handler/EditToolbar.Delete.js
@@ -25,28 +25,26 @@ L.EditToolbar.Delete = L.Handler.extend({
if (this._enabled || !this._hasAvailableLayers()) {
return;
}
+ this.fire('enabled', { handler: this.type});
+ //this disable other handlers
- L.Handler.prototype.enable.call(this);
+ this._map.fire('draw:deletestart', { handler: this.type });
+ //allow drawLayer to be updated before beginning deletion.
+ L.Handler.prototype.enable.call(this);
this._deletableLayers
.on('layeradd', this._enableLayerDelete, this)
.on('layerremove', this._disableLayerDelete, this);
-
- this.fire('enabled', { handler: this.type});
- this._map.fire('draw:editstart', { handler: this.type });
},
disable: function () {
if (!this._enabled) { return; }
-
- L.Handler.prototype.disable.call(this);
-
this._deletableLayers
.off('layeradd', this._enableLayerDelete, this)
.off('layerremove', this._disableLayerDelete, this);
-
+ L.Handler.prototype.disable.call(this);
+ this._map.fire('draw:deletestop', { handler: this.type });
this.fire('disabled', { handler: this.type});
- this._map.fire('draw:editstop', { handler: this.type });
},
addHooks: function () {
View
16 src/edit/handler/EditToolbar.Edit.js
@@ -28,28 +28,26 @@ L.EditToolbar.Edit = L.Handler.extend({
if (this._enabled || !this._hasAvailableLayers()) {
return;
}
+ this.fire('enabled', {handler: this.type});
+ //this disable other handlers
- L.Handler.prototype.enable.call(this);
+ this._map.fire('draw:editstart', { handler: this.type });
+ //allow drawLayer to be updated before beginning edition.
+ L.Handler.prototype.enable.call(this);
this._featureGroup
.on('layeradd', this._enableLayerEdit, this)
.on('layerremove', this._disableLayerEdit, this);
-
- this.fire('enabled', {handler: this.type});
- this._map.fire('draw:editstart', { handler: this.type });
},
disable: function () {
if (!this._enabled) { return; }
-
- this.fire('disabled', {handler: this.type});
- this._map.fire('draw:editstop', { handler: this.type });
-
this._featureGroup
.off('layeradd', this._enableLayerEdit, this)
.off('layerremove', this._disableLayerEdit, this);
-
L.Handler.prototype.disable.call(this);
+ this._map.fire('draw:editstop', { handler: this.type });
+ this.fire('disabled', {handler: this.type});
},
addHooks: function () {
Something went wrong with that request. Please try again.