|
31 | 31 | import MaplibreCgazAdminControl from '@undp-data/cgaz-admin-tool'; |
32 | 32 | import MaplibreStyleSwitcherControl from '@undp-data/style-switcher'; |
33 | 33 | import { MAPSTORE_CONTEXT_KEY, type MapStore } from '@undp-data/svelte-undp-components'; |
| 34 | + import { MaplibreMeasureControl } from '@watergis/maplibre-gl-terradraw'; |
| 35 | + import '@watergis/maplibre-gl-terradraw/dist/maplibre-gl-terradraw.css'; |
34 | 36 | import { |
35 | 37 | AttributionControl, |
36 | 38 | GeolocateControl, |
|
73 | 75 |
|
74 | 76 | let container: HTMLDivElement | undefined = $state(); |
75 | 77 | let styleSwitcher: MaplibreStyleSwitcherControl; |
| 78 | + let measureControl: MaplibreMeasureControl | undefined = $state(); |
76 | 79 |
|
77 | 80 | const layerListStorageKey = storageKeys.layerList(page.url.host); |
78 | 81 | const mapStyleStorageKey = storageKeys.mapStyle(page.url.host); |
|
224 | 227 | step: 9, |
225 | 228 | scrollTo: 'off' |
226 | 229 | }, |
227 | | -
|
| 230 | + { |
| 231 | + title: 'Measuring distance, area and elevation', |
| 232 | + intro: ` |
| 233 | + You can measure distance, area and elevation by drawing point, line or polygon. |
| 234 | + `, |
| 235 | + element: '.maplibregl-terradraw-render-button', |
| 236 | + position: 'left', |
| 237 | + step: 10, |
| 238 | + scrollTo: 'off' |
| 239 | + }, |
228 | 240 | { |
229 | 241 | title: 'Disable hillshade layer', |
230 | 242 | intro: ` |
231 | 243 | As default, a hillshade layer is shown on the basemap. You can also disable hillshade layer if you want. |
232 | 244 | `, |
233 | 245 | element: '.maplibregl-ctrl-hillshade-visibility', |
234 | 246 | position: 'left', |
235 | | - step: 10, |
| 247 | + step: 11, |
236 | 248 | scrollTo: 'off' |
237 | 249 | }, |
238 | 250 | { |
|
242 | 254 | `, |
243 | 255 | element: '.maplibregl-ctrl-geolocate', |
244 | 256 | position: 'left', |
245 | | - step: 11, |
| 257 | + step: 12, |
246 | 258 | scrollTo: 'off' |
247 | 259 | }, |
248 | 260 | { |
|
251 | 263 | 'You have completed map editor tour. Now you can start exploring GeoHub to create a beautiful map. You can always come back to the tour by clicking this button', |
252 | 264 | element: '.tour-control-button', |
253 | 265 | position: 'left', |
254 | | - step: 12, |
| 266 | + step: 13, |
255 | 267 | scrollTo: 'off' |
256 | 268 | } |
257 | 269 | ] |
|
448 | 460 | }); |
449 | 461 | $map.addControl(styleSwitcher, 'bottom-left'); |
450 | 462 |
|
| 463 | + measureControl = new MaplibreMeasureControl({ |
| 464 | + modes: ['render', 'point', 'linestring', 'polygon', 'delete'], |
| 465 | + open: false, |
| 466 | + computeElevation: true |
| 467 | + }); |
| 468 | + measureControl.fontGlyphs = ['Proxima Nova Italic']; |
| 469 | + $map.addControl(measureControl, 'bottom-right'); |
| 470 | +
|
451 | 471 | $map.once('load', mapInitializeAfterLoading); |
452 | 472 | }; |
453 | 473 |
|
|
474 | 494 |
|
475 | 495 | map.subscribe((value) => { |
476 | 496 | let storageValue = value ? value.getStyle() : null; |
| 497 | + if (storageValue && measureControl) { |
| 498 | + storageValue = measureControl.cleanStyle(storageValue, { excludeTerraDrawLayers: true }); |
| 499 | + } |
477 | 500 | toLocalStorage(mapStyleStorageKey, storageValue); |
478 | 501 | }); |
479 | 502 |
|
|
497 | 520 | $map.on('styledata', async () => { |
498 | 521 | $showProgressBarStore = false; |
499 | 522 | let storageValue = $map.getStyle(); |
| 523 | + if (storageValue && measureControl) { |
| 524 | + storageValue = measureControl.cleanStyle(storageValue, { excludeTerraDrawLayers: true }); |
| 525 | + } |
500 | 526 | toLocalStorage(mapStyleStorageKey, storageValue); |
501 | 527 | }); |
502 | 528 | $map.on('projectiontransition', () => { |
503 | 529 | let storageValue = $map.getStyle(); |
| 530 | + if (storageValue && measureControl) { |
| 531 | + storageValue = measureControl.cleanStyle(storageValue, { excludeTerraDrawLayers: true }); |
| 532 | + } |
504 | 533 | toLocalStorage(mapStyleStorageKey, storageValue); |
505 | 534 | }); |
506 | 535 | }; |
|
0 commit comments