@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.mjs CHANGED
@@ -2227,6 +2227,32 @@ function DrawingToolbar({
2227
2227
  }
2228
2228
  );
2229
2229
  }
2230
+ const BUILT_IN_BASEMAP_IDS = ["streets", "satellite", "dark"];
2231
+ const BUILT_IN_NAMES = {
2232
+ streets: "Streets",
2233
+ satellite: "Satellite",
2234
+ dark: "Dark"
2235
+ };
2236
+ function resolveBasemapChoices(order, customBasemaps) {
2237
+ const describe = (id) => {
2238
+ if (BUILT_IN_BASEMAP_IDS.includes(id)) {
2239
+ return { id, name: BUILT_IN_NAMES[id] ?? id, builtIn: true };
2240
+ }
2241
+ const custom = customBasemaps == null ? void 0 : customBasemaps[id];
2242
+ if (!custom) return void 0;
2243
+ return { id, name: custom.name || id, builtIn: false };
2244
+ };
2245
+ if (order) {
2246
+ return order.map(describe).filter((choice) => !!choice);
2247
+ }
2248
+ const customIds = Object.keys(customBasemaps ?? {}).filter(
2249
+ (id) => !BUILT_IN_BASEMAP_IDS.includes(id)
2250
+ );
2251
+ return [
2252
+ ...BUILT_IN_BASEMAP_IDS.map((id) => describe(id)),
2253
+ ...customIds.map(describe).filter((choice) => !!choice)
2254
+ ];
2255
+ }
2230
2256
  const PRESET_COLORS$1 = [
2231
2257
  "#3b82f6",
2232
2258
  "#ef4444",
@@ -2577,6 +2603,7 @@ function LayersPanel({
2577
2603
  is3DTerrainEnabled = false,
2578
2604
  onToggle3DTerrain,
2579
2605
  onUpdateAltitudeDisplayMode,
2606
+ availableBasemaps,
2580
2607
  hideSatellite = false,
2581
2608
  hideDark = false,
2582
2609
  hideTerrain = false,
@@ -3583,7 +3610,7 @@ function LayersPanel({
3583
3610
  )
3584
3611
  ] }),
3585
3612
  !hideBasemapSwitcher && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
3586
- /* @__PURE__ */ jsx("div", { className: "flex gap-1 flex-1", children: MAP_STYLES.filter((style) => {
3613
+ /* @__PURE__ */ jsx("div", { className: "flex gap-1 flex-1", children: (availableBasemaps ?? MAP_STYLES).filter((style) => {
3587
3614
  if (hideSatellite && style.id === "satellite") return false;
3588
3615
  if (hideDark && style.id === "dark") return false;
3589
3616
  return true;
@@ -7520,6 +7547,11 @@ function extract3DFlightPaths(features) {
7520
7547
  return paths;
7521
7548
  }
7522
7549
  const DEFAULT_LOCAL_GLYPHS_URL = "/fonts/{fontstack}/{range}.pbf";
7550
+ function basemapInsertAnchor(map) {
7551
+ if (map.getLayer("satellite-layer")) return "satellite-layer";
7552
+ if (map.getLayer("custom-polygon-fill")) return "custom-polygon-fill";
7553
+ return void 0;
7554
+ }
7523
7555
  function createBaseStyle(options) {
7524
7556
  const sources = {};
7525
7557
  const layers = [
@@ -7666,6 +7698,17 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
7666
7698
  const timelineUpdateTimerRef = useRef(null);
7667
7699
  const loadedBasemaps = useRef(new Set(enableSatellite ? ["satellite"] : []));
7668
7700
  const basemapLayerIds = useRef(new Map(enableSatellite ? [["satellite", ["satellite-layer"]]] : []));
7701
+ const availableBasemaps = useMemo(() => {
7702
+ const iconFor = (id) => {
7703
+ var _a;
7704
+ return ((_a = MAP_STYLES.find((style) => style.id === id)) == null ? void 0 : _a.icon) ?? Map$1;
7705
+ };
7706
+ return resolveBasemapChoices(basemapOrder, customBasemaps).map((choice) => ({
7707
+ id: choice.id,
7708
+ name: choice.name,
7709
+ icon: iconFor(choice.id)
7710
+ }));
7711
+ }, [basemapOrder, customBasemaps]);
7669
7712
  const loadingBasemaps = useRef(/* @__PURE__ */ new Set());
7670
7713
  const customBasemapRegistry = useRef(/* @__PURE__ */ new Map());
7671
7714
  const clusterPieManagers = useRef(/* @__PURE__ */ new Map());
@@ -9775,7 +9818,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
9775
9818
  newLayer.source = `${prefix}${newLayer.source}`;
9776
9819
  }
9777
9820
  try {
9778
- const beforeLayer = mapInstance.getLayer("satellite-layer") ? "satellite-layer" : mapInstance.getLayer("custom-polygon-fill") ? "custom-polygon-fill" : void 0;
9821
+ const beforeLayer = basemapInsertAnchor(mapInstance);
9779
9822
  mapInstance.addLayer(newLayer, beforeLayer);
9780
9823
  addedLayerIds.push(prefixedLayerId);
9781
9824
  } catch (e) {
@@ -9804,7 +9847,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
9804
9847
  console.error("Failed to load initial basemap:", err);
9805
9848
  });
9806
9849
  }
9807
- } else {
9850
+ } else if (mapInstance.getLayer("satellite-layer")) {
9808
9851
  mapInstance.setLayoutProperty("satellite-layer", "visibility", "visible");
9809
9852
  }
9810
9853
  if (customBasemaps) {
@@ -9828,12 +9871,12 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
9828
9871
  type: "raster",
9829
9872
  source: sourceId,
9830
9873
  layout: { visibility: isInitialStyle ? "visible" : "none" }
9831
- }, "satellite-layer");
9874
+ }, basemapInsertAnchor(mapInstance));
9832
9875
  loadedBasemaps.current.add(id);
9833
9876
  basemapLayerIds.current.set(id, [layerId]);
9834
9877
  }
9835
9878
  } else if (definition.type === "vector" && definition.style) {
9836
- loadedBasemaps.current.add(id);
9879
+ if (baseMapStyle === id) loadedBasemaps.current.add(id);
9837
9880
  }
9838
9881
  }
9839
9882
  }
@@ -10743,7 +10786,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10743
10786
  type: "raster",
10744
10787
  source: sourceId,
10745
10788
  layout: { visibility: "none" }
10746
- }, "satellite-layer");
10789
+ }, basemapInsertAnchor(map.current));
10747
10790
  loadedBasemaps.current.add(id);
10748
10791
  basemapLayerIds.current.set(id, [layerId]);
10749
10792
  }
@@ -11880,11 +11923,11 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
11880
11923
  }
11881
11924
  }, []);
11882
11925
  moveLabelsBeforeBasemapSymbolsRef.current = moveLabelsBeforeBasemapSymbols;
11883
- const loadBasemapStyle = useCallback(async (styleName) => {
11926
+ const loadBasemapStyle = useCallback(async (styleName, overrideStyleUrl) => {
11884
11927
  if (!map.current) return [];
11885
11928
  const mapInstance = map.current;
11886
11929
  const prefix = BASEMAP_LAYER_PREFIXES[styleName] || `${styleName}-`;
11887
- const styleUrl = EXTERNAL_STYLE_URLS[styleName];
11930
+ const styleUrl = overrideStyleUrl || EXTERNAL_STYLE_URLS[styleName];
11888
11931
  if (!styleUrl) {
11889
11932
  console.warn(`No external style URL for: ${styleName}`);
11890
11933
  return [];
@@ -11934,7 +11977,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
11934
11977
  newLayer.source = `${prefix}${newLayer.source}`;
11935
11978
  }
11936
11979
  try {
11937
- const beforeLayer = mapInstance.getLayer("satellite-layer") ? "satellite-layer" : mapInstance.getLayer("custom-polygon-fill") ? "custom-polygon-fill" : void 0;
11980
+ const beforeLayer = basemapInsertAnchor(mapInstance);
11938
11981
  mapInstance.addLayer(newLayer, beforeLayer);
11939
11982
  addedLayerIds.push(prefixedLayerId);
11940
11983
  } catch (e) {
@@ -11986,10 +12029,16 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
11986
12029
  type: "raster",
11987
12030
  source: sourceId,
11988
12031
  layout: { visibility: "none" }
11989
- }, "satellite-layer");
12032
+ }, basemapInsertAnchor(mapInstance));
11990
12033
  }
11991
12034
  loadedBasemaps.current.add(style);
11992
12035
  basemapLayerIds.current.set(style, [layerId]);
12036
+ } else if (customDef.type === "vector" && typeof customDef.style === "string") {
12037
+ loadingBasemaps.current.add(style);
12038
+ const layerIds = await loadBasemapStyle(style, customDef.style);
12039
+ basemapLayerIds.current.set(style, layerIds);
12040
+ loadedBasemaps.current.add(style);
12041
+ loadingBasemaps.current.delete(style);
11993
12042
  }
11994
12043
  }
11995
12044
  } else if (!loadedBasemaps.current.has(style) && !loadingBasemaps.current.has(style)) {
@@ -14675,6 +14724,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
14675
14724
  is3DTerrainEnabled,
14676
14725
  onToggle3DTerrain: handleToggle3DTerrain,
14677
14726
  onUpdateAltitudeDisplayMode: handleUpdateAltitudeDisplayMode,
14727
+ availableBasemaps,
14678
14728
  hideSatellite: !enableSatellite,
14679
14729
  hideDark: !enableDark,
14680
14730
  hideTerrain: !enableTerrain,