use store to access map object

This commit is contained in:
vcoppe
2024-04-17 11:44:37 +02:00
parent bd2d3eed66
commit ab0b425243
7 changed files with 48 additions and 55 deletions

View File

@@ -1,18 +1,20 @@
<script lang="ts">
import CustomControl from './CustomControl';
import mapboxgl from 'mapbox-gl';
export let map: mapboxgl.Map | null;
import { map } from '$lib/stores';
export let position: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' = 'top-right';
let container: HTMLDivElement | null = null;
$: if (map && container) {
if (position.includes('right')) container.classList.add('float-right');
else container.classList.add('float-left');
container.classList.remove('hidden');
let control = new CustomControl(container);
map.addControl(control, position);
$: if ($map && container) {
$map.on('load', () => {
if (position.includes('right')) container.classList.add('float-right');
else container.classList.add('float-left');
container.classList.remove('hidden');
let control = new CustomControl(container);
$map.addControl(control, position);
});
}
</script>