Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Rectangle and Circle drawing broken since Leaflet 1.0.0 #108

Merged
merged 1 commit into from
Nov 3, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions src/Leaflet.Editable.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,10 @@

registerForDrawing: function (editor) {
if (this._drawingEditor) this.unregisterForDrawing(this._drawingEditor);
this.map.on('mousemove touchmove', editor.onDrawingMouseMove, editor);
this.blockEvents();
editor.reset(); // Make sure editor tools still receive events.
this._drawingEditor = editor;
this.map.on('mousemove touchmove', editor.onDrawingMouseMove, editor);
this.map.on('mousedown', this.onMousedown, this);
this.map.on('mouseup', this.onMouseup, this);
L.DomUtil.addClass(this.map._container, this.options.drawingCSSClass);
Expand Down Expand Up @@ -1581,6 +1581,15 @@
this.refresh();
this.reset();
// Stop dragging map.
// L.Draggable has two workflows:
// - mousedown => mousemove => mouseup
// - touchstart => touchmove => touchend
// Problem: L.Map.Tap does not allow us to listen to touchstart, so we only
// can deal with mousedown, but then when in a touch device, we are dealing with
// simulated events (actually simulated by L.Map.Tap), which are no more taken
// into account by L.Draggable.
// Ref.: https://github.com/Leaflet/Leaflet.Editable/issues/103
e.originalEvent._simulated = false;
this.map.dragging._draggable._onUp(e.originalEvent);
// Now transfer ongoing drag action to the bottom right corner.
// Should we refine which corne will handle the drag according to
Expand All @@ -1590,9 +1599,16 @@

onDrawingMouseUp: function (e) {
this.commitDrawing(e);
e.originalEvent._simulated = false;
L.Editable.PathEditor.prototype.onDrawingMouseUp.call(this, e);
},

onDrawingMouseMove: function (e) {
e.originalEvent._simulated = false;
L.Editable.PathEditor.prototype.onDrawingMouseMove.call(this, e);
},


getDefaultLatLngs: function (latlngs) {
return latlngs || this.feature._latlngs[0];
},
Expand Down Expand Up @@ -1663,18 +1679,24 @@
this._resizeLatLng.update(e.latlng);
this.feature._latlng.update(e.latlng);
this.connect();
// this.commitDrawing(e);
// Stop dragging map.
e.originalEvent._simulated = false;
this.map.dragging._draggable._onUp(e.originalEvent);
// Now transfer ongoing drag action to the radius handler.
this._resizeLatLng.__vertex.dragging._draggable._onDown(e.originalEvent);
},

onDrawingMouseUp: function (e) {
this.commitDrawing(e);
e.originalEvent._simulated = false;
L.Editable.PathEditor.prototype.onDrawingMouseUp.call(this, e);
},

onDrawingMouseMove: function (e) {
e.originalEvent._simulated = false;
L.Editable.PathEditor.prototype.onDrawingMouseMove.call(this, e);
},

onDrag: function (e) {
L.Editable.PathEditor.prototype.onDrag.call(this, e);
this.feature.dragging.updateLatLng(this._resizeLatLng);
Expand Down