mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2025-08-31 15:43:25 +00:00
remove layer from map when removed from layer selection, maybe related to #110
This commit is contained in:
@@ -133,17 +133,6 @@
|
|||||||
selectedBasemap.set(value);
|
selectedBasemap.set(value);
|
||||||
});
|
});
|
||||||
|
|
||||||
function removeOverlayLayer(id: string) {
|
|
||||||
if ($map) {
|
|
||||||
let overlay = $customLayers.hasOwnProperty(id) ? $customLayers[id].value : overlays[id];
|
|
||||||
if (overlay.layers) {
|
|
||||||
$map.removeImport(id);
|
|
||||||
} else {
|
|
||||||
$map.removeLayer(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let open = false;
|
let open = false;
|
||||||
function openLayerControl() {
|
function openLayerControl() {
|
||||||
open = true;
|
open = true;
|
||||||
|
@@ -9,8 +9,14 @@
|
|||||||
import * as Select from '$lib/components/ui/select';
|
import * as Select from '$lib/components/ui/select';
|
||||||
import { Slider } from '$lib/components/ui/slider';
|
import { Slider } from '$lib/components/ui/slider';
|
||||||
|
|
||||||
import { basemapTree, overlays, overlayTree, overpassTree } from '$lib/assets/layers';
|
import {
|
||||||
import { isSelected } from '$lib/components/layer-control/utils';
|
basemapTree,
|
||||||
|
defaultBasemap,
|
||||||
|
overlays,
|
||||||
|
overlayTree,
|
||||||
|
overpassTree
|
||||||
|
} from '$lib/assets/layers';
|
||||||
|
import { getLayers, isSelected, toggle } from '$lib/components/layer-control/utils';
|
||||||
import { settings } from '$lib/db';
|
import { settings } from '$lib/db';
|
||||||
|
|
||||||
import { _ } from 'svelte-i18n';
|
import { _ } from 'svelte-i18n';
|
||||||
@@ -22,6 +28,7 @@
|
|||||||
selectedBasemapTree,
|
selectedBasemapTree,
|
||||||
selectedOverlayTree,
|
selectedOverlayTree,
|
||||||
selectedOverpassTree,
|
selectedOverpassTree,
|
||||||
|
currentBasemap,
|
||||||
currentOverlays,
|
currentOverlays,
|
||||||
customLayers,
|
customLayers,
|
||||||
opacities
|
opacities
|
||||||
@@ -46,6 +53,30 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$: if ($selectedBasemapTree && $currentBasemap) {
|
||||||
|
if (!isSelected($selectedBasemapTree, $currentBasemap)) {
|
||||||
|
if (!isSelected($selectedBasemapTree, defaultBasemap)) {
|
||||||
|
$selectedBasemapTree = toggle($selectedBasemapTree, defaultBasemap);
|
||||||
|
}
|
||||||
|
$currentBasemap = defaultBasemap;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$: if ($selectedOverlayTree && $currentOverlays) {
|
||||||
|
let overlayLayers = getLayers($currentOverlays);
|
||||||
|
let toRemove = Object.entries(overlayLayers).filter(
|
||||||
|
([id, checked]) => checked && !isSelected($selectedOverlayTree, id)
|
||||||
|
);
|
||||||
|
if (toRemove.length > 0) {
|
||||||
|
currentOverlays.update((tree) => {
|
||||||
|
toRemove.forEach(([id]) => {
|
||||||
|
toggle(tree, id);
|
||||||
|
});
|
||||||
|
return tree;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$: if ($selectedOverlay) {
|
$: if ($selectedOverlay) {
|
||||||
setOpacityFromSelection();
|
setOpacityFromSelection();
|
||||||
}
|
}
|
||||||
|
@@ -39,4 +39,15 @@ export function isSelected(node: LayerTreeType, id: string) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function toggle(node: LayerTreeType, id: string) {
|
||||||
|
Object.keys(node).forEach((key) => {
|
||||||
|
if (key === id) {
|
||||||
|
node[key] = !node[key];
|
||||||
|
} else if (typeof node[key] !== "boolean") {
|
||||||
|
toggle(node[key], id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
export const customBasemapUpdate = writable(0);
|
export const customBasemapUpdate = writable(0);
|
Reference in New Issue
Block a user