|
70 | 70 | <script> |
71 | 71 | var map = L.map('map'); |
72 | 72 |
|
| 73 | + function saveMapState(map) { |
| 74 | + localStorage.setItem('mapState', JSON.stringify({ |
| 75 | + center: map.getCenter(), |
| 76 | + zoom: map.getZoom() |
| 77 | + })); |
| 78 | + } |
| 79 | + |
| 80 | + function loadMapState() { |
| 81 | + const savedState = JSON.parse(localStorage.getItem('mapState')); |
| 82 | + return savedState ? { center: [savedState.center.lat, savedState.center.lng], zoom: savedState.zoom } : null; |
| 83 | + } |
| 84 | + const savedState = loadMapState(); |
| 85 | + |
73 | 86 | // Add a basemap (OpenStreetMap) |
74 | 87 | L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { |
75 | 88 | attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors' |
|
121 | 134 |
|
122 | 135 | const coords = []; |
123 | 136 | for (let j = 0; j < coordCount; j++) { |
124 | | - // Read delta lat and lon |
| 137 | + // Read delta lon and lat |
125 | 138 | const deltaLon = dataView.getInt32(offset, true) / 1000000; |
126 | 139 | offset += 4; |
127 | 140 | const deltaLat = dataView.getInt32(offset, true) / 1000000; |
|
167 | 180 | bounds.extend(polyline.getBounds()); |
168 | 181 | }); |
169 | 182 |
|
170 | | - if (bounds.isValid()) { |
171 | | - map.fitBounds(bounds); |
| 183 | + if (bounds.isValid()) { |
| 184 | + if (savedState) { |
| 185 | + map.setView(savedState.center, savedState.zoom); |
| 186 | + } else { |
| 187 | + map.fitBounds(bounds); |
| 188 | + } |
172 | 189 | } else { |
173 | 190 | console.error('Calculated bounds are not valid.'); |
174 | 191 | } |
175 | 192 |
|
| 193 | + map.on('moveend', () => saveMapState(map)); |
| 194 | + map.on('zoomend', () => saveMapState(map)); |
176 | 195 | } catch (error) { |
177 | 196 | console.error('Error rendering features:', error); |
178 | 197 | } |
|
0 commit comments