@swr-data-lab/components 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
<script lang="ts">import maplibre, {} from 'maplibre-gl';
|
|
2
2
|
import { onMount, onDestroy, getContext, hasContext } from 'svelte';
|
|
3
|
-
import { createMapContext } from '../context.svelte.js';
|
|
3
|
+
import { createMapContext, MapContext } from '../context.svelte.js';
|
|
4
4
|
import {} from '../types';
|
|
5
5
|
import FallbackStyle from './FallbackStyle';
|
|
6
|
-
let { children, options, style = FallbackStyle, minZoom = 0, maxZoom = 14.99, zoom = $bindable(), center = $bindable(), pitch = $bindable(0), bearing = $bindable(0), loading = $bindable(true), projection = { type: 'mercator' }, allowRotation = false, allowZoom = true, showDebug = false, initialLocation: receivedInitialLocation
|
|
6
|
+
let { children, options, style = FallbackStyle, minZoom = 0, maxZoom = 14.99, zoom = $bindable(), center = $bindable(), pitch = $bindable(0), bearing = $bindable(0), loading = $bindable(true), projection = { type: 'mercator' }, allowRotation = false, allowZoom = true, showDebug = false, initialLocation: receivedInitialLocation,
|
|
7
|
+
// Future: This should become bindable.readonly when that becomes
|
|
8
|
+
// available, see: https://github.com/sveltejs/svelte/issues/7712
|
|
9
|
+
mapContext = $bindable(), onmoveend, onmovestart } = $props();
|
|
7
10
|
let container;
|
|
8
11
|
// Merge initial location with default object so individual
|
|
9
12
|
// properties (like pitch) can be omitted by the caller
|
|
@@ -14,7 +17,7 @@ let initialLocation = {
|
|
|
14
17
|
pitch: 0,
|
|
15
18
|
...receivedInitialLocation
|
|
16
19
|
};
|
|
17
|
-
|
|
20
|
+
mapContext = createMapContext();
|
|
18
21
|
if (getContext('initialLocation') !== undefined && getContext('initialLocation') !== false) {
|
|
19
22
|
initialLocation = getContext('initialLocation');
|
|
20
23
|
}
|
|
@@ -43,6 +46,12 @@ onMount(() => {
|
|
|
43
46
|
pitch = mapContext.map?.getPitch();
|
|
44
47
|
bearing = mapContext.map?.getBearing();
|
|
45
48
|
});
|
|
49
|
+
if (onmoveend) {
|
|
50
|
+
mapContext.map.on('moveend', onmoveend);
|
|
51
|
+
}
|
|
52
|
+
if (onmovestart) {
|
|
53
|
+
mapContext.map.on('movestart', onmovestart);
|
|
54
|
+
}
|
|
46
55
|
});
|
|
47
56
|
onDestroy(async () => {
|
|
48
57
|
if (mapContext.map)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import maplibre, { type ProjectionSpecification, type StyleSpecification } from 'maplibre-gl';
|
|
1
|
+
import maplibre, { type MapLibreEvent, type ProjectionSpecification, type StyleSpecification } from 'maplibre-gl';
|
|
2
2
|
import { type Snippet } from 'svelte';
|
|
3
|
+
import { MapContext } from '../context.svelte.js';
|
|
3
4
|
import { type Location } from '../types';
|
|
4
5
|
interface MapProps {
|
|
5
6
|
style?: StyleSpecification | string;
|
|
@@ -16,8 +17,11 @@ interface MapProps {
|
|
|
16
17
|
projection?: ProjectionSpecification;
|
|
17
18
|
showDebug?: boolean;
|
|
18
19
|
options?: any;
|
|
20
|
+
mapContext?: MapContext;
|
|
21
|
+
onmovestart?: (e: MapLibreEvent) => null;
|
|
22
|
+
onmoveend?: (e: MapLibreEvent) => null;
|
|
19
23
|
children?: Snippet;
|
|
20
24
|
}
|
|
21
|
-
declare const Map: import("svelte").Component<MapProps, {}, "center" | "zoom" | "pitch" | "bearing" | "loading">;
|
|
25
|
+
declare const Map: import("svelte").Component<MapProps, {}, "center" | "zoom" | "pitch" | "bearing" | "loading" | "mapContext">;
|
|
22
26
|
type Map = ReturnType<typeof Map>;
|
|
23
27
|
export default Map;
|