maplibre-gl-layer-control 0.12.0 → 0.13.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/dist/index.cjs CHANGED
@@ -132,6 +132,18 @@ class CustomLayerRegistry {
132
132
  }
133
133
  return null;
134
134
  }
135
+ /**
136
+ * Get native MapLibre layer IDs for a custom layer.
137
+ * @param layerId The custom layer ID
138
+ * @returns Array of native layer IDs, or null if not available
139
+ */
140
+ getNativeLayerIds(layerId) {
141
+ const adapter = this.getAdapterForLayer(layerId);
142
+ if (adapter && adapter.getNativeLayerIds) {
143
+ return adapter.getNativeLayerIds(layerId);
144
+ }
145
+ return null;
146
+ }
135
147
  /**
136
148
  * Remove a custom layer through its adapter.
137
149
  * @param layerId The layer ID to remove
@@ -686,6 +698,7 @@ class LayerControl {
686
698
  __publicField(this, "customLayerRegistry", null);
687
699
  __publicField(this, "customLayerUnsubscribe", null);
688
700
  __publicField(this, "removedCustomLayerIds", /* @__PURE__ */ new Set());
701
+ __publicField(this, "nativeLayerGroups", /* @__PURE__ */ new Map());
689
702
  __publicField(this, "basemapStyleUrl", null);
690
703
  __publicField(this, "basemapLayerIds", null);
691
704
  __publicField(this, "widthSliderEl", null);
@@ -1083,6 +1096,7 @@ class LayerControl {
1083
1096
  */
1084
1097
  isDrawnLayer(layerId) {
1085
1098
  const drawnLayerPatterns = [
1099
+ // Drawing libraries
1086
1100
  /^gm[-_\s]/i,
1087
1101
  // Geoman (gm-main-*, gm_*, Gm Temporary...)
1088
1102
  /^gl-draw[-_]/i,
@@ -1093,8 +1107,15 @@ class LayerControl {
1093
1107
  // Terra Draw
1094
1108
  /^maplibre-gl-draw[-_]/i,
1095
1109
  // MapLibre GL Draw
1096
- /^draw[-_]layer/i
1110
+ /^draw[-_]layer/i,
1097
1111
  // Generic draw layers
1112
+ // maplibre-gl-components internal layers
1113
+ /^measure-/i,
1114
+ // MeasureControl (measure-{id}-fill, measure-{id}-line)
1115
+ /^pmtiles-source-/i,
1116
+ // PMTilesLayerControl (managed via adapter)
1117
+ /^stac-search-footprints/i
1118
+ // StacSearchControl footprint layers
1098
1119
  ];
1099
1120
  return drawnLayerPatterns.some((pattern) => pattern.test(layerId));
1100
1121
  }
@@ -2094,10 +2115,32 @@ class LayerControl {
2094
2115
  * Open style editor for a layer
2095
2116
  */
2096
2117
  openStyleEditor(layerId) {
2118
+ var _a;
2097
2119
  const itemEl = this.panel.querySelector(`[data-layer-id="${layerId}"]`);
2098
2120
  if (!itemEl) return;
2099
2121
  const layerState = this.state.layerStates[layerId];
2100
2122
  if (layerState == null ? void 0 : layerState.isCustomLayer) {
2123
+ const nativeLayerIds = (_a = this.customLayerRegistry) == null ? void 0 : _a.getNativeLayerIds(layerId);
2124
+ if (nativeLayerIds && nativeLayerIds.length > 0) {
2125
+ for (const nativeId of nativeLayerIds) {
2126
+ if (!this.state.originalStyles.has(nativeId)) {
2127
+ const nativeLayer = this.map.getLayer(nativeId);
2128
+ if (nativeLayer) {
2129
+ cacheOriginalLayerStyle(this.map, nativeId, this.state.originalStyles);
2130
+ }
2131
+ }
2132
+ }
2133
+ const editor3 = this.createNativeSubLayerStyleEditor(layerId, nativeLayerIds);
2134
+ if (editor3) {
2135
+ itemEl.appendChild(editor3);
2136
+ this.styleEditors.set(layerId, editor3);
2137
+ this.state.activeStyleEditor = layerId;
2138
+ setTimeout(() => {
2139
+ editor3.scrollIntoView({ behavior: "smooth", block: "nearest" });
2140
+ }, 50);
2141
+ return;
2142
+ }
2143
+ }
2101
2144
  const editor2 = this.createCustomLayerInfoPanel(layerId);
2102
2145
  itemEl.appendChild(editor2);
2103
2146
  this.styleEditors.set(layerId, editor2);
@@ -2176,6 +2219,106 @@ class LayerControl {
2176
2219
  editor.appendChild(actions);
2177
2220
  return editor;
2178
2221
  }
2222
+ /**
2223
+ * Create a combined style editor for custom layers with native MapLibre sublayers.
2224
+ * Groups controls by sublayer type (fill, line, circle, etc.).
2225
+ */
2226
+ createNativeSubLayerStyleEditor(layerId, nativeLayerIds) {
2227
+ const layersByType = /* @__PURE__ */ new Map();
2228
+ for (const nativeId of nativeLayerIds) {
2229
+ const layer = this.map.getLayer(nativeId);
2230
+ if (layer) {
2231
+ const type = layer.type;
2232
+ if (!layersByType.has(type)) {
2233
+ layersByType.set(type, []);
2234
+ }
2235
+ layersByType.get(type).push(nativeId);
2236
+ }
2237
+ }
2238
+ if (layersByType.size === 0) return null;
2239
+ const editor = document.createElement("div");
2240
+ editor.className = "layer-control-style-editor";
2241
+ const header = document.createElement("div");
2242
+ header.className = "style-editor-header";
2243
+ const title = document.createElement("span");
2244
+ title.className = "style-editor-title";
2245
+ title.textContent = "Edit Style";
2246
+ const closeBtn = document.createElement("button");
2247
+ closeBtn.className = "style-editor-close";
2248
+ closeBtn.innerHTML = "×";
2249
+ closeBtn.title = "Close";
2250
+ closeBtn.addEventListener("click", (e) => {
2251
+ e.stopPropagation();
2252
+ this.closeStyleEditor(layerId);
2253
+ });
2254
+ header.appendChild(title);
2255
+ header.appendChild(closeBtn);
2256
+ editor.appendChild(header);
2257
+ const controls = document.createElement("div");
2258
+ controls.className = "style-editor-controls";
2259
+ const typeLabels = {
2260
+ fill: "Fill",
2261
+ line: "Line",
2262
+ circle: "Circle",
2263
+ symbol: "Symbol",
2264
+ raster: "Raster"
2265
+ };
2266
+ for (const [type, ids] of layersByType) {
2267
+ if (layersByType.size > 1) {
2268
+ const sectionHeader = document.createElement("div");
2269
+ sectionHeader.className = "style-editor-section-header";
2270
+ sectionHeader.textContent = typeLabels[type] || type;
2271
+ controls.appendChild(sectionHeader);
2272
+ }
2273
+ const primaryId = ids[0];
2274
+ this.addStyleControlsForNativeGroup(controls, ids, primaryId, type);
2275
+ }
2276
+ const actions = document.createElement("div");
2277
+ actions.className = "style-editor-actions";
2278
+ const resetBtn = document.createElement("button");
2279
+ resetBtn.className = "style-editor-button style-editor-button-reset";
2280
+ resetBtn.textContent = "Reset";
2281
+ resetBtn.addEventListener("click", (e) => {
2282
+ e.stopPropagation();
2283
+ for (const nativeId of nativeLayerIds) {
2284
+ restoreOriginalStyle(this.map, nativeId, this.state.originalStyles);
2285
+ }
2286
+ this.closeStyleEditor(layerId);
2287
+ this.openStyleEditor(layerId);
2288
+ });
2289
+ const removeBtn = document.createElement("button");
2290
+ removeBtn.className = "style-editor-button style-editor-button-remove";
2291
+ removeBtn.textContent = "Remove";
2292
+ removeBtn.title = "Remove layer from map";
2293
+ removeBtn.addEventListener("click", (e) => {
2294
+ e.stopPropagation();
2295
+ if (confirm("Are you sure you want to remove this layer?")) {
2296
+ this.closeStyleEditor(layerId);
2297
+ this.removeLayer(layerId);
2298
+ }
2299
+ });
2300
+ const closeActionBtn = document.createElement("button");
2301
+ closeActionBtn.className = "style-editor-button style-editor-button-close";
2302
+ closeActionBtn.textContent = "Close";
2303
+ closeActionBtn.addEventListener("click", (e) => {
2304
+ e.stopPropagation();
2305
+ this.closeStyleEditor(layerId);
2306
+ });
2307
+ actions.appendChild(resetBtn);
2308
+ actions.appendChild(removeBtn);
2309
+ actions.appendChild(closeActionBtn);
2310
+ editor.appendChild(controls);
2311
+ editor.appendChild(actions);
2312
+ return editor;
2313
+ }
2314
+ /**
2315
+ * Add style controls for a group of native layers of the same type.
2316
+ * Changes to any control are applied to all layers in the group.
2317
+ */
2318
+ addStyleControlsForNativeGroup(container, layerIds, primaryLayerId, layerType) {
2319
+ this.nativeLayerGroups.set(primaryLayerId, layerIds);
2320
+ this.addStyleControlsForLayerType(container, primaryLayerId, layerType);
2321
+ }
2179
2322
  /**
2180
2323
  * Close style editor for a layer
2181
2324
  */
@@ -2185,6 +2328,7 @@ class LayerControl {
2185
2328
  editor.remove();
2186
2329
  this.styleEditors.delete(layerId);
2187
2330
  }
2331
+ this.nativeLayerGroups.clear();
2188
2332
  if (this.state.activeStyleEditor === layerId) {
2189
2333
  this.state.activeStyleEditor = null;
2190
2334
  }
@@ -2413,7 +2557,10 @@ class LayerControl {
2413
2557
  colorInput.addEventListener("input", () => {
2414
2558
  const color = colorInput.value;
2415
2559
  hexDisplay.value = color;
2416
- this.map.setPaintProperty(layerId, property, color);
2560
+ const targetIds = this.nativeLayerGroups.get(layerId) || [layerId];
2561
+ for (const id of targetIds) {
2562
+ this.map.setPaintProperty(id, property, color);
2563
+ }
2417
2564
  });
2418
2565
  inputWrapper.appendChild(colorInput);
2419
2566
  inputWrapper.appendChild(hexDisplay);
@@ -2446,7 +2593,10 @@ class LayerControl {
2446
2593
  slider.addEventListener("input", () => {
2447
2594
  const value = parseFloat(slider.value);
2448
2595
  valueDisplay.textContent = formatNumericValue(value, step);
2449
- this.map.setPaintProperty(layerId, property, value);
2596
+ const targetIds = this.nativeLayerGroups.get(layerId) || [layerId];
2597
+ for (const id of targetIds) {
2598
+ this.map.setPaintProperty(id, property, value);
2599
+ }
2450
2600
  });
2451
2601
  inputWrapper.appendChild(slider);
2452
2602
  inputWrapper.appendChild(valueDisplay);
@@ -3102,6 +3252,7 @@ class LayerControl {
3102
3252
  */
3103
3253
  removeLayer(layerId) {
3104
3254
  var _a, _b;
3255
+ this.state.isStyleOperationInProgress = true;
3105
3256
  const layerState = this.state.layerStates[layerId];
3106
3257
  if ((layerState == null ? void 0 : layerState.isCustomLayer) && this.customLayerRegistry) {
3107
3258
  this.removedCustomLayerIds.add(layerId);
@@ -3134,6 +3285,9 @@ class LayerControl {
3134
3285
  itemEl.remove();
3135
3286
  }
3136
3287
  (_b = this.onLayerRemove) == null ? void 0 : _b.call(this, layerId);
3288
+ setTimeout(() => {
3289
+ this.state.isStyleOperationInProgress = false;
3290
+ }, 200);
3137
3291
  }
3138
3292
  // ===== Drag and Drop Methods =====
3139
3293
  /**