nakarte

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

commit 62fd4f690c96ea81bac3d4685b2e35caee59a033
parent d6f9dd52c1fcbb219f49c5f52e4d25dee2cc5a43
Author: Sergej Orlov <wladimirych@gmail.com>
Date:   Tue,  6 Nov 2018 22:46:16 +0100

Merge branch '115-highlight-track-ends' into release-5

Diffstat:
Msrc/lib/leaflet.polyline-edit/edit_line.css | 10++++++++++
Msrc/lib/leaflet.polyline-edit/index.js | 35+++++++++++++++++++++++++++++++----
2 files changed, 41 insertions(+), 4 deletions(-)

diff --git a/src/lib/leaflet.polyline-edit/edit_line.css b/src/lib/leaflet.polyline-edit/edit_line.css @@ -30,4 +30,14 @@ .leaflet-line-drawing .leaflet-editable-line { pointer-events: none !important; +} + +.line-editor-node-marker-start { + background-color: rgb(20%, 75%, 20%); + z-index: 1000000 !important; +} + +.line-editor-node-marker-end { + background-color: rgb(90%, 20%, 20%); + z-index: 1000000 !important; } \ No newline at end of file diff --git a/src/lib/leaflet.polyline-edit/index.js b/src/lib/leaflet.polyline-edit/index.js @@ -62,6 +62,7 @@ L.Polyline.EditMixin = { var marker = e.target, nodeIndex = this.getLatLngs().indexOf(marker._lineNode); this.replaceNode(nodeIndex, marker.getLatLng()); + this._setupEndMarkers(); }, onNodeMarkerMovedChangeNode: function(e) { @@ -82,6 +83,7 @@ L.Polyline.EditMixin = { var marker = e.target, nodeIndex = this.getLatLngs().indexOf(marker._lineNode); this.removeNode(nodeIndex); + this._setupEndMarkers(); this.fire('nodeschanged'); }, @@ -126,10 +128,10 @@ L.Polyline.EditMixin = { } this.stopDrawingLine(); this._drawingDirection = direction; - if (e) { var newNodeIndex = this._drawingDirection === -1 ? 0 : this.getLatLngs().length; this.spliceLatLngs(newNodeIndex, 0, e.latlng); + this._setupEndMarkers(); this.fire('nodeschanged'); } @@ -150,6 +152,7 @@ L.Polyline.EditMixin = { this._drawingDirection = 0; L.DomUtil.removeClass(this._map._container, 'leaflet-line-drawing'); this._map.clickLocked = false; + this._setupEndMarkers(); this.fire('drawend'); }, @@ -234,10 +237,10 @@ L.Polyline.EditMixin = { if ((this._drawingDirection === -1 && nodeIndex === 1) || ((this._drawingDirection === 1 && nodeIndex === latlngs_n - 2))) { this.stopDrawingLine(); - } else if (nodeIndex === 0) { - this.startDrawingLine(-1, e); } else if (nodeIndex === this.getLatLngs().length - 1) { this.startDrawingLine(1, e); + } else if (nodeIndex === 0) { + this.startDrawingLine(-1, e); } }, @@ -304,6 +307,9 @@ L.Polyline.EditMixin = { if (!isAddingRight) { this.makeSegmentOverlay(index); } + if (nodes.length < 3) { + this._setupEndMarkers(); + } }, removeNode: function(index) { @@ -355,6 +361,27 @@ L.Polyline.EditMixin = { } }, + _setupEndMarkers: function() { + const nodesCount = this._latlngs.length; + if (nodesCount === 0) { + return; + } + 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'); + 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() { this.removeMarkers(); var latlngs = this.getLatLngs(), @@ -372,7 +399,7 @@ L.Polyline.EditMixin = { this.makeSegmentOverlay(i); } } - + this._setupEndMarkers(); }, spliceLatLngs: function(...args) {