@swr-data-lab/components 2.44.0 → 3.0.1
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.
- package/dist/maplibre/Map/Map.svelte +17 -10
- package/dist/maplibre/Map/Map.svelte.d.ts +2 -2
- package/dist/maplibre/MapStyle/SWRDataLabLight.js +14 -8
- package/dist/maplibre/VectorTileSource/VectorTileSource.svelte +10 -7
- package/dist/maplibre/VectorTileSource/VectorTileSource.svelte.d.ts +5 -2
- package/dist/maplibre/VectorTileSource/fetchTileJson.d.ts +2 -0
- package/dist/maplibre/VectorTileSource/fetchTileJson.js +16 -0
- package/dist/maplibre/VectorTileSource/types.d.ts +7 -0
- package/dist/maplibre/VectorTileSource/types.js +1 -0
- package/dist/maplibre/WithLinkLocation/WithLinkLocation.svelte +9 -14
- package/dist/maplibre/WithLinkLocation/WithLinkLocation.svelte.d.ts +6 -0
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script lang="ts">import maplibre, {} from 'maplibre-gl';
|
|
2
|
+
import {} from '../types';
|
|
2
3
|
import { onMount, onDestroy, getContext, hasContext } from 'svelte';
|
|
3
4
|
import { createMapContext, MapContext } from '../context.svelte.js';
|
|
4
|
-
import {} from '../types';
|
|
5
5
|
import FallbackStyle from './FallbackStyle';
|
|
6
6
|
import { de } from './locale';
|
|
7
7
|
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' }, allowPan = true, allowRotation = false, allowZoom = true, showDebug = false, cursor, initialBounds, maxBounds, initialLocation: receivedInitialLocation,
|
|
@@ -9,19 +9,20 @@ let { children, options, style = FallbackStyle, minZoom = 0, maxZoom = 14.99, zo
|
|
|
9
9
|
// available, see: https://github.com/sveltejs/svelte/issues/7712
|
|
10
10
|
mapContext = $bindable(), cooperativeGestures = false, onmoveend, onmovestart } = $props();
|
|
11
11
|
let container;
|
|
12
|
-
|
|
13
|
-
//
|
|
14
|
-
|
|
12
|
+
mapContext = createMapContext();
|
|
13
|
+
// Initial location is determined by (in order of precedence) :
|
|
14
|
+
// 1. An arbitrary default location
|
|
15
|
+
// 2. initialLocation prop
|
|
16
|
+
// 3. initialLocation context (notably set by <WithLinkLocation/>)
|
|
17
|
+
let contextLocation = getContext('initialLocation');
|
|
18
|
+
let initialLocation = $derived({
|
|
15
19
|
lat: 51.3,
|
|
16
20
|
lng: 10.2,
|
|
17
21
|
zoom: 5,
|
|
18
22
|
pitch: 0,
|
|
19
|
-
...receivedInitialLocation
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (getContext('initialLocation') !== undefined && getContext('initialLocation') !== false) {
|
|
23
|
-
initialLocation = getContext('initialLocation');
|
|
24
|
-
}
|
|
23
|
+
...receivedInitialLocation,
|
|
24
|
+
...contextLocation
|
|
25
|
+
});
|
|
25
26
|
onMount(() => {
|
|
26
27
|
mapContext.map = new maplibre.Map({
|
|
27
28
|
container,
|
|
@@ -76,6 +77,12 @@ $effect(() => {
|
|
|
76
77
|
mapContext.map?.setProjection(projection);
|
|
77
78
|
}
|
|
78
79
|
});
|
|
80
|
+
$effect(() => {
|
|
81
|
+
mapContext.map?.jumpTo({
|
|
82
|
+
center: [initialLocation.lng, initialLocation.lat],
|
|
83
|
+
zoom: initialLocation.zoom
|
|
84
|
+
});
|
|
85
|
+
});
|
|
79
86
|
$effect(() => {
|
|
80
87
|
if (allowZoom === false) {
|
|
81
88
|
mapContext.map?.scrollZoom.disable();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import maplibre, { type LngLatBoundsLike, type MapLibreEvent, type ProjectionSpecification, type StyleSpecification } from 'maplibre-gl';
|
|
2
|
+
import { type Location } from '../types';
|
|
2
3
|
import { type Snippet } from 'svelte';
|
|
3
4
|
import { MapContext } from '../context.svelte.js';
|
|
4
|
-
import { type Location } from '../types';
|
|
5
5
|
interface MapProps {
|
|
6
6
|
style?: StyleSpecification | string;
|
|
7
7
|
/**
|
|
@@ -24,7 +24,7 @@ interface MapProps {
|
|
|
24
24
|
showDebug?: boolean;
|
|
25
25
|
options?: any;
|
|
26
26
|
/**
|
|
27
|
-
* Set the mouse cursor. `""` (empty string) restores Maplibre's default behaviour. See VectorLayer/Default for a
|
|
27
|
+
* Set the mouse cursor. `""` (empty string) restores Maplibre's default behaviour. See VectorLayer/Default for a usage example
|
|
28
28
|
*/
|
|
29
29
|
cursor?: string;
|
|
30
30
|
mapContext?: MapContext;
|
|
@@ -7,26 +7,32 @@ import makeWalking from './components/Walking';
|
|
|
7
7
|
import makeRoads from './components/Roads';
|
|
8
8
|
import defaultOptions from './defaultOptions';
|
|
9
9
|
import makeHillshade from './components/Hillshade';
|
|
10
|
+
const water = {
|
|
11
|
+
stops: [
|
|
12
|
+
[6, 'white'],
|
|
13
|
+
[6.5, 'hsl(216, 50%, 92%)']
|
|
14
|
+
]
|
|
15
|
+
};
|
|
10
16
|
const tokens = {
|
|
11
17
|
sans_regular: ['swr_sans_regular'],
|
|
12
18
|
sans_medium: ['swr_sans_medium'],
|
|
13
19
|
sans_bold: ['swr_sans_bold'],
|
|
14
20
|
background: {
|
|
15
21
|
stops: [
|
|
16
|
-
[
|
|
17
|
-
[
|
|
22
|
+
[6, 'hsl(24, 20%, 97%)'],
|
|
23
|
+
[6.5, 'hsl(24, 10%, 99%)']
|
|
18
24
|
]
|
|
19
25
|
},
|
|
20
|
-
water
|
|
21
|
-
water_light:
|
|
22
|
-
water_ocean:
|
|
23
|
-
marsh: 'hsl(200, 14%,
|
|
26
|
+
water,
|
|
27
|
+
water_light: water,
|
|
28
|
+
water_ocean: water,
|
|
29
|
+
marsh: 'hsl(200, 14%, 93%)',
|
|
24
30
|
grass: 'hsl(133, 36%, 95%)',
|
|
25
31
|
grass_dark: 'hsl(127, 49%, 93%)',
|
|
26
32
|
sand: 'hsl(60, 0%, 95%)',
|
|
27
33
|
rock: 'hsl(192, 0%, 90%)',
|
|
28
34
|
street_primary: 'hsl(0, 4%, 95%)',
|
|
29
|
-
street_primary_faded: 'hsl(0, 4%,
|
|
35
|
+
street_primary_faded: 'hsl(0, 4%, 93%)',
|
|
30
36
|
street_primary_case: 'hsl(240, 1%, 84%)',
|
|
31
37
|
street_secondary: 'hsl(0, 0%, 95%)',
|
|
32
38
|
street_secondary_case: 'hsl(0, 0%, 75%)',
|
|
@@ -34,7 +40,7 @@ const tokens = {
|
|
|
34
40
|
street_tertiary_case: 'hsl(0, 0%, 70%)',
|
|
35
41
|
label_primary: 'hsl(240, 10%, 2%)',
|
|
36
42
|
label_secondary: 'hsl(0, 0%, 18%)',
|
|
37
|
-
label_tertiary: 'hsl(60, 1%,
|
|
43
|
+
label_tertiary: 'hsl(60, 1%, 25%)',
|
|
38
44
|
building: '#f3f2f1',
|
|
39
45
|
rail: '#d3d3d3',
|
|
40
46
|
boundary_country: '#8b8a89',
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
<script lang="ts">import {} from 'maplibre-gl';
|
|
2
2
|
import MapSource from '../Source/MapSource.svelte';
|
|
3
|
-
|
|
4
|
-
const
|
|
3
|
+
import fetchTileJSON from './fetchTileJson';
|
|
4
|
+
const { minZoom, maxZoom, id, url, tiles, attribution, promoteId } = $props();
|
|
5
|
+
let tileJsonData = $derived(url ? await fetchTileJSON(url) : {});
|
|
6
|
+
const sourceSpec = $derived({
|
|
5
7
|
type: 'vector',
|
|
6
|
-
tiles: [
|
|
7
|
-
maxzoom: maxZoom,
|
|
8
|
-
minzoom: minZoom,
|
|
9
|
-
attribution
|
|
10
|
-
|
|
8
|
+
tiles: tiles || tileJsonData.tiles || [],
|
|
9
|
+
maxzoom: maxZoom || tileJsonData.maxZoom || 24,
|
|
10
|
+
minzoom: minZoom || tileJsonData.minZoom || 0,
|
|
11
|
+
attribution: attribution || tileJsonData.attribution || '',
|
|
12
|
+
promoteId
|
|
13
|
+
});
|
|
11
14
|
</script>
|
|
12
15
|
|
|
13
16
|
<MapSource {id} {sourceSpec} />
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
import { type PromoteIdSpecification } from 'maplibre-gl';
|
|
1
2
|
interface VectorTileSourceProps {
|
|
2
3
|
id: string;
|
|
3
|
-
url
|
|
4
|
+
url?: string;
|
|
5
|
+
tiles?: string[];
|
|
4
6
|
minZoom?: number;
|
|
5
7
|
maxZoom?: number;
|
|
6
8
|
/**
|
|
7
|
-
* Attribution string for your data, usually rendered using an `<AttributionControl
|
|
9
|
+
* Attribution string for your data, usually rendered using an `<AttributionControl/>`
|
|
8
10
|
*/
|
|
9
11
|
attribution?: string;
|
|
12
|
+
promoteId?: PromoteIdSpecification;
|
|
10
13
|
}
|
|
11
14
|
declare const VectorTileSource: import("svelte").Component<VectorTileSourceProps, {}, "">;
|
|
12
15
|
type VectorTileSource = ReturnType<typeof VectorTileSource>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {} from './types';
|
|
2
|
+
// Workaround for https://github.com/versatiles-org/versatiles-rs/issues/184
|
|
3
|
+
// Drop when/if this lands: https://github.com/maplibre/maplibre-gl-js/issues/182
|
|
4
|
+
export default async function fetchTileJSON(url) {
|
|
5
|
+
const u = new URL(url);
|
|
6
|
+
const res = await fetch(u);
|
|
7
|
+
const data = await res.json();
|
|
8
|
+
// Simple heuristic for absolute URLs
|
|
9
|
+
const re = /(((http)s?)):\/\/.*/gi;
|
|
10
|
+
return {
|
|
11
|
+
tiles: data?.tiles.map((path) => (re.test(path) ? path : `${u.origin}${path}`)),
|
|
12
|
+
attribution: data?.attribution || data?.author,
|
|
13
|
+
minZoom: data?.minzoom,
|
|
14
|
+
maxZoom: data?.maxzoom
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -8,11 +8,11 @@ let geocoder;
|
|
|
8
8
|
if (service === 'maptiler') {
|
|
9
9
|
geocoder = new MaptilerGeocoderAPI(key);
|
|
10
10
|
}
|
|
11
|
-
let location = $state();
|
|
11
|
+
let location = $state({});
|
|
12
12
|
function bboxToArea(bbox) {
|
|
13
13
|
return (bbox[2] - bbox[0]) * (bbox[3] - bbox[1]);
|
|
14
14
|
}
|
|
15
|
-
|
|
15
|
+
$effect(async () => {
|
|
16
16
|
const params = new URLSearchParams(window.location.search);
|
|
17
17
|
if (params.has(urlParameter)) {
|
|
18
18
|
const config = {
|
|
@@ -23,22 +23,17 @@ onMount(async () => {
|
|
|
23
23
|
};
|
|
24
24
|
const res = await geocoder.forwardGeocode(config);
|
|
25
25
|
if (res.features[0].bbox && res.features[0].geometry.type === 'Point') {
|
|
26
|
-
location =
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
};
|
|
26
|
+
location.lat = res.features[0].geometry.coordinates[1];
|
|
27
|
+
location.lng = res.features[0].geometry.coordinates[0];
|
|
28
|
+
location.zoom = 11 - bboxToArea(res.features[0].bbox) * 5.5;
|
|
29
|
+
location.active = true;
|
|
31
30
|
}
|
|
32
31
|
}
|
|
33
32
|
else {
|
|
34
|
-
location =
|
|
33
|
+
location = {};
|
|
35
34
|
}
|
|
36
35
|
});
|
|
37
|
-
|
|
38
|
-
setContext('initialLocation', location);
|
|
39
|
-
});
|
|
36
|
+
setContext('initialLocation', location);
|
|
40
37
|
</script>
|
|
41
38
|
|
|
42
|
-
{
|
|
43
|
-
{@render children?.()}
|
|
44
|
-
{/if}
|
|
39
|
+
{@render children?.()}
|
|
@@ -10,7 +10,13 @@ interface WithLinkLocationProps {
|
|
|
10
10
|
* Limit search to one or more countries
|
|
11
11
|
*/
|
|
12
12
|
countries?: GeocodingLanguage | GeocodingCountry[];
|
|
13
|
+
/**
|
|
14
|
+
* Limit search to one or more languages
|
|
15
|
+
*/
|
|
13
16
|
languages?: GeocodingLanguage | GeocodingLanguage[];
|
|
17
|
+
/**
|
|
18
|
+
* Customise the URL parameter used to set the initial location
|
|
19
|
+
*/
|
|
14
20
|
urlParameter?: string;
|
|
15
21
|
children: Snippet;
|
|
16
22
|
}
|