maplibrex-svelte 0.1.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.
Files changed (109) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +300 -0
  3. package/dist/components/MapLibre.svelte +258 -0
  4. package/dist/components/MapLibre.svelte.d.ts +42 -0
  5. package/dist/components/controls/AttributionControl.svelte +21 -0
  6. package/dist/components/controls/AttributionControl.svelte.d.ts +11 -0
  7. package/dist/components/controls/Control.svelte +58 -0
  8. package/dist/components/controls/Control.svelte.d.ts +33 -0
  9. package/dist/components/controls/CustomControl.svelte +46 -0
  10. package/dist/components/controls/CustomControl.svelte.d.ts +13 -0
  11. package/dist/components/controls/FullscreenControl.svelte +32 -0
  12. package/dist/components/controls/FullscreenControl.svelte.d.ts +12 -0
  13. package/dist/components/controls/GeolocateControl.svelte +32 -0
  14. package/dist/components/controls/GeolocateControl.svelte.d.ts +12 -0
  15. package/dist/components/controls/GlobeControl.svelte +16 -0
  16. package/dist/components/controls/GlobeControl.svelte.d.ts +11 -0
  17. package/dist/components/controls/LogoControl.svelte +21 -0
  18. package/dist/components/controls/LogoControl.svelte.d.ts +11 -0
  19. package/dist/components/controls/NavigationControl.svelte +21 -0
  20. package/dist/components/controls/NavigationControl.svelte.d.ts +11 -0
  21. package/dist/components/controls/ScaleControl.svelte +21 -0
  22. package/dist/components/controls/ScaleControl.svelte.d.ts +11 -0
  23. package/dist/components/controls/TerrainControl.svelte +21 -0
  24. package/dist/components/controls/TerrainControl.svelte.d.ts +11 -0
  25. package/dist/components/data/FeatureState.svelte +56 -0
  26. package/dist/components/data/FeatureState.svelte.d.ts +13 -0
  27. package/dist/components/data/Protocol.svelte +24 -0
  28. package/dist/components/data/Protocol.svelte.d.ts +9 -0
  29. package/dist/components/layers/BackgroundLayer.svelte +21 -0
  30. package/dist/components/layers/BackgroundLayer.svelte.d.ts +17 -0
  31. package/dist/components/layers/CircleLayer.svelte +25 -0
  32. package/dist/components/layers/CircleLayer.svelte.d.ts +21 -0
  33. package/dist/components/layers/ColorReliefLayer.svelte +25 -0
  34. package/dist/components/layers/ColorReliefLayer.svelte.d.ts +21 -0
  35. package/dist/components/layers/CustomLayer.svelte +35 -0
  36. package/dist/components/layers/CustomLayer.svelte.d.ts +13 -0
  37. package/dist/components/layers/FillExtrusionLayer.svelte +25 -0
  38. package/dist/components/layers/FillExtrusionLayer.svelte.d.ts +21 -0
  39. package/dist/components/layers/FillLayer.svelte +25 -0
  40. package/dist/components/layers/FillLayer.svelte.d.ts +21 -0
  41. package/dist/components/layers/HeatmapLayer.svelte +25 -0
  42. package/dist/components/layers/HeatmapLayer.svelte.d.ts +21 -0
  43. package/dist/components/layers/HillshadeLayer.svelte +25 -0
  44. package/dist/components/layers/HillshadeLayer.svelte.d.ts +21 -0
  45. package/dist/components/layers/Layer.svelte +204 -0
  46. package/dist/components/layers/Layer.svelte.d.ts +29 -0
  47. package/dist/components/layers/LineLayer.svelte +25 -0
  48. package/dist/components/layers/LineLayer.svelte.d.ts +21 -0
  49. package/dist/components/layers/RasterLayer.svelte +25 -0
  50. package/dist/components/layers/RasterLayer.svelte.d.ts +21 -0
  51. package/dist/components/layers/SymbolLayer.svelte +25 -0
  52. package/dist/components/layers/SymbolLayer.svelte.d.ts +21 -0
  53. package/dist/components/overlays/Marker.svelte +204 -0
  54. package/dist/components/overlays/Marker.svelte.d.ts +27 -0
  55. package/dist/components/overlays/Popup.svelte +184 -0
  56. package/dist/components/overlays/Popup.svelte.d.ts +24 -0
  57. package/dist/components/sources/CanvasSource.svelte +16 -0
  58. package/dist/components/sources/CanvasSource.svelte.d.ts +13 -0
  59. package/dist/components/sources/GeoJSONSource.svelte +16 -0
  60. package/dist/components/sources/GeoJSONSource.svelte.d.ts +13 -0
  61. package/dist/components/sources/ImageSource.svelte +16 -0
  62. package/dist/components/sources/ImageSource.svelte.d.ts +13 -0
  63. package/dist/components/sources/RasterDEMSource.svelte +16 -0
  64. package/dist/components/sources/RasterDEMSource.svelte.d.ts +13 -0
  65. package/dist/components/sources/RasterSource.svelte +16 -0
  66. package/dist/components/sources/RasterSource.svelte.d.ts +13 -0
  67. package/dist/components/sources/Source.svelte +88 -0
  68. package/dist/components/sources/Source.svelte.d.ts +14 -0
  69. package/dist/components/sources/VectorSource.svelte +16 -0
  70. package/dist/components/sources/VectorSource.svelte.d.ts +13 -0
  71. package/dist/components/sources/VideoSource.svelte +16 -0
  72. package/dist/components/sources/VideoSource.svelte.d.ts +13 -0
  73. package/dist/components/style/GlobalState.svelte +67 -0
  74. package/dist/components/style/GlobalState.svelte.d.ts +8 -0
  75. package/dist/components/style/Image.svelte +92 -0
  76. package/dist/components/style/Image.svelte.d.ts +14 -0
  77. package/dist/components/style/Light.svelte +31 -0
  78. package/dist/components/style/Light.svelte.d.ts +4 -0
  79. package/dist/components/style/Projection.svelte +31 -0
  80. package/dist/components/style/Projection.svelte.d.ts +4 -0
  81. package/dist/components/style/Sky.svelte +31 -0
  82. package/dist/components/style/Sky.svelte.d.ts +4 -0
  83. package/dist/components/style/Terrain.svelte +50 -0
  84. package/dist/components/style/Terrain.svelte.d.ts +9 -0
  85. package/dist/context.d.ts +41 -0
  86. package/dist/context.js +31 -0
  87. package/dist/index.d.ts +57 -0
  88. package/dist/index.js +48 -0
  89. package/dist/internal/bind-events.svelte.d.ts +26 -0
  90. package/dist/internal/bind-events.svelte.js +49 -0
  91. package/dist/internal/camera.d.ts +15 -0
  92. package/dist/internal/camera.js +33 -0
  93. package/dist/internal/deep-equal.d.ts +6 -0
  94. package/dist/internal/deep-equal.js +25 -0
  95. package/dist/internal/diff.d.ts +15 -0
  96. package/dist/internal/diff.js +29 -0
  97. package/dist/internal/events.d.ts +22 -0
  98. package/dist/internal/events.js +40 -0
  99. package/dist/internal/interactions.d.ts +22 -0
  100. package/dist/internal/interactions.js +36 -0
  101. package/dist/internal/source.d.ts +25 -0
  102. package/dist/internal/source.js +25 -0
  103. package/dist/internal/stable-key.d.ts +9 -0
  104. package/dist/internal/stable-key.js +17 -0
  105. package/dist/internal/style-ops.d.ts +26 -0
  106. package/dist/internal/style-ops.js +56 -0
  107. package/dist/types.d.ts +21 -0
  108. package/dist/types.js +1 -0
  109. package/package.json +92 -0
@@ -0,0 +1,21 @@
1
+ import type { ColorReliefLayerSpecification } from 'maplibre-gl';
2
+ import type { Snippet } from 'svelte';
3
+ import type { LayerEventProps } from '../../types.js';
4
+ type Props = Omit<ColorReliefLayerSpecification, 'type' | 'id' | 'source' | 'source-layer'> & LayerEventProps & {
5
+ /** Unique within the style. Changing it recreates the layer. */
6
+ id: string;
7
+ /** Defaults to the id of the enclosing source component. */
8
+ source?: string;
9
+ /** Required for vector tile sources with more than one layer. */
10
+ sourceLayer?: string;
11
+ /** Insert before this layer id; changing it moves the layer. */
12
+ beforeId?: string;
13
+ /** Sugar over `layout.visibility`. @defaultValue true */
14
+ visible?: boolean;
15
+ children?: Snippet<[{
16
+ id: string;
17
+ }]>;
18
+ };
19
+ declare const ColorReliefLayer: import("svelte").Component<Props, {}, "">;
20
+ type ColorReliefLayer = ReturnType<typeof ColorReliefLayer>;
21
+ export default ColorReliefLayer;
@@ -0,0 +1,35 @@
1
+ <script lang="ts">
2
+ import type { CustomLayerInterface } from 'maplibre-gl';
3
+ import { untrack } from 'svelte';
4
+ import { getMapContext } from '../../context.js';
5
+ import { removeLayerIfPresent } from '../../internal/style-ops.js';
6
+
7
+ type Props = {
8
+ /**
9
+ * Your own WebGL layer: three.js, babylon.js, or raw GL. MapLibre calls
10
+ * its `onAdd`, `render` and `onRemove` hooks.
11
+ */
12
+ layer: CustomLayerInterface;
13
+ /** Insert before this layer id. */
14
+ beforeId?: string;
15
+ };
16
+
17
+ let { layer, beforeId }: Props = $props();
18
+
19
+ const context = getMapContext();
20
+
21
+ $effect(() => {
22
+ const map = context.map;
23
+ const ready = context.ready;
24
+ void context.styleEpoch;
25
+
26
+ const custom = layer;
27
+ const before = beforeId;
28
+
29
+ if (!map || !ready) return;
30
+
31
+ untrack(() => map.addLayer(custom, before));
32
+
33
+ return () => removeLayerIfPresent(map, custom.id);
34
+ });
35
+ </script>
@@ -0,0 +1,13 @@
1
+ import type { CustomLayerInterface } from 'maplibre-gl';
2
+ type Props = {
3
+ /**
4
+ * Your own WebGL layer: three.js, babylon.js, or raw GL. MapLibre calls
5
+ * its `onAdd`, `render` and `onRemove` hooks.
6
+ */
7
+ layer: CustomLayerInterface;
8
+ /** Insert before this layer id. */
9
+ beforeId?: string;
10
+ };
11
+ declare const CustomLayer: import("svelte").Component<Props, {}, "">;
12
+ type CustomLayer = ReturnType<typeof CustomLayer>;
13
+ export default CustomLayer;
@@ -0,0 +1,25 @@
1
+ <script lang="ts">
2
+ import type { FillExtrusionLayerSpecification } from 'maplibre-gl';
3
+ import type { Snippet } from 'svelte';
4
+ import Layer from './Layer.svelte';
5
+ import type { LayerEventProps } from '../../types.js';
6
+
7
+ type Props = Omit<FillExtrusionLayerSpecification, 'type' | 'id' | 'source' | 'source-layer'> &
8
+ LayerEventProps & {
9
+ /** Unique within the style. Changing it recreates the layer. */
10
+ id: string;
11
+ /** Defaults to the id of the enclosing source component. */
12
+ source?: string;
13
+ /** Required for vector tile sources with more than one layer. */
14
+ sourceLayer?: string;
15
+ /** Insert before this layer id; changing it moves the layer. */
16
+ beforeId?: string;
17
+ /** Sugar over `layout.visibility`. @defaultValue true */
18
+ visible?: boolean;
19
+ children?: Snippet<[{ id: string }]>;
20
+ };
21
+
22
+ let props: Props = $props();
23
+ </script>
24
+
25
+ <Layer type="fill-extrusion" {...props} />
@@ -0,0 +1,21 @@
1
+ import type { FillExtrusionLayerSpecification } from 'maplibre-gl';
2
+ import type { Snippet } from 'svelte';
3
+ import type { LayerEventProps } from '../../types.js';
4
+ type Props = Omit<FillExtrusionLayerSpecification, 'type' | 'id' | 'source' | 'source-layer'> & LayerEventProps & {
5
+ /** Unique within the style. Changing it recreates the layer. */
6
+ id: string;
7
+ /** Defaults to the id of the enclosing source component. */
8
+ source?: string;
9
+ /** Required for vector tile sources with more than one layer. */
10
+ sourceLayer?: string;
11
+ /** Insert before this layer id; changing it moves the layer. */
12
+ beforeId?: string;
13
+ /** Sugar over `layout.visibility`. @defaultValue true */
14
+ visible?: boolean;
15
+ children?: Snippet<[{
16
+ id: string;
17
+ }]>;
18
+ };
19
+ declare const FillExtrusionLayer: import("svelte").Component<Props, {}, "">;
20
+ type FillExtrusionLayer = ReturnType<typeof FillExtrusionLayer>;
21
+ export default FillExtrusionLayer;
@@ -0,0 +1,25 @@
1
+ <script lang="ts">
2
+ import type { FillLayerSpecification } from 'maplibre-gl';
3
+ import type { Snippet } from 'svelte';
4
+ import Layer from './Layer.svelte';
5
+ import type { LayerEventProps } from '../../types.js';
6
+
7
+ type Props = Omit<FillLayerSpecification, 'type' | 'id' | 'source' | 'source-layer'> &
8
+ LayerEventProps & {
9
+ /** Unique within the style. Changing it recreates the layer. */
10
+ id: string;
11
+ /** Defaults to the id of the enclosing source component. */
12
+ source?: string;
13
+ /** Required for vector tile sources with more than one layer. */
14
+ sourceLayer?: string;
15
+ /** Insert before this layer id; changing it moves the layer. */
16
+ beforeId?: string;
17
+ /** Sugar over `layout.visibility`. @defaultValue true */
18
+ visible?: boolean;
19
+ children?: Snippet<[{ id: string }]>;
20
+ };
21
+
22
+ let props: Props = $props();
23
+ </script>
24
+
25
+ <Layer type="fill" {...props} />
@@ -0,0 +1,21 @@
1
+ import type { FillLayerSpecification } from 'maplibre-gl';
2
+ import type { Snippet } from 'svelte';
3
+ import type { LayerEventProps } from '../../types.js';
4
+ type Props = Omit<FillLayerSpecification, 'type' | 'id' | 'source' | 'source-layer'> & LayerEventProps & {
5
+ /** Unique within the style. Changing it recreates the layer. */
6
+ id: string;
7
+ /** Defaults to the id of the enclosing source component. */
8
+ source?: string;
9
+ /** Required for vector tile sources with more than one layer. */
10
+ sourceLayer?: string;
11
+ /** Insert before this layer id; changing it moves the layer. */
12
+ beforeId?: string;
13
+ /** Sugar over `layout.visibility`. @defaultValue true */
14
+ visible?: boolean;
15
+ children?: Snippet<[{
16
+ id: string;
17
+ }]>;
18
+ };
19
+ declare const FillLayer: import("svelte").Component<Props, {}, "">;
20
+ type FillLayer = ReturnType<typeof FillLayer>;
21
+ export default FillLayer;
@@ -0,0 +1,25 @@
1
+ <script lang="ts">
2
+ import type { HeatmapLayerSpecification } from 'maplibre-gl';
3
+ import type { Snippet } from 'svelte';
4
+ import Layer from './Layer.svelte';
5
+ import type { LayerEventProps } from '../../types.js';
6
+
7
+ type Props = Omit<HeatmapLayerSpecification, 'type' | 'id' | 'source' | 'source-layer'> &
8
+ LayerEventProps & {
9
+ /** Unique within the style. Changing it recreates the layer. */
10
+ id: string;
11
+ /** Defaults to the id of the enclosing source component. */
12
+ source?: string;
13
+ /** Required for vector tile sources with more than one layer. */
14
+ sourceLayer?: string;
15
+ /** Insert before this layer id; changing it moves the layer. */
16
+ beforeId?: string;
17
+ /** Sugar over `layout.visibility`. @defaultValue true */
18
+ visible?: boolean;
19
+ children?: Snippet<[{ id: string }]>;
20
+ };
21
+
22
+ let props: Props = $props();
23
+ </script>
24
+
25
+ <Layer type="heatmap" {...props} />
@@ -0,0 +1,21 @@
1
+ import type { HeatmapLayerSpecification } from 'maplibre-gl';
2
+ import type { Snippet } from 'svelte';
3
+ import type { LayerEventProps } from '../../types.js';
4
+ type Props = Omit<HeatmapLayerSpecification, 'type' | 'id' | 'source' | 'source-layer'> & LayerEventProps & {
5
+ /** Unique within the style. Changing it recreates the layer. */
6
+ id: string;
7
+ /** Defaults to the id of the enclosing source component. */
8
+ source?: string;
9
+ /** Required for vector tile sources with more than one layer. */
10
+ sourceLayer?: string;
11
+ /** Insert before this layer id; changing it moves the layer. */
12
+ beforeId?: string;
13
+ /** Sugar over `layout.visibility`. @defaultValue true */
14
+ visible?: boolean;
15
+ children?: Snippet<[{
16
+ id: string;
17
+ }]>;
18
+ };
19
+ declare const HeatmapLayer: import("svelte").Component<Props, {}, "">;
20
+ type HeatmapLayer = ReturnType<typeof HeatmapLayer>;
21
+ export default HeatmapLayer;
@@ -0,0 +1,25 @@
1
+ <script lang="ts">
2
+ import type { HillshadeLayerSpecification } from 'maplibre-gl';
3
+ import type { Snippet } from 'svelte';
4
+ import Layer from './Layer.svelte';
5
+ import type { LayerEventProps } from '../../types.js';
6
+
7
+ type Props = Omit<HillshadeLayerSpecification, 'type' | 'id' | 'source' | 'source-layer'> &
8
+ LayerEventProps & {
9
+ /** Unique within the style. Changing it recreates the layer. */
10
+ id: string;
11
+ /** Defaults to the id of the enclosing source component. */
12
+ source?: string;
13
+ /** Required for vector tile sources with more than one layer. */
14
+ sourceLayer?: string;
15
+ /** Insert before this layer id; changing it moves the layer. */
16
+ beforeId?: string;
17
+ /** Sugar over `layout.visibility`. @defaultValue true */
18
+ visible?: boolean;
19
+ children?: Snippet<[{ id: string }]>;
20
+ };
21
+
22
+ let props: Props = $props();
23
+ </script>
24
+
25
+ <Layer type="hillshade" {...props} />
@@ -0,0 +1,21 @@
1
+ import type { HillshadeLayerSpecification } from 'maplibre-gl';
2
+ import type { Snippet } from 'svelte';
3
+ import type { LayerEventProps } from '../../types.js';
4
+ type Props = Omit<HillshadeLayerSpecification, 'type' | 'id' | 'source' | 'source-layer'> & LayerEventProps & {
5
+ /** Unique within the style. Changing it recreates the layer. */
6
+ id: string;
7
+ /** Defaults to the id of the enclosing source component. */
8
+ source?: string;
9
+ /** Required for vector tile sources with more than one layer. */
10
+ sourceLayer?: string;
11
+ /** Insert before this layer id; changing it moves the layer. */
12
+ beforeId?: string;
13
+ /** Sugar over `layout.visibility`. @defaultValue true */
14
+ visible?: boolean;
15
+ children?: Snippet<[{
16
+ id: string;
17
+ }]>;
18
+ };
19
+ declare const HillshadeLayer: import("svelte").Component<Props, {}, "">;
20
+ type HillshadeLayer = ReturnType<typeof HillshadeLayer>;
21
+ export default HillshadeLayer;
@@ -0,0 +1,204 @@
1
+ <script lang="ts">
2
+ import type { AddLayerObject, FilterSpecification, LayerSpecification } from 'maplibre-gl';
3
+ import { untrack, type Snippet } from 'svelte';
4
+ import { getMapContext, getSourceContext } from '../../context.js';
5
+ import { bindLayerEvents } from '../../internal/bind-events.svelte.js';
6
+ import { deepEqual } from '../../internal/deep-equal.js';
7
+ import { diffRecords } from '../../internal/diff.js';
8
+ import {
9
+ removeLayerIfPresent,
10
+ setLayoutProperty,
11
+ setPaintProperty
12
+ } from '../../internal/style-ops.js';
13
+ import type { LayerEventProps } from '../../types.js';
14
+
15
+ type StyleRecord = Record<string, unknown>;
16
+
17
+ type Props = LayerEventProps & {
18
+ /** Unique within the style. Changing it recreates the layer. */
19
+ id: string;
20
+ type: LayerSpecification['type'];
21
+ /** Defaults to the id of the enclosing source component. */
22
+ source?: string;
23
+ /** Required for vector tile sources with more than one layer. */
24
+ sourceLayer?: string;
25
+ filter?: FilterSpecification;
26
+ layout?: StyleRecord;
27
+ paint?: StyleRecord;
28
+ minzoom?: number;
29
+ maxzoom?: number;
30
+ /** Sugar over `layout.visibility`. @defaultValue true */
31
+ visible?: boolean;
32
+ /** Insert before this layer id; changing it moves the layer. */
33
+ beforeId?: string;
34
+ metadata?: unknown;
35
+ children?: Snippet<[{ id: string }]>;
36
+ };
37
+
38
+ let {
39
+ id,
40
+ type,
41
+ source,
42
+ sourceLayer,
43
+ filter,
44
+ layout,
45
+ paint,
46
+ minzoom,
47
+ maxzoom,
48
+ visible = true,
49
+ beforeId,
50
+ metadata,
51
+ children,
52
+ ...events
53
+ }: Props = $props();
54
+
55
+ const context = getMapContext();
56
+ const sourceContext = getSourceContext();
57
+
58
+ const resolvedSource = $derived(source ?? sourceContext?.id);
59
+ const resolvedLayout = $derived({
60
+ ...layout,
61
+ ...(visible ? {} : { visibility: 'none' })
62
+ } satisfies StyleRecord);
63
+
64
+ let mounted = $state(false);
65
+ let appliedPaint = $state<StyleRecord | undefined>();
66
+ let appliedLayout = $state<StyleRecord | undefined>();
67
+ let appliedFilter = $state<FilterSpecification | undefined>();
68
+
69
+ // Add and remove. Re-runs when the map appears, when the style is replaced,
70
+ // when the enclosing source is recreated, and on identity changes that
71
+ // MapLibre offers no setter for.
72
+ $effect(() => {
73
+ const map = context.map;
74
+ const ready = context.ready;
75
+ void context.styleEpoch;
76
+ void sourceContext?.epoch;
77
+
78
+ const layerId = id;
79
+ const layerType = type;
80
+ const sourceId = resolvedSource;
81
+
82
+ if (!map || !ready) return;
83
+
84
+ if (layerType !== 'background' && !sourceId) {
85
+ throw new Error(
86
+ `[maplibrex] Layer "${layerId}" needs a source: pass \`source\` or nest it inside a source component.`
87
+ );
88
+ }
89
+
90
+ untrack(() => {
91
+ map.addLayer(
92
+ {
93
+ id: layerId,
94
+ type: layerType,
95
+ ...(sourceId ? { source: sourceId } : {}),
96
+ ...(sourceLayer ? { 'source-layer': sourceLayer } : {}),
97
+ ...(filter ? { filter } : {}),
98
+ ...(minzoom !== undefined ? { minzoom } : {}),
99
+ ...(maxzoom !== undefined ? { maxzoom } : {}),
100
+ ...(metadata !== undefined ? { metadata } : {}),
101
+ layout: resolvedLayout,
102
+ paint: paint ?? {}
103
+ } as AddLayerObject,
104
+ beforeId
105
+ );
106
+
107
+ appliedPaint = paint;
108
+ appliedLayout = resolvedLayout;
109
+ appliedFilter = filter;
110
+ mounted = true;
111
+ });
112
+
113
+ return () => {
114
+ mounted = false;
115
+ appliedPaint = undefined;
116
+ appliedLayout = undefined;
117
+ appliedFilter = undefined;
118
+ removeLayerIfPresent(map, layerId);
119
+ };
120
+ });
121
+
122
+ // Paint and layout are pushed property by property. Recreating the layer to
123
+ // change one colour would drop its tiles and restart every transition.
124
+ $effect(() => {
125
+ const map = context.map;
126
+ const next = paint;
127
+ if (!map || !mounted) return;
128
+
129
+ const { changed, removed } = diffRecords<unknown>(
130
+ untrack(() => appliedPaint),
131
+ next
132
+ );
133
+ if (changed.length === 0 && removed.length === 0) return;
134
+
135
+ untrack(() => {
136
+ for (const [key, value] of changed) setPaintProperty(map, id, key, value);
137
+ for (const key of removed) setPaintProperty(map, id, key, undefined);
138
+ appliedPaint = next;
139
+ });
140
+ });
141
+
142
+ $effect(() => {
143
+ const map = context.map;
144
+ const next = resolvedLayout;
145
+ if (!map || !mounted) return;
146
+
147
+ const { changed, removed } = diffRecords<unknown>(
148
+ untrack(() => appliedLayout),
149
+ next
150
+ );
151
+ if (changed.length === 0 && removed.length === 0) return;
152
+
153
+ untrack(() => {
154
+ for (const [key, value] of changed) setLayoutProperty(map, id, key, value);
155
+ for (const key of removed) setLayoutProperty(map, id, key, undefined);
156
+ appliedLayout = next;
157
+ });
158
+ });
159
+
160
+ $effect(() => {
161
+ const map = context.map;
162
+ const next = filter;
163
+ if (!map || !mounted) return;
164
+ if (
165
+ deepEqual(
166
+ untrack(() => appliedFilter),
167
+ next
168
+ )
169
+ )
170
+ return;
171
+
172
+ untrack(() => {
173
+ map.setFilter(id, next);
174
+ appliedFilter = next;
175
+ });
176
+ });
177
+
178
+ $effect(() => {
179
+ const map = context.map;
180
+ const range = { minzoom, maxzoom };
181
+ if (!map || !mounted) return;
182
+ if (range.minzoom === undefined && range.maxzoom === undefined) return;
183
+
184
+ untrack(() => map.setLayerZoomRange(id, range.minzoom ?? 0, range.maxzoom ?? 24));
185
+ });
186
+
187
+ $effect(() => {
188
+ const map = context.map;
189
+ const target = beforeId;
190
+ if (!map || !mounted) return;
191
+
192
+ untrack(() => map.moveLayer(id, target));
193
+ });
194
+
195
+ bindLayerEvents(
196
+ () => (mounted ? context.map : null),
197
+ () => id,
198
+ () => events
199
+ );
200
+ </script>
201
+
202
+ {#if mounted}
203
+ {@render children?.({ id })}
204
+ {/if}
@@ -0,0 +1,29 @@
1
+ import type { FilterSpecification, LayerSpecification } from 'maplibre-gl';
2
+ import { type Snippet } from 'svelte';
3
+ import type { LayerEventProps } from '../../types.js';
4
+ type StyleRecord = Record<string, unknown>;
5
+ type Props = LayerEventProps & {
6
+ /** Unique within the style. Changing it recreates the layer. */
7
+ id: string;
8
+ type: LayerSpecification['type'];
9
+ /** Defaults to the id of the enclosing source component. */
10
+ source?: string;
11
+ /** Required for vector tile sources with more than one layer. */
12
+ sourceLayer?: string;
13
+ filter?: FilterSpecification;
14
+ layout?: StyleRecord;
15
+ paint?: StyleRecord;
16
+ minzoom?: number;
17
+ maxzoom?: number;
18
+ /** Sugar over `layout.visibility`. @defaultValue true */
19
+ visible?: boolean;
20
+ /** Insert before this layer id; changing it moves the layer. */
21
+ beforeId?: string;
22
+ metadata?: unknown;
23
+ children?: Snippet<[{
24
+ id: string;
25
+ }]>;
26
+ };
27
+ declare const Layer: import("svelte").Component<Props, {}, "">;
28
+ type Layer = ReturnType<typeof Layer>;
29
+ export default Layer;
@@ -0,0 +1,25 @@
1
+ <script lang="ts">
2
+ import type { LineLayerSpecification } from 'maplibre-gl';
3
+ import type { Snippet } from 'svelte';
4
+ import Layer from './Layer.svelte';
5
+ import type { LayerEventProps } from '../../types.js';
6
+
7
+ type Props = Omit<LineLayerSpecification, 'type' | 'id' | 'source' | 'source-layer'> &
8
+ LayerEventProps & {
9
+ /** Unique within the style. Changing it recreates the layer. */
10
+ id: string;
11
+ /** Defaults to the id of the enclosing source component. */
12
+ source?: string;
13
+ /** Required for vector tile sources with more than one layer. */
14
+ sourceLayer?: string;
15
+ /** Insert before this layer id; changing it moves the layer. */
16
+ beforeId?: string;
17
+ /** Sugar over `layout.visibility`. @defaultValue true */
18
+ visible?: boolean;
19
+ children?: Snippet<[{ id: string }]>;
20
+ };
21
+
22
+ let props: Props = $props();
23
+ </script>
24
+
25
+ <Layer type="line" {...props} />
@@ -0,0 +1,21 @@
1
+ import type { LineLayerSpecification } from 'maplibre-gl';
2
+ import type { Snippet } from 'svelte';
3
+ import type { LayerEventProps } from '../../types.js';
4
+ type Props = Omit<LineLayerSpecification, 'type' | 'id' | 'source' | 'source-layer'> & LayerEventProps & {
5
+ /** Unique within the style. Changing it recreates the layer. */
6
+ id: string;
7
+ /** Defaults to the id of the enclosing source component. */
8
+ source?: string;
9
+ /** Required for vector tile sources with more than one layer. */
10
+ sourceLayer?: string;
11
+ /** Insert before this layer id; changing it moves the layer. */
12
+ beforeId?: string;
13
+ /** Sugar over `layout.visibility`. @defaultValue true */
14
+ visible?: boolean;
15
+ children?: Snippet<[{
16
+ id: string;
17
+ }]>;
18
+ };
19
+ declare const LineLayer: import("svelte").Component<Props, {}, "">;
20
+ type LineLayer = ReturnType<typeof LineLayer>;
21
+ export default LineLayer;
@@ -0,0 +1,25 @@
1
+ <script lang="ts">
2
+ import type { RasterLayerSpecification } from 'maplibre-gl';
3
+ import type { Snippet } from 'svelte';
4
+ import Layer from './Layer.svelte';
5
+ import type { LayerEventProps } from '../../types.js';
6
+
7
+ type Props = Omit<RasterLayerSpecification, 'type' | 'id' | 'source' | 'source-layer'> &
8
+ LayerEventProps & {
9
+ /** Unique within the style. Changing it recreates the layer. */
10
+ id: string;
11
+ /** Defaults to the id of the enclosing source component. */
12
+ source?: string;
13
+ /** Required for vector tile sources with more than one layer. */
14
+ sourceLayer?: string;
15
+ /** Insert before this layer id; changing it moves the layer. */
16
+ beforeId?: string;
17
+ /** Sugar over `layout.visibility`. @defaultValue true */
18
+ visible?: boolean;
19
+ children?: Snippet<[{ id: string }]>;
20
+ };
21
+
22
+ let props: Props = $props();
23
+ </script>
24
+
25
+ <Layer type="raster" {...props} />
@@ -0,0 +1,21 @@
1
+ import type { RasterLayerSpecification } from 'maplibre-gl';
2
+ import type { Snippet } from 'svelte';
3
+ import type { LayerEventProps } from '../../types.js';
4
+ type Props = Omit<RasterLayerSpecification, 'type' | 'id' | 'source' | 'source-layer'> & LayerEventProps & {
5
+ /** Unique within the style. Changing it recreates the layer. */
6
+ id: string;
7
+ /** Defaults to the id of the enclosing source component. */
8
+ source?: string;
9
+ /** Required for vector tile sources with more than one layer. */
10
+ sourceLayer?: string;
11
+ /** Insert before this layer id; changing it moves the layer. */
12
+ beforeId?: string;
13
+ /** Sugar over `layout.visibility`. @defaultValue true */
14
+ visible?: boolean;
15
+ children?: Snippet<[{
16
+ id: string;
17
+ }]>;
18
+ };
19
+ declare const RasterLayer: import("svelte").Component<Props, {}, "">;
20
+ type RasterLayer = ReturnType<typeof RasterLayer>;
21
+ export default RasterLayer;
@@ -0,0 +1,25 @@
1
+ <script lang="ts">
2
+ import type { SymbolLayerSpecification } from 'maplibre-gl';
3
+ import type { Snippet } from 'svelte';
4
+ import Layer from './Layer.svelte';
5
+ import type { LayerEventProps } from '../../types.js';
6
+
7
+ type Props = Omit<SymbolLayerSpecification, 'type' | 'id' | 'source' | 'source-layer'> &
8
+ LayerEventProps & {
9
+ /** Unique within the style. Changing it recreates the layer. */
10
+ id: string;
11
+ /** Defaults to the id of the enclosing source component. */
12
+ source?: string;
13
+ /** Required for vector tile sources with more than one layer. */
14
+ sourceLayer?: string;
15
+ /** Insert before this layer id; changing it moves the layer. */
16
+ beforeId?: string;
17
+ /** Sugar over `layout.visibility`. @defaultValue true */
18
+ visible?: boolean;
19
+ children?: Snippet<[{ id: string }]>;
20
+ };
21
+
22
+ let props: Props = $props();
23
+ </script>
24
+
25
+ <Layer type="symbol" {...props} />
@@ -0,0 +1,21 @@
1
+ import type { SymbolLayerSpecification } from 'maplibre-gl';
2
+ import type { Snippet } from 'svelte';
3
+ import type { LayerEventProps } from '../../types.js';
4
+ type Props = Omit<SymbolLayerSpecification, 'type' | 'id' | 'source' | 'source-layer'> & LayerEventProps & {
5
+ /** Unique within the style. Changing it recreates the layer. */
6
+ id: string;
7
+ /** Defaults to the id of the enclosing source component. */
8
+ source?: string;
9
+ /** Required for vector tile sources with more than one layer. */
10
+ sourceLayer?: string;
11
+ /** Insert before this layer id; changing it moves the layer. */
12
+ beforeId?: string;
13
+ /** Sugar over `layout.visibility`. @defaultValue true */
14
+ visible?: boolean;
15
+ children?: Snippet<[{
16
+ id: string;
17
+ }]>;
18
+ };
19
+ declare const SymbolLayer: import("svelte").Component<Props, {}, "">;
20
+ type SymbolLayer = ReturnType<typeof SymbolLayer>;
21
+ export default SymbolLayer;