nakarte

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

commit cd35f5c243e7a0ad28bd495ffccc1709ffe36cbe
parent 7b100b3e184ccd9169158bcecb6332d8d971ff67
Author: myadzel <myadzel@gmail.com>
Date:   Wed, 28 Dec 2022 00:35:14 +0300

fix url to copy (issue #516)

Diffstat:
Msrc/App.js | 4+++-
Msrc/lib/leaflet.control.track-list/track-list.js | 23++++++++++++++++++++---
2 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/src/App.js b/src/App.js @@ -79,7 +79,9 @@ function setUp() { // eslint-disable-line complexity } ); - const tracklist = new L.Control.TrackList(); + const tracklist = new L.Control.TrackList({ + keysToExcludeOnCopyLink: ['q', 'r'] + }); /* controls top-left corner */ 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,22 @@ const TrackSegment = L.MeasuredLine.extend({ }); TrackSegment.mergeOptions(L.Polyline.EditMixinOptions); +function getLinkToShare(keysToExclude, paramsToAdd) { + const {origin, pathname, hash} = window.location; + + const params = new URLSearchParams(hash.substring(1)); + + for (const key of keysToExclude) { + params.delete(key); + } + + for (const [key, value] of Object.entries(paramsToAdd)) { + params.set(key, value); + } + + return origin + pathname + '#' + decodeURIComponent(params.toString()); +} + function unwrapLatLngsCrossing180Meridian(latngs) { if (latngs.length === 0) { return []; @@ -98,13 +114,14 @@ L.Control.TrackList = L.Control.extend({ weight: 13, opacity: 0.6, }, + keysToExcludeOnCopyLink: [], }, includes: L.Mixin.Events, colors: TRACKLIST_TRACK_COLORS, - initialize: function() { - L.Control.prototype.initialize.call(this); + initialize: function(options) { + L.Control.prototype.initialize.call(this, options); this.tracks = ko.observableArray(); this.url = ko.observable(''); this.readingFiles = ko.observable(0); @@ -594,7 +611,7 @@ L.Control.TrackList = L.Control.extend({ let serialized = tracks.map((track) => this.trackToString(track)).join('/'); const hashDigest = md5(serialized, null, true); const key = btoa(hashDigest).replace(/\//ug, '_').replace(/\+/ug, '-').replace(/=/ug, ''); - const url = window.location + '&nktl=' + key; + const url = getLinkToShare(this.options.keysToExcludeOnCopyLink, {nktl: key}); copyToClipboard(url, mouseEvent); fetch(`${config.tracksStorageServer}/track/${key}`, { method: 'POST',