maplibre-gl-layer-control 0.17.4 → 0.18.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 +31 -0
- package/dist/index.cjs +533 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +533 -16
- package/dist/index.mjs.map +1 -1
- package/dist/maplibre-gl-layer-control.css +59 -6
- package/dist/types/index.d.ts +195 -0
- package/package.json +1 -1
|
@@ -287,13 +287,13 @@
|
|
|
287
287
|
|
|
288
288
|
/* Style button */
|
|
289
289
|
.layer-control-style-button {
|
|
290
|
-
width:
|
|
291
|
-
height:
|
|
290
|
+
width: 18px;
|
|
291
|
+
height: 18px;
|
|
292
292
|
border-radius: 4px;
|
|
293
293
|
border: none;
|
|
294
294
|
background: none;
|
|
295
295
|
cursor: pointer;
|
|
296
|
-
font-size:
|
|
296
|
+
font-size: 12px;
|
|
297
297
|
color: #444;
|
|
298
298
|
display: flex;
|
|
299
299
|
align-items: center;
|
|
@@ -577,14 +577,14 @@
|
|
|
577
577
|
/* Style button */
|
|
578
578
|
.layer-control-style-button {
|
|
579
579
|
flex: 0 0 auto;
|
|
580
|
-
width:
|
|
581
|
-
height:
|
|
580
|
+
width: 18px;
|
|
581
|
+
height: 18px;
|
|
582
582
|
border: 1px solid #ddd;
|
|
583
583
|
border-radius: 3px;
|
|
584
584
|
background: white;
|
|
585
585
|
color: #666;
|
|
586
586
|
cursor: pointer;
|
|
587
|
-
font-size:
|
|
587
|
+
font-size: 12px;
|
|
588
588
|
padding: 0;
|
|
589
589
|
line-height: 1;
|
|
590
590
|
transition: all 0.2s ease;
|
|
@@ -1064,6 +1064,59 @@
|
|
|
1064
1064
|
box-shadow: 0 0 0 2px rgba(47, 111, 237, 0.2);
|
|
1065
1065
|
}
|
|
1066
1066
|
|
|
1067
|
+
/* ===== Layer Groups ===== */
|
|
1068
|
+
.layer-control-group {
|
|
1069
|
+
box-sizing: border-box;
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
.layer-control-group-row {
|
|
1073
|
+
padding: 4px 0;
|
|
1074
|
+
border-bottom: 1px solid #f0f0f0;
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
.layer-control-group-name {
|
|
1078
|
+
font-weight: 600;
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
.layer-control-group-toggle {
|
|
1082
|
+
flex: 0 0 auto;
|
|
1083
|
+
width: 18px;
|
|
1084
|
+
height: 18px;
|
|
1085
|
+
padding: 0;
|
|
1086
|
+
border: none;
|
|
1087
|
+
background: none;
|
|
1088
|
+
color: #666;
|
|
1089
|
+
cursor: pointer;
|
|
1090
|
+
display: flex;
|
|
1091
|
+
align-items: center;
|
|
1092
|
+
justify-content: center;
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
.layer-control-group-toggle svg {
|
|
1096
|
+
width: 12px;
|
|
1097
|
+
height: 12px;
|
|
1098
|
+
transform: rotate(90deg);
|
|
1099
|
+
transition: transform 0.15s ease;
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
.layer-control-group.collapsed > .layer-control-group-row .layer-control-group-toggle svg {
|
|
1103
|
+
transform: rotate(0deg);
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1106
|
+
.layer-control-group-children {
|
|
1107
|
+
padding-left: 14px;
|
|
1108
|
+
box-sizing: border-box;
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
.layer-control-group.collapsed > .layer-control-group-children {
|
|
1112
|
+
display: none;
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
/* A hidden group hides its layers on the map, so dim their rows */
|
|
1116
|
+
.layer-control-group-hidden > .layer-control-group-children {
|
|
1117
|
+
opacity: 0.55;
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1067
1120
|
/* ===== Drag and Drop Styles ===== */
|
|
1068
1121
|
.layer-control-drag-handle {
|
|
1069
1122
|
width: 16px;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -79,6 +79,30 @@ export declare interface CustomLayerAdapter {
|
|
|
79
79
|
* for these native layers instead of the generic "custom layer" message.
|
|
80
80
|
*/
|
|
81
81
|
getNativeLayerIds?(layerId: string): string[];
|
|
82
|
+
/**
|
|
83
|
+
* Get the layer groups this adapter defines (optional). When any adapter
|
|
84
|
+
* returns groups, the panel nests each layer under its group (see
|
|
85
|
+
* {@link getLayerGroupId}) as collapsible folders, and drag-and-drop and the
|
|
86
|
+
* context-menu moves keep a layer among the other layers of its own group.
|
|
87
|
+
* Groups that contain no layer, directly or through a nested group, are not
|
|
88
|
+
* shown.
|
|
89
|
+
*/
|
|
90
|
+
getGroups?(): LayerGroupState[];
|
|
91
|
+
/**
|
|
92
|
+
* Get the ID of the group a layer belongs to, or undefined when the layer
|
|
93
|
+
* sits at the top level (optional; required for groups to have members).
|
|
94
|
+
*/
|
|
95
|
+
getLayerGroupId?(layerId: string): string | undefined;
|
|
96
|
+
/** Set group visibility (optional; called from the group's checkbox). */
|
|
97
|
+
setGroupVisibility?(groupId: string, visible: boolean): void;
|
|
98
|
+
/** Set group opacity (0-1) (optional; called from the group's slider). */
|
|
99
|
+
setGroupOpacity?(groupId: string, opacity: number): void;
|
|
100
|
+
/**
|
|
101
|
+
* Record that a group was collapsed or expanded in the panel (optional).
|
|
102
|
+
* Without it the control still folds the group, but only until the panel is
|
|
103
|
+
* rebuilt from the adapter's `getGroups`.
|
|
104
|
+
*/
|
|
105
|
+
setGroupCollapsed?(groupId: string, collapsed: boolean): void;
|
|
82
106
|
}
|
|
83
107
|
|
|
84
108
|
/**
|
|
@@ -104,6 +128,11 @@ export declare class CustomLayerRegistry {
|
|
|
104
128
|
* @returns Array of layer IDs
|
|
105
129
|
*/
|
|
106
130
|
getAllLayerIds(): string[];
|
|
131
|
+
/**
|
|
132
|
+
* Get each adapter's layer IDs as a separate list, in adapter order.
|
|
133
|
+
* @returns One array of layer IDs per registered adapter
|
|
134
|
+
*/
|
|
135
|
+
getLayerIdGroups(): string[][];
|
|
107
136
|
/**
|
|
108
137
|
* Check if a layer ID is managed by any adapter.
|
|
109
138
|
* @param layerId The layer ID to check
|
|
@@ -160,6 +189,45 @@ export declare class CustomLayerRegistry {
|
|
|
160
189
|
* @returns true if the operation was handled by an adapter
|
|
161
190
|
*/
|
|
162
191
|
removeLayer(layerId: string): boolean;
|
|
192
|
+
/**
|
|
193
|
+
* Get the layer groups of every adapter. When two adapters define the same
|
|
194
|
+
* group ID, the first registered adapter's group wins.
|
|
195
|
+
* @returns The groups, in adapter order
|
|
196
|
+
*/
|
|
197
|
+
getGroups(): LayerGroupState[];
|
|
198
|
+
/**
|
|
199
|
+
* Get the ID of the group a custom layer belongs to.
|
|
200
|
+
* @param layerId The layer ID
|
|
201
|
+
* @returns The group ID, or undefined when the layer is ungrouped
|
|
202
|
+
*/
|
|
203
|
+
getLayerGroupId(layerId: string): string | undefined;
|
|
204
|
+
/**
|
|
205
|
+
* Get the adapter that defines a group.
|
|
206
|
+
* @param groupId The group ID
|
|
207
|
+
* @returns The adapter or null if no adapter defines the group
|
|
208
|
+
*/
|
|
209
|
+
private getAdapterForGroup;
|
|
210
|
+
/**
|
|
211
|
+
* Set visibility of a group.
|
|
212
|
+
* @param groupId The group ID
|
|
213
|
+
* @param visible Whether the group should be visible
|
|
214
|
+
* @returns true if the operation was handled by an adapter
|
|
215
|
+
*/
|
|
216
|
+
setGroupVisibility(groupId: string, visible: boolean): boolean;
|
|
217
|
+
/**
|
|
218
|
+
* Set opacity of a group.
|
|
219
|
+
* @param groupId The group ID
|
|
220
|
+
* @param opacity The opacity value (0-1)
|
|
221
|
+
* @returns true if the operation was handled by an adapter
|
|
222
|
+
*/
|
|
223
|
+
setGroupOpacity(groupId: string, opacity: number): boolean;
|
|
224
|
+
/**
|
|
225
|
+
* Record that a group was collapsed or expanded.
|
|
226
|
+
* @param groupId The group ID
|
|
227
|
+
* @param collapsed Whether the group is now collapsed
|
|
228
|
+
* @returns true if the operation was handled by an adapter
|
|
229
|
+
*/
|
|
230
|
+
setGroupCollapsed(groupId: string, collapsed: boolean): boolean;
|
|
163
231
|
/**
|
|
164
232
|
* Subscribe to layer changes across all adapters.
|
|
165
233
|
* @param callback Function called when layers are added or removed
|
|
@@ -261,6 +329,10 @@ export declare class LayerControl implements IControl {
|
|
|
261
329
|
private customLayerUnsubscribe;
|
|
262
330
|
private removedCustomLayerIds;
|
|
263
331
|
private nativeLayerGroups;
|
|
332
|
+
/** Layer groups from the custom layer adapters, as of the last panel build */
|
|
333
|
+
private groupStates;
|
|
334
|
+
/** Group IDs, parents, and memberships the panel was last built from */
|
|
335
|
+
private groupStructureKey;
|
|
264
336
|
private basemapStyleUrl;
|
|
265
337
|
private basemapLayerIds;
|
|
266
338
|
private widthFrame;
|
|
@@ -428,6 +500,82 @@ export declare class LayerControl implements IControl {
|
|
|
428
500
|
* Build layer items (called initially and when layers change)
|
|
429
501
|
*/
|
|
430
502
|
private buildLayerItems;
|
|
503
|
+
/**
|
|
504
|
+
* Get the ID of the group a layer belongs to, ignoring a group ID that no
|
|
505
|
+
* adapter defines.
|
|
506
|
+
* @param layerId The layer ID
|
|
507
|
+
* @returns The group ID, or undefined when the layer is ungrouped
|
|
508
|
+
*/
|
|
509
|
+
private getLayerGroupIdOf;
|
|
510
|
+
/**
|
|
511
|
+
* Get the element a group's rows go into, creating the group (and any
|
|
512
|
+
* enclosing groups) on first use.
|
|
513
|
+
* @param groupId The group ID, or undefined for the panel's top level
|
|
514
|
+
* @param containers Group child containers already created in this build
|
|
515
|
+
* @param visiting Groups on the current parent chain, to stop on a cycle
|
|
516
|
+
* @returns The element to append the group's rows to
|
|
517
|
+
*/
|
|
518
|
+
private getGroupContainer;
|
|
519
|
+
/**
|
|
520
|
+
* Summarize the group structure the panel is built from: each group's ID
|
|
521
|
+
* and parent, and each layer's group. A change to any of these needs a
|
|
522
|
+
* rebuild; a change to a group's name, visibility, opacity, or collapsed
|
|
523
|
+
* state does not.
|
|
524
|
+
* @param groups The groups to summarize
|
|
525
|
+
* @returns A string that changes whenever the structure does
|
|
526
|
+
*/
|
|
527
|
+
private computeGroupStructureKey;
|
|
528
|
+
/**
|
|
529
|
+
* Create the element for a layer group: a header row with a collapse
|
|
530
|
+
* toggle, visibility checkbox, name, and opacity slider, followed by a
|
|
531
|
+
* container for the group's layers and nested groups.
|
|
532
|
+
* @param group The group to render
|
|
533
|
+
* @returns The group element and its child container
|
|
534
|
+
*/
|
|
535
|
+
private createGroupItem;
|
|
536
|
+
/**
|
|
537
|
+
* Show a group's state on its element.
|
|
538
|
+
* @param element The group element
|
|
539
|
+
* @param group The group state to show
|
|
540
|
+
*/
|
|
541
|
+
private updateGroupElement;
|
|
542
|
+
/**
|
|
543
|
+
* Get the element of a rendered group.
|
|
544
|
+
* @param groupId The group ID
|
|
545
|
+
* @returns The group element, or null when the group is not rendered
|
|
546
|
+
*/
|
|
547
|
+
private getGroupElement;
|
|
548
|
+
/**
|
|
549
|
+
* Remove group elements left without any layer row, e.g. after their last
|
|
550
|
+
* layer was removed.
|
|
551
|
+
*/
|
|
552
|
+
private pruneEmptyGroups;
|
|
553
|
+
/**
|
|
554
|
+
* Set a group's visibility from the panel and report it to its adapter.
|
|
555
|
+
* @param groupId The group ID
|
|
556
|
+
* @param visible Whether the group should be visible
|
|
557
|
+
*/
|
|
558
|
+
private setGroupVisibility;
|
|
559
|
+
/**
|
|
560
|
+
* Set a group's opacity from the panel and report it to its adapter.
|
|
561
|
+
* @param groupId The group ID
|
|
562
|
+
* @param opacity The opacity value (0-1)
|
|
563
|
+
*/
|
|
564
|
+
private setGroupOpacity;
|
|
565
|
+
/**
|
|
566
|
+
* Collapse or expand a group in the panel and report it to its adapter.
|
|
567
|
+
* @param groupId The group ID
|
|
568
|
+
* @param collapsed Whether the group should be collapsed
|
|
569
|
+
*/
|
|
570
|
+
private setGroupCollapsed;
|
|
571
|
+
/**
|
|
572
|
+
* Re-read the layer groups from the custom layer adapters. Call this after
|
|
573
|
+
* groups change outside the control. The panel is rebuilt when a group was
|
|
574
|
+
* added, removed, or re-parented, or a layer changed group; otherwise the
|
|
575
|
+
* group rows' name, visibility, opacity, and collapsed state are updated in
|
|
576
|
+
* place.
|
|
577
|
+
*/
|
|
578
|
+
refreshGroups(): void;
|
|
431
579
|
/**
|
|
432
580
|
* Add a single layer item to the panel
|
|
433
581
|
*/
|
|
@@ -756,6 +904,23 @@ export declare class LayerControl implements IControl {
|
|
|
756
904
|
* Move a layer to the bottom (lowest rendering order among user layers)
|
|
757
905
|
*/
|
|
758
906
|
private moveLayerToBottom;
|
|
907
|
+
/**
|
|
908
|
+
* Move a layer within its own group (or among the top-level rows), so the
|
|
909
|
+
* context-menu moves never carry it out of its group. A nested group counts
|
|
910
|
+
* as one block: moving up or down steps past the whole block.
|
|
911
|
+
* @param layerId The layer ID
|
|
912
|
+
* @param direction Where to move the layer within its group
|
|
913
|
+
*/
|
|
914
|
+
private moveLayerWithinGroup;
|
|
915
|
+
/**
|
|
916
|
+
* Identify which row of a group a layer falls under: the layer itself when
|
|
917
|
+
* it belongs to the group directly, or the nested group that holds it.
|
|
918
|
+
* @param layerId The layer ID
|
|
919
|
+
* @param groupId The group, or undefined for the panel's top level
|
|
920
|
+
* @returns `layer:<id>` or `group:<id>`, or null when the layer is not
|
|
921
|
+
* inside the group at all
|
|
922
|
+
*/
|
|
923
|
+
private getChildKeyWithin;
|
|
759
924
|
/**
|
|
760
925
|
* Show inline remove confirmation instead of browser confirm() dialog.
|
|
761
926
|
* Works in Jupyter notebooks where native dialogs may not appear.
|
|
@@ -793,6 +958,11 @@ export declare class LayerControl implements IControl {
|
|
|
793
958
|
* Apply UI order to map layers
|
|
794
959
|
*/
|
|
795
960
|
private applyUIOrderToMap;
|
|
961
|
+
/**
|
|
962
|
+
* Restack the map's MapLibre layers to match a panel order.
|
|
963
|
+
* @param uiLayerIds User layer IDs top-to-bottom, as the panel lists them
|
|
964
|
+
*/
|
|
965
|
+
private applyLayerOrderToMap;
|
|
796
966
|
}
|
|
797
967
|
|
|
798
968
|
/**
|
|
@@ -890,6 +1060,31 @@ export declare interface LayerControlOptions {
|
|
|
890
1060
|
onBackgroundPresetsChange?: (presets: BackgroundPresets) => void;
|
|
891
1061
|
}
|
|
892
1062
|
|
|
1063
|
+
/**
|
|
1064
|
+
* A collapsible folder of layers in the panel. Supplied by a
|
|
1065
|
+
* {@link CustomLayerAdapter} through `getGroups`; layers join a group through
|
|
1066
|
+
* the adapter's `getLayerGroupId`.
|
|
1067
|
+
*
|
|
1068
|
+
* A group's `visible` and `opacity` are its own settings, separate from those
|
|
1069
|
+
* of its layers. The control shows and edits them but never folds them into
|
|
1070
|
+
* the layer rows: applying a hidden or translucent group to its layers on the
|
|
1071
|
+
* map is the adapter's job.
|
|
1072
|
+
*/
|
|
1073
|
+
export declare interface LayerGroupState {
|
|
1074
|
+
/** Unique group ID */
|
|
1075
|
+
id: string;
|
|
1076
|
+
/** Display name for the group */
|
|
1077
|
+
name: string;
|
|
1078
|
+
/** ID of the enclosing group, or undefined for a top-level group */
|
|
1079
|
+
parentId?: string;
|
|
1080
|
+
/** Whether the group is visible */
|
|
1081
|
+
visible: boolean;
|
|
1082
|
+
/** Group opacity (0-1) */
|
|
1083
|
+
opacity: number;
|
|
1084
|
+
/** Whether the group's rows are folded away in the panel */
|
|
1085
|
+
collapsed: boolean;
|
|
1086
|
+
}
|
|
1087
|
+
|
|
893
1088
|
/**
|
|
894
1089
|
* State for a single layer
|
|
895
1090
|
*/
|