commit 681d20aa0cbd119256583b89d34135789aa08458
parent 4aac7b24e5cecccc4557256413a11efff3ef715a
Author: Sergey Orlov <wladimirych@gmail.com>
Date: Sun, 5 Jul 2020 17:13:02 +0200
tracks: fix track length updates after edit actions
total track length was not updating after
* segment removal
* join
* shortcut
Diffstat:
2 files changed, 6 insertions(+), 11 deletions(-)
diff --git a/src/lib/leaflet.control.track-list/track-list.js b/src/lib/leaflet.control.track-list/track-list.js
@@ -781,9 +781,8 @@ L.Control.TrackList = L.Control.extend({
const polyline = e.target;
const track = polyline._parentTrack;
if (polyline.getLatLngs().length < 2) {
- track.feature.removeLayer(polyline);
+ this.deleteTrackSegment(polyline);
}
- this.onTrackLengthChanged(track);
if (this._editedLine === polyline) {
this._editedLine = null;
}
@@ -812,6 +811,7 @@ L.Control.TrackList = L.Control.extend({
// polyline.on('editingstart', polyline.setMeasureTicksVisible.bind(polyline, false));
// polyline.on('editingend', this.setTrackMeasureTicksVisibility.bind(this, track));
track.feature.addLayer(polyline);
+ this.onTrackLengthChanged(track);
return polyline;
},
@@ -1101,7 +1101,9 @@ L.Control.TrackList = L.Control.extend({
},
deleteTrackSegment: function(trackSegment) {
- trackSegment._parentTrack.feature.removeLayer(trackSegment);
+ const track = trackSegment._parentTrack;
+ track.feature.removeLayer(trackSegment);
+ this.onTrackLengthChanged(track);
},
newTrackFromSegment: function(trackSegment) {
@@ -1148,7 +1150,6 @@ L.Control.TrackList = L.Control.extend({
this.onTrackVisibilityChanged(track);
this.attachColorSelector(track);
this.attachActionsMenu(track);
- this.onTrackLengthChanged(track);
return track;
},
diff --git a/src/lib/leaflet.polyline-edit/index.js b/src/lib/leaflet.polyline-edit/index.js
@@ -76,7 +76,6 @@ L.Polyline.EditMixin = {
onNodeMarkerMovedChangeNode: function(e) {
var marker = e.target,
latlng = marker.getLatLng(),
- // nodeIndex = this.getLatLngs().indexOf(marker._lineNode);
node = marker._lineNode;
node.lat = latlng.lat;
node.lng = latlng.lng;
@@ -95,7 +94,6 @@ L.Polyline.EditMixin = {
nodeIndex = this.getMarkerIndex(marker);
this.removeNode(nodeIndex);
this._setupEndMarkers();
- this.fire('nodeschanged');
},
onMapClick: function(e) {
@@ -143,7 +141,6 @@ L.Polyline.EditMixin = {
var newNodeIndex = this._drawingDirection === -1 ? 0 : this.getLatLngs().length;
this.spliceLatLngs(newNodeIndex, 0, e.latlng);
this._setupEndMarkers();
- this.fire('nodeschanged');
}
this._map.on('mousemove', this.onMouseMoveFollowEndNode, this);
@@ -158,7 +155,6 @@ L.Polyline.EditMixin = {
this._map.off('mousemove', this.onMouseMoveFollowEndNode, this);
var nodeIndex = this._drawingDirection === -1 ? 0 : this.getLatLngs().length - 1;
this.spliceLatLngs(nodeIndex, 1);
- this.fire('nodeschanged');
this._drawingDirection = 0;
L.DomUtil.removeClass(this._map._container, 'leaflet-line-drawing');
this._map.clickLocked = false;
@@ -188,7 +184,6 @@ L.Polyline.EditMixin = {
if (this._drawingDirection && this.getLatLngs().length > 2) {
const nodeIndex = this._drawingDirection === 1 ? this.getLatLngs().length - 2 : 1;
this.removeNode(nodeIndex);
- this.fire('nodeschanged');
L.DomEvent.preventDefault(e);
}
break;
@@ -204,7 +199,6 @@ L.Polyline.EditMixin = {
latlng = wrapLatLngToTarget(latlng, this._latlngs[nodeIndex]);
}
this.spliceLatLngs(nodeIndex, 1, latlng);
- this.fire('nodeschanged');
},
makeNodeMarker: function(nodeIndex) {
@@ -299,7 +293,6 @@ L.Polyline.EditMixin = {
L.Draggable._dragging.finishDrag();
}
latlngs[nodeIndex]._nodeMarker.dragging._draggable._onDown(e.originalEvent);
- this.fire('nodeschanged');
},
addNode: function(index, latlng) {
@@ -428,6 +421,7 @@ L.Polyline.EditMixin = {
const latlngs = this.getLatLngs();
const res = latlngs.splice(...args);
this.setLatLngs(latlngs);
+ this.fire('nodeschanged');
return res;
// this._latlngs.splice(...args);
// this.redraw();