mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2025-09-02 16:52:31 +00:00
fix custom controls mounting
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onMount } from 'svelte';
|
import { onDestroy, onMount } from 'svelte';
|
||||||
|
|
||||||
import mapboxgl from 'mapbox-gl';
|
import mapboxgl from 'mapbox-gl';
|
||||||
import 'mapbox-gl/dist/mapbox-gl.css';
|
import 'mapbox-gl/dist/mapbox-gl.css';
|
||||||
@@ -115,6 +115,13 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
onDestroy(() => {
|
||||||
|
if ($map) {
|
||||||
|
$map.remove();
|
||||||
|
$map = null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
$: if (
|
$: if (
|
||||||
$map &&
|
$map &&
|
||||||
(!$verticalFileView || !$elevationProfile || $bottomPanelSize || $rightPanelSize)
|
(!$verticalFileView || !$elevationProfile || $bottomPanelSize || $rightPanelSize)
|
||||||
|
@@ -1,32 +1,17 @@
|
|||||||
<script lang="ts" context="module">
|
|
||||||
import { writable } from 'svelte/store';
|
|
||||||
|
|
||||||
let currentId = 0;
|
|
||||||
|
|
||||||
function getId() {
|
|
||||||
return currentId++;
|
|
||||||
}
|
|
||||||
|
|
||||||
let lastInitializedId = writable(-1);
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import CustomControl from './CustomControl';
|
import CustomControl from './CustomControl';
|
||||||
|
|
||||||
import { map } from '$lib/stores';
|
import { map } from '$lib/stores';
|
||||||
|
|
||||||
export let position: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' = 'top-right';
|
export let position: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' = 'top-right';
|
||||||
|
|
||||||
let container: HTMLDivElement | null = null;
|
let container: HTMLDivElement | null = null;
|
||||||
let id = getId();
|
|
||||||
|
|
||||||
$: if ($map && container && $lastInitializedId + 1 === id) {
|
$: if ($map && container) {
|
||||||
if (position.includes('right')) container.classList.add('float-right');
|
if (position.includes('right')) container.classList.add('float-right');
|
||||||
else container.classList.add('float-left');
|
else container.classList.add('float-left');
|
||||||
container.classList.remove('hidden');
|
container.classList.remove('hidden');
|
||||||
let control = new CustomControl(container);
|
let control = new CustomControl(container);
|
||||||
$map.addControl(control, position);
|
$map.addControl(control, position);
|
||||||
lastInitializedId.set(id);
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user