From 1eeaddc1bd710879e0350b3c3336fba5db48207b Mon Sep 17 00:00:00 2001 From: vcoppe Date: Fri, 12 Apr 2024 12:38:19 +0200 Subject: [PATCH] layer control progress --- website/src/lib/assets/layers.ts | 34 ++++++- .../src/lib/components/LayerControl.svelte | 92 ++++++++----------- website/src/lib/components/LayerTree.svelte | 35 +++++++ website/src/lib/components/Map.svelte | 2 +- 4 files changed, 109 insertions(+), 54 deletions(-) create mode 100644 website/src/lib/components/LayerTree.svelte diff --git a/website/src/lib/assets/layers.ts b/website/src/lib/assets/layers.ts index 597ef0b2..b9371fef 100644 --- a/website/src/lib/assets/layers.ts +++ b/website/src/lib/assets/layers.ts @@ -369,4 +369,36 @@ export const opacities: { [key: string]: number; } = { ignFrCadastre: 0.5, ignSlope: 0.4, swisstopoSlope: 0.4, -}; \ No newline at end of file +}; + +export const basemapTree = { + world: ['mapboxOutdoors', 'mapboxSatellite', 'openStreetMap', 'openTopoMap', 'openHikingMap', 'cyclOSM'], + countries: { + bulgaria: ['bgMountains'], + finland: ['finlandTopo'], + france: ['ignPlanV2', 'ignFrScan25', 'ignSatellite'], + newZealand: ['linz', 'linzTopo'], + norway: ['norwayTopo'], + spain: ['ignEs'], + sweden: ['swedenTopo'], + switzerland: ['swisstopo'], + unitedKingdom: ['ordnanceSurvey'], + unitedStates: ['usgs'], + }, +} + +export const overlayTree = { + world: { + cyclOSM: ['cyclOSMlite'], + waymarkedTrails: ['waymarkedTrailsHiking', 'waymarkedTrailsCycling', 'waymarkedTrailsMTB', 'waymarkedTrailsSkating', 'waymarkedTrailsHorseRiding', 'waymarkedTrailsWinter'] + }, + countries: { + france: ['ignFrCadastre', 'ignSlope'], + switzerland: ['swisstopoSlope', 'swisstopoCycling', 'swisstopoMountainBike'], + }, +} + +export const defaultBasemap = 'mapboxOutdoors'; + +export const defaultAvailableBasemaps = ['mapboxOutdoors', 'mapboxSatellite', 'openStreetMap', 'openTopoMap', 'openHikingMap', 'cyclOSM']; +export const defaultAvailableOverlays = ['cyclOSMlite', 'waymarkedTrailsHiking', 'waymarkedTrailsCycling', 'waymarkedTrailsMTB', 'waymarkedTrailsSkating', 'waymarkedTrailsHorseRiding', 'waymarkedTrailsWinter']; \ No newline at end of file diff --git a/website/src/lib/components/LayerControl.svelte b/website/src/lib/components/LayerControl.svelte index 77ac3d26..ea54b74c 100644 --- a/website/src/lib/components/LayerControl.svelte +++ b/website/src/lib/components/LayerControl.svelte @@ -5,16 +5,22 @@ import Fa from 'svelte-fa'; import { faLayerGroup } from '@fortawesome/free-solid-svg-icons'; - import { Label } from '$lib/components/ui/label'; - import * as RadioGroup from '$lib/components/ui/radio-group'; - import { Checkbox } from '$lib/components/ui/checkbox'; - - import { basemaps, overlays, opacities } from '$lib/assets/layers'; + import { + basemaps, + basemapTree, + overlays, + overlayTree, + opacities, + defaultBasemap, + defaultAvailableBasemaps, + defaultAvailableOverlays + } from '$lib/assets/layers'; + import LayerTree from './LayerTree.svelte'; export let map: mapboxgl.Map | null; $: if (map) { - map?.setStyle(basemaps['mapboxOutdoors']); + map?.setStyle(basemaps[defaultBasemap]); } @@ -22,50 +28,32 @@
- + { + map.setStyle(basemaps[id]); + }} + onOverlayChange={(id, checked) => { + if (checked) { + if (!map.getSource(id)) { + map.addSource(id, overlays[id]); + } + map.addLayer({ + id, + type: overlays[id].type === 'raster' ? 'raster' : 'line', + source: id, + paint: { + ...(id in opacities + ? overlays[id].type === 'raster' + ? { 'raster-opacity': opacities[id] } + : { 'line-opacity': opacities[id] } + : {}) + } + }); + } else { + map.removeLayer(id); + } + }} + /> diff --git a/website/src/lib/components/LayerTree.svelte b/website/src/lib/components/LayerTree.svelte new file mode 100644 index 00000000..28878850 --- /dev/null +++ b/website/src/lib/components/LayerTree.svelte @@ -0,0 +1,35 @@ + + + diff --git a/website/src/lib/components/Map.svelte b/website/src/lib/components/Map.svelte index 767176a9..a1d8d5d3 100644 --- a/website/src/lib/components/Map.svelte +++ b/website/src/lib/components/Map.svelte @@ -19,7 +19,7 @@ map = new mapboxgl.Map({ container: 'map', style: { version: 8, sources: {}, layers: [] }, - projection: 'mercator', + projection: { name: 'mercator' }, hash: true, language: 'auto', attributionControl: false,