maplibre-gl-layer-control 0.18.1 → 0.18.3
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 +90 -8
- package/dist/LayerControl-BVcYNnJ3.cjs +6117 -0
- package/dist/LayerControl-BVcYNnJ3.cjs.map +1 -0
- package/dist/LayerControl-dS3dARlw.js +6118 -0
- package/dist/LayerControl-dS3dARlw.js.map +1 -0
- package/dist/index.cjs +20 -4873
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +20 -4873
- package/dist/index.mjs.map +1 -1
- package/dist/maplibre-gl-layer-control.css +168 -1
- package/dist/react.cjs +269 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.mjs +269 -0
- package/dist/react.mjs.map +1 -0
- package/dist/types/index.d.ts +204 -18
- package/dist/types/react.d.ts +519 -0
- package/package.json +15 -2
package/dist/react.mjs
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import { useRef, useEffect, useState, useCallback } from "react";
|
|
2
|
+
import { L as LayerControl, g as getLayerType, s as setLayerOpacity, p as cacheOriginalLayerStyle, q as restoreOriginalStyle, c as clamp, a as getLayerOpacity } from "./LayerControl-dS3dARlw.js";
|
|
3
|
+
function LayerControlReact({
|
|
4
|
+
map,
|
|
5
|
+
position = "top-right",
|
|
6
|
+
...options
|
|
7
|
+
}) {
|
|
8
|
+
const controlRef = useRef(null);
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
if (!map) return;
|
|
11
|
+
const control = new LayerControl(options);
|
|
12
|
+
controlRef.current = control;
|
|
13
|
+
map.addControl(control, position);
|
|
14
|
+
return () => {
|
|
15
|
+
if (controlRef.current) {
|
|
16
|
+
map.removeControl(controlRef.current);
|
|
17
|
+
controlRef.current = null;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
}, [map, position]);
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
}, [options]);
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
function useLayerState({
|
|
26
|
+
map,
|
|
27
|
+
initialStates
|
|
28
|
+
}) {
|
|
29
|
+
const [layerStates, setLayerStates] = useState(initialStates);
|
|
30
|
+
const toggleVisibility = useCallback(
|
|
31
|
+
(layerId) => {
|
|
32
|
+
setLayerStates((prev) => {
|
|
33
|
+
var _a;
|
|
34
|
+
const newVisible = !((_a = prev[layerId]) == null ? void 0 : _a.visible);
|
|
35
|
+
const newStates = {
|
|
36
|
+
...prev,
|
|
37
|
+
[layerId]: {
|
|
38
|
+
...prev[layerId],
|
|
39
|
+
visible: newVisible
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
map.setLayoutProperty(layerId, "visibility", newVisible ? "visible" : "none");
|
|
43
|
+
return newStates;
|
|
44
|
+
});
|
|
45
|
+
},
|
|
46
|
+
[map]
|
|
47
|
+
);
|
|
48
|
+
const setOpacity = useCallback(
|
|
49
|
+
(layerId, opacity) => {
|
|
50
|
+
setLayerStates((prev) => {
|
|
51
|
+
const newStates = {
|
|
52
|
+
...prev,
|
|
53
|
+
[layerId]: {
|
|
54
|
+
...prev[layerId],
|
|
55
|
+
opacity
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
const layerType = getLayerType(map, layerId);
|
|
59
|
+
if (layerType) {
|
|
60
|
+
setLayerOpacity(map, layerId, layerType, opacity);
|
|
61
|
+
}
|
|
62
|
+
return newStates;
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
[map]
|
|
66
|
+
);
|
|
67
|
+
const updateLayerState = useCallback(
|
|
68
|
+
(layerId, updates) => {
|
|
69
|
+
setLayerStates((prev) => ({
|
|
70
|
+
...prev,
|
|
71
|
+
[layerId]: {
|
|
72
|
+
...prev[layerId],
|
|
73
|
+
...updates
|
|
74
|
+
}
|
|
75
|
+
}));
|
|
76
|
+
if (updates.visible !== void 0) {
|
|
77
|
+
map.setLayoutProperty(layerId, "visibility", updates.visible ? "visible" : "none");
|
|
78
|
+
}
|
|
79
|
+
if (updates.opacity !== void 0) {
|
|
80
|
+
const layerType = getLayerType(map, layerId);
|
|
81
|
+
if (layerType) {
|
|
82
|
+
setLayerOpacity(map, layerId, layerType, updates.opacity);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
[map]
|
|
87
|
+
);
|
|
88
|
+
return {
|
|
89
|
+
layerStates,
|
|
90
|
+
toggleVisibility,
|
|
91
|
+
setOpacity,
|
|
92
|
+
updateLayerState
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function useStyleEditor({ map }) {
|
|
96
|
+
const [activeEditor, setActiveEditor] = useState(null);
|
|
97
|
+
const [originalStyles, setOriginalStyles] = useState(
|
|
98
|
+
/* @__PURE__ */ new Map()
|
|
99
|
+
);
|
|
100
|
+
const openEditor = useCallback(
|
|
101
|
+
(layerId) => {
|
|
102
|
+
if (!originalStyles.has(layerId)) {
|
|
103
|
+
const newOriginalStyles = new Map(originalStyles);
|
|
104
|
+
cacheOriginalLayerStyle(map, layerId, newOriginalStyles);
|
|
105
|
+
setOriginalStyles(newOriginalStyles);
|
|
106
|
+
}
|
|
107
|
+
setActiveEditor(layerId);
|
|
108
|
+
},
|
|
109
|
+
[map, originalStyles]
|
|
110
|
+
);
|
|
111
|
+
const closeEditor = useCallback(() => {
|
|
112
|
+
setActiveEditor(null);
|
|
113
|
+
}, []);
|
|
114
|
+
const toggleEditor = useCallback(
|
|
115
|
+
(layerId) => {
|
|
116
|
+
if (activeEditor === layerId) {
|
|
117
|
+
closeEditor();
|
|
118
|
+
} else {
|
|
119
|
+
openEditor(layerId);
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
[activeEditor, openEditor, closeEditor]
|
|
123
|
+
);
|
|
124
|
+
const resetStyle = useCallback(
|
|
125
|
+
(layerId) => {
|
|
126
|
+
restoreOriginalStyle(map, layerId, originalStyles);
|
|
127
|
+
},
|
|
128
|
+
[map, originalStyles]
|
|
129
|
+
);
|
|
130
|
+
const applyStyle = useCallback(
|
|
131
|
+
(layerId, property, value) => {
|
|
132
|
+
try {
|
|
133
|
+
map.setPaintProperty(layerId, property, value);
|
|
134
|
+
} catch (error) {
|
|
135
|
+
console.warn(`Failed to apply style ${property} to ${layerId}:`, error);
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
[map]
|
|
139
|
+
);
|
|
140
|
+
return {
|
|
141
|
+
activeEditor,
|
|
142
|
+
originalStyles,
|
|
143
|
+
openEditor,
|
|
144
|
+
closeEditor,
|
|
145
|
+
toggleEditor,
|
|
146
|
+
resetStyle,
|
|
147
|
+
applyStyle
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
function usePanelWidth({
|
|
151
|
+
initialWidth = 320,
|
|
152
|
+
minWidth = 240,
|
|
153
|
+
maxWidth = 420
|
|
154
|
+
} = {}) {
|
|
155
|
+
const [width, setWidthState] = useState(initialWidth);
|
|
156
|
+
const setWidth = useCallback(
|
|
157
|
+
(newWidth) => {
|
|
158
|
+
setWidthState(clamp(newWidth, minWidth, maxWidth));
|
|
159
|
+
},
|
|
160
|
+
[minWidth, maxWidth]
|
|
161
|
+
);
|
|
162
|
+
const increaseWidth = useCallback(
|
|
163
|
+
(step = 10) => {
|
|
164
|
+
setWidth(width + step);
|
|
165
|
+
},
|
|
166
|
+
[width, setWidth]
|
|
167
|
+
);
|
|
168
|
+
const decreaseWidth = useCallback(
|
|
169
|
+
(step = 10) => {
|
|
170
|
+
setWidth(width - step);
|
|
171
|
+
},
|
|
172
|
+
[width, setWidth]
|
|
173
|
+
);
|
|
174
|
+
const resetWidth = useCallback(() => {
|
|
175
|
+
setWidthState(initialWidth);
|
|
176
|
+
}, [initialWidth]);
|
|
177
|
+
return {
|
|
178
|
+
width,
|
|
179
|
+
setWidth,
|
|
180
|
+
increaseWidth,
|
|
181
|
+
decreaseWidth,
|
|
182
|
+
resetWidth
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
function useMapLayerSync({
|
|
186
|
+
map,
|
|
187
|
+
onLayerStatesChange,
|
|
188
|
+
onNewLayers,
|
|
189
|
+
trackedLayers = []
|
|
190
|
+
}) {
|
|
191
|
+
const updateLayerStates = useCallback(() => {
|
|
192
|
+
if (!onLayerStatesChange) return;
|
|
193
|
+
const style = map.getStyle();
|
|
194
|
+
if (!style || !style.layers) return;
|
|
195
|
+
const layerStates = {};
|
|
196
|
+
style.layers.forEach((layer) => {
|
|
197
|
+
if (trackedLayers.length > 0 && !trackedLayers.includes(layer.id)) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
try {
|
|
201
|
+
const layerType = layer.type;
|
|
202
|
+
const visibility = map.getLayoutProperty(layer.id, "visibility");
|
|
203
|
+
const opacity = getLayerOpacity(map, layer.id, layerType);
|
|
204
|
+
layerStates[layer.id] = {
|
|
205
|
+
visible: visibility !== "none",
|
|
206
|
+
opacity,
|
|
207
|
+
name: layer.id.replace(/-/g, " ").replace(/\b\w/g, (l) => l.toUpperCase())
|
|
208
|
+
};
|
|
209
|
+
} catch (error) {
|
|
210
|
+
console.warn(`Failed to sync state for layer ${layer.id}:`, error);
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
onLayerStatesChange(layerStates);
|
|
214
|
+
}, [map, onLayerStatesChange, trackedLayers]);
|
|
215
|
+
const checkForNewLayers = useCallback(() => {
|
|
216
|
+
if (!onNewLayers) return;
|
|
217
|
+
const style = map.getStyle();
|
|
218
|
+
if (!style || !style.layers) return;
|
|
219
|
+
const currentLayerIds = style.layers.map((layer) => layer.id).filter((id) => {
|
|
220
|
+
if (trackedLayers.length > 0) {
|
|
221
|
+
return trackedLayers.includes(id);
|
|
222
|
+
}
|
|
223
|
+
return true;
|
|
224
|
+
});
|
|
225
|
+
onNewLayers(currentLayerIds);
|
|
226
|
+
}, [map, onNewLayers, trackedLayers]);
|
|
227
|
+
useEffect(() => {
|
|
228
|
+
if (!map) return;
|
|
229
|
+
const handleStyleData = () => {
|
|
230
|
+
setTimeout(() => {
|
|
231
|
+
updateLayerStates();
|
|
232
|
+
checkForNewLayers();
|
|
233
|
+
}, 100);
|
|
234
|
+
};
|
|
235
|
+
const handleData = (e) => {
|
|
236
|
+
if (e.sourceDataType === "content") {
|
|
237
|
+
setTimeout(() => {
|
|
238
|
+
updateLayerStates();
|
|
239
|
+
checkForNewLayers();
|
|
240
|
+
}, 100);
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
const handleSourceData = (e) => {
|
|
244
|
+
if (e.sourceDataType === "metadata") {
|
|
245
|
+
setTimeout(() => {
|
|
246
|
+
checkForNewLayers();
|
|
247
|
+
}, 150);
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
map.on("styledata", handleStyleData);
|
|
251
|
+
map.on("data", handleData);
|
|
252
|
+
map.on("sourcedata", handleSourceData);
|
|
253
|
+
updateLayerStates();
|
|
254
|
+
checkForNewLayers();
|
|
255
|
+
return () => {
|
|
256
|
+
map.off("styledata", handleStyleData);
|
|
257
|
+
map.off("data", handleData);
|
|
258
|
+
map.off("sourcedata", handleSourceData);
|
|
259
|
+
};
|
|
260
|
+
}, [map, updateLayerStates, checkForNewLayers]);
|
|
261
|
+
}
|
|
262
|
+
export {
|
|
263
|
+
LayerControlReact,
|
|
264
|
+
useLayerState,
|
|
265
|
+
useMapLayerSync,
|
|
266
|
+
usePanelWidth,
|
|
267
|
+
useStyleEditor
|
|
268
|
+
};
|
|
269
|
+
//# sourceMappingURL=react.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.mjs","sources":["../src/lib/core/LayerControlReact.tsx","../src/lib/hooks/useLayerState.ts","../src/lib/hooks/useStyleEditor.ts","../src/lib/hooks/usePanelWidth.ts","../src/lib/hooks/useMapLayerSync.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\nimport type { Map as MapLibreMap } from 'maplibre-gl';\nimport { LayerControl } from './LayerControl';\nimport type { LayerControlOptions } from './types';\n\nexport interface LayerControlReactProps extends LayerControlOptions {\n /** MapLibre map instance */\n map: MapLibreMap;\n /** Position on the map */\n position?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';\n}\n\n/**\n * React wrapper for LayerControl\n *\n * @example\n * ```tsx\n * import { LayerControlReact } from 'maplibre-gl-layer-control/react';\n *\n * function MapComponent() {\n * const [map, setMap] = useState<MapLibreMap | null>(null);\n *\n * return (\n * <>\n * <div ref={(el) => {\n * if (el && !map) {\n * const newMap = new maplibregl.Map({ container: el, ... });\n * setMap(newMap);\n * }\n * }} />\n * {map && (\n * <LayerControlReact\n * map={map}\n * position=\"top-right\"\n * layerStates={{\n * 'my-layer': { visible: true, opacity: 1, name: 'My Layer' }\n * }}\n * />\n * )}\n * </>\n * );\n * }\n * ```\n */\nexport function LayerControlReact({\n map,\n position = 'top-right',\n ...options\n}: LayerControlReactProps) {\n const controlRef = useRef<LayerControl | null>(null);\n\n useEffect(() => {\n if (!map) return;\n\n // Create and add control\n const control = new LayerControl(options);\n controlRef.current = control;\n map.addControl(control, position);\n\n // Cleanup on unmount\n return () => {\n if (controlRef.current) {\n map.removeControl(controlRef.current);\n controlRef.current = null;\n }\n };\n }, [map, position]); // Only recreate if map or position changes\n\n // Update control options if they change\n useEffect(() => {\n // Note: LayerControl doesn't currently support updating options after creation\n // This is a placeholder for future enhancement\n // For now, changing options will require remounting the component\n }, [options]);\n\n return null; // This component doesn't render anything\n}\n","import { useState, useCallback } from 'react';\nimport type { Map as MapLibreMap } from 'maplibre-gl';\nimport type { LayerState } from '../core/types';\nimport { getLayerType, setLayerOpacity } from '../utils/layerUtils';\n\nexport interface UseLayerStateOptions {\n /** MapLibre map instance */\n map: MapLibreMap;\n /** Initial layer states */\n initialStates: Record<string, LayerState>;\n}\n\nexport interface UseLayerStateReturn {\n /** Current layer states */\n layerStates: Record<string, LayerState>;\n /** Toggle layer visibility */\n toggleVisibility: (layerId: string) => void;\n /** Set layer opacity */\n setOpacity: (layerId: string, opacity: number) => void;\n /** Update a layer state */\n updateLayerState: (layerId: string, updates: Partial<LayerState>) => void;\n}\n\n/**\n * Hook for managing layer visibility and opacity state\n *\n * @example\n * ```tsx\n * const { layerStates, toggleVisibility, setOpacity } = useLayerState({\n * map,\n * initialStates: {\n * 'my-layer': { visible: true, opacity: 1, name: 'My Layer' }\n * }\n * });\n * ```\n */\nexport function useLayerState({\n map,\n initialStates,\n}: UseLayerStateOptions): UseLayerStateReturn {\n const [layerStates, setLayerStates] = useState<Record<string, LayerState>>(initialStates);\n\n const toggleVisibility = useCallback(\n (layerId: string) => {\n setLayerStates((prev) => {\n const newVisible = !prev[layerId]?.visible;\n const newStates = {\n ...prev,\n [layerId]: {\n ...prev[layerId],\n visible: newVisible,\n },\n };\n\n // Update map\n map.setLayoutProperty(layerId, 'visibility', newVisible ? 'visible' : 'none');\n\n return newStates;\n });\n },\n [map]\n );\n\n const setOpacity = useCallback(\n (layerId: string, opacity: number) => {\n setLayerStates((prev) => {\n const newStates = {\n ...prev,\n [layerId]: {\n ...prev[layerId],\n opacity,\n },\n };\n\n // Update map\n const layerType = getLayerType(map, layerId);\n if (layerType) {\n setLayerOpacity(map, layerId, layerType, opacity);\n }\n\n return newStates;\n });\n },\n [map]\n );\n\n const updateLayerState = useCallback(\n (layerId: string, updates: Partial<LayerState>) => {\n setLayerStates((prev) => ({\n ...prev,\n [layerId]: {\n ...prev[layerId],\n ...updates,\n },\n }));\n\n // Apply updates to map\n if (updates.visible !== undefined) {\n map.setLayoutProperty(layerId, 'visibility', updates.visible ? 'visible' : 'none');\n }\n if (updates.opacity !== undefined) {\n const layerType = getLayerType(map, layerId);\n if (layerType) {\n setLayerOpacity(map, layerId, layerType, updates.opacity);\n }\n }\n },\n [map]\n );\n\n return {\n layerStates,\n toggleVisibility,\n setOpacity,\n updateLayerState,\n };\n}\n","import { useState, useCallback } from 'react';\nimport type { Map as MapLibreMap, AllPaintProperties } from 'maplibre-gl';\nimport type { OriginalStyle } from '../core/types';\nimport { cacheOriginalLayerStyle, restoreOriginalStyle } from '../utils/styleCache';\n\nexport interface UseStyleEditorOptions {\n /** MapLibre map instance */\n map: MapLibreMap;\n}\n\nexport interface UseStyleEditorReturn {\n /** Currently active editor (layer ID) */\n activeEditor: string | null;\n /** Original styles cache */\n originalStyles: Map<string, OriginalStyle>;\n /** Open style editor for a layer */\n openEditor: (layerId: string) => void;\n /** Close the active editor */\n closeEditor: () => void;\n /** Toggle editor for a layer */\n toggleEditor: (layerId: string) => void;\n /** Reset layer to original style */\n resetStyle: (layerId: string) => void;\n /** Apply style changes */\n applyStyle: (layerId: string, property: string, value: any) => void;\n}\n\n/**\n * Hook for managing style editor state\n *\n * @example\n * ```tsx\n * const { activeEditor, openEditor, closeEditor, resetStyle } = useStyleEditor({ map });\n *\n * return (\n * <button onClick={() => openEditor('my-layer')}>\n * Edit Style\n * </button>\n * );\n * ```\n */\nexport function useStyleEditor({ map }: UseStyleEditorOptions): UseStyleEditorReturn {\n const [activeEditor, setActiveEditor] = useState<string | null>(null);\n const [originalStyles, setOriginalStyles] = useState<Map<string, OriginalStyle>>(\n new Map()\n );\n\n const openEditor = useCallback(\n (layerId: string) => {\n // Cache original style if not already cached\n if (!originalStyles.has(layerId)) {\n const newOriginalStyles = new Map(originalStyles);\n cacheOriginalLayerStyle(map, layerId, newOriginalStyles);\n setOriginalStyles(newOriginalStyles);\n }\n\n setActiveEditor(layerId);\n },\n [map, originalStyles]\n );\n\n const closeEditor = useCallback(() => {\n setActiveEditor(null);\n }, []);\n\n const toggleEditor = useCallback(\n (layerId: string) => {\n if (activeEditor === layerId) {\n closeEditor();\n } else {\n openEditor(layerId);\n }\n },\n [activeEditor, openEditor, closeEditor]\n );\n\n const resetStyle = useCallback(\n (layerId: string) => {\n restoreOriginalStyle(map, layerId, originalStyles);\n },\n [map, originalStyles]\n );\n\n const applyStyle = useCallback(\n (layerId: string, property: string, value: any) => {\n try {\n map.setPaintProperty(layerId, property as keyof AllPaintProperties, value);\n } catch (error) {\n console.warn(`Failed to apply style ${property} to ${layerId}:`, error);\n }\n },\n [map]\n );\n\n return {\n activeEditor,\n originalStyles,\n openEditor,\n closeEditor,\n toggleEditor,\n resetStyle,\n applyStyle,\n };\n}\n","import { useState, useCallback } from 'react';\nimport { clamp } from '../utils/formatters';\n\nexport interface UsePanelWidthOptions {\n /** Initial width */\n initialWidth?: number;\n /** Minimum width */\n minWidth?: number;\n /** Maximum width */\n maxWidth?: number;\n}\n\nexport interface UsePanelWidthReturn {\n /** Current panel width */\n width: number;\n /** Set panel width (clamped to min/max) */\n setWidth: (width: number) => void;\n /** Increase width by step */\n increaseWidth: (step?: number) => void;\n /** Decrease width by step */\n decreaseWidth: (step?: number) => void;\n /** Reset to initial width */\n resetWidth: () => void;\n}\n\n/**\n * Hook for managing panel width state\n *\n * @example\n * ```tsx\n * const { width, setWidth, increaseWidth, decreaseWidth } = usePanelWidth({\n * initialWidth: 320,\n * minWidth: 240,\n * maxWidth: 420\n * });\n *\n * return (\n * <div style={{ width: `${width}px` }}>\n * <button onClick={() => decreaseWidth(10)}>-</button>\n * <span>{width}px</span>\n * <button onClick={() => increaseWidth(10)}>+</button>\n * </div>\n * );\n * ```\n */\nexport function usePanelWidth({\n initialWidth = 320,\n minWidth = 240,\n maxWidth = 420,\n}: UsePanelWidthOptions = {}): UsePanelWidthReturn {\n const [width, setWidthState] = useState(initialWidth);\n\n const setWidth = useCallback(\n (newWidth: number) => {\n setWidthState(clamp(newWidth, minWidth, maxWidth));\n },\n [minWidth, maxWidth]\n );\n\n const increaseWidth = useCallback(\n (step = 10) => {\n setWidth(width + step);\n },\n [width, setWidth]\n );\n\n const decreaseWidth = useCallback(\n (step = 10) => {\n setWidth(width - step);\n },\n [width, setWidth]\n );\n\n const resetWidth = useCallback(() => {\n setWidthState(initialWidth);\n }, [initialWidth]);\n\n return {\n width,\n setWidth,\n increaseWidth,\n decreaseWidth,\n resetWidth,\n };\n}\n","import { useEffect, useCallback } from 'react';\nimport type { Map as MapLibreMap } from 'maplibre-gl';\nimport type { LayerState } from '../core/types';\nimport { getLayerOpacity } from '../utils/layerUtils';\n\nexport interface UseMapLayerSyncOptions {\n /** MapLibre map instance */\n map: MapLibreMap;\n /** Callback when layer states change on the map */\n onLayerStatesChange?: (layerStates: Record<string, LayerState>) => void;\n /** Callback when new layers are detected */\n onNewLayers?: (layerIds: string[]) => void;\n /** Layers to track (empty = track all) */\n trackedLayers?: string[];\n}\n\n/**\n * Hook to sync React state with MapLibre map layer changes\n *\n * @example\n * ```tsx\n * useMapLayerSync({\n * map,\n * onLayerStatesChange: (states) => {\n * console.log('Layer states updated:', states);\n * },\n * onNewLayers: (layerIds) => {\n * console.log('New layers detected:', layerIds);\n * }\n * });\n * ```\n */\nexport function useMapLayerSync({\n map,\n onLayerStatesChange,\n onNewLayers,\n trackedLayers = [],\n}: UseMapLayerSyncOptions): void {\n const updateLayerStates = useCallback(() => {\n if (!onLayerStatesChange) return;\n\n const style = map.getStyle();\n if (!style || !style.layers) return;\n\n const layerStates: Record<string, LayerState> = {};\n\n style.layers.forEach((layer) => {\n // Filter by tracked layers if specified\n if (trackedLayers.length > 0 && !trackedLayers.includes(layer.id)) {\n return;\n }\n\n try {\n const layerType = layer.type;\n const visibility = map.getLayoutProperty(layer.id, 'visibility');\n const opacity = getLayerOpacity(map, layer.id, layerType);\n\n layerStates[layer.id] = {\n visible: visibility !== 'none',\n opacity,\n name: layer.id.replace(/-/g, ' ').replace(/\\b\\w/g, (l) => l.toUpperCase()),\n };\n } catch (error) {\n console.warn(`Failed to sync state for layer ${layer.id}:`, error);\n }\n });\n\n onLayerStatesChange(layerStates);\n }, [map, onLayerStatesChange, trackedLayers]);\n\n const checkForNewLayers = useCallback(() => {\n if (!onNewLayers) return;\n\n const style = map.getStyle();\n if (!style || !style.layers) return;\n\n const currentLayerIds = style.layers\n .map((layer) => layer.id)\n .filter((id) => {\n if (trackedLayers.length > 0) {\n return trackedLayers.includes(id);\n }\n return true;\n });\n\n onNewLayers(currentLayerIds);\n }, [map, onNewLayers, trackedLayers]);\n\n useEffect(() => {\n if (!map) return;\n\n // Set up event listeners for map changes\n const handleStyleData = () => {\n setTimeout(() => {\n updateLayerStates();\n checkForNewLayers();\n }, 100);\n };\n\n const handleData = (e: any) => {\n if (e.sourceDataType === 'content') {\n setTimeout(() => {\n updateLayerStates();\n checkForNewLayers();\n }, 100);\n }\n };\n\n const handleSourceData = (e: any) => {\n if (e.sourceDataType === 'metadata') {\n setTimeout(() => {\n checkForNewLayers();\n }, 150);\n }\n };\n\n map.on('styledata', handleStyleData);\n map.on('data', handleData);\n map.on('sourcedata', handleSourceData);\n\n // Initial sync\n updateLayerStates();\n checkForNewLayers();\n\n // Cleanup\n return () => {\n map.off('styledata', handleStyleData);\n map.off('data', handleData);\n map.off('sourcedata', handleSourceData);\n };\n }, [map, updateLayerStates, checkForNewLayers]);\n}\n"],"names":[],"mappings":";;AA4CO,SAAS,kBAAkB;AAAA,EAChC;AAAA,EACA,WAAW;AAAA,EACX,GAAG;AACL,GAA2B;AACzB,QAAM,aAAa,OAA4B,IAAI;AAEnD,YAAU,MAAM;AACd,QAAI,CAAC,IAAK;AAGV,UAAM,UAAU,IAAI,aAAa,OAAO;AACxC,eAAW,UAAU;AACrB,QAAI,WAAW,SAAS,QAAQ;AAGhC,WAAO,MAAM;AACX,UAAI,WAAW,SAAS;AACtB,YAAI,cAAc,WAAW,OAAO;AACpC,mBAAW,UAAU;AAAA,MACvB;AAAA,IACF;AAAA,EACF,GAAG,CAAC,KAAK,QAAQ,CAAC;AAGlB,YAAU,MAAM;AAAA,EAIhB,GAAG,CAAC,OAAO,CAAC;AAEZ,SAAO;AACT;ACxCO,SAAS,cAAc;AAAA,EAC5B;AAAA,EACA;AACF,GAA8C;AAC5C,QAAM,CAAC,aAAa,cAAc,IAAI,SAAqC,aAAa;AAExF,QAAM,mBAAmB;AAAA,IACvB,CAAC,YAAoB;AACnB,qBAAe,CAAC,SAAS;;AACvB,cAAM,aAAa,GAAC,UAAK,OAAO,MAAZ,mBAAe;AACnC,cAAM,YAAY;AAAA,U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AI,IAAI,aAAa,eAAe;AACpC,UAAI,IAAI,QAAQ,UAAU;AAC1B,UAAI,IAAI,cAAc,gBAAgB;AAAA,IACxC;AAAA,EACF,GAAG,CAAC,KAAK,mBAAmB,iBAAiB,CAAC;AAChD;"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -22,6 +22,21 @@ export declare type BackgroundPresets = Record<string, BackgroundLayerVisibility
|
|
|
22
22
|
*/
|
|
23
23
|
export declare function clamp(value: number, min: number, max: number): number;
|
|
24
24
|
|
|
25
|
+
export declare interface ColorCategories {
|
|
26
|
+
/** Paint property that supplies the categories. */
|
|
27
|
+
property: string;
|
|
28
|
+
categories: ColorCategory[];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export declare interface ColorCategory {
|
|
32
|
+
/** Text shown next to the swatch. */
|
|
33
|
+
label: string;
|
|
34
|
+
/** Normalized hex, or null for an unsupported output (gray swatch). */
|
|
35
|
+
color: string | null;
|
|
36
|
+
/** Full label or JSON condition for the tooltip. */
|
|
37
|
+
title: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
25
40
|
/**
|
|
26
41
|
* Create an SVG symbol for the Background layer group
|
|
27
42
|
* @param size Symbol size in pixels (default: 16)
|
|
@@ -29,6 +44,9 @@ export declare function clamp(value: number, min: number, max: number): number;
|
|
|
29
44
|
*/
|
|
30
45
|
export declare function createBackgroundGroupSymbolSVG(size?: number): string;
|
|
31
46
|
|
|
47
|
+
/** Fixed categorized-renderer indicator, independent of layer colors. */
|
|
48
|
+
export declare function createCategorizedSymbolSVG(size?: number): string;
|
|
49
|
+
|
|
32
50
|
/**
|
|
33
51
|
* Create an SVG symbol for a layer type
|
|
34
52
|
* @param layerType The MapLibre layer type
|
|
@@ -48,7 +66,12 @@ export declare interface CustomLayerAdapter {
|
|
|
48
66
|
type: string;
|
|
49
67
|
/** Get all layer IDs managed by this adapter */
|
|
50
68
|
getLayerIds(): string[];
|
|
51
|
-
/**
|
|
69
|
+
/**
|
|
70
|
+
* Get the current state of a layer. For a native map layer the adapter lists
|
|
71
|
+
* in `getLayerIds`, report the layer's own visibility and opacity, without
|
|
72
|
+
* folding in any group's: the control shows these values in the layer's row
|
|
73
|
+
* and style editor and never reads them back from the map.
|
|
74
|
+
*/
|
|
52
75
|
getLayerState(layerId: string): LayerState | null;
|
|
53
76
|
/** Set layer visibility */
|
|
54
77
|
setVisibility(layerId: string, visible: boolean): void;
|
|
@@ -249,6 +272,19 @@ export declare class CustomLayerRegistry {
|
|
|
249
272
|
*/
|
|
250
273
|
export declare function darkenColor(hexColor: string, amount: number): string;
|
|
251
274
|
|
|
275
|
+
/** Registered pattern pixels and metadata, compatible with map.getImage(). */
|
|
276
|
+
export declare interface FillPatternImage {
|
|
277
|
+
data: {
|
|
278
|
+
width: number;
|
|
279
|
+
height: number;
|
|
280
|
+
data: Uint8Array | Uint8ClampedArray;
|
|
281
|
+
};
|
|
282
|
+
pixelRatio: number;
|
|
283
|
+
sdf: boolean;
|
|
284
|
+
/** Incremented by MapLibre when image pixels change. */
|
|
285
|
+
version?: number;
|
|
286
|
+
}
|
|
287
|
+
|
|
252
288
|
/**
|
|
253
289
|
* Format a numeric value based on the step size
|
|
254
290
|
* @param value Numeric value to format
|
|
@@ -266,6 +302,9 @@ export declare function formatNumericValue(value: number, step: number): string;
|
|
|
266
302
|
*/
|
|
267
303
|
export declare function getLayerColor(map: Map_2, layerId: string, layerType: string): string | null;
|
|
268
304
|
|
|
305
|
+
/** Get ordered categories from a top-level match/case color expression. */
|
|
306
|
+
export declare function getLayerColorCategories(map: Map_2, layerId: string, layerType: string): ColorCategories | null;
|
|
307
|
+
|
|
269
308
|
/**
|
|
270
309
|
* Get the primary color directly from a layer specification
|
|
271
310
|
* @param layer The layer specification
|
|
@@ -282,6 +321,23 @@ export declare function getLayerColorFromSpec(layer: LayerSpecification): string
|
|
|
282
321
|
*/
|
|
283
322
|
export declare function getLayerOpacity(map: Map_2, layerId: string, layerType: string): number;
|
|
284
323
|
|
|
324
|
+
/**
|
|
325
|
+
* Get additional symbol styles from runtime paint properties, falling back to
|
|
326
|
+
* the layer definition when a runtime property is unavailable
|
|
327
|
+
* @param map The MapLibre map instance
|
|
328
|
+
* @param layerId The layer ID
|
|
329
|
+
* @param layerType The layer type
|
|
330
|
+
* @returns The resolved dash pattern, circle border style, or fill pattern
|
|
331
|
+
*/
|
|
332
|
+
export declare function getLayerSymbolStyle(map: Map_2, layerId: string, layerType: string): LayerSymbolStyle;
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Get additional symbol styles directly from a layer specification
|
|
336
|
+
* @param layer The layer specification
|
|
337
|
+
* @returns The resolved dash pattern or circle border style
|
|
338
|
+
*/
|
|
339
|
+
export declare function getLayerSymbolStyleFromSpec(layer: LayerSpecification): LayerSymbolStyle;
|
|
340
|
+
|
|
285
341
|
/**
|
|
286
342
|
* Get layer type from map
|
|
287
343
|
* @param map MapLibre map instance
|
|
@@ -309,6 +365,7 @@ export declare class LayerControl implements IControl {
|
|
|
309
365
|
private panel;
|
|
310
366
|
private resizeHandler;
|
|
311
367
|
private mapResizeHandler;
|
|
368
|
+
private mapLayerListeners;
|
|
312
369
|
private state;
|
|
313
370
|
private targetLayers;
|
|
314
371
|
private styleEditors;
|
|
@@ -321,6 +378,7 @@ export declare class LayerControl implements IControl {
|
|
|
321
378
|
/** Explicit max panel height; null means fill available vertical space */
|
|
322
379
|
private maxPanelHeight;
|
|
323
380
|
private showStyleEditor;
|
|
381
|
+
private showAllStyleProperties;
|
|
324
382
|
private showOpacitySlider;
|
|
325
383
|
private showLayerSymbol;
|
|
326
384
|
private excludeDrawnLayers;
|
|
@@ -580,6 +638,10 @@ export declare class LayerControl implements IControl {
|
|
|
580
638
|
* Add a single layer item to the panel
|
|
581
639
|
*/
|
|
582
640
|
private addLayerItem;
|
|
641
|
+
/** Refresh changed category legends without rebuilding rows or style editors. */
|
|
642
|
+
private refreshLayerCategories;
|
|
643
|
+
/** Apply categories in place without disturbing the row or its style editor. */
|
|
644
|
+
private applyLayerCategories;
|
|
583
645
|
/**
|
|
584
646
|
* Create a symbol element for a layer
|
|
585
647
|
* @param layerId The layer ID
|
|
@@ -592,6 +654,8 @@ export declare class LayerControl implements IControl {
|
|
|
592
654
|
* @returns The symbol HTML element
|
|
593
655
|
*/
|
|
594
656
|
private createBackgroundLayerSymbol;
|
|
657
|
+
/** Refresh pattern images and SDF tint after paint, sprite, or image changes. */
|
|
658
|
+
private updateFillSymbols;
|
|
595
659
|
/**
|
|
596
660
|
* Create a symbol element for the Background layer group
|
|
597
661
|
* Shows a stacked layers icon to represent multiple background layers
|
|
@@ -604,10 +668,10 @@ export declare class LayerControl implements IControl {
|
|
|
604
668
|
private toggleLayerVisibility;
|
|
605
669
|
/**
|
|
606
670
|
* Show a small popup that lets the user type an exact opacity percentage
|
|
607
|
-
* (0-100)
|
|
671
|
+
* (0-100). Triggered by double-clicking an opacity slider.
|
|
608
672
|
*
|
|
609
|
-
* @param
|
|
610
|
-
* @param
|
|
673
|
+
* @param slider The opacity range input being edited
|
|
674
|
+
* @param applyOpacity Called with the chosen opacity (0-1) when the user confirms
|
|
611
675
|
*/
|
|
612
676
|
private showOpacityInput;
|
|
613
677
|
/**
|
|
@@ -618,6 +682,24 @@ export declare class LayerControl implements IControl {
|
|
|
618
682
|
* Change layer opacity
|
|
619
683
|
*/
|
|
620
684
|
private changeLayerOpacity;
|
|
685
|
+
/**
|
|
686
|
+
* Get the opacity property an adapter owns for a native map layer: the layer
|
|
687
|
+
* type's primary opacity property, when an adapter reports state for the
|
|
688
|
+
* layer. Such a layer's paint value is its own opacity combined with the
|
|
689
|
+
* adapter's folder opacity, so it must be written and read through the
|
|
690
|
+
* adapter. Returns null for other layers, including custom layers and
|
|
691
|
+
* layers with native sub-layer groups.
|
|
692
|
+
* @param layerId The layer ID
|
|
693
|
+
*/
|
|
694
|
+
private getAdapterOwnedOpacityProperty;
|
|
695
|
+
/**
|
|
696
|
+
* Get the value a style editor control shows for a paint property: the
|
|
697
|
+
* adapter's own opacity for an adapter-owned opacity property, otherwise the
|
|
698
|
+
* map's paint value.
|
|
699
|
+
* @param layerId The layer ID
|
|
700
|
+
* @param property The paint property
|
|
701
|
+
*/
|
|
702
|
+
private getStyleValue;
|
|
621
703
|
/**
|
|
622
704
|
* Check if a layer is a user-added layer (vs basemap layer)
|
|
623
705
|
* Used primarily for the background legend to determine which layers are background
|
|
@@ -775,6 +857,16 @@ export declare class LayerControl implements IControl {
|
|
|
775
857
|
* Add controls for fill layers
|
|
776
858
|
*/
|
|
777
859
|
private addFillControls;
|
|
860
|
+
/** Fill pattern picker group, with the Fill Color re-render hook. */
|
|
861
|
+
private addFillPatternGroup;
|
|
862
|
+
/**
|
|
863
|
+
* `showAllStyleProperties`: add every control the editor supports for a
|
|
864
|
+
* layer type. Controls are created from the style-spec default and then
|
|
865
|
+
* refreshed from the map, so unset properties show their effective value
|
|
866
|
+
* without anything being written to the style.
|
|
867
|
+
*/
|
|
868
|
+
private addAllStyleControls;
|
|
869
|
+
private renderFillPatternPicker;
|
|
778
870
|
/**
|
|
779
871
|
* Add controls for line layers
|
|
780
872
|
*/
|
|
@@ -825,10 +917,59 @@ export declare class LayerControl implements IControl {
|
|
|
825
917
|
* Create a slider control
|
|
826
918
|
*/
|
|
827
919
|
private createSliderControl;
|
|
920
|
+
/**
|
|
921
|
+
* Read the effective value a managed (`showAllStyleProperties`) control
|
|
922
|
+
* should display: the layer's own value, else the inherited value, else the
|
|
923
|
+
* style-spec default. Returns `expressionOf` (the property whose value is
|
|
924
|
+
* not editable) when that value is an expression or otherwise not a plain
|
|
925
|
+
* number/color.
|
|
926
|
+
*/
|
|
927
|
+
private resolveEffectiveValue;
|
|
928
|
+
/**
|
|
929
|
+
* Explain why a managed control cannot take effect on any of the layers it
|
|
930
|
+
* edits (style-spec `requires` dependencies), or null when it can. With
|
|
931
|
+
* grouped native sublayers the control stays enabled while at least one
|
|
932
|
+
* layer in the group can still use the edit.
|
|
933
|
+
*/
|
|
934
|
+
private getDependencyReason;
|
|
935
|
+
/**
|
|
936
|
+
* Re-evaluate every managed control under `root` from the current map
|
|
937
|
+
* state (see {@link refreshManagedControl}). `inheritsFrom` limits the pass
|
|
938
|
+
* to controls whose unset value follows that property.
|
|
939
|
+
*/
|
|
940
|
+
private refreshManagedControls;
|
|
941
|
+
/**
|
|
942
|
+
* Update a managed control's displayed value and its enabled/disabled state
|
|
943
|
+
* with explanation from the current map state. Reads only; never writes to
|
|
944
|
+
* the map.
|
|
945
|
+
*/
|
|
946
|
+
private refreshManagedControl;
|
|
947
|
+
/** Show or clear the explanation for a disabled managed control. */
|
|
948
|
+
private setControlUnavailableReason;
|
|
949
|
+
/**
|
|
950
|
+
* A control's inputs are disabled while it is unavailable (dependency or
|
|
951
|
+
* expression) or while a non-SDF fill pattern owns its color.
|
|
952
|
+
*/
|
|
953
|
+
private syncControlDisabled;
|
|
954
|
+
/**
|
|
955
|
+
* Unset properties that a managed control added on top of the layer's
|
|
956
|
+
* original style, so Reset Style returns the layer to what it was before the
|
|
957
|
+
* user edited a control the original style never set.
|
|
958
|
+
*/
|
|
959
|
+
private clearUserAddedProperties;
|
|
828
960
|
/**
|
|
829
961
|
* Reset layer style to original
|
|
830
962
|
*/
|
|
831
963
|
private resetLayerStyle;
|
|
964
|
+
/**
|
|
965
|
+
* Read the visibility and opacity a layer's panel row should show. A native
|
|
966
|
+
* layer an adapter manages reports its own values; the map's paint and layout
|
|
967
|
+
* hold those combined with the adapter's folder settings, so reading them
|
|
968
|
+
* back would corrupt the row.
|
|
969
|
+
* @param layerId The layer ID
|
|
970
|
+
* @param layerType The layer's map type
|
|
971
|
+
*/
|
|
972
|
+
private readLayerRowState;
|
|
832
973
|
/**
|
|
833
974
|
* Update layer states from map (sync UI with map)
|
|
834
975
|
*/
|
|
@@ -837,6 +978,10 @@ export declare class LayerControl implements IControl {
|
|
|
837
978
|
* Update UI elements for a specific layer
|
|
838
979
|
*/
|
|
839
980
|
private updateUIForLayer;
|
|
981
|
+
/**
|
|
982
|
+
* The panel's layer rows, by layer ID
|
|
983
|
+
*/
|
|
984
|
+
private rowsByLayerId;
|
|
840
985
|
/**
|
|
841
986
|
* Check for new layers and add them to the control, remove deleted layers
|
|
842
987
|
*/
|
|
@@ -975,7 +1120,7 @@ export declare interface LayerControlOptions {
|
|
|
975
1120
|
layerStates?: PartialLayerStates;
|
|
976
1121
|
/** Array of layer IDs to control (if not specified, controls all layers) */
|
|
977
1122
|
layers?: string[];
|
|
978
|
-
/** Initial panel width in pixels (default:
|
|
1123
|
+
/** Initial panel width in pixels (default: 350) */
|
|
979
1124
|
panelWidth?: number;
|
|
980
1125
|
/** Minimum panel width in pixels (default: 240) */
|
|
981
1126
|
panelMinWidth?: number;
|
|
@@ -983,6 +1128,24 @@ export declare interface LayerControlOptions {
|
|
|
983
1128
|
panelMaxWidth?: number;
|
|
984
1129
|
/** Whether to show the style editor button (gear icon) for layers (default: true) */
|
|
985
1130
|
showStyleEditor?: boolean;
|
|
1131
|
+
/**
|
|
1132
|
+
* Whether the style editor shows every property control it supports for a
|
|
1133
|
+
* layer's type, even when the property is absent from the layer style
|
|
1134
|
+
* (default: false). When false, controls for optional properties (e.g.
|
|
1135
|
+
* `fill-opacity`, `fill-outline-color`) only appear once the layer sets them.
|
|
1136
|
+
*
|
|
1137
|
+
* Unset properties start at their effective value: the style-spec default,
|
|
1138
|
+
* or the inherited value (`fill-outline-color` follows `fill-color`).
|
|
1139
|
+
* Opening or closing the editor never writes to the map style; a property is
|
|
1140
|
+
* set only when the user edits its control, and Reset Style unsets it again.
|
|
1141
|
+
* A control that cannot take effect (e.g. outline color with
|
|
1142
|
+
* `fill-antialias: false` or a fill pattern, text properties without a
|
|
1143
|
+
* `text-field`, icon opacity without an `icon-image`) or whose value is a
|
|
1144
|
+
* data-driven expression stays visible but disabled with an explanation;
|
|
1145
|
+
* expressions are never replaced. Applies to ordinary layers and to native
|
|
1146
|
+
* sublayers exposed by custom-layer adapters.
|
|
1147
|
+
*/
|
|
1148
|
+
showAllStyleProperties?: boolean;
|
|
986
1149
|
/** Whether to show the opacity slider for layers (default: true) */
|
|
987
1150
|
showOpacitySlider?: boolean;
|
|
988
1151
|
/** Whether to show layer type symbols/icons next to layer names (default: true) */
|
|
@@ -1018,14 +1181,18 @@ export declare interface LayerControlOptions {
|
|
|
1018
1181
|
/** Callback when a layer is removed via context menu */
|
|
1019
1182
|
onLayerRemove?: (layerId: string) => void;
|
|
1020
1183
|
/**
|
|
1021
|
-
* Callback fired whenever a paint property
|
|
1022
|
-
* style editor (a slider/color input, or
|
|
1023
|
-
* layer the open style editor belongs to (`layerId`), the
|
|
1024
|
-
* property name (e.g. `"raster-brightness-max"`,
|
|
1025
|
-
*
|
|
1026
|
-
*
|
|
1027
|
-
*
|
|
1028
|
-
*
|
|
1184
|
+
* Callback fired whenever a paint property changes through the per-layer
|
|
1185
|
+
* style editor (a slider/color input/pattern picker, or Reset Style).
|
|
1186
|
+
* Reports the layer the open style editor belongs to (`layerId`), the
|
|
1187
|
+
* MapLibre paint property name (e.g. `"raster-brightness-max"`,
|
|
1188
|
+
* `"fill-color"`, or `"fill-pattern"`), and the new value. Pattern selection
|
|
1189
|
+
* reports its image ID; selecting None reports `undefined`. Reset reports
|
|
1190
|
+
* the restored raw value, including a string, expression, or `undefined`
|
|
1191
|
+
* for `fill-pattern`, and `undefined` for a property that
|
|
1192
|
+
* `showAllStyleProperties` exposed and the user set on a layer that did not
|
|
1193
|
+
* have it. Lets consumers mirror changes into their own store so
|
|
1194
|
+
* external style UI stays in sync. The control still applies changes to the
|
|
1195
|
+
* map itself; this callback is purely a notification.
|
|
1029
1196
|
*/
|
|
1030
1197
|
onLayerStyleChange?: (layerId: string, property: string, value: unknown) => void;
|
|
1031
1198
|
/**
|
|
@@ -1109,12 +1276,25 @@ export declare interface LayerStates {
|
|
|
1109
1276
|
}
|
|
1110
1277
|
|
|
1111
1278
|
/**
|
|
1112
|
-
*
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1279
|
+
* Additional paint properties that affect a layer's preview symbol.
|
|
1280
|
+
*/
|
|
1281
|
+
export declare interface LayerSymbolStyle {
|
|
1282
|
+
/** line-dasharray in line-width units. */
|
|
1283
|
+
dasharray?: number[];
|
|
1284
|
+
/** Circle border colour; null disables the border. */
|
|
1285
|
+
strokeColor?: string | null;
|
|
1286
|
+
/** Registered MapLibre image for a fill-pattern; SDF images use the fill color. */
|
|
1287
|
+
fillPattern?: FillPatternImage;
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
/**
|
|
1291
|
+
* Normalize a color value to six-digit RGB hex.
|
|
1292
|
+
* String values are parsed as CSS colors; numeric arrays use RGB byte channels.
|
|
1293
|
+
* Alpha channels are ignored.
|
|
1294
|
+
* @param value Color value in CSS string or RGB(A) array format
|
|
1295
|
+
* @returns Normalized hex color string, or null when the value is invalid
|
|
1116
1296
|
*/
|
|
1117
|
-
export declare function normalizeColor(value:
|
|
1297
|
+
export declare function normalizeColor(value: unknown): string | null;
|
|
1118
1298
|
|
|
1119
1299
|
/**
|
|
1120
1300
|
* Paint properties for different layer types
|
|
@@ -1191,6 +1371,12 @@ export declare interface SymbolOptions {
|
|
|
1191
1371
|
size?: number;
|
|
1192
1372
|
/** Stroke width for line symbols (default: 2) */
|
|
1193
1373
|
strokeWidth?: number;
|
|
1374
|
+
/** line-dasharray in line-width units; rendered to fit the line swatch. */
|
|
1375
|
+
dasharray?: number[];
|
|
1376
|
+
/** Circle border colour; null disables the border. */
|
|
1377
|
+
strokeColor?: string | null;
|
|
1378
|
+
/** Registered MapLibre image for a fill-pattern; SDF images use the fill color. */
|
|
1379
|
+
fillPattern?: FillPatternImage;
|
|
1194
1380
|
}
|
|
1195
1381
|
|
|
1196
1382
|
export { }
|