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
package/README.md
CHANGED
|
@@ -29,6 +29,7 @@ A comprehensive layer control for MapLibre GL with advanced styling capabilities
|
|
|
29
29
|
- ✅ **TypeScript** - Full type safety and IntelliSense support
|
|
30
30
|
- ✅ **React integration** - Optional React components and hooks
|
|
31
31
|
- ✅ **Custom layer adapters** - Integrate non-MapLibre layers (deck.gl, Zarr, etc.)
|
|
32
|
+
- ✅ **Layer groups** - Nest an adapter's layers in collapsible, nestable folders with their own visibility checkbox and opacity slider
|
|
32
33
|
|
|
33
34
|
## Installation
|
|
34
35
|
|
|
@@ -469,6 +470,36 @@ deckLayers.set('my-deck-layer', myDeckLayer);
|
|
|
469
470
|
deckAdapter.notifyLayerAdded('my-deck-layer');
|
|
470
471
|
```
|
|
471
472
|
|
|
473
|
+
#### Layer Groups
|
|
474
|
+
|
|
475
|
+
An adapter can organize its layers into collapsible folders by implementing the optional group methods. The panel then nests each layer under its group, nested groups included, and gives every group a collapse toggle, a visibility checkbox, and an opacity slider.
|
|
476
|
+
|
|
477
|
+
```typescript
|
|
478
|
+
interface LayerGroupState {
|
|
479
|
+
id: string;
|
|
480
|
+
name: string;
|
|
481
|
+
parentId?: string; // enclosing group; omit for a top-level group
|
|
482
|
+
visible: boolean;
|
|
483
|
+
opacity: number; // 0-1
|
|
484
|
+
collapsed: boolean;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
interface CustomLayerAdapter {
|
|
488
|
+
// ...the methods above, plus:
|
|
489
|
+
getGroups?(): LayerGroupState[];
|
|
490
|
+
getLayerGroupId?(layerId: string): string | undefined;
|
|
491
|
+
setGroupVisibility?(groupId: string, visible: boolean): void;
|
|
492
|
+
setGroupOpacity?(groupId: string, opacity: number): void;
|
|
493
|
+
setGroupCollapsed?(groupId: string, collapsed: boolean): void;
|
|
494
|
+
}
|
|
495
|
+
```
|
|
496
|
+
|
|
497
|
+
- A group's `visible` and `opacity` are its own settings. The control shows and edits them, but it never folds them into the layer rows or applies them to the map: hiding or fading a group's layers is the adapter's job (for example, by ANDing the group's visibility into each child's).
|
|
498
|
+
- A group renders at the position of its top-most layer. Groups with no layers, directly or through a nested group, are not shown.
|
|
499
|
+
- Drag-and-drop and the context-menu moves keep a layer inside its own group, where a nested group counts as one block (a layer moves past it whole). Groups themselves cannot be dragged.
|
|
500
|
+
- **Show All** / **Hide All** also show or hide every group.
|
|
501
|
+
- When groups change outside the control, call `layerControl.refreshGroups()`. It rebuilds the panel when a group was added, removed, or re-parented, or a layer changed group, and otherwise updates the group rows in place.
|
|
502
|
+
|
|
472
503
|
#### Limitations
|
|
473
504
|
|
|
474
505
|
- **Style Editor**: The style editor (gear icon) is not available for custom layers since they don't use MapLibre's paint properties. Clicking the gear icon will show an info panel explaining this.
|