nakarte

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

commit 7cacdf07efa18d215587a34a15838e19f063b621
parent 0cba9b0cc0dc5ff8aeabe605467c2aa4850c830e
Author: Sergej Orlov <wladimirych@gmail.com>
Date:   Mon,  5 Nov 2018 22:22:58 +0100

[track edit] consider last remaining node as start, not end #115

Diffstat:
Msrc/lib/leaflet.polyline-edit/index.js | 23++++++++++++++++++-----
1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/src/lib/leaflet.polyline-edit/index.js b/src/lib/leaflet.polyline-edit/index.js @@ -118,10 +118,10 @@ L.Polyline.EditMixin = { } this.stopDrawingLine(); this._drawingDirection = direction; - this._setupEndMarkers(); if (e) { var newNodeIndex = this._drawingDirection === -1 ? 0 : this.getLatLngs().length; this.spliceLatLngs(newNodeIndex, 0, e.latlng); + this._setupEndMarkers(); this.fire('nodeschanged'); } @@ -289,6 +289,9 @@ L.Polyline.EditMixin = { if (!isAddingRight) { this.makeSegmentOverlay(index); } + if (nodes.length < 3) { + this._setupEndMarkers(); + } }, removeNode: function(index) { @@ -342,13 +345,23 @@ L.Polyline.EditMixin = { _setupEndMarkers: function() { const nodesCount = this._latlngs.length; - if (nodesCount == 0) { + if (nodesCount === 0) { return; } - const startIcon = this._latlngs[0]._nodeMarker._icon; + const startIndex = this._drawingDirection === -1 ? 1 : 0; + const endIndex = this._drawingDirection === 1 ? nodesCount - 2 : nodesCount - 1; + const startIcon = this._latlngs[startIndex]._nodeMarker._icon; L.DomUtil[this._drawingDirection !== -1 ? 'addClass' : 'removeClass'](startIcon, 'line-editor-node-marker-start'); - const endIcon = this._latlngs[nodesCount - 1]._nodeMarker._icon; - L.DomUtil[this._drawingDirection !== 1 ? 'addClass' : 'removeClass'](endIcon, 'line-editor-node-marker-end'); + if (endIndex >= 0) { + const endIcon = this._latlngs[endIndex]._nodeMarker._icon; + let func; + if (this._drawingDirection !== 1 && endIndex > 0) { + func = L.DomUtil.addClass; + } else { + func = L.DomUtil.removeClass; + } + func(endIcon, 'line-editor-node-marker-end'); + } }, setupMarkers: function() {