@octostar/map-component 0.2.17 → 0.2.18

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
@@ -2248,6 +2248,32 @@ function DrawingToolbar({
2248
2248
  }
2249
2249
  );
2250
2250
  }
2251
+ const BUILT_IN_BASEMAP_IDS = ["streets", "satellite", "dark"];
2252
+ const BUILT_IN_NAMES = {
2253
+ streets: "Streets",
2254
+ satellite: "Satellite",
2255
+ dark: "Dark"
2256
+ };
2257
+ function resolveBasemapChoices(order, customBasemaps) {
2258
+ const describe = (id) => {
2259
+ if (BUILT_IN_BASEMAP_IDS.includes(id)) {
2260
+ return { id, name: BUILT_IN_NAMES[id] ?? id, builtIn: true };
2261
+ }
2262
+ const custom = customBasemaps == null ? void 0 : customBasemaps[id];
2263
+ if (!custom) return void 0;
2264
+ return { id, name: custom.name || id, builtIn: false };
2265
+ };
2266
+ if (order) {
2267
+ return order.map(describe).filter((choice) => !!choice);
2268
+ }
2269
+ const customIds = Object.keys(customBasemaps ?? {}).filter(
2270
+ (id) => !BUILT_IN_BASEMAP_IDS.includes(id)
2271
+ );
2272
+ return [
2273
+ ...BUILT_IN_BASEMAP_IDS.map((id) => describe(id)),
2274
+ ...customIds.map(describe).filter((choice) => !!choice)
2275
+ ];
2276
+ }
2251
2277
  const PRESET_COLORS$1 = [
2252
2278
  "#3b82f6",
2253
2279
  "#ef4444",
@@ -2598,6 +2624,7 @@ function LayersPanel({
2598
2624
  is3DTerrainEnabled = false,
2599
2625
  onToggle3DTerrain,
2600
2626
  onUpdateAltitudeDisplayMode,
2627
+ availableBasemaps,
2601
2628
  hideSatellite = false,
2602
2629
  hideDark = false,
2603
2630
  hideTerrain = false,
@@ -3604,7 +3631,7 @@ function LayersPanel({
3604
3631
  )
3605
3632
  ] }),
3606
3633
  !hideBasemapSwitcher && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
3607
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex gap-1 flex-1", children: MAP_STYLES.filter((style) => {
3634
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex gap-1 flex-1", children: (availableBasemaps ?? MAP_STYLES).filter((style) => {
3608
3635
  if (hideSatellite && style.id === "satellite") return false;
3609
3636
  if (hideDark && style.id === "dark") return false;
3610
3637
  return true;
@@ -7541,6 +7568,11 @@ function extract3DFlightPaths(features) {
7541
7568
  return paths;
7542
7569
  }
7543
7570
  const DEFAULT_LOCAL_GLYPHS_URL = "/fonts/{fontstack}/{range}.pbf";
7571
+ function basemapInsertAnchor(map) {
7572
+ if (map.getLayer("satellite-layer")) return "satellite-layer";
7573
+ if (map.getLayer("custom-polygon-fill")) return "custom-polygon-fill";
7574
+ return void 0;
7575
+ }
7544
7576
  function createBaseStyle(options) {
7545
7577
  const sources = {};
7546
7578
  const layers = [
@@ -7687,6 +7719,17 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
7687
7719
  const timelineUpdateTimerRef = react.useRef(null);
7688
7720
  const loadedBasemaps = react.useRef(new Set(enableSatellite ? ["satellite"] : []));
7689
7721
  const basemapLayerIds = react.useRef(new Map(enableSatellite ? [["satellite", ["satellite-layer"]]] : []));
7722
+ const availableBasemaps = react.useMemo(() => {
7723
+ const iconFor = (id) => {
7724
+ var _a;
7725
+ return ((_a = MAP_STYLES.find((style) => style.id === id)) == null ? void 0 : _a.icon) ?? lucideReact.Map;
7726
+ };
7727
+ return resolveBasemapChoices(basemapOrder, customBasemaps).map((choice) => ({
7728
+ id: choice.id,
7729
+ name: choice.name,
7730
+ icon: iconFor(choice.id)
7731
+ }));
7732
+ }, [basemapOrder, customBasemaps]);
7690
7733
  const loadingBasemaps = react.useRef(/* @__PURE__ */ new Set());
7691
7734
  const customBasemapRegistry = react.useRef(/* @__PURE__ */ new Map());
7692
7735
  const clusterPieManagers = react.useRef(/* @__PURE__ */ new Map());
@@ -9796,7 +9839,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
9796
9839
  newLayer.source = `${prefix}${newLayer.source}`;
9797
9840
  }
9798
9841
  try {
9799
- const beforeLayer = mapInstance.getLayer("satellite-layer") ? "satellite-layer" : mapInstance.getLayer("custom-polygon-fill") ? "custom-polygon-fill" : void 0;
9842
+ const beforeLayer = basemapInsertAnchor(mapInstance);
9800
9843
  mapInstance.addLayer(newLayer, beforeLayer);
9801
9844
  addedLayerIds.push(prefixedLayerId);
9802
9845
  } catch (e) {
@@ -9825,7 +9868,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
9825
9868
  console.error("Failed to load initial basemap:", err);
9826
9869
  });
9827
9870
  }
9828
- } else {
9871
+ } else if (mapInstance.getLayer("satellite-layer")) {
9829
9872
  mapInstance.setLayoutProperty("satellite-layer", "visibility", "visible");
9830
9873
  }
9831
9874
  if (customBasemaps) {
@@ -9849,12 +9892,12 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
9849
9892
  type: "raster",
9850
9893
  source: sourceId,
9851
9894
  layout: { visibility: isInitialStyle ? "visible" : "none" }
9852
- }, "satellite-layer");
9895
+ }, basemapInsertAnchor(mapInstance));
9853
9896
  loadedBasemaps.current.add(id);
9854
9897
  basemapLayerIds.current.set(id, [layerId]);
9855
9898
  }
9856
9899
  } else if (definition.type === "vector" && definition.style) {
9857
- loadedBasemaps.current.add(id);
9900
+ if (baseMapStyle === id) loadedBasemaps.current.add(id);
9858
9901
  }
9859
9902
  }
9860
9903
  }
@@ -10764,7 +10807,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
10764
10807
  type: "raster",
10765
10808
  source: sourceId,
10766
10809
  layout: { visibility: "none" }
10767
- }, "satellite-layer");
10810
+ }, basemapInsertAnchor(map.current));
10768
10811
  loadedBasemaps.current.add(id);
10769
10812
  basemapLayerIds.current.set(id, [layerId]);
10770
10813
  }
@@ -11901,11 +11944,11 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
11901
11944
  }
11902
11945
  }, []);
11903
11946
  moveLabelsBeforeBasemapSymbolsRef.current = moveLabelsBeforeBasemapSymbols;
11904
- const loadBasemapStyle = react.useCallback(async (styleName) => {
11947
+ const loadBasemapStyle = react.useCallback(async (styleName, overrideStyleUrl) => {
11905
11948
  if (!map.current) return [];
11906
11949
  const mapInstance = map.current;
11907
11950
  const prefix = BASEMAP_LAYER_PREFIXES[styleName] || `${styleName}-`;
11908
- const styleUrl = EXTERNAL_STYLE_URLS[styleName];
11951
+ const styleUrl = overrideStyleUrl || EXTERNAL_STYLE_URLS[styleName];
11909
11952
  if (!styleUrl) {
11910
11953
  console.warn(`No external style URL for: ${styleName}`);
11911
11954
  return [];
@@ -11955,7 +11998,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
11955
11998
  newLayer.source = `${prefix}${newLayer.source}`;
11956
11999
  }
11957
12000
  try {
11958
- const beforeLayer = mapInstance.getLayer("satellite-layer") ? "satellite-layer" : mapInstance.getLayer("custom-polygon-fill") ? "custom-polygon-fill" : void 0;
12001
+ const beforeLayer = basemapInsertAnchor(mapInstance);
11959
12002
  mapInstance.addLayer(newLayer, beforeLayer);
11960
12003
  addedLayerIds.push(prefixedLayerId);
11961
12004
  } catch (e) {
@@ -12007,10 +12050,16 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
12007
12050
  type: "raster",
12008
12051
  source: sourceId,
12009
12052
  layout: { visibility: "none" }
12010
- }, "satellite-layer");
12053
+ }, basemapInsertAnchor(mapInstance));
12011
12054
  }
12012
12055
  loadedBasemaps.current.add(style);
12013
12056
  basemapLayerIds.current.set(style, [layerId]);
12057
+ } else if (customDef.type === "vector" && typeof customDef.style === "string") {
12058
+ loadingBasemaps.current.add(style);
12059
+ const layerIds = await loadBasemapStyle(style, customDef.style);
12060
+ basemapLayerIds.current.set(style, layerIds);
12061
+ loadedBasemaps.current.add(style);
12062
+ loadingBasemaps.current.delete(style);
12014
12063
  }
12015
12064
  }
12016
12065
  } else if (!loadedBasemaps.current.has(style) && !loadingBasemaps.current.has(style)) {
@@ -14696,6 +14745,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
14696
14745
  is3DTerrainEnabled,
14697
14746
  onToggle3DTerrain: handleToggle3DTerrain,
14698
14747
  onUpdateAltitudeDisplayMode: handleUpdateAltitudeDisplayMode,
14748
+ availableBasemaps,
14699
14749
  hideSatellite: !enableSatellite,
14700
14750
  hideDark: !enableDark,
14701
14751
  hideTerrain: !enableTerrain,