nakarte

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

commit 86fabeee80ee0414554a8d66ccc080a4b73f3de1
parent 5e2cee12db93467f1f378f5122a9c67d1d46dc98
Author: Sergey Orlov <wladimirych@gmail.com>
Date:   Fri, 29 May 2020 22:36:26 +0200

tracks: unwrap loaded tracks crossing 180 meridian, fixes #258

Diffstat:
Msrc/lib/leaflet.control.track-list/track-list.js | 16++++++++++++++++
1 file changed, 16 insertions(+), 0 deletions(-)

diff --git a/src/lib/leaflet.control.track-list/track-list.js b/src/lib/leaflet.control.track-list/track-list.js @@ -41,6 +41,21 @@ const TrackSegment = L.MeasuredLine.extend({ }); TrackSegment.mergeOptions(L.Polyline.EditMixinOptions); +function unwrapLatLngsCrossing180Meridian(latngs) { + if (latngs.length === 0) { + return []; + } + const unwrapped = [latngs[0]]; + let lastUnwrapped; + let prevUnwrapped = latngs[0]; + for (let i = 1; i < latngs.length; i++) { + lastUnwrapped = wrapLatLngToTarget(latngs[i], prevUnwrapped); + unwrapped.push(lastUnwrapped); + prevUnwrapped = lastUnwrapped; + } + return unwrapped; +} + L.Control.TrackList = L.Control.extend({ options: {position: 'bottomright'}, includes: L.Mixin.Events, @@ -288,6 +303,7 @@ L.Control.TrackList = L.Control.extend({ if (!data_empty) { if (geodata.tracks) { geodata.tracks = geodata.tracks.map(function(line) { + line = unwrapLatLngsCrossing180Meridian(line); line = L.LineUtil.simplifyLatlngs(line, 360 / (1 << 24)); if (line.length === 1) { line.push(line[0]);