@swr-data-lab/components 1.11.3 → 1.12.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.
- package/.storybook/blocks/Mermaid.jsx +9 -0
- package/.storybook/main.ts +23 -17
- package/.storybook/preview.ts +42 -13
- package/package.json +72 -68
- package/src/DesignTokens/Tokens.ts +15 -12
- package/src/Select/Select.stories.svelte +3 -3
- package/src/Switcher/Switcher.svelte +1 -0
- package/src/index.js +12 -0
- package/src/maplibre/AttributionControl/AttributionControl.stories.svelte +29 -0
- package/src/maplibre/AttributionControl/AttributionControl.svelte +45 -0
- package/src/maplibre/AttributionControl/index.js +2 -0
- package/src/maplibre/GeocoderControl/GeocoderAPIs.ts +49 -0
- package/src/maplibre/GeocoderControl/GeocoderControl.stories.svelte +78 -0
- package/src/maplibre/GeocoderControl/GeocoderControl.svelte +207 -0
- package/src/maplibre/GeocoderControl/index.js +2 -0
- package/src/maplibre/Map/FallbackStyle.ts +18 -0
- package/src/maplibre/Map/Map.stories.svelte +118 -0
- package/src/maplibre/Map/Map.svelte +283 -0
- package/src/maplibre/Map/index.js +2 -0
- package/src/maplibre/MapControl/MapControl.mdx +12 -0
- package/src/maplibre/MapControl/MapControl.stories.svelte +56 -0
- package/src/maplibre/MapControl/MapControl.svelte +41 -0
- package/src/maplibre/MapControl/index.js +2 -0
- package/src/maplibre/MapStyle/SWRDataLabLight.mdx +86 -0
- package/src/maplibre/MapStyle/SWRDataLabLight.stories.svelte +41 -0
- package/src/maplibre/MapStyle/SWRDataLabLight.ts +72 -0
- package/src/maplibre/MapStyle/components/Admin.ts +173 -0
- package/src/maplibre/MapStyle/components/Buildings.ts +23 -0
- package/src/maplibre/MapStyle/components/Landuse.ts +499 -0
- package/src/maplibre/MapStyle/components/Natural.ts +1 -0
- package/src/maplibre/MapStyle/components/PlaceLabels.ts +199 -0
- package/src/maplibre/MapStyle/components/Roads.ts +2345 -0
- package/src/maplibre/MapStyle/components/Transit.ts +507 -0
- package/src/maplibre/MapStyle/components/Walking.ts +1538 -0
- package/src/maplibre/MapStyle/index.js +2 -0
- package/src/maplibre/MapStyle/tokens.ts +21 -0
- package/src/maplibre/Maplibre.mdx +91 -0
- package/src/maplibre/NavigationControl/NavigationControl.stories.svelte +39 -0
- package/src/maplibre/NavigationControl/NavigationControl.svelte +36 -0
- package/src/maplibre/NavigationControl/index.js +2 -0
- package/src/maplibre/ScaleControl/ScaleControl.stories.svelte +71 -0
- package/src/maplibre/ScaleControl/ScaleControl.svelte +25 -0
- package/src/maplibre/ScaleControl/index.js +2 -0
- package/src/maplibre/Source/MapSource.stories.svelte +9 -0
- package/src/maplibre/Source/MapSource.svelte +61 -0
- package/src/maplibre/Source/index.js +2 -0
- package/src/maplibre/Source/source.ts +89 -0
- package/src/maplibre/Tooltip/Tooltip.stories.svelte +192 -0
- package/src/maplibre/Tooltip/Tooltip.svelte +175 -0
- package/src/maplibre/Tooltip/index.js +2 -0
- package/src/maplibre/VectorLayer/VectorLayer.stories.svelte +65 -0
- package/src/maplibre/VectorLayer/VectorLayer.svelte +142 -0
- package/src/maplibre/VectorLayer/index.js +2 -0
- package/src/maplibre/VectorTileSource/VectorTileSource.mdx +19 -0
- package/src/maplibre/VectorTileSource/VectorTileSource.stories.svelte +46 -0
- package/src/maplibre/VectorTileSource/VectorTileSource.svelte +24 -0
- package/src/maplibre/VectorTileSource/index.js +2 -0
- package/src/maplibre/WithLinkLocation/WithLinkLocation.mdx +11 -0
- package/src/maplibre/WithLinkLocation/WithLinkLocation.stories.svelte +29 -0
- package/src/maplibre/WithLinkLocation/WithLinkLocation.svelte +83 -0
- package/src/maplibre/WithLinkLocation/index.js +2 -0
- package/src/maplibre/context.svelte.ts +89 -0
- package/src/maplibre/types.ts +12 -0
- package/src/maplibre/utils.ts +52 -0
- package/tsconfig.json +1 -0
package/.storybook/main.ts
CHANGED
|
@@ -2,27 +2,33 @@ import { dirname, join } from 'path';
|
|
|
2
2
|
import type { StorybookConfig } from '@storybook/sveltekit';
|
|
3
3
|
|
|
4
4
|
function getAbsolutePath(value: string): any {
|
|
5
|
-
|
|
5
|
+
if (process.platform.includes('win')) {
|
|
6
|
+
return value;
|
|
7
|
+
} else {
|
|
8
|
+
return dirname(require.resolve(join(value, 'package.json')));
|
|
9
|
+
}
|
|
6
10
|
}
|
|
7
11
|
|
|
8
12
|
const config: StorybookConfig = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
stories: ['../src/**/*.stories.@(js|ts|svelte)', '../src/**/*.mdx'],
|
|
14
|
+
addons: [
|
|
15
|
+
{
|
|
16
|
+
name: getAbsolutePath('@storybook/addon-svelte-csf'),
|
|
17
|
+
options: {
|
|
18
|
+
legacyTemplate: true
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
getAbsolutePath('@storybook/addon-links'),
|
|
22
|
+
getAbsolutePath('@chromatic-com/storybook'),
|
|
23
|
+
getAbsolutePath('@storybook/addon-vitest'),
|
|
24
|
+
getAbsolutePath('@storybook/addon-docs')
|
|
25
|
+
],
|
|
26
|
+
framework: {
|
|
27
|
+
name: getAbsolutePath('@storybook/sveltekit'),
|
|
28
|
+
options: {}
|
|
29
|
+
},
|
|
13
30
|
|
|
14
|
-
|
|
15
|
-
name: getAbsolutePath("@storybook/addon-svelte-csf"),
|
|
16
|
-
options: {
|
|
17
|
-
legacyTemplate: true
|
|
18
|
-
}
|
|
19
|
-
}, getAbsolutePath('@storybook/addon-links'), getAbsolutePath('@chromatic-com/storybook'), getAbsolutePath('@storybook/addon-vitest'), getAbsolutePath("@storybook/addon-docs")],
|
|
20
|
-
framework: {
|
|
21
|
-
name: getAbsolutePath("@storybook/sveltekit"),
|
|
22
|
-
options: {}
|
|
23
|
-
},
|
|
24
|
-
|
|
25
|
-
docs: {}
|
|
31
|
+
docs: {}
|
|
26
32
|
};
|
|
27
33
|
|
|
28
34
|
export default config;
|
package/.storybook/preview.ts
CHANGED
|
@@ -1,18 +1,47 @@
|
|
|
1
|
-
import type { Preview } from
|
|
1
|
+
import type { Preview } from '@storybook/sveltekit';
|
|
2
2
|
|
|
3
3
|
const preview: Preview = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
4
|
+
parameters: {
|
|
5
|
+
options: {
|
|
6
|
+
storySort: {
|
|
7
|
+
order: [
|
|
8
|
+
'About',
|
|
9
|
+
'Design Tokens',
|
|
10
|
+
'Typography',
|
|
11
|
+
['Headline', 'Copy', 'Caption'],
|
|
12
|
+
'Display',
|
|
13
|
+
'Chart',
|
|
14
|
+
['ChartHeader'],
|
|
15
|
+
'Maplibre',
|
|
16
|
+
[
|
|
17
|
+
'Map',
|
|
18
|
+
'MapStyle',
|
|
19
|
+
'Source',
|
|
20
|
+
'Layer',
|
|
21
|
+
'Control',
|
|
22
|
+
[
|
|
23
|
+
'ScaleControl',
|
|
24
|
+
'GeoCoderControl',
|
|
25
|
+
'AttributionControl',
|
|
26
|
+
'NavigationControl',
|
|
27
|
+
'MapControl'
|
|
28
|
+
],
|
|
29
|
+
'Style',
|
|
30
|
+
'Tooltip'
|
|
31
|
+
],
|
|
32
|
+
'Form',
|
|
33
|
+
'Deprecated'
|
|
34
|
+
]
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
controls: {
|
|
38
|
+
matchers: {
|
|
39
|
+
color: /(background|color)$/i,
|
|
40
|
+
date: /Date$/i
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
tags: ['autodocs']
|
|
16
45
|
};
|
|
17
46
|
|
|
18
47
|
export default preview;
|
package/package.json
CHANGED
|
@@ -1,70 +1,74 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
2
|
+
"name": "@swr-data-lab/components",
|
|
3
|
+
"description": "SWR Data Lab component library",
|
|
4
|
+
"author": "SWR Data Lab",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "restricted"
|
|
7
|
+
},
|
|
8
|
+
"scripts": {
|
|
9
|
+
"dev": "vite dev",
|
|
10
|
+
"build": "vite build",
|
|
11
|
+
"preview": "vite preview",
|
|
12
|
+
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
|
13
|
+
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
|
14
|
+
"storybook": "storybook dev -p 6006",
|
|
15
|
+
"start": "storybook dev -p 6006",
|
|
16
|
+
"build-storybook": "storybook build --disable-telemetry",
|
|
17
|
+
"test-storybook": "vitest run --project=storybook",
|
|
18
|
+
"test-storybook:ci": "concurrently -k -s first -n \"Storybook,Test\" -c \"magenta,blue\" \"npm run build-storybook --quiet && npx http-server storybook-static --port 6006 --silent\" \"wait-on tcp:6006 && npm run test-storybook\"",
|
|
19
|
+
"semantic-release": "semantic-release"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@maplibre/maplibre-gl-geocoder": "^1.8.0",
|
|
23
|
+
"@versatiles/style": "^5.6.0",
|
|
24
|
+
"maplibre-gl": "^5.5.0",
|
|
25
|
+
"svelte-select": "^5.8.3"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@chromatic-com/storybook": "^4.0.0-next.6",
|
|
29
|
+
"@semantic-release/changelog": "^6.0.3",
|
|
30
|
+
"@semantic-release/git": "^10.0.1",
|
|
31
|
+
"@semantic-release/npm": "^12.0.1",
|
|
32
|
+
"@storybook/addon-docs": "^9.0.0-beta.11",
|
|
33
|
+
"@storybook/addon-links": "^9.0.0-beta.11",
|
|
34
|
+
"@storybook/addon-svelte-csf": "^5.0.0-next.30",
|
|
35
|
+
"@storybook/addon-vitest": "^9.0.0-beta.11",
|
|
36
|
+
"@storybook/sveltekit": "^9.0.0-beta.11",
|
|
37
|
+
"@storybook/test-runner": "^0.23.0-next.1",
|
|
38
|
+
"@sveltejs/adapter-auto": "^3.0.0",
|
|
39
|
+
"@sveltejs/kit": "^2.0.0",
|
|
40
|
+
"@sveltejs/vite-plugin-svelte": "^5.0.3",
|
|
41
|
+
"@vitest/browser": "^3.1.1",
|
|
42
|
+
"@vitest/coverage-v8": "^3.1.1",
|
|
43
|
+
"concurrently": "^9.0.1",
|
|
44
|
+
"http-server": "^14.1.1",
|
|
45
|
+
"mdx-mermaid": "^2.0.3",
|
|
46
|
+
"playwright": "^1.51.1",
|
|
47
|
+
"sass-embedded": "^1.78.0",
|
|
48
|
+
"semantic-release": "^24.1.2",
|
|
49
|
+
"storybook": "^9.0.0-beta.11",
|
|
50
|
+
"svelte": "^5.23.0",
|
|
51
|
+
"svelte-check": "^4.0.0",
|
|
52
|
+
"typescript": "^5.0.0",
|
|
53
|
+
"vite": "^6.0.0",
|
|
54
|
+
"vitest": "^3.1.1",
|
|
55
|
+
"wait-on": "^8.0.1"
|
|
56
|
+
},
|
|
57
|
+
"type": "module",
|
|
58
|
+
"release": {
|
|
59
|
+
"plugins": [
|
|
60
|
+
"@semantic-release/commit-analyzer",
|
|
61
|
+
"@semantic-release/release-notes-generator",
|
|
62
|
+
"@semantic-release/npm"
|
|
63
|
+
]
|
|
64
|
+
},
|
|
65
|
+
"exports": {
|
|
66
|
+
".": {
|
|
67
|
+
"svelte": "./src/index.js"
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
"version": "1.12.0",
|
|
71
|
+
"overrides": {
|
|
72
|
+
"storybook": "$storybook"
|
|
73
|
+
}
|
|
70
74
|
}
|
|
@@ -2,10 +2,10 @@ interface ColourMap {
|
|
|
2
2
|
[index: string]: ColourPalette | ColourList;
|
|
3
3
|
}
|
|
4
4
|
interface ColourPalette {
|
|
5
|
-
[index: string]: string
|
|
5
|
+
[index: string]: string;
|
|
6
6
|
}
|
|
7
7
|
interface ColourList {
|
|
8
|
-
[index: number]: string
|
|
8
|
+
[index: number]: string;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
const shades: ColourMap = {
|
|
@@ -142,9 +142,13 @@ const shades: ColourMap = {
|
|
|
142
142
|
dark5: '#1D0B40'
|
|
143
143
|
},
|
|
144
144
|
gray: {
|
|
145
|
+
light5: 'hsl(225, 2%, 95%)',
|
|
145
146
|
light3: 'hsl(225, 2%, 77%)',
|
|
146
147
|
base: 'hsl(227, 2%, 50%)',
|
|
147
|
-
|
|
148
|
+
dark2: 'hsl(236, 2%, 38%)',
|
|
149
|
+
dark3: 'hsl(236, 2%, 32%)',
|
|
150
|
+
dark4: 'hsl(236, 2%, 22%)',
|
|
151
|
+
dark5: 'hsl(236, 2%, 5%)'
|
|
148
152
|
}
|
|
149
153
|
};
|
|
150
154
|
|
|
@@ -164,18 +168,17 @@ const scales: ColourMap = {
|
|
|
164
168
|
forest_plum: [...Object.values(shades.forest).reverse(), ...Object.values(shades.plum)]
|
|
165
169
|
};
|
|
166
170
|
|
|
167
|
-
|
|
168
171
|
const typography = {
|
|
169
172
|
wide: {
|
|
170
173
|
sizes: {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
174
|
+
'fs-small-3': '0.75rem',
|
|
175
|
+
'fs-small-2': '0.875rem',
|
|
176
|
+
'fs-small-1': '1rem',
|
|
177
|
+
'fs-base': '1.25rem',
|
|
178
|
+
'fs-large-1': '1.5rem',
|
|
179
|
+
'fs-large-2': '2rem',
|
|
180
|
+
'fs-large-3': '2.5rem',
|
|
181
|
+
'fs-large-4': '3.5rem'
|
|
179
182
|
}
|
|
180
183
|
}
|
|
181
184
|
};
|
|
@@ -136,17 +136,17 @@
|
|
|
136
136
|
expect(canvas.getByTestId('custom-item-title').innerText).toEqual('Journalismus');
|
|
137
137
|
expect(canvas.getByTestId('custom-item-addon').innerText).toContain('Redakteur/in');
|
|
138
138
|
await userEvent.type(select, '{enter}');
|
|
139
|
-
expect(selectedItem
|
|
139
|
+
expect(selectedItem?.details.title).toEqual('Journalismus');
|
|
140
140
|
});
|
|
141
141
|
|
|
142
142
|
await step('Entering an item\'s "title" selects that item', async () => {
|
|
143
143
|
await userEvent.type(select, 'Tierpflege{enter}');
|
|
144
|
-
expect(selectedItem
|
|
144
|
+
expect(selectedItem?.details.title).toEqual('Tierpflege');
|
|
145
145
|
});
|
|
146
146
|
|
|
147
147
|
await step('Entering an item\'s "addon" selects that item', async () => {
|
|
148
148
|
await userEvent.type(select, 'Zirkuskünstler{enter}');
|
|
149
|
-
expect(selectedItem
|
|
149
|
+
expect(selectedItem?.details.title).toEqual('Schauspiel und Tanz');
|
|
150
150
|
});
|
|
151
151
|
}}
|
|
152
152
|
>
|
package/src/index.js
CHANGED
|
@@ -10,3 +10,15 @@ export { default as ChartHeader } from './ChartHeader/ChartHeader.svelte';
|
|
|
10
10
|
export { default as ChartFooter } from './ChartFooter/ChartFooter.svelte';
|
|
11
11
|
export { default as Middot } from './Middot/Middot.svelte';
|
|
12
12
|
export { default as FormLabel } from './FormLabel/FormLabel.svelte';
|
|
13
|
+
|
|
14
|
+
export { default as Map } from './maplibre/Map/Map.svelte';
|
|
15
|
+
export { SWRDataLabLight } from './maplibre/MapStyle';
|
|
16
|
+
export { default as MapControl } from './maplibre/MapControl/MapControl.svelte';
|
|
17
|
+
export { default as AttributionControl } from './maplibre/AttributionControl/AttributionControl.svelte';
|
|
18
|
+
export { default as GeoCoderControl } from './maplibre/GeoCoderControl/GeoCoderControl.svelte';
|
|
19
|
+
export { default as NavigationControl } from './maplibre/NavigationControl/NavigationControl.svelte';
|
|
20
|
+
export { default as ScaleControl } from './maplibre/ScaleControl/ScaleControl.svelte';
|
|
21
|
+
export { default as VectorLayer } from './maplibre/VectorLayer/VectorLayer.svelte';
|
|
22
|
+
export { default as VectorTileSource } from './maplibre/VectorTileSource/VectorTileSource.svelte';
|
|
23
|
+
export { default as Tooltip } from './maplibre/Tooltip/Tooltip.svelte';
|
|
24
|
+
export { default as WithLinkLocation } from './maplibre/WithLinkLocation/WithLinkLocation.svelte';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<script context="module" lang="ts">
|
|
2
|
+
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
3
|
+
import AttributionControl from './AttributionControl.svelte';
|
|
4
|
+
import DesignTokens from '../../DesignTokens/DesignTokens.svelte';
|
|
5
|
+
import Map from '../Map/Map.svelte';
|
|
6
|
+
import { SWRDataLabLight } from '../MapStyle';
|
|
7
|
+
|
|
8
|
+
const { Story } = defineMeta({
|
|
9
|
+
title: 'Maplibre/Control/AttributionControl',
|
|
10
|
+
component: AttributionControl
|
|
11
|
+
});
|
|
12
|
+
</script>
|
|
13
|
+
|
|
14
|
+
<Story asChild name="Default">
|
|
15
|
+
<DesignTokens>
|
|
16
|
+
<div class="container">
|
|
17
|
+
<Map style={SWRDataLabLight} initialLocation={{ lat: 51, lng: 10, zoom: 20 }}>
|
|
18
|
+
<AttributionControl customAttribution="SWR Data Lab" position="bottom-left" />
|
|
19
|
+
</Map>
|
|
20
|
+
</div>
|
|
21
|
+
</DesignTokens>
|
|
22
|
+
</Story>
|
|
23
|
+
|
|
24
|
+
<style>
|
|
25
|
+
.container {
|
|
26
|
+
width: 500px;
|
|
27
|
+
height: 300px;
|
|
28
|
+
}
|
|
29
|
+
</style>
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { type ControlPosition, AttributionControl } from 'maplibre-gl';
|
|
3
|
+
import MapControl from '../MapControl/MapControl.svelte';
|
|
4
|
+
|
|
5
|
+
interface AttributionControlProps {
|
|
6
|
+
position?: ControlPosition;
|
|
7
|
+
customAttribution?: string;
|
|
8
|
+
}
|
|
9
|
+
const { position = 'bottom-right', customAttribution }: AttributionControlProps = $props();
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
<MapControl
|
|
13
|
+
{position}
|
|
14
|
+
control={new AttributionControl({
|
|
15
|
+
customAttribution,
|
|
16
|
+
compact: false
|
|
17
|
+
})}
|
|
18
|
+
/>
|
|
19
|
+
|
|
20
|
+
<style>
|
|
21
|
+
:global {
|
|
22
|
+
.maplibregl-ctrl.maplibregl-ctrl-attrib {
|
|
23
|
+
font-size: var(--fs-small-3);
|
|
24
|
+
letter-spacing: 0.005em;
|
|
25
|
+
word-spacing: 0.005em;
|
|
26
|
+
font-family: var(--swr-sans);
|
|
27
|
+
}
|
|
28
|
+
.maplibregl-ctrl-attrib.maplibregl-compact-show .maplibregl-ctrl-attrib-inner {
|
|
29
|
+
display: block;
|
|
30
|
+
}
|
|
31
|
+
.maplibregl-ctrl-attrib-button {
|
|
32
|
+
display: none;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.maplibregl-ctrl-attrib a {
|
|
36
|
+
color: inherit;
|
|
37
|
+
text-decoration: none;
|
|
38
|
+
text-underline-offset: 0.2em;
|
|
39
|
+
}
|
|
40
|
+
.maplibregl-ctrl-attrib a:hover {
|
|
41
|
+
color: inherit;
|
|
42
|
+
text-decoration: underline;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
</style>
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type CarmenGeojsonFeature,
|
|
3
|
+
type MaplibreGeocoderApi,
|
|
4
|
+
type MaplibreGeocoderApiConfig,
|
|
5
|
+
type MaplibreGeocoderFeatureResults
|
|
6
|
+
} from '@maplibre/maplibre-gl-geocoder';
|
|
7
|
+
|
|
8
|
+
export class MaptilerGeocoderAPI implements MaplibreGeocoderApi {
|
|
9
|
+
key: string;
|
|
10
|
+
|
|
11
|
+
constructor(key: string) {
|
|
12
|
+
this.key = key;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async forwardGeocode(config: MaplibreGeocoderApiConfig): Promise<MaplibreGeocoderFeatureResults> {
|
|
16
|
+
const result: MaplibreGeocoderFeatureResults = {
|
|
17
|
+
type: 'FeatureCollection',
|
|
18
|
+
features: []
|
|
19
|
+
};
|
|
20
|
+
try {
|
|
21
|
+
const response = await fetch(
|
|
22
|
+
`https://api.maptiler.com/geocoding/${config.query}.json?country=${config.countries}&language=${config.language}&key=${this.key}`
|
|
23
|
+
);
|
|
24
|
+
const geojson = await response.json();
|
|
25
|
+
for (const feature of geojson.features) {
|
|
26
|
+
const res: CarmenGeojsonFeature = {
|
|
27
|
+
type: 'Feature',
|
|
28
|
+
id: feature.id,
|
|
29
|
+
place_type: ['place'],
|
|
30
|
+
place_name: feature.place_name,
|
|
31
|
+
language: feature.properties.display_name,
|
|
32
|
+
text: feature.text,
|
|
33
|
+
bbox: feature.bbox,
|
|
34
|
+
geometry: {
|
|
35
|
+
type: 'Point',
|
|
36
|
+
coordinates: feature.center
|
|
37
|
+
},
|
|
38
|
+
properties: {
|
|
39
|
+
text: feature.text
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
result.features.push(res);
|
|
43
|
+
}
|
|
44
|
+
} catch (e) {
|
|
45
|
+
console.error(`Failed to forwardGeocode with error: ${e}`);
|
|
46
|
+
}
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
<script context="module" lang="ts">
|
|
2
|
+
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
3
|
+
import { within, expect } from 'storybook/test';
|
|
4
|
+
|
|
5
|
+
import GeocoderControl from './GeocoderControl.svelte';
|
|
6
|
+
import DesignTokens from '../../DesignTokens/DesignTokens.svelte';
|
|
7
|
+
import Map from '../Map/Map.svelte';
|
|
8
|
+
|
|
9
|
+
import { SWRDataLabLight } from '../MapStyle';
|
|
10
|
+
|
|
11
|
+
const { Story } = defineMeta({
|
|
12
|
+
title: 'Maplibre/Control/GeoCoderControl',
|
|
13
|
+
component: GeocoderControl
|
|
14
|
+
});
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
<Story
|
|
18
|
+
asChild
|
|
19
|
+
name="Default"
|
|
20
|
+
play={async ({ canvasElement, step }) => {
|
|
21
|
+
const canvas = within(canvasElement);
|
|
22
|
+
const containerEl = canvas.getByTestId('map-container');
|
|
23
|
+
|
|
24
|
+
await step('Geocoder control renders', async () => {
|
|
25
|
+
const el = containerEl.querySelector('.maplibregl-ctrl-geocoder');
|
|
26
|
+
expect(el).toBeTruthy();
|
|
27
|
+
});
|
|
28
|
+
await step('Localised placeholder text renders', async () => {
|
|
29
|
+
const el = containerEl.querySelector('.maplibregl-ctrl-geocoder input');
|
|
30
|
+
expect(el).toHaveAttribute('placeholder', 'Suche');
|
|
31
|
+
});
|
|
32
|
+
}}
|
|
33
|
+
>
|
|
34
|
+
<DesignTokens>
|
|
35
|
+
<div class="container">
|
|
36
|
+
<Map style={SWRDataLabLight} initialLocation={{ lat: 51, lng: 10, zoom: 20 }}>
|
|
37
|
+
<GeocoderControl languages="de" service="maptiler" key="V32kPHZjMa0Mkn6YvSzA" />
|
|
38
|
+
</Map>
|
|
39
|
+
</div>
|
|
40
|
+
</DesignTokens>
|
|
41
|
+
</Story>
|
|
42
|
+
<Story
|
|
43
|
+
asChild
|
|
44
|
+
name="Custom placeholder text"
|
|
45
|
+
play={async ({ canvasElement, step }) => {
|
|
46
|
+
const canvas = within(canvasElement);
|
|
47
|
+
const containerEl = canvas.getByTestId('map-container');
|
|
48
|
+
|
|
49
|
+
await step('Geocoder control renders', async () => {
|
|
50
|
+
const el = containerEl.querySelector('.maplibregl-ctrl-geocoder');
|
|
51
|
+
expect(el).toBeTruthy();
|
|
52
|
+
});
|
|
53
|
+
await step('Custom placeholder text renders', async () => {
|
|
54
|
+
const el = containerEl.querySelector('.maplibregl-ctrl-geocoder input');
|
|
55
|
+
expect(el).toHaveAttribute('placeholder', 'My placeholder text');
|
|
56
|
+
});
|
|
57
|
+
}}
|
|
58
|
+
>
|
|
59
|
+
<DesignTokens>
|
|
60
|
+
<div class="container">
|
|
61
|
+
<Map style={SWRDataLabLight} initialLocation={{ lat: 51, lng: 10, zoom: 20 }}>
|
|
62
|
+
<GeocoderControl
|
|
63
|
+
placeholder="My placeholder text"
|
|
64
|
+
languages="de"
|
|
65
|
+
service="maptiler"
|
|
66
|
+
key="V32kPHZjMa0Mkn6YvSzA"
|
|
67
|
+
/>
|
|
68
|
+
</Map>
|
|
69
|
+
</div>
|
|
70
|
+
</DesignTokens>
|
|
71
|
+
</Story>
|
|
72
|
+
|
|
73
|
+
<style>
|
|
74
|
+
.container {
|
|
75
|
+
width: 500px;
|
|
76
|
+
height: 300px;
|
|
77
|
+
}
|
|
78
|
+
</style>
|