@classic-homes/maps-svelte 0.1.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/README.md +432 -0
- package/dist/lib/components/base/MapContainer.svelte +68 -0
- package/dist/lib/components/base/MapContainer.svelte.d.ts +18 -0
- package/dist/lib/components/base/MapEmpty.svelte +42 -0
- package/dist/lib/components/base/MapEmpty.svelte.d.ts +8 -0
- package/dist/lib/components/base/MapError.svelte +54 -0
- package/dist/lib/components/base/MapError.svelte.d.ts +9 -0
- package/dist/lib/components/base/MapSkeleton.svelte +45 -0
- package/dist/lib/components/base/MapSkeleton.svelte.d.ts +7 -0
- package/dist/lib/components/base/index.d.ts +4 -0
- package/dist/lib/components/base/index.js +4 -0
- package/dist/lib/components/controls/CoordinateDisplay.svelte +163 -0
- package/dist/lib/components/controls/CoordinateDisplay.svelte.d.ts +6 -0
- package/dist/lib/components/controls/Legend.svelte +179 -0
- package/dist/lib/components/controls/Legend.svelte.d.ts +6 -0
- package/dist/lib/components/controls/LegendGroup.svelte +216 -0
- package/dist/lib/components/controls/LegendGroup.svelte.d.ts +6 -0
- package/dist/lib/components/controls/index.d.ts +3 -0
- package/dist/lib/components/controls/index.js +3 -0
- package/dist/lib/components/core/Map.svelte +434 -0
- package/dist/lib/components/core/Map.svelte.d.ts +11 -0
- package/dist/lib/components/core/Marker.svelte +185 -0
- package/dist/lib/components/core/Marker.svelte.d.ts +9 -0
- package/dist/lib/components/core/Popup.svelte +205 -0
- package/dist/lib/components/core/Popup.svelte.d.ts +11 -0
- package/dist/lib/components/core/PopupCard.svelte +17 -0
- package/dist/lib/components/core/PopupCard.svelte.d.ts +10 -0
- package/dist/lib/components/core/PopupContent.svelte +17 -0
- package/dist/lib/components/core/PopupContent.svelte.d.ts +10 -0
- package/dist/lib/components/core/PopupFooter.svelte +22 -0
- package/dist/lib/components/core/PopupFooter.svelte.d.ts +10 -0
- package/dist/lib/components/core/PopupHeader.svelte +45 -0
- package/dist/lib/components/core/PopupHeader.svelte.d.ts +14 -0
- package/dist/lib/components/core/Source.svelte +326 -0
- package/dist/lib/components/core/Source.svelte.d.ts +59 -0
- package/dist/lib/components/core/index.d.ts +8 -0
- package/dist/lib/components/core/index.js +8 -0
- package/dist/lib/components/deck/DeckOverlay.svelte +135 -0
- package/dist/lib/components/deck/DeckOverlay.svelte.d.ts +25 -0
- package/dist/lib/components/deck/index.d.ts +1 -0
- package/dist/lib/components/deck/index.js +1 -0
- package/dist/lib/components/index.d.ts +5 -0
- package/dist/lib/components/index.js +10 -0
- package/dist/lib/components/layers/CircleLayer.svelte +78 -0
- package/dist/lib/components/layers/CircleLayer.svelte.d.ts +11 -0
- package/dist/lib/components/layers/FillExtrusionLayer.svelte +75 -0
- package/dist/lib/components/layers/FillExtrusionLayer.svelte.d.ts +11 -0
- package/dist/lib/components/layers/FillLayer.svelte +70 -0
- package/dist/lib/components/layers/FillLayer.svelte.d.ts +11 -0
- package/dist/lib/components/layers/HeatmapLayer.svelte +68 -0
- package/dist/lib/components/layers/HeatmapLayer.svelte.d.ts +11 -0
- package/dist/lib/components/layers/LineLayer.svelte +81 -0
- package/dist/lib/components/layers/LineLayer.svelte.d.ts +11 -0
- package/dist/lib/components/layers/SymbolLayer.svelte +108 -0
- package/dist/lib/components/layers/SymbolLayer.svelte.d.ts +11 -0
- package/dist/lib/components/layers/index.d.ts +7 -0
- package/dist/lib/components/layers/index.js +6 -0
- package/dist/lib/components/layers/useLayer.svelte.d.ts +38 -0
- package/dist/lib/components/layers/useLayer.svelte.js +286 -0
- package/dist/lib/composables/index.d.ts +3 -0
- package/dist/lib/composables/index.js +3 -0
- package/dist/lib/composables/useMapContext.svelte.d.ts +62 -0
- package/dist/lib/composables/useMapContext.svelte.js +58 -0
- package/dist/lib/composables/useMapTheme.svelte.d.ts +11 -0
- package/dist/lib/composables/useMapTheme.svelte.js +66 -0
- package/dist/lib/composables/useReducedMotion.svelte.d.ts +6 -0
- package/dist/lib/composables/useReducedMotion.svelte.js +26 -0
- package/dist/lib/index.d.ts +12 -0
- package/dist/lib/index.js +29 -0
- package/dist/lib/utils.d.ts +2 -0
- package/dist/lib/utils.js +5 -0
- package/package.json +75 -0
package/README.md
ADDED
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
# @classic-homes/maps-svelte
|
|
2
|
+
|
|
3
|
+
Svelte 5 components for MapLibre GL maps in the Classic Theme design system.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @classic-homes/maps-svelte maplibre-gl
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- **Svelte 5 Runes**: Modern `$state`, `$derived`, `$effect` patterns
|
|
14
|
+
- **7 Layer Types**: Fill, Line, Circle, Symbol, FillExtrusion, Heatmap, Raster
|
|
15
|
+
- **Controls**: Navigation, Scale, Geolocation, Legend, Coordinate Display
|
|
16
|
+
- **Clustering**: Built-in cluster support with expansion utilities
|
|
17
|
+
- **Deck.gl Integration**: Optional overlay for advanced visualizations
|
|
18
|
+
- **Accessibility**: ARIA labels, keyboard navigation, reduced motion support
|
|
19
|
+
- **Theme Integration**: Light/dark themes from design tokens
|
|
20
|
+
|
|
21
|
+
## Quick Start
|
|
22
|
+
|
|
23
|
+
```svelte
|
|
24
|
+
<script lang="ts">
|
|
25
|
+
import { Map, MapContainer, Source, FillLayer } from '@classic-homes/maps-svelte';
|
|
26
|
+
import 'maplibre-gl/dist/maplibre-gl.css';
|
|
27
|
+
|
|
28
|
+
let geojsonData = $state(/* your data */);
|
|
29
|
+
</script>
|
|
30
|
+
|
|
31
|
+
<MapContainer class="h-[500px]">
|
|
32
|
+
<Map
|
|
33
|
+
initialCenter={[-122.4, 37.8]}
|
|
34
|
+
initialZoom={12}
|
|
35
|
+
onClick={(e) => console.log('Clicked:', e.lngLat)}
|
|
36
|
+
>
|
|
37
|
+
<Source id="lots" data={geojsonData}>
|
|
38
|
+
<FillLayer id="lots-fill" fillColor="#22c55e" fillOpacity={0.7} />
|
|
39
|
+
</Source>
|
|
40
|
+
</Map>
|
|
41
|
+
</MapContainer>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Components
|
|
45
|
+
|
|
46
|
+
### Map Container
|
|
47
|
+
|
|
48
|
+
```svelte
|
|
49
|
+
<script lang="ts">
|
|
50
|
+
import { MapContainer, MapSkeleton, MapError, MapEmpty } from '@classic-homes/maps-svelte';
|
|
51
|
+
|
|
52
|
+
let isLoading = $state(true);
|
|
53
|
+
let error = $state<string | null>(null);
|
|
54
|
+
</script>
|
|
55
|
+
|
|
56
|
+
<MapContainer class="h-[500px]">
|
|
57
|
+
{#if isLoading}
|
|
58
|
+
<MapSkeleton />
|
|
59
|
+
{:else if error}
|
|
60
|
+
<MapError message={error} onRetry={() => reload()} />
|
|
61
|
+
{:else}
|
|
62
|
+
<Map>...</Map>
|
|
63
|
+
{/if}
|
|
64
|
+
</MapContainer>
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Core Map
|
|
68
|
+
|
|
69
|
+
```svelte
|
|
70
|
+
<script lang="ts">
|
|
71
|
+
import { Map, useMapContext } from '@classic-homes/maps-svelte';
|
|
72
|
+
import { lightBasicStyle } from '@classic-homes/maps-core';
|
|
73
|
+
|
|
74
|
+
function handleClick(e) {
|
|
75
|
+
console.log('Clicked:', e.lngLat);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function handleMove(e) {
|
|
79
|
+
console.log('Viewport:', e.center, e.zoom);
|
|
80
|
+
}
|
|
81
|
+
</script>
|
|
82
|
+
|
|
83
|
+
<Map
|
|
84
|
+
initialCenter={[-122.4, 37.8]}
|
|
85
|
+
initialZoom={12}
|
|
86
|
+
initialBearing={0}
|
|
87
|
+
initialPitch={0}
|
|
88
|
+
{bounds}
|
|
89
|
+
fitBoundsOptions={{ padding: 50 }}
|
|
90
|
+
style={lightBasicStyle}
|
|
91
|
+
theme="light"
|
|
92
|
+
interactive={true}
|
|
93
|
+
scrollZoom={true}
|
|
94
|
+
dragPan={true}
|
|
95
|
+
onClick={handleClick}
|
|
96
|
+
onHover={handleHover}
|
|
97
|
+
onMove={handleMove}
|
|
98
|
+
onLoad={handleLoad}
|
|
99
|
+
>
|
|
100
|
+
<slot />
|
|
101
|
+
</Map>
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Accessing Map Context
|
|
105
|
+
|
|
106
|
+
```svelte
|
|
107
|
+
<script lang="ts">
|
|
108
|
+
import { useMapContext, tryUseMapContext } from '@classic-homes/maps-svelte';
|
|
109
|
+
|
|
110
|
+
// Throws if not within Map component
|
|
111
|
+
const { map, loaded } = useMapContext();
|
|
112
|
+
|
|
113
|
+
// Returns null if not within Map
|
|
114
|
+
const context = tryUseMapContext();
|
|
115
|
+
</script>
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Data Sources
|
|
119
|
+
|
|
120
|
+
```svelte
|
|
121
|
+
<script lang="ts">
|
|
122
|
+
import { Source } from '@classic-homes/maps-svelte';
|
|
123
|
+
</script>
|
|
124
|
+
|
|
125
|
+
<!-- GeoJSON data -->
|
|
126
|
+
<Source id="features" data={geojsonFeatureCollection}>
|
|
127
|
+
<!-- Layers go here -->
|
|
128
|
+
</Source>
|
|
129
|
+
|
|
130
|
+
<!-- URL source -->
|
|
131
|
+
<Source id="remote" data="https://example.com/data.geojson">
|
|
132
|
+
<!-- Layers go here -->
|
|
133
|
+
</Source>
|
|
134
|
+
|
|
135
|
+
<!-- With clustering -->
|
|
136
|
+
<Source id="points" data={pointData} cluster={true} clusterRadius={50} clusterMaxZoom={14}>
|
|
137
|
+
<!-- Layers go here -->
|
|
138
|
+
</Source>
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Layer Components
|
|
142
|
+
|
|
143
|
+
```svelte
|
|
144
|
+
<script lang="ts">
|
|
145
|
+
import {
|
|
146
|
+
FillLayer,
|
|
147
|
+
LineLayer,
|
|
148
|
+
CircleLayer,
|
|
149
|
+
SymbolLayer,
|
|
150
|
+
FillExtrusionLayer,
|
|
151
|
+
HeatmapLayer,
|
|
152
|
+
} from '@classic-homes/maps-svelte';
|
|
153
|
+
</script>
|
|
154
|
+
|
|
155
|
+
<!-- Fill layer (polygons) -->
|
|
156
|
+
<FillLayer
|
|
157
|
+
id="polygons"
|
|
158
|
+
source="features"
|
|
159
|
+
fillColor="#22c55e"
|
|
160
|
+
fillOpacity={0.7}
|
|
161
|
+
fillOutlineColor="#166534"
|
|
162
|
+
onClick={handleClick}
|
|
163
|
+
onHover={handleHover}
|
|
164
|
+
/>
|
|
165
|
+
|
|
166
|
+
<!-- Line layer -->
|
|
167
|
+
<LineLayer id="lines" source="features" lineColor="#3b82f6" lineWidth={2} lineCap="round" />
|
|
168
|
+
|
|
169
|
+
<!-- Circle layer (points) -->
|
|
170
|
+
<CircleLayer
|
|
171
|
+
id="points"
|
|
172
|
+
source="features"
|
|
173
|
+
circleRadius={6}
|
|
174
|
+
circleColor="#ef4444"
|
|
175
|
+
circleStrokeWidth={2}
|
|
176
|
+
circleStrokeColor="#ffffff"
|
|
177
|
+
/>
|
|
178
|
+
|
|
179
|
+
<!-- Symbol layer (labels/icons) -->
|
|
180
|
+
<SymbolLayer
|
|
181
|
+
id="labels"
|
|
182
|
+
source="features"
|
|
183
|
+
textField={['get', 'name']}
|
|
184
|
+
textSize={12}
|
|
185
|
+
iconImage="marker"
|
|
186
|
+
/>
|
|
187
|
+
|
|
188
|
+
<!-- 3D extrusions -->
|
|
189
|
+
<FillExtrusionLayer
|
|
190
|
+
id="buildings"
|
|
191
|
+
source="features"
|
|
192
|
+
fillExtrusionHeight={['get', 'height']}
|
|
193
|
+
fillExtrusionColor="#94a3b8"
|
|
194
|
+
fillExtrusionOpacity={0.9}
|
|
195
|
+
/>
|
|
196
|
+
|
|
197
|
+
<!-- Heatmap -->
|
|
198
|
+
<HeatmapLayer
|
|
199
|
+
id="heat"
|
|
200
|
+
source="features"
|
|
201
|
+
heatmapWeight={1}
|
|
202
|
+
heatmapIntensity={0.5}
|
|
203
|
+
heatmapRadius={30}
|
|
204
|
+
/>
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### Markers and Popups
|
|
208
|
+
|
|
209
|
+
```svelte
|
|
210
|
+
<script lang="ts">
|
|
211
|
+
import {
|
|
212
|
+
Marker,
|
|
213
|
+
Popup,
|
|
214
|
+
PopupCard,
|
|
215
|
+
PopupHeader,
|
|
216
|
+
PopupContent,
|
|
217
|
+
PopupFooter,
|
|
218
|
+
} from '@classic-homes/maps-svelte';
|
|
219
|
+
</script>
|
|
220
|
+
|
|
221
|
+
<!-- Custom marker with popup -->
|
|
222
|
+
<Marker
|
|
223
|
+
lngLat={[-122.4, 37.8]}
|
|
224
|
+
anchor="bottom"
|
|
225
|
+
draggable={true}
|
|
226
|
+
onClick={handleClick}
|
|
227
|
+
onDragEnd={handleDrag}
|
|
228
|
+
>
|
|
229
|
+
<div class="custom-marker">
|
|
230
|
+
<MapPinIcon />
|
|
231
|
+
</div>
|
|
232
|
+
</Marker>
|
|
233
|
+
|
|
234
|
+
<!-- Popup with card styling -->
|
|
235
|
+
<Popup lngLat={[-122.4, 37.8]} anchor="bottom" closeOnClick={false}>
|
|
236
|
+
<PopupCard>
|
|
237
|
+
<PopupHeader>
|
|
238
|
+
<h3>Location Name</h3>
|
|
239
|
+
</PopupHeader>
|
|
240
|
+
<PopupContent>
|
|
241
|
+
<p>Description goes here</p>
|
|
242
|
+
</PopupContent>
|
|
243
|
+
<PopupFooter>
|
|
244
|
+
<button>View Details</button>
|
|
245
|
+
</PopupFooter>
|
|
246
|
+
</PopupCard>
|
|
247
|
+
</Popup>
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
### Controls
|
|
251
|
+
|
|
252
|
+
```svelte
|
|
253
|
+
<script lang="ts">
|
|
254
|
+
import { Legend, LegendGroup, CoordinateDisplay } from '@classic-homes/maps-svelte';
|
|
255
|
+
</script>
|
|
256
|
+
|
|
257
|
+
<!-- Legend -->
|
|
258
|
+
<Legend
|
|
259
|
+
position="bottom-left"
|
|
260
|
+
title="Status"
|
|
261
|
+
items={[
|
|
262
|
+
{ label: 'Available', color: '#22c55e' },
|
|
263
|
+
{ label: 'Pending', color: '#f59e0b' },
|
|
264
|
+
{ label: 'Sold', color: '#ef4444' },
|
|
265
|
+
]}
|
|
266
|
+
/>
|
|
267
|
+
|
|
268
|
+
<!-- Legend group with collapsible sections -->
|
|
269
|
+
<LegendGroup
|
|
270
|
+
position="bottom-left"
|
|
271
|
+
legends={[
|
|
272
|
+
{
|
|
273
|
+
title: 'Status',
|
|
274
|
+
items: [{ label: 'Available', color: '#22c55e' }],
|
|
275
|
+
},
|
|
276
|
+
{
|
|
277
|
+
title: 'Price',
|
|
278
|
+
gradient: {
|
|
279
|
+
stops: [
|
|
280
|
+
{ value: 0, color: '#eff6ff', label: '$0' },
|
|
281
|
+
{ value: 100, color: '#1e40af', label: '$1M+' },
|
|
282
|
+
],
|
|
283
|
+
},
|
|
284
|
+
},
|
|
285
|
+
]}
|
|
286
|
+
/>
|
|
287
|
+
|
|
288
|
+
<!-- Coordinate display -->
|
|
289
|
+
<CoordinateDisplay position="bottom-right" precision={4} />
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
### Deck.gl Overlay
|
|
293
|
+
|
|
294
|
+
```svelte
|
|
295
|
+
<script lang="ts">
|
|
296
|
+
import { DeckOverlay } from '@classic-homes/maps-svelte';
|
|
297
|
+
import { ScatterplotLayer } from '@deck.gl/layers';
|
|
298
|
+
|
|
299
|
+
const layers = $derived([
|
|
300
|
+
new ScatterplotLayer({
|
|
301
|
+
id: 'scatter',
|
|
302
|
+
data: points,
|
|
303
|
+
getPosition: (d) => d.coordinates,
|
|
304
|
+
getRadius: 100,
|
|
305
|
+
getFillColor: [255, 0, 0],
|
|
306
|
+
}),
|
|
307
|
+
]);
|
|
308
|
+
</script>
|
|
309
|
+
|
|
310
|
+
<Map>
|
|
311
|
+
<DeckOverlay {layers} />
|
|
312
|
+
</Map>
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
## Composables
|
|
316
|
+
|
|
317
|
+
### useMapTheme
|
|
318
|
+
|
|
319
|
+
```svelte
|
|
320
|
+
<script lang="ts">
|
|
321
|
+
import { useMapTheme } from '@classic-homes/maps-svelte';
|
|
322
|
+
|
|
323
|
+
const { theme, style, isDark, toggleTheme } = useMapTheme();
|
|
324
|
+
</script>
|
|
325
|
+
|
|
326
|
+
<Map style={style.current} theme={theme.current}>
|
|
327
|
+
<slot />
|
|
328
|
+
</Map>
|
|
329
|
+
<button onclick={toggleTheme}>
|
|
330
|
+
{isDark.current ? 'Light Mode' : 'Dark Mode'}
|
|
331
|
+
</button>
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
### useReducedMotion
|
|
335
|
+
|
|
336
|
+
```svelte
|
|
337
|
+
<script lang="ts">
|
|
338
|
+
import { useReducedMotion } from '@classic-homes/maps-svelte';
|
|
339
|
+
|
|
340
|
+
const prefersReducedMotion = useReducedMotion();
|
|
341
|
+
|
|
342
|
+
function flyToLocation(lngLat) {
|
|
343
|
+
map.flyTo({
|
|
344
|
+
center: lngLat,
|
|
345
|
+
duration: prefersReducedMotion.current ? 0 : 1000,
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
</script>
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
## Cluster Utilities
|
|
352
|
+
|
|
353
|
+
```svelte
|
|
354
|
+
<script lang="ts">
|
|
355
|
+
import {
|
|
356
|
+
isClusterFeature,
|
|
357
|
+
expandCluster,
|
|
358
|
+
getClusterBounds,
|
|
359
|
+
expandClusterToBounds,
|
|
360
|
+
} from '@classic-homes/maps-svelte';
|
|
361
|
+
|
|
362
|
+
function handleClusterClick(e) {
|
|
363
|
+
const feature = e.features[0];
|
|
364
|
+
|
|
365
|
+
if (isClusterFeature(feature)) {
|
|
366
|
+
// Option 1: Zoom to expand
|
|
367
|
+
expandCluster(map, 'source-id', feature.id, (zoom) => {
|
|
368
|
+
map.flyTo({ center: e.lngLat, zoom });
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
// Option 2: Fit to cluster bounds
|
|
372
|
+
expandClusterToBounds(map, 'source-id', feature, (bounds) => {
|
|
373
|
+
map.fitBounds(bounds, { padding: 50 });
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
</script>
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
## Reactive Updates
|
|
381
|
+
|
|
382
|
+
Svelte 5's fine-grained reactivity automatically handles prop updates:
|
|
383
|
+
|
|
384
|
+
```svelte
|
|
385
|
+
<script lang="ts">
|
|
386
|
+
let data = $state(initialData);
|
|
387
|
+
let fillColor = $state('#22c55e');
|
|
388
|
+
|
|
389
|
+
// Data changes automatically update the source
|
|
390
|
+
function updateData(newData) {
|
|
391
|
+
data = newData;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
// Style changes automatically update the layer
|
|
395
|
+
function updateColor(color) {
|
|
396
|
+
fillColor = color;
|
|
397
|
+
}
|
|
398
|
+
</script>
|
|
399
|
+
|
|
400
|
+
<Source id="lots" {data}>
|
|
401
|
+
<FillLayer id="lots-fill" {fillColor} fillOpacity={0.7} />
|
|
402
|
+
</Source>
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
## TypeScript
|
|
406
|
+
|
|
407
|
+
All components are fully typed:
|
|
408
|
+
|
|
409
|
+
```typescript
|
|
410
|
+
import type {
|
|
411
|
+
MapContextValue,
|
|
412
|
+
SvelteFeatureClickEventParams,
|
|
413
|
+
SvelteFeatureHoverEventParams,
|
|
414
|
+
} from '@classic-homes/maps-svelte';
|
|
415
|
+
|
|
416
|
+
import type {
|
|
417
|
+
MapClickEventParams,
|
|
418
|
+
MapHoverEventParams,
|
|
419
|
+
FeatureClickEventParams,
|
|
420
|
+
GeoJSONFeatureCollection,
|
|
421
|
+
LngLat,
|
|
422
|
+
} from '@classic-homes/maps-core';
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
## Peer Dependencies
|
|
426
|
+
|
|
427
|
+
- `svelte` >= 5.0.0
|
|
428
|
+
- `maplibre-gl` >= 4.0.0 || >= 5.0.0
|
|
429
|
+
|
|
430
|
+
## License
|
|
431
|
+
|
|
432
|
+
MIT
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import { cn } from '../../utils.js';
|
|
4
|
+
import MapSkeleton from './MapSkeleton.svelte';
|
|
5
|
+
import MapError from './MapError.svelte';
|
|
6
|
+
import MapEmpty from './MapEmpty.svelte';
|
|
7
|
+
|
|
8
|
+
interface Props {
|
|
9
|
+
title: string;
|
|
10
|
+
description?: string;
|
|
11
|
+
height?: number | string;
|
|
12
|
+
width?: number | string;
|
|
13
|
+
loading?: boolean;
|
|
14
|
+
error?: string | null;
|
|
15
|
+
empty?: boolean;
|
|
16
|
+
emptyMessage?: string;
|
|
17
|
+
onRetry?: () => void;
|
|
18
|
+
class?: string;
|
|
19
|
+
wrapperClass?: string;
|
|
20
|
+
children: Snippet;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
let {
|
|
24
|
+
title,
|
|
25
|
+
description,
|
|
26
|
+
height = 400,
|
|
27
|
+
width = '100%',
|
|
28
|
+
loading,
|
|
29
|
+
error,
|
|
30
|
+
empty,
|
|
31
|
+
emptyMessage,
|
|
32
|
+
onRetry,
|
|
33
|
+
class: className,
|
|
34
|
+
wrapperClass,
|
|
35
|
+
children,
|
|
36
|
+
}: Props = $props();
|
|
37
|
+
|
|
38
|
+
const heightStyle = $derived(typeof height === 'number' ? `${height}px` : height);
|
|
39
|
+
const widthStyle = $derived(typeof width === 'number' ? `${width}px` : width);
|
|
40
|
+
const descriptionId = $derived(
|
|
41
|
+
description ? `${title.replace(/\s+/g, '-').toLowerCase()}-desc` : undefined
|
|
42
|
+
);
|
|
43
|
+
</script>
|
|
44
|
+
|
|
45
|
+
{#if loading}
|
|
46
|
+
<MapSkeleton {height} class={wrapperClass} />
|
|
47
|
+
{:else if error}
|
|
48
|
+
<MapError message={error} {height} {onRetry} class={wrapperClass} />
|
|
49
|
+
{:else if empty}
|
|
50
|
+
<MapEmpty message={emptyMessage} {height} class={wrapperClass} />
|
|
51
|
+
{:else}
|
|
52
|
+
<div
|
|
53
|
+
role="application"
|
|
54
|
+
aria-label={title}
|
|
55
|
+
aria-describedby={descriptionId}
|
|
56
|
+
data-testid="map-container"
|
|
57
|
+
class={cn('relative overflow-hidden rounded-lg border border-border', wrapperClass)}
|
|
58
|
+
style:width={widthStyle}
|
|
59
|
+
style:height={heightStyle}
|
|
60
|
+
>
|
|
61
|
+
{#if description}
|
|
62
|
+
<span id={descriptionId} class="sr-only">{description}</span>
|
|
63
|
+
{/if}
|
|
64
|
+
<div class={cn('relative h-full w-full', className)}>
|
|
65
|
+
{@render children()}
|
|
66
|
+
</div>
|
|
67
|
+
</div>
|
|
68
|
+
{/if}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
interface Props {
|
|
3
|
+
title: string;
|
|
4
|
+
description?: string;
|
|
5
|
+
height?: number | string;
|
|
6
|
+
width?: number | string;
|
|
7
|
+
loading?: boolean;
|
|
8
|
+
error?: string | null;
|
|
9
|
+
empty?: boolean;
|
|
10
|
+
emptyMessage?: string;
|
|
11
|
+
onRetry?: () => void;
|
|
12
|
+
class?: string;
|
|
13
|
+
wrapperClass?: string;
|
|
14
|
+
children: Snippet;
|
|
15
|
+
}
|
|
16
|
+
declare const MapContainer: import("svelte").Component<Props, {}, "">;
|
|
17
|
+
type MapContainer = ReturnType<typeof MapContainer>;
|
|
18
|
+
export default MapContainer;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { cn } from '../../utils.js';
|
|
3
|
+
|
|
4
|
+
interface Props {
|
|
5
|
+
message?: string;
|
|
6
|
+
height?: number | string;
|
|
7
|
+
class?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
let { message = 'No map data to display', height = 400, class: className }: Props = $props();
|
|
11
|
+
|
|
12
|
+
const heightStyle = $derived(typeof height === 'number' ? `${height}px` : height);
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
<div
|
|
16
|
+
class={cn(
|
|
17
|
+
'flex flex-col items-center justify-center rounded-lg border border-border bg-muted/50',
|
|
18
|
+
className
|
|
19
|
+
)}
|
|
20
|
+
style:height={heightStyle}
|
|
21
|
+
role="status"
|
|
22
|
+
aria-label={message}
|
|
23
|
+
>
|
|
24
|
+
<div class="flex flex-col items-center gap-3 text-center">
|
|
25
|
+
<svg
|
|
26
|
+
class="h-10 w-10 text-muted-foreground"
|
|
27
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
28
|
+
fill="none"
|
|
29
|
+
viewBox="0 0 24 24"
|
|
30
|
+
stroke="currentColor"
|
|
31
|
+
stroke-width="1.5"
|
|
32
|
+
aria-hidden="true"
|
|
33
|
+
>
|
|
34
|
+
<path
|
|
35
|
+
stroke-linecap="round"
|
|
36
|
+
stroke-linejoin="round"
|
|
37
|
+
d="M9 6.75V15m6-6v8.25m.503 3.498l4.875-2.437c.381-.19.622-.58.622-1.006V4.82c0-.836-.88-1.38-1.628-1.006l-3.869 1.934c-.317.159-.69.159-1.006 0L9.503 3.252a1.125 1.125 0 00-1.006 0L3.622 5.689C3.24 5.88 3 6.27 3 6.695V19.18c0 .836.88 1.38 1.628 1.006l3.869-1.934c.317-.159.69-.159 1.006 0l4.994 2.497c.317.158.69.158 1.006 0z"
|
|
38
|
+
/>
|
|
39
|
+
</svg>
|
|
40
|
+
<p class="text-sm text-muted-foreground">{message}</p>
|
|
41
|
+
</div>
|
|
42
|
+
</div>
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { cn } from '../../utils.js';
|
|
3
|
+
|
|
4
|
+
interface Props {
|
|
5
|
+
message?: string;
|
|
6
|
+
height?: number | string;
|
|
7
|
+
onRetry?: () => void;
|
|
8
|
+
class?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
let { message = 'Failed to load map', height = 400, onRetry, class: className }: Props = $props();
|
|
12
|
+
|
|
13
|
+
const heightStyle = $derived(typeof height === 'number' ? `${height}px` : height);
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<div
|
|
17
|
+
class={cn(
|
|
18
|
+
'flex flex-col items-center justify-center rounded-lg border border-destructive/50 bg-destructive/5',
|
|
19
|
+
className
|
|
20
|
+
)}
|
|
21
|
+
style:height={heightStyle}
|
|
22
|
+
role="alert"
|
|
23
|
+
aria-live="polite"
|
|
24
|
+
>
|
|
25
|
+
<div class="flex flex-col items-center gap-3 text-center">
|
|
26
|
+
<svg
|
|
27
|
+
class="h-10 w-10 text-destructive"
|
|
28
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
29
|
+
fill="none"
|
|
30
|
+
viewBox="0 0 24 24"
|
|
31
|
+
stroke="currentColor"
|
|
32
|
+
stroke-width="2"
|
|
33
|
+
aria-hidden="true"
|
|
34
|
+
>
|
|
35
|
+
<path
|
|
36
|
+
stroke-linecap="round"
|
|
37
|
+
stroke-linejoin="round"
|
|
38
|
+
d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"
|
|
39
|
+
/>
|
|
40
|
+
</svg>
|
|
41
|
+
<div class="space-y-1">
|
|
42
|
+
<p class="text-sm font-medium text-destructive">{message}</p>
|
|
43
|
+
<p class="text-xs text-muted-foreground">Check your connection and try again</p>
|
|
44
|
+
</div>
|
|
45
|
+
{#if onRetry}
|
|
46
|
+
<button
|
|
47
|
+
onclick={onRetry}
|
|
48
|
+
class="mt-2 rounded-md border border-input bg-background px-4 py-2 text-sm font-medium shadow-sm transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"
|
|
49
|
+
>
|
|
50
|
+
Retry
|
|
51
|
+
</button>
|
|
52
|
+
{/if}
|
|
53
|
+
</div>
|
|
54
|
+
</div>
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { cn } from '../../utils.js';
|
|
3
|
+
|
|
4
|
+
interface Props {
|
|
5
|
+
height?: number | string;
|
|
6
|
+
class?: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
let { height = 400, class: className }: Props = $props();
|
|
10
|
+
|
|
11
|
+
const heightStyle = $derived(typeof height === 'number' ? `${height}px` : height);
|
|
12
|
+
</script>
|
|
13
|
+
|
|
14
|
+
<div
|
|
15
|
+
class={cn('relative animate-pulse rounded-lg border border-border bg-muted', className)}
|
|
16
|
+
style:height={heightStyle}
|
|
17
|
+
role="progressbar"
|
|
18
|
+
aria-label="Loading map"
|
|
19
|
+
aria-busy="true"
|
|
20
|
+
>
|
|
21
|
+
<div class="absolute inset-0 flex items-center justify-center">
|
|
22
|
+
<div class="flex flex-col items-center gap-2 text-muted-foreground">
|
|
23
|
+
<svg
|
|
24
|
+
class="h-8 w-8 animate-spin"
|
|
25
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
26
|
+
fill="none"
|
|
27
|
+
viewBox="0 0 24 24"
|
|
28
|
+
>
|
|
29
|
+
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4" />
|
|
30
|
+
<path
|
|
31
|
+
class="opacity-75"
|
|
32
|
+
fill="currentColor"
|
|
33
|
+
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
|
|
34
|
+
/>
|
|
35
|
+
</svg>
|
|
36
|
+
<span class="text-sm">Loading map...</span>
|
|
37
|
+
</div>
|
|
38
|
+
</div>
|
|
39
|
+
<!-- Placeholder map grid -->
|
|
40
|
+
<div class="absolute inset-4 grid grid-cols-4 grid-rows-4 gap-1 opacity-20">
|
|
41
|
+
{#each Array(16) as _}
|
|
42
|
+
<div class="rounded bg-muted-foreground/20"></div>
|
|
43
|
+
{/each}
|
|
44
|
+
</div>
|
|
45
|
+
</div>
|