fix custom layer creation, relates to #12

This commit is contained in:
vcoppe
2024-07-16 13:26:11 +02:00
parent bbfa096fe8
commit 210dd2fe98
2 changed files with 27 additions and 18 deletions

View File

@@ -99,15 +99,21 @@
function addLayer(layerId: string) { function addLayer(layerId: string) {
if (layerType === 'basemap') { if (layerType === 'basemap') {
if (!$selectedBasemapTree.basemaps.hasOwnProperty('custom')) { selectedBasemapTree.update(($tree) => {
$selectedBasemapTree.basemaps['custom'] = {}; if (!$tree.basemaps.hasOwnProperty('custom')) {
} $tree.basemaps['custom'] = {};
$selectedBasemapTree.basemaps['custom'][layerId] = true; }
$tree.basemaps['custom'][layerId] = true;
return $tree;
});
} else { } else {
if (!$selectedOverlayTree.overlays.hasOwnProperty('custom')) { selectedOverlayTree.update(($tree) => {
$selectedOverlayTree.overlays['custom'] = {}; if (!$tree.overlays.hasOwnProperty('custom')) {
} $tree.overlays['custom'] = {};
$selectedOverlayTree.overlays['custom'][layerId] = true; }
$tree.overlays['custom'][layerId] = true;
return $tree;
});
} }
} }

View File

@@ -8,6 +8,7 @@
import { _ } from 'svelte-i18n'; import { _ } from 'svelte-i18n';
import { settings } from '$lib/db'; import { settings } from '$lib/db';
import { beforeUpdate } from 'svelte';
export let name: string; export let name: string;
export let node: LayerTreeType; export let node: LayerTreeType;
@@ -18,17 +19,19 @@
const { customLayers } = settings; const { customLayers } = settings;
$: if (checked !== undefined) { beforeUpdate(() => {
Object.keys(node).forEach((id) => { if (checked !== undefined) {
if (!checked.hasOwnProperty(id)) { Object.keys(node).forEach((id) => {
if (typeof node[id] == 'boolean') { if (!checked.hasOwnProperty(id)) {
checked[id] = false; if (typeof node[id] == 'boolean') {
} else { checked[id] = false;
checked[id] = {}; } else {
checked[id] = {};
}
} }
} });
}); }
} });
</script> </script>
<div class="flex flex-col gap-[3px]"> <div class="flex flex-col gap-[3px]">