From 95c73a3d775614c69b7fecf817bdd8d2020ffcb2 Mon Sep 17 00:00:00 2001 From: snkashis Date: Thu, 28 Feb 2013 10:38:27 +0000 Subject: [PATCH 1/4] handle drag handlers properly to avoid errors if moving while removed. --- debug/map/remove_while_dragging.html | 29 ++++++++++++++++++++++++++++ src/dom/Draggable.js | 4 ++++ src/layer/marker/Marker.js | 4 ++++ 3 files changed, 37 insertions(+) create mode 100644 debug/map/remove_while_dragging.html diff --git a/debug/map/remove_while_dragging.html b/debug/map/remove_while_dragging.html new file mode 100644 index 00000000..6da80b53 --- /dev/null +++ b/debug/map/remove_while_dragging.html @@ -0,0 +1,29 @@ + + + + Leaflet debug page + + + + + + + + + + + +
+ + + + \ No newline at end of file diff --git a/src/dom/Draggable.js b/src/dom/Draggable.js index 4c8c53d3..ac0cea50 100644 --- a/src/dom/Draggable.js +++ b/src/dom/Draggable.js @@ -37,6 +37,10 @@ L.Draggable = L.Class.extend({ disable: function () { if (!this._enabled) { return; } + + this.off('dragstart', this._onDragStart) + .off('drag', this._onDrag) + .off('dragend', this._onDragEnd); for (var i = L.Draggable.START.length - 1; i >= 0; i--) { L.DomEvent.off(this._dragStartTarget, L.Draggable.START[i], this._onDown, this); diff --git a/src/layer/marker/Marker.js b/src/layer/marker/Marker.js index 2c3a76a8..64bb44cd 100644 --- a/src/layer/marker/Marker.js +++ b/src/layer/marker/Marker.js @@ -41,6 +41,10 @@ L.Marker = L.Class.extend({ }, onRemove: function (map) { + if (this.dragging) { + this.dragging.removeHooks(); + } + this._removeIcon(); this.fire('remove'); From ed08a5b1dc1df7930c9cd0449cd81e2818846d21 Mon Sep 17 00:00:00 2001 From: snkashis Date: Thu, 28 Feb 2013 10:46:54 +0000 Subject: [PATCH 2/4] call disable, not removeHooks --- src/layer/marker/Marker.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/layer/marker/Marker.js b/src/layer/marker/Marker.js index 64bb44cd..5c0687f0 100644 --- a/src/layer/marker/Marker.js +++ b/src/layer/marker/Marker.js @@ -42,7 +42,7 @@ L.Marker = L.Class.extend({ onRemove: function (map) { if (this.dragging) { - this.dragging.removeHooks(); + this.dragging.disable(); } this._removeIcon(); From 71167baa52448f30e4d66509ff07039075cd2898 Mon Sep 17 00:00:00 2001 From: snkashis Date: Thu, 28 Feb 2013 10:47:39 +0000 Subject: [PATCH 3/4] move test location --- debug/{map => tests}/remove_while_dragging.html | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename debug/{map => tests}/remove_while_dragging.html (100%) diff --git a/debug/map/remove_while_dragging.html b/debug/tests/remove_while_dragging.html similarity index 100% rename from debug/map/remove_while_dragging.html rename to debug/tests/remove_while_dragging.html From 1df4c4a98f7250348d4feb38bb6bddf070378a28 Mon Sep 17 00:00:00 2001 From: snkashis Date: Thu, 28 Feb 2013 11:01:26 +0000 Subject: [PATCH 4/4] work with handlers in right place --- src/dom/Draggable.js | 4 ---- src/layer/marker/Marker.Drag.js | 5 +++++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/dom/Draggable.js b/src/dom/Draggable.js index ac0cea50..4c8c53d3 100644 --- a/src/dom/Draggable.js +++ b/src/dom/Draggable.js @@ -37,10 +37,6 @@ L.Draggable = L.Class.extend({ disable: function () { if (!this._enabled) { return; } - - this.off('dragstart', this._onDragStart) - .off('drag', this._onDrag) - .off('dragend', this._onDragEnd); for (var i = L.Draggable.START.length - 1; i >= 0; i--) { L.DomEvent.off(this._dragStartTarget, L.Draggable.START[i], this._onDown, this); diff --git a/src/layer/marker/Marker.Drag.js b/src/layer/marker/Marker.Drag.js index 93786d41..822f5dac 100644 --- a/src/layer/marker/Marker.Drag.js +++ b/src/layer/marker/Marker.Drag.js @@ -19,6 +19,11 @@ L.Handler.MarkerDrag = L.Handler.extend({ }, removeHooks: function () { + this._draggable + .off('dragstart', this._onDragStart) + .off('drag', this._onDrag) + .off('dragend', this._onDragEnd); + this._draggable.disable(); },