maplibre-gl-layer-control 0.18.2 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +108 -7
- package/dist/LayerControl-BxSfUXK6.cjs +6251 -0
- package/dist/LayerControl-BxSfUXK6.cjs.map +1 -0
- package/dist/LayerControl-CvH3r0T2.js +6252 -0
- package/dist/LayerControl-CvH3r0T2.js.map +1 -0
- package/dist/index.cjs +20 -5166
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +20 -5166
- 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 +236 -18
- package/dist/types/react.d.ts +528 -0
- package/package.json +12 -2
|
@@ -0,0 +1,528 @@
|
|
|
1
|
+
import { Map as Map_2 } from 'maplibre-gl';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A single background-layer visibility preset: a map of style-layer ID to
|
|
5
|
+
* whether that layer should be visible.
|
|
6
|
+
*/
|
|
7
|
+
declare type BackgroundLayerVisibility = Record<string, boolean>;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Collection of named background-layer visibility presets, keyed by preset name.
|
|
11
|
+
*/
|
|
12
|
+
declare type BackgroundPresets = Record<string, BackgroundLayerVisibility>;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Context menu state
|
|
16
|
+
*/
|
|
17
|
+
declare interface ContextMenuState {
|
|
18
|
+
/** Whether the context menu is visible */
|
|
19
|
+
visible: boolean;
|
|
20
|
+
/** The layer ID that the context menu is targeting */
|
|
21
|
+
targetLayerId: string | null;
|
|
22
|
+
/** X position of the context menu */
|
|
23
|
+
x: number;
|
|
24
|
+
/** Y position of the context menu */
|
|
25
|
+
y: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Adapter interface for custom (non-MapLibre) layers.
|
|
30
|
+
* Implement this interface to integrate custom layer types (e.g., deck.gl layers)
|
|
31
|
+
* with the layer control.
|
|
32
|
+
*/
|
|
33
|
+
declare interface CustomLayerAdapter {
|
|
34
|
+
/** Unique type identifier for this adapter (e.g., 'cog', 'zarr', 'deck') */
|
|
35
|
+
type: string;
|
|
36
|
+
/** Get all layer IDs managed by this adapter */
|
|
37
|
+
getLayerIds(): string[];
|
|
38
|
+
/**
|
|
39
|
+
* Get the current state of a layer. For a native map layer the adapter lists
|
|
40
|
+
* in `getLayerIds`, report the layer's own visibility and opacity, without
|
|
41
|
+
* folding in any group's: the control shows these values in the layer's row
|
|
42
|
+
* and style editor and never reads them back from the map.
|
|
43
|
+
*/
|
|
44
|
+
getLayerState(layerId: string): LayerState | null;
|
|
45
|
+
/** Set layer visibility */
|
|
46
|
+
setVisibility(layerId: string, visible: boolean): void;
|
|
47
|
+
/** Set layer opacity (0-1) */
|
|
48
|
+
setOpacity(layerId: string, opacity: number): void;
|
|
49
|
+
/** Get display name for a layer */
|
|
50
|
+
getName(layerId: string): string;
|
|
51
|
+
/** Get layer symbol type for UI display (optional) */
|
|
52
|
+
getSymbolType?(layerId: string): string;
|
|
53
|
+
/**
|
|
54
|
+
* Subscribe to layer changes (add/remove).
|
|
55
|
+
* Returns an unsubscribe function.
|
|
56
|
+
*/
|
|
57
|
+
onLayerChange?(callback: (event: 'add' | 'remove', layerId: string) => void): () => void;
|
|
58
|
+
/**
|
|
59
|
+
* Get the bounds of a layer (optional).
|
|
60
|
+
* Returns [west, south, east, north] or null if not available.
|
|
61
|
+
*/
|
|
62
|
+
getBounds?(layerId: string): [number, number, number, number] | null;
|
|
63
|
+
/**
|
|
64
|
+
* Remove a layer (optional).
|
|
65
|
+
* Called when user removes a layer via context menu.
|
|
66
|
+
*/
|
|
67
|
+
removeLayer?(layerId: string): void;
|
|
68
|
+
/**
|
|
69
|
+
* Get native MapLibre layer IDs for a custom layer (optional).
|
|
70
|
+
* When provided, the style editor will show paint property controls
|
|
71
|
+
* for these native layers instead of the generic "custom layer" message.
|
|
72
|
+
*/
|
|
73
|
+
getNativeLayerIds?(layerId: string): string[];
|
|
74
|
+
/**
|
|
75
|
+
* Get the layer groups this adapter defines (optional). When any adapter
|
|
76
|
+
* returns groups, the panel nests each layer under its group (see
|
|
77
|
+
* {@link getLayerGroupId}) as collapsible folders, and drag-and-drop and the
|
|
78
|
+
* context-menu moves keep a layer among the other layers of its own group.
|
|
79
|
+
* Groups that contain no layer, directly or through a nested group, are not
|
|
80
|
+
* shown.
|
|
81
|
+
*/
|
|
82
|
+
getGroups?(): LayerGroupState[];
|
|
83
|
+
/**
|
|
84
|
+
* Get the ID of the group a layer belongs to, or undefined when the layer
|
|
85
|
+
* sits at the top level (optional; required for groups to have members).
|
|
86
|
+
*/
|
|
87
|
+
getLayerGroupId?(layerId: string): string | undefined;
|
|
88
|
+
/** Set group visibility (optional; called from the group's checkbox). */
|
|
89
|
+
setGroupVisibility?(groupId: string, visible: boolean): void;
|
|
90
|
+
/** Set group opacity (0-1) (optional; called from the group's slider). */
|
|
91
|
+
setGroupOpacity?(groupId: string, opacity: number): void;
|
|
92
|
+
/**
|
|
93
|
+
* Record that a group was collapsed or expanded in the panel (optional).
|
|
94
|
+
* Without it the control still folds the group, but only until the panel is
|
|
95
|
+
* rebuilt from the adapter's `getGroups`.
|
|
96
|
+
*/
|
|
97
|
+
setGroupCollapsed?(groupId: string, collapsed: boolean): void;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Drag state for layer reordering
|
|
102
|
+
*/
|
|
103
|
+
declare interface DragState {
|
|
104
|
+
/** Whether drag is active */
|
|
105
|
+
active: boolean;
|
|
106
|
+
/** The layer ID being dragged */
|
|
107
|
+
layerId: string | null;
|
|
108
|
+
/** Starting Y position of the drag */
|
|
109
|
+
startY: number;
|
|
110
|
+
/** Current Y position of the drag */
|
|
111
|
+
currentY: number;
|
|
112
|
+
/** Placeholder element showing drop location */
|
|
113
|
+
placeholder: HTMLElement | null;
|
|
114
|
+
/** The element being dragged (clone) */
|
|
115
|
+
draggedElement: HTMLElement | null;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Internal control state (not exported)
|
|
120
|
+
*/
|
|
121
|
+
export declare interface InternalControlState {
|
|
122
|
+
collapsed: boolean;
|
|
123
|
+
panelWidth: number;
|
|
124
|
+
activeStyleEditor: string | null;
|
|
125
|
+
layerStates: LayerStates;
|
|
126
|
+
originalStyles: Map<string, OriginalStyle>;
|
|
127
|
+
userInteractingWithSlider: boolean;
|
|
128
|
+
/** Whether the background legend panel is open */
|
|
129
|
+
backgroundLegendOpen: boolean;
|
|
130
|
+
/** Layer IDs whose category sub-legend is expanded */
|
|
131
|
+
expandedCategoryLayers: Set<string>;
|
|
132
|
+
/** Individual background layer visibility states */
|
|
133
|
+
backgroundLayerVisibility: Map<string, boolean>;
|
|
134
|
+
/** Whether to show only rendered layers in background legend */
|
|
135
|
+
onlyRenderedFilter: boolean;
|
|
136
|
+
/** Context menu state */
|
|
137
|
+
contextMenu: ContextMenuState;
|
|
138
|
+
/** Layer ID currently being renamed */
|
|
139
|
+
renamingLayerId: string | null;
|
|
140
|
+
/** Custom layer names set by user (layerId -> customName) */
|
|
141
|
+
customLayerNames: Map<string, string>;
|
|
142
|
+
/** Drag state for layer reordering */
|
|
143
|
+
drag: DragState;
|
|
144
|
+
/** Whether a style operation is in progress (prevents checkForNewLayers from running) */
|
|
145
|
+
isStyleOperationInProgress: boolean;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Options for LayerControl constructor
|
|
150
|
+
*/
|
|
151
|
+
export declare interface LayerControlOptions {
|
|
152
|
+
/** Whether the control starts collapsed (default: true) */
|
|
153
|
+
collapsed?: boolean;
|
|
154
|
+
/** Initial layer states (keyed by layer ID). Partial values are accepted; unspecified fields will be auto-detected from the map. */
|
|
155
|
+
layerStates?: PartialLayerStates;
|
|
156
|
+
/** Array of layer IDs to control (if not specified, controls all layers) */
|
|
157
|
+
layers?: string[];
|
|
158
|
+
/** Initial panel width in pixels (default: 350) */
|
|
159
|
+
panelWidth?: number;
|
|
160
|
+
/** Minimum panel width in pixels (default: 240) */
|
|
161
|
+
panelMinWidth?: number;
|
|
162
|
+
/** Maximum panel width in pixels (default: 960) */
|
|
163
|
+
panelMaxWidth?: number;
|
|
164
|
+
/** Whether to show the style editor button (gear icon) for layers (default: true) */
|
|
165
|
+
showStyleEditor?: boolean;
|
|
166
|
+
/**
|
|
167
|
+
* Whether the style editor shows every property control it supports for a
|
|
168
|
+
* layer's type, even when the property is absent from the layer style
|
|
169
|
+
* (default: false). When false, controls for optional properties (e.g.
|
|
170
|
+
* `fill-opacity`, `fill-outline-color`) only appear once the layer sets them.
|
|
171
|
+
*
|
|
172
|
+
* Unset properties start at their effective value: the style-spec default,
|
|
173
|
+
* or the inherited value (`fill-outline-color` follows `fill-color`).
|
|
174
|
+
* Opening or closing the editor never writes to the map style; a property is
|
|
175
|
+
* set only when the user edits its control, and Reset Style unsets it again.
|
|
176
|
+
* A control that cannot take effect (e.g. outline color with
|
|
177
|
+
* `fill-antialias: false` or a fill pattern, text properties without a
|
|
178
|
+
* `text-field`, icon opacity without an `icon-image`) or whose value is a
|
|
179
|
+
* data-driven expression stays visible but disabled with an explanation;
|
|
180
|
+
* expressions are never replaced. Applies to ordinary layers and to native
|
|
181
|
+
* sublayers exposed by custom-layer adapters.
|
|
182
|
+
*/
|
|
183
|
+
showAllStyleProperties?: boolean;
|
|
184
|
+
/** Whether to show the opacity slider for layers (default: true) */
|
|
185
|
+
showOpacitySlider?: boolean;
|
|
186
|
+
/** Whether to show layer type symbols/icons next to layer names (default: true) */
|
|
187
|
+
showLayerSymbol?: boolean;
|
|
188
|
+
/**
|
|
189
|
+
* Maximum panel height in pixels. When omitted, the panel grows to fill the
|
|
190
|
+
* available vertical space in the map container and only becomes scrollable
|
|
191
|
+
* once the layer list is taller than that space. Set an explicit value to
|
|
192
|
+
* cap the height instead.
|
|
193
|
+
*/
|
|
194
|
+
panelMaxHeight?: number;
|
|
195
|
+
/** Whether to exclude drawn layers from drawing libraries like Geoman, Mapbox GL Draw, etc. (default: true) */
|
|
196
|
+
excludeDrawnLayers?: boolean;
|
|
197
|
+
/** Array of wildcard patterns to exclude layers by name (e.g., ['*-temp-*', 'debug-*']) */
|
|
198
|
+
excludeLayers?: string[];
|
|
199
|
+
/** Custom layer adapters for non-MapLibre layers (e.g., deck.gl COG layers, Zarr layers) */
|
|
200
|
+
customLayerAdapters?: CustomLayerAdapter[];
|
|
201
|
+
/**
|
|
202
|
+
* URL of the basemap style JSON. If provided, all layers defined in this style
|
|
203
|
+
* will be grouped under "Background", and all other layers will be shown individually
|
|
204
|
+
* in the layer control. This provides reliable distinction between basemap layers
|
|
205
|
+
* and user-added layers.
|
|
206
|
+
*/
|
|
207
|
+
basemapStyleUrl?: string;
|
|
208
|
+
/**
|
|
209
|
+
* IDs of the layers that make up the basemap, for applications that already
|
|
210
|
+
* know them (or have no fetchable style URL, such as a style built in code).
|
|
211
|
+
* Those layers are grouped under "Background" and every other layer is
|
|
212
|
+
* treated as user-added. Takes precedence over `basemapStyleUrl` (nothing is
|
|
213
|
+
* fetched), and an empty array is honoured as "no basemap layers" rather than
|
|
214
|
+
* falling back to heuristic detection.
|
|
215
|
+
*/
|
|
216
|
+
basemapLayerIds?: string[];
|
|
217
|
+
/** Whether to enable context menu (right-click) on layers (default: true) */
|
|
218
|
+
enableContextMenu?: boolean;
|
|
219
|
+
/** Whether to enable drag-and-drop reordering of layers (default: true) */
|
|
220
|
+
enableDragAndDrop?: boolean;
|
|
221
|
+
/** Callback when a layer is renamed via context menu */
|
|
222
|
+
onLayerRename?: (layerId: string, oldName: string, newName: string) => void;
|
|
223
|
+
/** Callback when layers are reordered via drag-and-drop */
|
|
224
|
+
onLayerReorder?: (layerOrder: string[]) => void;
|
|
225
|
+
/** Callback when a layer is removed via context menu */
|
|
226
|
+
onLayerRemove?: (layerId: string) => void;
|
|
227
|
+
/**
|
|
228
|
+
* Callback fired whenever a paint property changes through the per-layer
|
|
229
|
+
* style editor (a slider/color input/pattern picker, or Reset Style).
|
|
230
|
+
* Reports the layer the open style editor belongs to (`layerId`), the
|
|
231
|
+
* MapLibre paint property name (e.g. `"raster-brightness-max"`,
|
|
232
|
+
* `"fill-color"`, or `"fill-pattern"`), and the new value. Pattern selection
|
|
233
|
+
* reports its image ID; selecting None reports `undefined`. Reset reports
|
|
234
|
+
* the restored raw value, including a string, expression, or `undefined`
|
|
235
|
+
* for `fill-pattern`, and `undefined` for a property that
|
|
236
|
+
* `showAllStyleProperties` exposed and the user set on a layer that did not
|
|
237
|
+
* have it. Lets consumers mirror changes into their own store so
|
|
238
|
+
* external style UI stays in sync. The control still applies changes to the
|
|
239
|
+
* map itself; this callback is purely a notification.
|
|
240
|
+
*/
|
|
241
|
+
onLayerStyleChange?: (layerId: string, property: string, value: unknown) => void;
|
|
242
|
+
/**
|
|
243
|
+
* Callback fired when the Background (basemap) group visibility is toggled
|
|
244
|
+
* via the control's checkbox. Lets consumers mirror the new state into their
|
|
245
|
+
* own store so external basemap UI (e.g. a separate layer panel) stays in sync.
|
|
246
|
+
*/
|
|
247
|
+
onBackgroundVisibilityChange?: (visible: boolean) => void;
|
|
248
|
+
/**
|
|
249
|
+
* Callback fired when the Background (basemap) group opacity is changed via
|
|
250
|
+
* the control's slider. Lets consumers mirror the new opacity into their own
|
|
251
|
+
* store so external basemap UI stays in sync.
|
|
252
|
+
*/
|
|
253
|
+
onBackgroundOpacityChange?: (opacity: number) => void;
|
|
254
|
+
/**
|
|
255
|
+
* Whether to show the "Saved configurations" controls in the Background Layers
|
|
256
|
+
* panel, letting users save the current basemap element visibility as a named
|
|
257
|
+
* preset and re-apply it later with one click (default: true).
|
|
258
|
+
*/
|
|
259
|
+
enableBackgroundPresets?: boolean;
|
|
260
|
+
/**
|
|
261
|
+
* localStorage key under which background-layer visibility presets are stored.
|
|
262
|
+
* Presets persist across sessions and projects (default:
|
|
263
|
+
* 'maplibre-layer-control:background-presets').
|
|
264
|
+
*/
|
|
265
|
+
backgroundPresetStorageKey?: string;
|
|
266
|
+
/**
|
|
267
|
+
* Callback fired whenever the set of saved background presets changes
|
|
268
|
+
* (created or deleted). Receives the full preset map. Applying a preset does
|
|
269
|
+
* not change the stored set, so it does not trigger this callback.
|
|
270
|
+
*/
|
|
271
|
+
onBackgroundPresetsChange?: (presets: BackgroundPresets) => void;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* React wrapper for LayerControl
|
|
276
|
+
*
|
|
277
|
+
* @example
|
|
278
|
+
* ```tsx
|
|
279
|
+
* import { LayerControlReact } from 'maplibre-gl-layer-control/react';
|
|
280
|
+
*
|
|
281
|
+
* function MapComponent() {
|
|
282
|
+
* const [map, setMap] = useState<MapLibreMap | null>(null);
|
|
283
|
+
*
|
|
284
|
+
* return (
|
|
285
|
+
* <>
|
|
286
|
+
* <div ref={(el) => {
|
|
287
|
+
* if (el && !map) {
|
|
288
|
+
* const newMap = new maplibregl.Map({ container: el, ... });
|
|
289
|
+
* setMap(newMap);
|
|
290
|
+
* }
|
|
291
|
+
* }} />
|
|
292
|
+
* {map && (
|
|
293
|
+
* <LayerControlReact
|
|
294
|
+
* map={map}
|
|
295
|
+
* position="top-right"
|
|
296
|
+
* layerStates={{
|
|
297
|
+
* 'my-layer': { visible: true, opacity: 1, name: 'My Layer' }
|
|
298
|
+
* }}
|
|
299
|
+
* />
|
|
300
|
+
* )}
|
|
301
|
+
* </>
|
|
302
|
+
* );
|
|
303
|
+
* }
|
|
304
|
+
* ```
|
|
305
|
+
*/
|
|
306
|
+
export declare function LayerControlReact({ map, position, ...options }: LayerControlReactProps): null;
|
|
307
|
+
|
|
308
|
+
export declare interface LayerControlReactProps extends LayerControlOptions {
|
|
309
|
+
/** MapLibre map instance */
|
|
310
|
+
map: Map_2;
|
|
311
|
+
/** Position on the map */
|
|
312
|
+
position?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* A collapsible folder of layers in the panel. Supplied by a
|
|
317
|
+
* {@link CustomLayerAdapter} through `getGroups`; layers join a group through
|
|
318
|
+
* the adapter's `getLayerGroupId`.
|
|
319
|
+
*
|
|
320
|
+
* A group's `visible` and `opacity` are its own settings, separate from those
|
|
321
|
+
* of its layers. The control shows and edits them but never folds them into
|
|
322
|
+
* the layer rows: applying a hidden or translucent group to its layers on the
|
|
323
|
+
* map is the adapter's job.
|
|
324
|
+
*/
|
|
325
|
+
declare interface LayerGroupState {
|
|
326
|
+
/** Unique group ID */
|
|
327
|
+
id: string;
|
|
328
|
+
/** Display name for the group */
|
|
329
|
+
name: string;
|
|
330
|
+
/** ID of the enclosing group, or undefined for a top-level group */
|
|
331
|
+
parentId?: string;
|
|
332
|
+
/** Whether the group is visible */
|
|
333
|
+
visible: boolean;
|
|
334
|
+
/** Group opacity (0-1) */
|
|
335
|
+
opacity: number;
|
|
336
|
+
/** Whether the group's rows are folded away in the panel */
|
|
337
|
+
collapsed: boolean;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* State for a single layer
|
|
342
|
+
*/
|
|
343
|
+
export declare interface LayerState {
|
|
344
|
+
/** Whether the layer is visible */
|
|
345
|
+
visible: boolean;
|
|
346
|
+
/** Layer opacity (0-1) */
|
|
347
|
+
opacity: number;
|
|
348
|
+
/** Display name for the layer */
|
|
349
|
+
name: string;
|
|
350
|
+
/** Whether this is a custom (non-MapLibre) layer */
|
|
351
|
+
isCustomLayer?: boolean;
|
|
352
|
+
/** Custom layer type identifier (e.g., 'cog', 'zarr') */
|
|
353
|
+
customLayerType?: string;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Collection of layer states keyed by layer ID
|
|
358
|
+
*/
|
|
359
|
+
declare interface LayerStates {
|
|
360
|
+
[layerId: string]: LayerState;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Original style cache for a layer (used for reset functionality)
|
|
365
|
+
*/
|
|
366
|
+
export declare interface OriginalStyle {
|
|
367
|
+
/** Original paint properties */
|
|
368
|
+
paint: Record<string, any>;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* Partial layer state for user-provided initial configuration.
|
|
373
|
+
* Users can specify only the properties they want to override (e.g., just `name`).
|
|
374
|
+
*/
|
|
375
|
+
declare type PartialLayerState = Partial<LayerState>;
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* Collection of partial layer states keyed by layer ID (for options input)
|
|
379
|
+
*/
|
|
380
|
+
declare interface PartialLayerStates {
|
|
381
|
+
[layerId: string]: PartialLayerState;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* Hook for managing layer visibility and opacity state
|
|
386
|
+
*
|
|
387
|
+
* @example
|
|
388
|
+
* ```tsx
|
|
389
|
+
* const { layerStates, toggleVisibility, setOpacity } = useLayerState({
|
|
390
|
+
* map,
|
|
391
|
+
* initialStates: {
|
|
392
|
+
* 'my-layer': { visible: true, opacity: 1, name: 'My Layer' }
|
|
393
|
+
* }
|
|
394
|
+
* });
|
|
395
|
+
* ```
|
|
396
|
+
*/
|
|
397
|
+
export declare function useLayerState({ map, initialStates, }: UseLayerStateOptions): UseLayerStateReturn;
|
|
398
|
+
|
|
399
|
+
export declare interface UseLayerStateOptions {
|
|
400
|
+
/** MapLibre map instance */
|
|
401
|
+
map: Map_2;
|
|
402
|
+
/** Initial layer states */
|
|
403
|
+
initialStates: Record<string, LayerState>;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
export declare interface UseLayerStateReturn {
|
|
407
|
+
/** Current layer states */
|
|
408
|
+
layerStates: Record<string, LayerState>;
|
|
409
|
+
/** Toggle layer visibility */
|
|
410
|
+
toggleVisibility: (layerId: string) => void;
|
|
411
|
+
/** Set layer opacity */
|
|
412
|
+
setOpacity: (layerId: string, opacity: number) => void;
|
|
413
|
+
/** Update a layer state */
|
|
414
|
+
updateLayerState: (layerId: string, updates: Partial<LayerState>) => void;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Hook to sync React state with MapLibre map layer changes
|
|
419
|
+
*
|
|
420
|
+
* @example
|
|
421
|
+
* ```tsx
|
|
422
|
+
* useMapLayerSync({
|
|
423
|
+
* map,
|
|
424
|
+
* onLayerStatesChange: (states) => {
|
|
425
|
+
* console.log('Layer states updated:', states);
|
|
426
|
+
* },
|
|
427
|
+
* onNewLayers: (layerIds) => {
|
|
428
|
+
* console.log('New layers detected:', layerIds);
|
|
429
|
+
* }
|
|
430
|
+
* });
|
|
431
|
+
* ```
|
|
432
|
+
*/
|
|
433
|
+
export declare function useMapLayerSync({ map, onLayerStatesChange, onNewLayers, trackedLayers, }: UseMapLayerSyncOptions): void;
|
|
434
|
+
|
|
435
|
+
export declare interface UseMapLayerSyncOptions {
|
|
436
|
+
/** MapLibre map instance */
|
|
437
|
+
map: Map_2;
|
|
438
|
+
/** Callback when layer states change on the map */
|
|
439
|
+
onLayerStatesChange?: (layerStates: Record<string, LayerState>) => void;
|
|
440
|
+
/** Callback when new layers are detected */
|
|
441
|
+
onNewLayers?: (layerIds: string[]) => void;
|
|
442
|
+
/** Layers to track (empty = track all) */
|
|
443
|
+
trackedLayers?: string[];
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* Hook for managing panel width state
|
|
448
|
+
*
|
|
449
|
+
* @example
|
|
450
|
+
* ```tsx
|
|
451
|
+
* const { width, setWidth, increaseWidth, decreaseWidth } = usePanelWidth({
|
|
452
|
+
* initialWidth: 320,
|
|
453
|
+
* minWidth: 240,
|
|
454
|
+
* maxWidth: 420
|
|
455
|
+
* });
|
|
456
|
+
*
|
|
457
|
+
* return (
|
|
458
|
+
* <div style={{ width: `${width}px` }}>
|
|
459
|
+
* <button onClick={() => decreaseWidth(10)}>-</button>
|
|
460
|
+
* <span>{width}px</span>
|
|
461
|
+
* <button onClick={() => increaseWidth(10)}>+</button>
|
|
462
|
+
* </div>
|
|
463
|
+
* );
|
|
464
|
+
* ```
|
|
465
|
+
*/
|
|
466
|
+
export declare function usePanelWidth({ initialWidth, minWidth, maxWidth, }?: UsePanelWidthOptions): UsePanelWidthReturn;
|
|
467
|
+
|
|
468
|
+
export declare interface UsePanelWidthOptions {
|
|
469
|
+
/** Initial width */
|
|
470
|
+
initialWidth?: number;
|
|
471
|
+
/** Minimum width */
|
|
472
|
+
minWidth?: number;
|
|
473
|
+
/** Maximum width */
|
|
474
|
+
maxWidth?: number;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
export declare interface UsePanelWidthReturn {
|
|
478
|
+
/** Current panel width */
|
|
479
|
+
width: number;
|
|
480
|
+
/** Set panel width (clamped to min/max) */
|
|
481
|
+
setWidth: (width: number) => void;
|
|
482
|
+
/** Increase width by step */
|
|
483
|
+
increaseWidth: (step?: number) => void;
|
|
484
|
+
/** Decrease width by step */
|
|
485
|
+
decreaseWidth: (step?: number) => void;
|
|
486
|
+
/** Reset to initial width */
|
|
487
|
+
resetWidth: () => void;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* Hook for managing style editor state
|
|
492
|
+
*
|
|
493
|
+
* @example
|
|
494
|
+
* ```tsx
|
|
495
|
+
* const { activeEditor, openEditor, closeEditor, resetStyle } = useStyleEditor({ map });
|
|
496
|
+
*
|
|
497
|
+
* return (
|
|
498
|
+
* <button onClick={() => openEditor('my-layer')}>
|
|
499
|
+
* Edit Style
|
|
500
|
+
* </button>
|
|
501
|
+
* );
|
|
502
|
+
* ```
|
|
503
|
+
*/
|
|
504
|
+
export declare function useStyleEditor({ map }: UseStyleEditorOptions): UseStyleEditorReturn;
|
|
505
|
+
|
|
506
|
+
export declare interface UseStyleEditorOptions {
|
|
507
|
+
/** MapLibre map instance */
|
|
508
|
+
map: Map_2;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
export declare interface UseStyleEditorReturn {
|
|
512
|
+
/** Currently active editor (layer ID) */
|
|
513
|
+
activeEditor: string | null;
|
|
514
|
+
/** Original styles cache */
|
|
515
|
+
originalStyles: Map<string, OriginalStyle>;
|
|
516
|
+
/** Open style editor for a layer */
|
|
517
|
+
openEditor: (layerId: string) => void;
|
|
518
|
+
/** Close the active editor */
|
|
519
|
+
closeEditor: () => void;
|
|
520
|
+
/** Toggle editor for a layer */
|
|
521
|
+
toggleEditor: (layerId: string) => void;
|
|
522
|
+
/** Reset layer to original style */
|
|
523
|
+
resetStyle: (layerId: string) => void;
|
|
524
|
+
/** Apply style changes */
|
|
525
|
+
applyStyle: (layerId: string, property: string, value: any) => void;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
export { }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "maplibre-gl-layer-control",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"description": "A comprehensive layer control for MapLibre GL with advanced styling capabilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -17,6 +17,16 @@
|
|
|
17
17
|
"default": "./dist/index.cjs"
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
|
+
"./react": {
|
|
21
|
+
"import": {
|
|
22
|
+
"types": "./dist/types/react.d.ts",
|
|
23
|
+
"default": "./dist/react.mjs"
|
|
24
|
+
},
|
|
25
|
+
"require": {
|
|
26
|
+
"types": "./dist/types/react.d.ts",
|
|
27
|
+
"default": "./dist/react.cjs"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
20
30
|
"./style.css": "./dist/maplibre-gl-layer-control.css"
|
|
21
31
|
},
|
|
22
32
|
"files": [
|
|
@@ -81,7 +91,7 @@
|
|
|
81
91
|
"@vitest/ui": "^4.0.17",
|
|
82
92
|
"eslint": "^9.17.0",
|
|
83
93
|
"jsdom": "^25.0.0",
|
|
84
|
-
"maplibre-gl": "^
|
|
94
|
+
"maplibre-gl": "^6.13.0",
|
|
85
95
|
"prettier": "^3.4.0",
|
|
86
96
|
"react": "^18.3.0",
|
|
87
97
|
"react-dom": "^18.3.0",
|