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.
@@ -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
- /** Get the current state of a layer */
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
@@ -288,7 +327,7 @@ export declare function getLayerOpacity(map: Map_2, layerId: string, layerType:
288
327
  * @param map The MapLibre map instance
289
328
  * @param layerId The layer ID
290
329
  * @param layerType The layer type
291
- * @returns The resolved dash pattern or circle border style
330
+ * @returns The resolved dash pattern, circle border style, or fill pattern
292
331
  */
293
332
  export declare function getLayerSymbolStyle(map: Map_2, layerId: string, layerType: string): LayerSymbolStyle;
294
333
 
@@ -326,6 +365,7 @@ export declare class LayerControl implements IControl {
326
365
  private panel;
327
366
  private resizeHandler;
328
367
  private mapResizeHandler;
368
+ private mapLayerListeners;
329
369
  private state;
330
370
  private targetLayers;
331
371
  private styleEditors;
@@ -338,6 +378,7 @@ export declare class LayerControl implements IControl {
338
378
  /** Explicit max panel height; null means fill available vertical space */
339
379
  private maxPanelHeight;
340
380
  private showStyleEditor;
381
+ private showAllStyleProperties;
341
382
  private showOpacitySlider;
342
383
  private showLayerSymbol;
343
384
  private excludeDrawnLayers;
@@ -352,6 +393,12 @@ export declare class LayerControl implements IControl {
352
393
  private groupStructureKey;
353
394
  private basemapStyleUrl;
354
395
  private basemapLayerIds;
396
+ /** True when `basemapLayerIds` came from the option, which is authoritative even when empty. */
397
+ private basemapLayerIdsProvided;
398
+ /** Set once onAdd has listed the map's layers (after any basemapStyleUrl fetch). */
399
+ private layersListed;
400
+ /** Panel order set through setLayerOrder, used to order layers with nothing on the map. */
401
+ private layerOrderHint;
355
402
  private widthFrame;
356
403
  private opacityInputEl;
357
404
  private resizeHandleEls;
@@ -376,6 +423,13 @@ export declare class LayerControl implements IControl {
376
423
  private backgroundPresetStorageKey;
377
424
  private onBackgroundPresetsChange?;
378
425
  constructor(options?: LayerControlOptions);
426
+ /**
427
+ * Whether basemap membership is decided by a known list of basemap layer IDs
428
+ * (the `basemapLayerIds` option, or the layers of `basemapStyleUrl`) rather
429
+ * than by heuristics. A fetched style only counts when it had layers; an
430
+ * explicit list counts even when empty.
431
+ */
432
+ private hasBasemapLayerIds;
379
433
  /**
380
434
  * Called when the control is added to the map
381
435
  */
@@ -506,13 +560,55 @@ export declare class LayerControl implements IControl {
506
560
  */
507
561
  private toggle;
508
562
  /**
509
- * Expand the panel
563
+ * Whether the panel is collapsed (closed). Before the control is added to a
564
+ * map this reflects the `collapsed` option.
565
+ * @returns True while the panel is closed
566
+ */
567
+ isCollapsed(): boolean;
568
+ /**
569
+ * Expand (open) the panel. Before the control is added to a map this only
570
+ * records the state, and the panel opens when it is built.
510
571
  */
511
- private expand;
572
+ expand(): void;
512
573
  /**
513
- * Collapse the panel
574
+ * Collapse (close) the panel.
575
+ */
576
+ collapse(): void;
577
+ /**
578
+ * Update a layer row's visibility, opacity and name in place, without
579
+ * touching the map or firing any callback. Use it to mirror changes made
580
+ * outside the control (for example by an application store that owns layer
581
+ * state) into an already-built panel without rebuilding it.
582
+ *
583
+ * Only layers the control already lists are updated, with one exception:
584
+ * `"Background"` adds the Background row when the control has none (a style
585
+ * whose basemap lives in style imports has no root basemap layers to detect,
586
+ * so the control would otherwise show no Background row). It returns false
587
+ * until the control has listed the map's layers (after `onAdd`, and after a
588
+ * `basemapStyleUrl` fetch), since seeding state earlier would stop the
589
+ * control from detecting layers on its own.
590
+ *
591
+ * @param layerId The layer ID, or `"Background"` for the basemap row
592
+ * @param state The fields to change; omitted fields keep their value
593
+ * @returns True if a layer state was updated or created
514
594
  */
515
- private collapse;
595
+ setLayerState(layerId: string, state: Partial<Pick<LayerState, "visible" | "opacity" | "name">>): boolean;
596
+ /**
597
+ * Set the order the panel lists layers in, then redraw the rows.
598
+ *
599
+ * Layers whose native MapLibre layers are on the map are always listed in
600
+ * map stacking order; this order applies to the rest (custom-adapter layers
601
+ * with nothing on the map yet, such as hidden ones). Use it to put the panel
602
+ * back after an application refused a drag or context-menu move, since the
603
+ * control has already moved the row by then. Layers not listed keep their
604
+ * relative order after the listed ones, and Background stays at the bottom.
605
+ * A hidden custom layer whose adapter has other layers on the map keeps its
606
+ * slot beside them in that adapter's list, since the adapter is the source of
607
+ * truth for where it sits; this order breaks the remaining ties.
608
+ *
609
+ * @param layerIds Layer IDs, top of the panel first
610
+ */
611
+ setLayerOrder(layerIds: readonly string[]): void;
516
612
  /**
517
613
  * Build layer items (called initially and when layers change)
518
614
  */
@@ -597,6 +693,10 @@ export declare class LayerControl implements IControl {
597
693
  * Add a single layer item to the panel
598
694
  */
599
695
  private addLayerItem;
696
+ /** Refresh changed category legends without rebuilding rows or style editors. */
697
+ private refreshLayerCategories;
698
+ /** Apply categories in place without disturbing the row or its style editor. */
699
+ private applyLayerCategories;
600
700
  /**
601
701
  * Create a symbol element for a layer
602
702
  * @param layerId The layer ID
@@ -609,6 +709,8 @@ export declare class LayerControl implements IControl {
609
709
  * @returns The symbol HTML element
610
710
  */
611
711
  private createBackgroundLayerSymbol;
712
+ /** Refresh pattern images and SDF tint after paint, sprite, or image changes. */
713
+ private updateFillSymbols;
612
714
  /**
613
715
  * Create a symbol element for the Background layer group
614
716
  * Shows a stacked layers icon to represent multiple background layers
@@ -621,10 +723,10 @@ export declare class LayerControl implements IControl {
621
723
  private toggleLayerVisibility;
622
724
  /**
623
725
  * Show a small popup that lets the user type an exact opacity percentage
624
- * (0-100) for a layer. Triggered by double-clicking the opacity slider.
726
+ * (0-100). Triggered by double-clicking an opacity slider.
625
727
  *
626
- * @param layerId The layer ID whose opacity is being edited
627
- * @param slider The opacity range input associated with the layer row
728
+ * @param slider The opacity range input being edited
729
+ * @param applyOpacity Called with the chosen opacity (0-1) when the user confirms
628
730
  */
629
731
  private showOpacityInput;
630
732
  /**
@@ -635,6 +737,24 @@ export declare class LayerControl implements IControl {
635
737
  * Change layer opacity
636
738
  */
637
739
  private changeLayerOpacity;
740
+ /**
741
+ * Get the opacity property an adapter owns for a native map layer: the layer
742
+ * type's primary opacity property, when an adapter reports state for the
743
+ * layer. Such a layer's paint value is its own opacity combined with the
744
+ * adapter's folder opacity, so it must be written and read through the
745
+ * adapter. Returns null for other layers, including custom layers and
746
+ * layers with native sub-layer groups.
747
+ * @param layerId The layer ID
748
+ */
749
+ private getAdapterOwnedOpacityProperty;
750
+ /**
751
+ * Get the value a style editor control shows for a paint property: the
752
+ * adapter's own opacity for an adapter-owned opacity property, otherwise the
753
+ * map's paint value.
754
+ * @param layerId The layer ID
755
+ * @param property The paint property
756
+ */
757
+ private getStyleValue;
638
758
  /**
639
759
  * Check if a layer is a user-added layer (vs basemap layer)
640
760
  * Used primarily for the background legend to determine which layers are background
@@ -792,6 +912,16 @@ export declare class LayerControl implements IControl {
792
912
  * Add controls for fill layers
793
913
  */
794
914
  private addFillControls;
915
+ /** Fill pattern picker group, with the Fill Color re-render hook. */
916
+ private addFillPatternGroup;
917
+ /**
918
+ * `showAllStyleProperties`: add every control the editor supports for a
919
+ * layer type. Controls are created from the style-spec default and then
920
+ * refreshed from the map, so unset properties show their effective value
921
+ * without anything being written to the style.
922
+ */
923
+ private addAllStyleControls;
924
+ private renderFillPatternPicker;
795
925
  /**
796
926
  * Add controls for line layers
797
927
  */
@@ -842,10 +972,59 @@ export declare class LayerControl implements IControl {
842
972
  * Create a slider control
843
973
  */
844
974
  private createSliderControl;
975
+ /**
976
+ * Read the effective value a managed (`showAllStyleProperties`) control
977
+ * should display: the layer's own value, else the inherited value, else the
978
+ * style-spec default. Returns `expressionOf` (the property whose value is
979
+ * not editable) when that value is an expression or otherwise not a plain
980
+ * number/color.
981
+ */
982
+ private resolveEffectiveValue;
983
+ /**
984
+ * Explain why a managed control cannot take effect on any of the layers it
985
+ * edits (style-spec `requires` dependencies), or null when it can. With
986
+ * grouped native sublayers the control stays enabled while at least one
987
+ * layer in the group can still use the edit.
988
+ */
989
+ private getDependencyReason;
990
+ /**
991
+ * Re-evaluate every managed control under `root` from the current map
992
+ * state (see {@link refreshManagedControl}). `inheritsFrom` limits the pass
993
+ * to controls whose unset value follows that property.
994
+ */
995
+ private refreshManagedControls;
996
+ /**
997
+ * Update a managed control's displayed value and its enabled/disabled state
998
+ * with explanation from the current map state. Reads only; never writes to
999
+ * the map.
1000
+ */
1001
+ private refreshManagedControl;
1002
+ /** Show or clear the explanation for a disabled managed control. */
1003
+ private setControlUnavailableReason;
1004
+ /**
1005
+ * A control's inputs are disabled while it is unavailable (dependency or
1006
+ * expression) or while a non-SDF fill pattern owns its color.
1007
+ */
1008
+ private syncControlDisabled;
1009
+ /**
1010
+ * Unset properties that a managed control added on top of the layer's
1011
+ * original style, so Reset Style returns the layer to what it was before the
1012
+ * user edited a control the original style never set.
1013
+ */
1014
+ private clearUserAddedProperties;
845
1015
  /**
846
1016
  * Reset layer style to original
847
1017
  */
848
1018
  private resetLayerStyle;
1019
+ /**
1020
+ * Read the visibility and opacity a layer's panel row should show. A native
1021
+ * layer an adapter manages reports its own values; the map's paint and layout
1022
+ * hold those combined with the adapter's folder settings, so reading them
1023
+ * back would corrupt the row.
1024
+ * @param layerId The layer ID
1025
+ * @param layerType The layer's map type
1026
+ */
1027
+ private readLayerRowState;
849
1028
  /**
850
1029
  * Update layer states from map (sync UI with map)
851
1030
  */
@@ -854,6 +1033,10 @@ export declare class LayerControl implements IControl {
854
1033
  * Update UI elements for a specific layer
855
1034
  */
856
1035
  private updateUIForLayer;
1036
+ /**
1037
+ * The panel's layer rows, by layer ID
1038
+ */
1039
+ private rowsByLayerId;
857
1040
  /**
858
1041
  * Check for new layers and add them to the control, remove deleted layers
859
1042
  */
@@ -992,7 +1175,7 @@ export declare interface LayerControlOptions {
992
1175
  layerStates?: PartialLayerStates;
993
1176
  /** Array of layer IDs to control (if not specified, controls all layers) */
994
1177
  layers?: string[];
995
- /** Initial panel width in pixels (default: 320) */
1178
+ /** Initial panel width in pixels (default: 350) */
996
1179
  panelWidth?: number;
997
1180
  /** Minimum panel width in pixels (default: 240) */
998
1181
  panelMinWidth?: number;
@@ -1000,6 +1183,24 @@ export declare interface LayerControlOptions {
1000
1183
  panelMaxWidth?: number;
1001
1184
  /** Whether to show the style editor button (gear icon) for layers (default: true) */
1002
1185
  showStyleEditor?: boolean;
1186
+ /**
1187
+ * Whether the style editor shows every property control it supports for a
1188
+ * layer's type, even when the property is absent from the layer style
1189
+ * (default: false). When false, controls for optional properties (e.g.
1190
+ * `fill-opacity`, `fill-outline-color`) only appear once the layer sets them.
1191
+ *
1192
+ * Unset properties start at their effective value: the style-spec default,
1193
+ * or the inherited value (`fill-outline-color` follows `fill-color`).
1194
+ * Opening or closing the editor never writes to the map style; a property is
1195
+ * set only when the user edits its control, and Reset Style unsets it again.
1196
+ * A control that cannot take effect (e.g. outline color with
1197
+ * `fill-antialias: false` or a fill pattern, text properties without a
1198
+ * `text-field`, icon opacity without an `icon-image`) or whose value is a
1199
+ * data-driven expression stays visible but disabled with an explanation;
1200
+ * expressions are never replaced. Applies to ordinary layers and to native
1201
+ * sublayers exposed by custom-layer adapters.
1202
+ */
1203
+ showAllStyleProperties?: boolean;
1003
1204
  /** Whether to show the opacity slider for layers (default: true) */
1004
1205
  showOpacitySlider?: boolean;
1005
1206
  /** Whether to show layer type symbols/icons next to layer names (default: true) */
@@ -1024,6 +1225,15 @@ export declare interface LayerControlOptions {
1024
1225
  * and user-added layers.
1025
1226
  */
1026
1227
  basemapStyleUrl?: string;
1228
+ /**
1229
+ * IDs of the layers that make up the basemap, for applications that already
1230
+ * know them (or have no fetchable style URL, such as a style built in code).
1231
+ * Those layers are grouped under "Background" and every other layer is
1232
+ * treated as user-added. Takes precedence over `basemapStyleUrl` (nothing is
1233
+ * fetched), and an empty array is honoured as "no basemap layers" rather than
1234
+ * falling back to heuristic detection.
1235
+ */
1236
+ basemapLayerIds?: string[];
1027
1237
  /** Whether to enable context menu (right-click) on layers (default: true) */
1028
1238
  enableContextMenu?: boolean;
1029
1239
  /** Whether to enable drag-and-drop reordering of layers (default: true) */
@@ -1035,14 +1245,18 @@ export declare interface LayerControlOptions {
1035
1245
  /** Callback when a layer is removed via context menu */
1036
1246
  onLayerRemove?: (layerId: string) => void;
1037
1247
  /**
1038
- * Callback fired whenever a paint property is changed through the per-layer
1039
- * style editor (a slider/color input, or the Reset button). Reports the
1040
- * layer the open style editor belongs to (`layerId`), the MapLibre paint
1041
- * property name (e.g. `"raster-brightness-max"`, `"fill-color"`), and the new
1042
- * value (a number for sliders, a hex string for color pickers). Lets
1043
- * consumers mirror the change into their own store so external style UI
1044
- * (e.g. a separate sidebar) stays in sync. The control still applies the
1045
- * change to the map itself; this callback is purely a notification.
1248
+ * Callback fired whenever a paint property changes through the per-layer
1249
+ * style editor (a slider/color input/pattern picker, or Reset Style).
1250
+ * Reports the layer the open style editor belongs to (`layerId`), the
1251
+ * MapLibre paint property name (e.g. `"raster-brightness-max"`,
1252
+ * `"fill-color"`, or `"fill-pattern"`), and the new value. Pattern selection
1253
+ * reports its image ID; selecting None reports `undefined`. Reset reports
1254
+ * the restored raw value, including a string, expression, or `undefined`
1255
+ * for `fill-pattern`, and `undefined` for a property that
1256
+ * `showAllStyleProperties` exposed and the user set on a layer that did not
1257
+ * have it. Lets consumers mirror changes into their own store so
1258
+ * external style UI stays in sync. The control still applies changes to the
1259
+ * map itself; this callback is purely a notification.
1046
1260
  */
1047
1261
  onLayerStyleChange?: (layerId: string, property: string, value: unknown) => void;
1048
1262
  /**
@@ -1133,6 +1347,8 @@ export declare interface LayerSymbolStyle {
1133
1347
  dasharray?: number[];
1134
1348
  /** Circle border colour; null disables the border. */
1135
1349
  strokeColor?: string | null;
1350
+ /** Registered MapLibre image for a fill-pattern; SDF images use the fill color. */
1351
+ fillPattern?: FillPatternImage;
1136
1352
  }
1137
1353
 
1138
1354
  /**
@@ -1223,6 +1439,8 @@ export declare interface SymbolOptions {
1223
1439
  dasharray?: number[];
1224
1440
  /** Circle border colour; null disables the border. */
1225
1441
  strokeColor?: string | null;
1442
+ /** Registered MapLibre image for a fill-pattern; SDF images use the fill color. */
1443
+ fillPattern?: FillPatternImage;
1226
1444
  }
1227
1445
 
1228
1446
  export { }