maplibre-gl-layer-control 0.3.0 → 0.5.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.
@@ -153,6 +153,41 @@
153
153
  pointer-events: none;
154
154
  }
155
155
 
156
+ /* Action buttons (Show All / Hide All) */
157
+ .layer-control-actions {
158
+ display: flex;
159
+ gap: 8px;
160
+ padding-bottom: 6px;
161
+ border-bottom: 1px solid #e0e0e0;
162
+ margin-bottom: 4px;
163
+ }
164
+
165
+ .layer-control-action-btn {
166
+ flex: 1;
167
+ padding: 3px 8px;
168
+ font-size: 11px;
169
+ font-weight: 600;
170
+ color: #ffffff !important;
171
+ background: #2f6fed !important;
172
+ border: 1px solid #2f6fed !important;
173
+ border-radius: 4px;
174
+ cursor: pointer;
175
+ transition: all 0.15s ease;
176
+ width: auto;
177
+ height: auto;
178
+ }
179
+
180
+ .layer-control-action-btn:hover {
181
+ background: #1d5bd6 !important;
182
+ border-color: #1d5bd6 !important;
183
+ color: #ffffff !important;
184
+ }
185
+
186
+ .layer-control-action-btn:active {
187
+ background: #1a4fc2 !important;
188
+ border-color: #1a4fc2 !important;
189
+ }
190
+
156
191
  /* Layer items */
157
192
  .layer-control-item {
158
193
  display: flex;
@@ -173,6 +208,7 @@
173
208
  gap: 8px;
174
209
  width: 100%;
175
210
  box-sizing: border-box;
211
+ min-height: 20px;
176
212
  }
177
213
 
178
214
  .layer-control-checkbox {
@@ -191,6 +227,22 @@
191
227
  white-space: nowrap;
192
228
  }
193
229
 
230
+ /* Layer symbol/icon */
231
+ .layer-control-symbol {
232
+ display: inline-flex;
233
+ align-items: center;
234
+ justify-content: center;
235
+ width: 18px;
236
+ height: 18px;
237
+ flex-shrink: 0;
238
+ }
239
+
240
+ .layer-control-symbol svg {
241
+ width: 16px;
242
+ height: 16px;
243
+ display: block;
244
+ }
245
+
194
246
  .layer-control-opacity {
195
247
  flex: 0 0 140px;
196
248
  height: 16px;
@@ -224,18 +276,19 @@
224
276
 
225
277
  /* Style button */
226
278
  .layer-control-style-button {
227
- width: 26px;
228
- height: 26px;
279
+ width: 20px;
280
+ height: 20px;
229
281
  border-radius: 4px;
230
282
  border: none;
231
283
  background: none;
232
284
  cursor: pointer;
233
- font-size: 14px;
285
+ font-size: 16px;
234
286
  color: #444;
235
287
  display: flex;
236
288
  align-items: center;
237
289
  justify-content: center;
238
290
  transition: background-color 0.1s ease;
291
+ flex-shrink: 0;
239
292
  }
240
293
 
241
294
  .layer-control-style-button:hover {
@@ -513,14 +566,14 @@
513
566
  /* Style button */
514
567
  .layer-control-style-button {
515
568
  flex: 0 0 auto;
516
- width: 24px;
517
- height: 24px;
569
+ width: 20px;
570
+ height: 20px;
518
571
  border: 1px solid #ddd;
519
572
  border-radius: 3px;
520
573
  background: white;
521
574
  color: #666;
522
575
  cursor: pointer;
523
- font-size: 14px;
576
+ font-size: 16px;
524
577
  padding: 0;
525
578
  line-height: 1;
526
579
  transition: all 0.2s ease;
@@ -771,6 +824,22 @@
771
824
  flex-shrink: 0;
772
825
  }
773
826
 
827
+ /* Layer symbol in background legend */
828
+ .background-legend-layer-symbol {
829
+ display: inline-flex;
830
+ align-items: center;
831
+ justify-content: center;
832
+ width: 14px;
833
+ height: 14px;
834
+ flex-shrink: 0;
835
+ }
836
+
837
+ .background-legend-layer-symbol svg {
838
+ width: 14px;
839
+ height: 14px;
840
+ display: block;
841
+ }
842
+
774
843
  .background-legend-layer-name {
775
844
  flex: 1;
776
845
  font-size: 11px;
@@ -1,4 +1,5 @@
1
1
  import { IControl } from 'maplibre-gl';
2
+ import { LayerSpecification } from 'maplibre-gl';
2
3
  import { Map as Map_2 } from 'maplibre-gl';
3
4
 
4
5
  /**
@@ -10,6 +11,30 @@ import { Map as Map_2 } from 'maplibre-gl';
10
11
  */
11
12
  export declare function clamp(value: number, min: number, max: number): number;
12
13
 
14
+ /**
15
+ * Create an SVG symbol for the Background layer group
16
+ * @param size Symbol size in pixels (default: 16)
17
+ * @returns SVG markup string
18
+ */
19
+ export declare function createBackgroundGroupSymbolSVG(size?: number): string;
20
+
21
+ /**
22
+ * Create an SVG symbol for a layer type
23
+ * @param layerType The MapLibre layer type
24
+ * @param color The primary color (hex format), or null for default
25
+ * @param options Optional configuration
26
+ * @returns SVG markup string
27
+ */
28
+ export declare function createLayerSymbolSVG(layerType: string, color: string | null, options?: SymbolOptions): string;
29
+
30
+ /**
31
+ * Darken a hex color by a given amount
32
+ * @param hexColor The hex color to darken (e.g., '#ff0000')
33
+ * @param amount Amount to darken (0-1, where 1 is fully black)
34
+ * @returns The darkened hex color
35
+ */
36
+ export declare function darkenColor(hexColor: string, amount: number): string;
37
+
13
38
  /**
14
39
  * Format a numeric value based on the step size
15
40
  * @param value Numeric value to format
@@ -18,6 +43,22 @@ export declare function clamp(value: number, min: number, max: number): number;
18
43
  */
19
44
  export declare function formatNumericValue(value: number, step: number): string;
20
45
 
46
+ /**
47
+ * Get the primary color from a layer's paint properties
48
+ * @param map The MapLibre map instance
49
+ * @param layerId The layer ID
50
+ * @param layerType The layer type
51
+ * @returns The normalized hex color, or null if not found
52
+ */
53
+ export declare function getLayerColor(map: Map_2, layerId: string, layerType: string): string | null;
54
+
55
+ /**
56
+ * Get the primary color directly from a layer specification
57
+ * @param layer The layer specification
58
+ * @returns The normalized hex color, or null if not found
59
+ */
60
+ export declare function getLayerColorFromSpec(layer: LayerSpecification): string | null;
61
+
21
62
  /**
22
63
  * Get the current opacity value for a layer
23
64
  * @param map MapLibre map instance
@@ -56,6 +97,11 @@ export declare class LayerControl implements IControl {
56
97
  private styleEditors;
57
98
  private minPanelWidth;
58
99
  private maxPanelWidth;
100
+ private maxPanelHeight;
101
+ private showStyleEditor;
102
+ private showOpacitySlider;
103
+ private showLayerSymbol;
104
+ private excludeDrawnLayers;
59
105
  private widthSliderEl;
60
106
  private widthThumbEl;
61
107
  private widthValueEl;
@@ -77,10 +123,21 @@ export declare class LayerControl implements IControl {
77
123
  * Auto-detect layers from the map and populate layerStates
78
124
  */
79
125
  private autoDetectLayers;
126
+ /**
127
+ * Get the source IDs that were part of the original style (from the style URL)
128
+ * Sources added via map.addSource() are considered user-added
129
+ */
130
+ private getOriginalStyleSourceIds;
80
131
  /**
81
132
  * Generate a friendly display name from a layer ID
82
133
  */
83
134
  private generateFriendlyName;
135
+ /**
136
+ * Check if a layer ID belongs to a drawing library (Geoman, Mapbox GL Draw, etc.)
137
+ * @param layerId The layer ID to check
138
+ * @returns true if the layer is from a drawing library
139
+ */
140
+ private isDrawnLayer;
84
141
  /**
85
142
  * Create the main container element
86
143
  */
@@ -93,6 +150,14 @@ export declare class LayerControl implements IControl {
93
150
  * Create the panel element
94
151
  */
95
152
  private createPanel;
153
+ /**
154
+ * Create action buttons for Show All / Hide All
155
+ */
156
+ private createActionButtons;
157
+ /**
158
+ * Set visibility of all layers
159
+ */
160
+ private setAllLayersVisibility;
96
161
  /**
97
162
  * Create the panel header with title and width control
98
163
  */
@@ -145,6 +210,24 @@ export declare class LayerControl implements IControl {
145
210
  * Add a single layer item to the panel
146
211
  */
147
212
  private addLayerItem;
213
+ /**
214
+ * Create a symbol element for a layer
215
+ * @param layerId The layer ID
216
+ * @returns The symbol HTML element, or null if layer not found
217
+ */
218
+ private createLayerSymbol;
219
+ /**
220
+ * Create a symbol element for a background layer
221
+ * @param layer The layer specification
222
+ * @returns The symbol HTML element
223
+ */
224
+ private createBackgroundLayerSymbol;
225
+ /**
226
+ * Create a symbol element for the Background layer group
227
+ * Shows a stacked layers icon to represent multiple background layers
228
+ * @returns The symbol HTML element
229
+ */
230
+ private createBackgroundGroupSymbol;
148
231
  /**
149
232
  * Toggle layer visibility
150
233
  */
@@ -270,7 +353,7 @@ export declare class LayerControl implements IControl {
270
353
  */
271
354
  private updateUIForLayer;
272
355
  /**
273
- * Check for new layers and add them to the control
356
+ * Check for new layers and add them to the control, remove deleted layers
274
357
  */
275
358
  private checkForNewLayers;
276
359
  }
@@ -291,6 +374,16 @@ export declare interface LayerControlOptions {
291
374
  panelMinWidth?: number;
292
375
  /** Maximum panel width in pixels (default: 420) */
293
376
  panelMaxWidth?: number;
377
+ /** Whether to show the style editor button (gear icon) for layers (default: true) */
378
+ showStyleEditor?: boolean;
379
+ /** Whether to show the opacity slider for layers (default: true) */
380
+ showOpacitySlider?: boolean;
381
+ /** Whether to show layer type symbols/icons next to layer names (default: true) */
382
+ showLayerSymbol?: boolean;
383
+ /** Maximum panel height in pixels (default: 600). When content exceeds this height, the panel becomes scrollable. */
384
+ panelMaxHeight?: number;
385
+ /** Whether to exclude drawn layers from drawing libraries like Geoman, Mapbox GL Draw, etc. (default: true) */
386
+ excludeDrawnLayers?: boolean;
294
387
  }
295
388
 
296
389
  /**
@@ -373,4 +466,14 @@ export declare interface StyleControlConfig {
373
466
  defaultValue?: any;
374
467
  }
375
468
 
469
+ /**
470
+ * Symbol generation options
471
+ */
472
+ export declare interface SymbolOptions {
473
+ /** Symbol size in pixels (default: 16) */
474
+ size?: number;
475
+ /** Stroke width for line symbols (default: 2) */
476
+ strokeWidth?: number;
477
+ }
478
+
376
479
  export { }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "maplibre-gl-layer-control",
3
- "version": "0.3.0",
3
+ "version": "0.5.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",