nakarte

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

commit c3b3e6d21c7d6919ef55050815c54bfc76d226b8
parent 2c67fb80f5044e8712057019727f90242f62fad3
Author: Sergej Orlov <wladimirych@gmail.com>
Date:   Sun, 26 Mar 2017 01:16:04 +0300

[azimuth] exclusive with track editing

Diffstat:
Msrc/App.js | 8+++++++-
Msrc/lib/leaflet.control.azimuth/index.js | 3+++
Msrc/lib/leaflet.control.track-list/track-list.js | 24++++++++++++++++--------
3 files changed, 26 insertions(+), 9 deletions(-)

diff --git a/src/App.js b/src/App.js @@ -62,7 +62,7 @@ function setUp() { new L.Control.Coordinates({position: 'topleft'}).addTo(map); - new L.Control.Azimuth({position: 'topleft'}).addTo(map); + const azimuthControl = new L.Control.Azimuth({position: 'topleft'}).addTo(map); /////////// controls top-right corner @@ -110,6 +110,12 @@ function setUp() { raiseControlsOnFocus(map); L.DomEvent.on(window, 'beforeunload', () => tracklist.saveTracksToStorage()); + + tracklist.on('startedit elevation-shown', () => azimuthControl.setEnabled(false)); + azimuthControl.on('enabled', () => { + tracklist.stopEditLine(); + tracklist.hideElevationProfile(); + }) } export default {setUp}; diff --git a/src/lib/leaflet.control.azimuth/index.js b/src/lib/leaflet.control.azimuth/index.js @@ -51,6 +51,8 @@ L.Control.Azimuth = L.Control.extend({ position: 'bottomleft' }, + includes: L.Mixin.Events, + initialize: function(options) { L.Control.prototype.initialize.call(this, options); this.trueAzimuth = ko.observable(null); @@ -118,6 +120,7 @@ L.Control.Azimuth = L.Control.extend({ L.DomUtil.addClass(this._container, 'expanded'); L.DomUtil.addClass(this._map._container, 'azimuth-control-active'); this._map.on('click', this.onMapClick, this); + this.fire('enabled'); } else { L.DomUtil.removeClass(this._container, 'expanded'); L.DomUtil.removeClass(this._map._container, 'azimuth-control-active'); diff --git a/src/lib/leaflet.control.track-list/track-list.js b/src/lib/leaflet.control.track-list/track-list.js @@ -39,6 +39,7 @@ TrackSegment.mergeOptions(L.Polyline.EditMixinOptions); L.Control.TrackList = L.Control.extend({ options: {position: 'bottomright'}, + includes: L.Mixin.Events, colors: ['#77f', '#f95', '#0ff', '#f77', '#f7f', '#ee5'], @@ -560,6 +561,7 @@ L.Control.TrackList = L.Control.extend({ setTimeout(this.onLineEditEnd.bind(this, track, polyline), 0); }.bind(this) ); + this.fire('startedit'); }, placeNewPoint: function(track) { @@ -576,6 +578,7 @@ L.Control.TrackList = L.Control.extend({ this._editedPoint = marker; this.map.on('click', this.placePoint, this); L.DomEvent.on(document, 'keyup', this.stopPlacingPointOnEscPressed, this); + this.fire('startedit'); }, placePoint: function(e) { @@ -1017,14 +1020,13 @@ L.Control.TrackList = L.Control.extend({ }, showElevationProfileForSegment: function(line) { - if (this._elevationControl) { - this._elevationControl.removeFrom(this._map); - } + this.hideElevationProfile(); this.stopEditLine(); - this._elevationControl = new L.Control.ElevationProfile(this._map, line.getLatLngs(), { - samplingInterval: this.calcSamplingInterval(line.getLength()) + this._elevationControl = new ElevationProfile(this._map, line.getLatLngs(), { + samplingInterval: calcSamplingInterval(line.getLength()) } ); + this.fire('elevation-shown'); }, showElevationProfileForTrack: function(track) { @@ -1037,13 +1039,19 @@ L.Control.TrackList = L.Control.extend({ } path = path.concat(lines[i].getLatLngs()); } - if (this._elevationControl) { - this._elevationControl.removeFrom(this._map); - } + this.hideElevationProfile(); this._elevationControl = new ElevationProfile(this._map, path, { samplingInterval: calcSamplingInterval(new L.MeasuredLine(path).getLength()) } ); + this.fire('elevation-shown'); + }, + + hideElevationProfile: function() { + if (this._elevationControl) { + this._elevationControl.removeFrom(this._map); + } + this._elevationControl = null; }, hasTracks: function() {