Skip to content

Commit a63463a

Browse files
committed
Save & restore map coordinates, zoom, and time period
1 parent 29616aa commit a63463a

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

js/tracker.js

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -858,20 +858,35 @@ function clean_refresh(text, force, history_step) {
858858
}
859859

860860
function load() {
861+
var qm = offline.get("qm");
862+
if (qm != null) {
863+
wvar.mode = qm;
864+
}
865+
866+
coords = offline.get("mc");
867+
if (coords == null) {
868+
coords = [53.467511,-2.233894];
869+
}
870+
871+
zoomLevel = offline.get("mz");
872+
if (zoomLevel == null) {
873+
zoomLevel = 5;
874+
}
875+
861876
//initialize map object
862877
map = new L.map(document.getElementById('map'), {
863-
zoom: 5,
878+
zoom: zoomLevel,
864879
zoomControl: false,
865880
zoomAnimationThreshold: 0,
866881
zoomAnimation: true,
867882
markerZoomAnimation: false,
868-
center: [53.467511,-2.233894],
883+
center: coords,
869884
layers: baseMaps[selectedLayer],
870885
worldCopyJump: true,
871886
preferCanvas: true,
872887
});
873888

874-
map.setView([53.467511,-2.233894], 5, {animate: false});
889+
map.setView(coords, zoomLevel, {animate: false});
875890

876891
// fullscreen button
877892
map.addControl(new L.Control.Fullscreen({ position: 'bottomleft' }));
@@ -911,8 +926,7 @@ function load() {
911926
onAdd: function(map) {
912927
var div = L.DomUtil.create('div');
913928

914-
div.innerHTML = '<select name="timeperiod" id="timeperiod" style="width:auto !important;height:30px;" onchange="clean_refresh(this.value)"><option value="0">Live Only</option><option value="1h">1 hour</option><option value="3h" selected="selected">3 hours</option><option value="6h">6 hours</option><option value="12h">12 hours</option></select>';
915-
div.innerHTML.onload = setTimeValue();
929+
div.innerHTML = '<select name="timeperiod" id="timeperiod" style="width:auto !important;height:30px;"><option value="0">Live Only</option><option value="1h">1 hour</option><option value="3h">3 hours</option><option value="6h">6 hours</option><option value="12h">12 hours</option></select>';
916930

917931
return div;
918932
},
@@ -1012,6 +1026,10 @@ function load() {
10121026
lhash_update();
10131027
sidebar_update();
10141028
sub_to_nearby_sondes();
1029+
1030+
var latlng = map.getCenter();
1031+
offline.set("mc", [roundNumber(latlng.lat, 5), roundNumber(latlng.lng, 5)]);
1032+
offline.set("mz", map.getZoom());
10151033
});
10161034

10171035
map.on('baselayerchange', function (e) {
@@ -1067,6 +1085,13 @@ function load() {
10671085
lhash_update();
10681086
});
10691087

1088+
var timeperiod_select = document.getElementById("timeperiod");
1089+
timeperiod_select.value = wvar.mode;
1090+
timeperiod_select.addEventListener("change", function() {
1091+
offline.set("qm", this.value);
1092+
clean_refresh(this.value);
1093+
});
1094+
10701095
startAjax();
10711096
liveData();
10721097
};
@@ -1139,12 +1164,6 @@ function load() {
11391164
}, 500);
11401165
}
11411166

1142-
function setTimeValue() {
1143-
setTimeout(function() {
1144-
document.getElementById("timeperiod").value = wvar.mode;
1145-
}, 100);
1146-
}
1147-
11481167
function shareVehicle(callsign) {
11491168
const shareData = {
11501169
title: 'SondeHub: ' + vehicles[callsign].marker.options.title + ' Flight Information',

0 commit comments

Comments
 (0)