nakarte

Source code of https://map.sikmir.ru (fork)
git clone git://git.sikmir.ru/nakarte
Log | Files | Refs | LICENSE

commit dc68ddd3a6b601fa7b50c5ee8cf64c5980339943
parent 11ebfbb333caf4b52f759f898352747fc83f6431
Author: Sergej Orlov <wladimirych@gmail.com>
Date:   Wed,  2 Aug 2017 01:12:57 +0300

[tracks edit] after pressing Enter/Esc remove tracks with single point in single line

Diffstat:
Msrc/lib/leaflet.control.track-list/track-list.js | 9++++++---
Msrc/lib/leaflet.polyline-edit/index.js | 9+++++----
2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/src/lib/leaflet.control.track-list/track-list.js b/src/lib/leaflet.control.track-list/track-list.js @@ -561,8 +561,8 @@ L.Control.TrackList = L.Control.extend({ } polyline.startEdit(); this._editedLine = polyline; - polyline.once('editend', function() { - setTimeout(this.onLineEditEnd.bind(this, track, polyline), 0); + polyline.once('editend', function(e) { + setTimeout(this.onLineEditEnd.bind(this, e, track, polyline), 0); }.bind(this) ); this.fire('startedit'); @@ -642,7 +642,7 @@ L.Control.TrackList = L.Control.extend({ }, - onLineEditEnd: function(track, polyline) { + onLineEditEnd: function(e, track, polyline) { if (polyline.getLatLngs().length < 2) { track.feature.removeLayer(polyline); } @@ -650,6 +650,9 @@ L.Control.TrackList = L.Control.extend({ if (this._editedLine === polyline) { this._editedLine = null; } + if (!this.getTrackPolylines(track).length && !this.getTrackPoints(track).length && e.userCancelled) { + this.removeTrack(track); + } }, addTrackSegment: function(track, sourcePoints) { diff --git a/src/lib/leaflet.polyline-edit/index.js b/src/lib/leaflet.polyline-edit/index.js @@ -24,7 +24,7 @@ L.Polyline.EditMixin = { } }, - stopEdit: function() { + stopEdit: function(userCancelled) { if (this._editing) { this.stopDrawingLine(); this._editing = false; @@ -36,7 +36,7 @@ L.Polyline.EditMixin = { .off('dragend', this.onMapEndDrag, this); this.setStyle(this._storedStyle); L.DomUtil.removeClass(this._map._container, 'leaflet-line-editing'); - this.fire('editend', {target: this}); + this.fire('editend', {target: this, userCancelled}); } }, @@ -89,7 +89,7 @@ L.Polyline.EditMixin = { this.addNode(newNodeIndex, e.latlng); } else { if (!this.preventStopEdit) { - this.stopEdit(); + this.stopEdit(true); } } }, @@ -140,6 +140,7 @@ L.Polyline.EditMixin = { this._drawingDirection = 0; L.DomUtil.removeClass(this._map._container, 'leaflet-line-drawing'); this._map.clickLocked = false; + this.fire('drawend'); }, @@ -155,7 +156,7 @@ L.Polyline.EditMixin = { this.stopDrawingLine(); } else { if (!this.preventStopEdit) { - this.stopEdit(); + this.stopEdit(true); } } L.DomEvent.stop(e);