nakarte

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

commit 6d53389b5e224f88a2fff116eb41682fdaf06c0d
parent 69b20dda8deffdf20222539c3a4d0c611a64590c
Author: Sergej Orlov <wladimirych@gmail.com>
Date:   Thu, 18 Dec 2025 10:13:54 +0100

JNX: store new settings (zoom level, scale correction) in hash state

Related to: #77

Diffstat:
Msrc/lib/leaflet.control.jnx/hash-state.js | 17++++++++++++++---
Msrc/lib/leaflet.control.jnx/index.js | 13++++++++++---
2 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/src/lib/leaflet.control.jnx/hash-state.js b/src/lib/leaflet.control.jnx/hash-state.js @@ -3,7 +3,7 @@ import '~/lib/leaflet.hashState/leaflet.hashState'; L.Control.JNX.include(L.Mixin.HashState); L.Control.JNX.include({ - stateChangeEvents: ['selectionchange'], + stateChangeEvents: ['settingschange'], serializeState: function() { let state; @@ -13,7 +13,9 @@ L.Control.JNX.include({ bounds.getSouth().toFixed(5), bounds.getWest().toFixed(5), bounds.getNorth().toFixed(5), - bounds.getEast().toFixed(5) + bounds.getEast().toFixed(5), + this.zoomLevel() ?? '', + this.fixZoom() ? '1' : '0', ]; } return state; @@ -36,7 +38,7 @@ L.Control.JNX.include({ return value; } - if (values && values.length === 4) { + if (values && values.length >= 4) { let south, west, north, east; try { south = validateFloatRange(values[0], -86, 86); @@ -50,6 +52,15 @@ L.Control.JNX.include({ throw e; } this.setAreaSelector([[south, west], [north, east]]); + + let zoomLevel = parseInt(values[4], 10); + if (!this.zoomChoices()?.[zoomLevel]) { + zoomLevel = null; + } + this.zoomLevel(zoomLevel); + + this.fixZoom(values[5] === '1'); + return true; } return false; diff --git a/src/lib/leaflet.control.jnx/index.js b/src/lib/leaflet.control.jnx/index.js @@ -26,6 +26,9 @@ L.Control.JNX = L.Control.extend({ this.zoomLevel = ko.observable(null); this.zoomChoices = ko.observable(null); this.fixZoom = ko.observable(false); + + this.zoomLevel.subscribe(() => this.fireChangeEvent()); + this.fixZoom.subscribe(() => this.fireChangeEvent()); }, getLayerForJnx: function () { @@ -92,10 +95,10 @@ L.Control.JNX = L.Control.extend({ }; metersPerPixel *= 2; } - this.zoomChoices(choices); - if (!this.zoomChoices()[this.zoomLevel()]) { + if (!choices[this.zoomLevel()]) { this.zoomLevel(null); } + this.zoomChoices(choices); }, notifyProgress: function (value, maxValue) { @@ -187,9 +190,13 @@ L.Control.JNX = L.Control.extend({ this.onSelectorChange(); }, + fireChangeEvent: function () { + this.fire('settingschange'); + }, + onSelectorChange: function () { this.updateZoomChoices(); - this.fire('selectionchange'); + this.fireChangeEvent(); }, moveMapToAreaSelector: function () {