nakarte

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

commit 9ea8492a0893faf8f59add52a6fb1415fe646215
parent ea0617233566f1bbdc1a9abe330be7448cfd7082
Author: Sergej Orlov <wladimirych@gmail.com>
Date:   Fri, 24 Mar 2017 12:33:51 +0300

[elevation profile] moved function calcSamplingInterval to profiles module

Diffstat:
Msrc/lib/leaflet.control.elevation-profile/index.js | 25++++++++++++++++++++++++-
Msrc/lib/leaflet.control.track-list/track-list.js | 22+++-------------------
2 files changed, 27 insertions(+), 20 deletions(-)

diff --git a/src/lib/leaflet.control.elevation-profile/index.js b/src/lib/leaflet.control.elevation-profile/index.js @@ -6,6 +6,22 @@ import 'lib/leaflet.control.commons'; import {notify} from 'lib/notifications'; import logging from 'lib/logging'; +function calcSamplingInterval(length) { + var targetPointsN = 2000; + var maxPointsN = 9999; + var samplingIntgerval = length / targetPointsN; + if (samplingIntgerval < 10) { + samplingIntgerval = 10; + } + if (samplingIntgerval > 50) { + samplingIntgerval = 50; + } + if (length / samplingIntgerval > maxPointsN) { + samplingIntgerval = length / maxPointsN; + } + return samplingIntgerval; +} + function createSvg(tagName, attributes, parent) { var element = document.createElementNS('http://www.w3.org/2000/svg', tagName); if (attributes) { @@ -198,12 +214,14 @@ var DragEvents = L.Class.extend({ } ); -L.Control.ElevationProfile = L.Class.extend({ +const ElevationProfile = L.Class.extend({ options: { elevationsServer: config.elevationsServer, samplingInterval: 50 }, + includes: L.Mixin.Events, + initialize: function(map, latlngs, options) { L.setOptions(this, options); this.path = latlngs; @@ -224,6 +242,7 @@ L.Control.ElevationProfile = L.Class.extend({ .catch((e) => { logging.captureException(e, {extra: {description: 'while getting elevation'}}); notify(`Failed to get elevation data: ${e.message}`); + self._addTo(map); }); this.values = null; @@ -287,6 +306,7 @@ L.Control.ElevationProfile = L.Class.extend({ map.removeLayer(this.trackMarker); map.removeLayer(this.polyLineSelection); this._map = null; + this.fire('remove'); return this; }, @@ -798,3 +818,5 @@ L.Control.ElevationProfile = L.Class.extend({ } } ); + +export {ElevationProfile, calcSamplingInterval}; +\ No newline at end of file diff --git a/src/lib/leaflet.control.track-list/track-list.js b/src/lib/leaflet.control.track-list/track-list.js @@ -14,7 +14,7 @@ import 'lib/leaflet.layer.canvasMarkers'; import 'lib/leaflet.lineutil.simplifyLatLngs'; import iconFromBackgroundImage from 'lib/iconFromBackgroundImage'; import 'lib/controls-styles/controls-styles.css'; -import 'lib/leaflet.control.elevation-profile'; +import {ElevationProfile, calcSamplingInterval} from 'lib/leaflet.control.elevation-profile'; import 'lib/leaflet.control.commons'; import {blobFromString} from 'lib/binary-strings'; import 'lib/leaflet.polyline-edit'; @@ -1016,22 +1016,6 @@ L.Control.TrackList = L.Control.extend({ ); }, - calcSamplingInterval: function(length) { - var targetPointsN = 2000; - var maxPointsN = 9999; - var samplingIntgerval = length / targetPointsN; - if (samplingIntgerval < 10) { - samplingIntgerval = 10; - } - if (samplingIntgerval > 50) { - samplingIntgerval = 50; - } - if (length / samplingIntgerval > maxPointsN) { - samplingIntgerval = length / maxPointsN; - } - return samplingIntgerval; - }, - showElevationProfileForSegment: function(line) { if (this._elevationControl) { this._elevationControl.removeFrom(this._map); @@ -1056,8 +1040,8 @@ L.Control.TrackList = L.Control.extend({ if (this._elevationControl) { this._elevationControl.removeFrom(this._map); } - this._elevationControl = new L.Control.ElevationProfile(this._map, path, { - samplingInterval: this.calcSamplingInterval(new L.MeasuredLine(path).getLength()) + this._elevationControl = new ElevationProfile(this._map, path, { + samplingInterval: calcSamplingInterval(new L.MeasuredLine(path).getLength()) } ); },