@classic-homes/maps-react 0.1.2 → 0.1.4

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.js CHANGED
@@ -7,10 +7,11 @@ import maplibregl from 'maplibre-gl';
7
7
  import 'maplibre-gl/dist/maplibre-gl.css';
8
8
  import '@classic-homes/maps-core/styles/controls.css';
9
9
  import '@classic-homes/maps-core/styles/marker.css';
10
- import { generateMapDescription, applyMarkerProtection, applyMarkerChildProtection, removeMarkerProtection, darkBasicStyle, lightBasicStyle, darkTheme, lightTheme, THEME_DARK, THEME_LIGHT, calculateBounds, computeVerticalOffsetStyle, computePositionClasses, formatCoordinates } from '@classic-homes/maps-core';
11
- export { THEME_DARK, THEME_LIGHT, calculateBounds, calculateCentroid, combineBounds, countFeaturesByType, createHoverExpression, createSelectionExpression, darkBasicStyle, darkTheme, expandCluster, expandClusterToBounds, extendBounds, filterByGeometryType, formatArea, formatCoordinates, formatDistance, generateMapDescription, getClusterBounds, getClusterChildren, getClusterExpansionZoom, getClusterLeaves, getHighlightStyle, getSelectionStyle, isClusterFeature, isValidBounds, lightBasicStyle, lightTheme, loadGeoJSON, validateGeoJSON } from '@classic-homes/maps-core';
10
+ import { generateMapDescription, applyMarkerProtection, applyMarkerChildProtection, removeMarkerProtection, darkBasicStyle, lightBasicStyle, darkTheme, lightTheme, THEME_DARK, THEME_LIGHT, calculateBounds, computeVerticalOffsetStyle, computePositionClasses, formatCoordinates, getAvailableBasemaps, FREE_BASEMAPS, resolveBasemapThumbnail, resolveBasemapStyle } from '@classic-homes/maps-core';
11
+ export { BUILTIN_BASEMAPS, FREE_BASEMAPS, OSM_STANDARD, THEME_DARK, THEME_LIGHT, calculateBounds, calculateCentroid, combineBounds, countFeaturesByType, createHoverExpression, createSelectionExpression, darkBasicStyle, darkTheme, expandCluster, expandClusterToBounds, extendBounds, filterByGeometryType, formatArea, formatCoordinates, formatDistance, generateMapDescription, getAvailableBasemaps, getClusterBounds, getClusterChildren, getClusterExpansionZoom, getClusterLeaves, getHighlightStyle, getSelectionStyle, isClusterFeature, isValidBounds, lightBasicStyle, lightTheme, loadGeoJSON, resolveBasemapStyle, validateGeoJSON } from '@classic-homes/maps-core';
12
12
  import * as ReactDOM from 'react-dom';
13
13
  import { cva } from 'class-variance-authority';
14
+ import '@classic-homes/maps-core/styles/basemap-switcher.css';
14
15
 
15
16
  // src/components/base/MapContainer.tsx
16
17
  function cn(...inputs) {
@@ -272,11 +273,7 @@ function useReducedMotion() {
272
273
  }, []);
273
274
  return prefersReducedMotion2;
274
275
  }
275
- var MapContext = React6.createContext({
276
- map: null,
277
- loaded: false,
278
- controlOffsets: {}
279
- });
276
+ var MapContext = React6.createContext(null);
280
277
  function useMap() {
281
278
  const context = React6.useContext(MapContext);
282
279
  if (!context) {
@@ -346,6 +343,14 @@ var Map = React6.forwardRef(
346
343
  const mapRef = React6.useRef(null);
347
344
  const [mapLoaded, setMapLoaded] = React6.useState(false);
348
345
  const [mapError, setMapError] = React6.useState(null);
346
+ const [styleVersion, setStyleVersion] = React6.useState(0);
347
+ const activeStyleOverrideRef = React6.useRef(
348
+ null
349
+ );
350
+ const setMapStyle = React6.useCallback((style) => {
351
+ activeStyleOverrideRef.current = style;
352
+ mapRef.current?.setStyle(style);
353
+ }, []);
349
354
  const customControlRegistryRef = React6.useRef({
350
355
  "top-left": [],
351
356
  "top-right": [],
@@ -355,6 +360,10 @@ var Map = React6.forwardRef(
355
360
  const [, forceUpdate] = React6.useReducer((x) => x + 1, 0);
356
361
  const prefersReducedMotion2 = useReducedMotion();
357
362
  const { style: themeStyle } = useMapTheme(themePref);
363
+ const onLoadRef = React6.useRef(onLoad);
364
+ onLoadRef.current = onLoad;
365
+ const onErrorRef = React6.useRef(onError);
366
+ onErrorRef.current = onError;
358
367
  const mapStyle = customStyle || themeStyle;
359
368
  const controlOffsets = React6.useMemo(() => {
360
369
  const offsets = {
@@ -450,6 +459,9 @@ var Map = React6.forwardRef(
450
459
  attributionControl: attributionControl ? { customAttribution } : false
451
460
  });
452
461
  mapRef.current = map;
462
+ map.on("style.load", () => {
463
+ setStyleVersion((v) => v + 1);
464
+ });
453
465
  if (navigationControl) {
454
466
  map.addControl(
455
467
  new maplibregl.NavigationControl({
@@ -483,12 +495,15 @@ var Map = React6.forwardRef(
483
495
  animate: animation && !prefersReducedMotion2
484
496
  });
485
497
  }
486
- onLoad?.({ type: "load", loaded: true });
498
+ onLoadRef.current?.({ type: "load", loaded: true });
487
499
  });
488
500
  map.on("error", (e) => {
489
501
  const errorMessage = e.error?.message || "Map error";
490
- setMapError(errorMessage);
491
- onError?.({ type: "error", message: errorMessage, error: e.error });
502
+ const isTransient = errorMessage.includes("non-existing layer") || errorMessage.includes("Cannot filter");
503
+ if (!isTransient) {
504
+ setMapError(errorMessage);
505
+ }
506
+ onErrorRef.current?.({ type: "error", message: errorMessage, error: e.error });
492
507
  });
493
508
  return () => {
494
509
  map.remove();
@@ -498,13 +513,24 @@ var Map = React6.forwardRef(
498
513
  } catch (err) {
499
514
  const errorMessage = err instanceof Error ? err.message : "Failed to initialize map";
500
515
  setMapError(errorMessage);
501
- onError?.({ type: "error", message: errorMessage, error: err });
516
+ onErrorRef.current?.({ type: "error", message: errorMessage, error: err });
502
517
  }
503
518
  }, []);
519
+ const styleInitialized = React6.useRef(false);
504
520
  React6.useEffect(() => {
505
521
  if (!mapRef.current || !mapLoaded) return;
522
+ if (!styleInitialized.current) {
523
+ styleInitialized.current = true;
524
+ return;
525
+ }
526
+ if (activeStyleOverrideRef.current) return;
506
527
  mapRef.current.setStyle(mapStyle);
507
528
  }, [mapStyle, mapLoaded]);
529
+ React6.useEffect(() => {
530
+ if (customStyle) {
531
+ activeStyleOverrideRef.current = null;
532
+ }
533
+ }, [customStyle]);
508
534
  React6.useEffect(() => {
509
535
  const map = mapRef.current;
510
536
  if (!map || !mapLoaded) return;
@@ -625,7 +651,9 @@ var Map = React6.forwardRef(
625
651
  controlOffsets,
626
652
  registerControl,
627
653
  unregisterControl,
628
- getCustomControlOffset
654
+ getCustomControlOffset,
655
+ styleVersion,
656
+ setMapStyle
629
657
  },
630
658
  children: [
631
659
  /* @__PURE__ */ jsx("div", { ref: containerRef, className: "absolute inset-0" }),
@@ -657,7 +685,7 @@ var Source = ({
657
685
  fitBoundsAnimate = true,
658
686
  children
659
687
  }) => {
660
- const { map, loaded } = useMap();
688
+ const { map, loaded, styleVersion } = useMap();
661
689
  const sourceAdded = React6.useRef(false);
662
690
  const initialFitDone = React6.useRef(false);
663
691
  const fitBoundsParamsRef = React6.useRef({
@@ -693,7 +721,7 @@ var Source = ({
693
721
  return;
694
722
  }
695
723
  const prefersReducedMotion2 = typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
696
- requestAnimationFrame(() => {
724
+ const rafHandle = requestAnimationFrame(() => {
697
725
  if (cancelledRef.current || initialFitDone.current) return;
698
726
  try {
699
727
  const centerLng = (swLng + neLng) / 2;
@@ -716,6 +744,7 @@ var Source = ({
716
744
  console.warn("[maps-react] Source: fitBounds failed", err);
717
745
  }
718
746
  });
747
+ return rafHandle;
719
748
  },
720
749
  [map]
721
750
  );
@@ -791,18 +820,21 @@ var Source = ({
791
820
  return;
792
821
  }
793
822
  const cancelledRef = { current: false };
823
+ const rafHandles = [];
794
824
  const handleSourceData = (e) => {
795
825
  if (cancelledRef.current) return;
796
826
  if (e.sourceId === id && e.isSourceLoaded) {
797
827
  map.off("sourcedata", handleSourceData);
798
- performFitBounds(cancelledRef);
828
+ const h = performFitBounds(cancelledRef);
829
+ if (h !== void 0) rafHandles.push(h);
799
830
  }
800
831
  };
801
832
  map.on("sourcedata", handleSourceData);
802
833
  const handleIdle = () => {
803
834
  if (cancelledRef.current) return;
804
835
  map.off("idle", handleIdle);
805
- performFitBounds(cancelledRef);
836
+ const h = performFitBounds(cancelledRef);
837
+ if (h !== void 0) rafHandles.push(h);
806
838
  };
807
839
  map.once("idle", handleIdle);
808
840
  map.addSource(id, sourceConfig);
@@ -811,12 +843,16 @@ var Source = ({
811
843
  if (source && map.isSourceLoaded(id)) {
812
844
  map.off("sourcedata", handleSourceData);
813
845
  map.off("idle", handleIdle);
814
- performFitBounds(cancelledRef);
846
+ const h = performFitBounds(cancelledRef);
847
+ if (h !== void 0) rafHandles.push(h);
815
848
  }
816
849
  const cleanupListeners = () => {
817
850
  cancelledRef.current = true;
818
851
  map.off("sourcedata", handleSourceData);
819
852
  map.off("idle", handleIdle);
853
+ for (const h of rafHandles) {
854
+ cancelAnimationFrame(h);
855
+ }
820
856
  };
821
857
  return () => {
822
858
  cleanupListeners();
@@ -838,7 +874,6 @@ var Source = ({
838
874
  } catch {
839
875
  }
840
876
  sourceAdded.current = false;
841
- initialFitDone.current = false;
842
877
  }
843
878
  };
844
879
  } catch (err) {
@@ -858,8 +893,10 @@ var Source = ({
858
893
  clusterMaxZoom,
859
894
  generateId,
860
895
  promoteId,
861
- performFitBounds
896
+ performFitBounds,
862
897
  // stable due to using ref for params
898
+ styleVersion
899
+ // re-add source after basemap style changes
863
900
  ]);
864
901
  React6.useEffect(() => {
865
902
  if (!map || !loaded || !sourceAdded.current || type !== "geojson") return;
@@ -899,6 +936,12 @@ var Marker = React6.forwardRef(
899
936
  const originalLngLatRef = React6.useRef();
900
937
  const clickHandlerRef = React6.useRef(null);
901
938
  const [mounted, setMounted] = React6.useState(false);
939
+ const onClickRef = React6.useRef(onClick);
940
+ onClickRef.current = onClick;
941
+ const onDragRef = React6.useRef(onDrag);
942
+ onDragRef.current = onDrag;
943
+ const onDragEndRef = React6.useRef(onDragEnd);
944
+ onDragEndRef.current = onDragEnd;
902
945
  React6.useEffect(() => {
903
946
  setMounted(true);
904
947
  return () => setMounted(false);
@@ -940,12 +983,13 @@ var Marker = React6.forwardRef(
940
983
  ref.current = marker;
941
984
  }
942
985
  }
943
- if (onClick) {
986
+ {
944
987
  const element = marker.getElement();
945
988
  const handleClick = (e) => {
989
+ if (!onClickRef.current) return;
946
990
  e.stopPropagation();
947
991
  const lngLat = marker.getLngLat();
948
- onClick({
992
+ onClickRef.current({
949
993
  type: "click",
950
994
  markerId: id || "",
951
995
  lngLat: [lngLat.lng, lngLat.lat],
@@ -961,26 +1005,22 @@ var Marker = React6.forwardRef(
961
1005
  originalLngLatRef.current = [lngLat.lng, lngLat.lat];
962
1006
  });
963
1007
  marker.on("drag", () => {
964
- if (onDrag) {
965
- const lngLat = marker.getLngLat();
966
- onDrag({
967
- type: "drag",
968
- markerId: id || "",
969
- lngLat: [lngLat.lng, lngLat.lat],
970
- originalLngLat: originalLngLatRef.current
971
- });
972
- }
1008
+ const lngLat = marker.getLngLat();
1009
+ onDragRef.current?.({
1010
+ type: "drag",
1011
+ markerId: id || "",
1012
+ lngLat: [lngLat.lng, lngLat.lat],
1013
+ originalLngLat: originalLngLatRef.current
1014
+ });
973
1015
  });
974
1016
  marker.on("dragend", () => {
975
- if (onDragEnd) {
976
- const lngLat = marker.getLngLat();
977
- onDragEnd({
978
- type: "dragend",
979
- markerId: id || "",
980
- lngLat: [lngLat.lng, lngLat.lat],
981
- originalLngLat: originalLngLatRef.current
982
- });
983
- }
1017
+ const lngLat = marker.getLngLat();
1018
+ onDragEndRef.current?.({
1019
+ type: "dragend",
1020
+ markerId: id || "",
1021
+ lngLat: [lngLat.lng, lngLat.lat],
1022
+ originalLngLat: originalLngLatRef.current
1023
+ });
984
1024
  });
985
1025
  }
986
1026
  return () => {
@@ -1070,8 +1110,14 @@ var Popup = React6.forwardRef(
1070
1110
  }, ref) => {
1071
1111
  const { map, loaded } = useMap();
1072
1112
  const popupRef = React6.useRef(null);
1113
+ const onOpenRef = React6.useRef(onOpen);
1114
+ onOpenRef.current = onOpen;
1115
+ const onCloseRef = React6.useRef(onClose);
1116
+ onCloseRef.current = onClose;
1117
+ const coordinatesRef = React6.useRef(coordinates);
1118
+ coordinatesRef.current = coordinates;
1073
1119
  const containerRef = React6.useRef(null);
1074
- if (!containerRef.current) {
1120
+ if (!containerRef.current && typeof document !== "undefined") {
1075
1121
  containerRef.current = document.createElement("div");
1076
1122
  containerRef.current.className = "maplibregl-popup-content-wrapper";
1077
1123
  }
@@ -1094,23 +1140,16 @@ var Popup = React6.forwardRef(
1094
1140
  });
1095
1141
  popup.setDOMContent(containerRef.current);
1096
1142
  popupRef.current = popup;
1097
- if (ref) {
1098
- if (typeof ref === "function") {
1099
- ref(popup);
1100
- } else {
1101
- ref.current = popup;
1102
- }
1103
- }
1104
1143
  popup.on("open", () => {
1105
- onOpen?.({
1144
+ onOpenRef.current?.({
1106
1145
  type: "open",
1107
- lngLat: coordinates
1146
+ lngLat: coordinatesRef.current
1108
1147
  });
1109
1148
  });
1110
1149
  popup.on("close", () => {
1111
- onClose?.({
1150
+ onCloseRef.current?.({
1112
1151
  type: "close",
1113
- lngLat: coordinates
1152
+ lngLat: coordinatesRef.current
1114
1153
  });
1115
1154
  });
1116
1155
  return () => {
@@ -1126,12 +1165,16 @@ var Popup = React6.forwardRef(
1126
1165
  anchor,
1127
1166
  offset,
1128
1167
  maxWidth,
1129
- focusAfterOpen,
1130
- ref,
1131
- onOpen,
1132
- onClose,
1133
- coordinates
1168
+ focusAfterOpen
1134
1169
  ]);
1170
+ React6.useEffect(() => {
1171
+ if (!popupRef.current || !ref) return;
1172
+ if (typeof ref === "function") {
1173
+ ref(popupRef.current);
1174
+ } else {
1175
+ ref.current = popupRef.current;
1176
+ }
1177
+ }, [ref]);
1135
1178
  React6.useEffect(() => {
1136
1179
  if (popupRef.current) {
1137
1180
  popupRef.current.setLngLat(coordinates);
@@ -1139,10 +1182,11 @@ var Popup = React6.forwardRef(
1139
1182
  }, [coordinates]);
1140
1183
  React6.useEffect(() => {
1141
1184
  if (!map || !popupRef.current || !contentReady) return;
1185
+ let rafHandle;
1142
1186
  if (open) {
1143
1187
  popupRef.current.setLngLat(coordinates).addTo(map);
1144
1188
  if (autoPan) {
1145
- requestAnimationFrame(() => {
1189
+ rafHandle = requestAnimationFrame(() => {
1146
1190
  if (popupRef.current && map) {
1147
1191
  panToFitPopup(map, popupRef.current, normalizePadding(autoPanPadding));
1148
1192
  }
@@ -1151,7 +1195,13 @@ var Popup = React6.forwardRef(
1151
1195
  } else {
1152
1196
  popupRef.current.remove();
1153
1197
  }
1198
+ return () => {
1199
+ if (rafHandle !== void 0) {
1200
+ cancelAnimationFrame(rafHandle);
1201
+ }
1202
+ };
1154
1203
  }, [map, open, coordinates, autoPan, autoPanPadding, contentReady]);
1204
+ if (!containerRef.current) return null;
1155
1205
  return ReactDOM.createPortal(
1156
1206
  /* @__PURE__ */ jsx("div", { ref: contentCallbackRef, children }),
1157
1207
  containerRef.current
@@ -1239,11 +1289,14 @@ function useLayer({
1239
1289
  onHover,
1240
1290
  hoverThrottleMs = 0
1241
1291
  }) {
1242
- const { map, loaded } = useMap();
1292
+ const { map, loaded, styleVersion } = useMap();
1243
1293
  const [layerAdded, setLayerAdded] = React6.useState(false);
1244
1294
  const hoveredFeatureId = React6.useRef(null);
1245
1295
  const lastHoverCallTime = React6.useRef(0);
1246
1296
  const lastMousePosition = React6.useRef(null);
1297
+ React6.useEffect(() => {
1298
+ hoveredFeatureId.current = null;
1299
+ }, [styleVersion]);
1247
1300
  React6.useEffect(() => {
1248
1301
  if (!map || !loaded) return;
1249
1302
  if (!map.getSource(source)) {
@@ -1270,7 +1323,7 @@ function useLayer({
1270
1323
  }
1271
1324
  addLayer();
1272
1325
  function addLayer() {
1273
- if (layerAdded || map.getLayer(id)) {
1326
+ if (map.getLayer(id)) {
1274
1327
  setLayerAdded(true);
1275
1328
  return;
1276
1329
  }
@@ -1304,7 +1357,7 @@ function useLayer({
1304
1357
  }
1305
1358
  }
1306
1359
  return () => {
1307
- if (map && layerAdded) {
1360
+ if (map) {
1308
1361
  try {
1309
1362
  if (map.getLayer(id)) {
1310
1363
  map.removeLayer(id);
@@ -1314,29 +1367,23 @@ function useLayer({
1314
1367
  setLayerAdded(false);
1315
1368
  }
1316
1369
  };
1317
- }, [map, loaded, id, source, sourceLayer, type, beforeId, layerAdded]);
1370
+ }, [map, loaded, id, source, sourceLayer, type, beforeId, styleVersion]);
1318
1371
  React6.useEffect(() => {
1319
1372
  if (!map || !layerAdded) return;
1320
- try {
1321
- map.setLayoutProperty(id, "visibility", visible ? "visible" : "none");
1322
- } catch {
1323
- }
1373
+ if (!map.getLayer(id)) return;
1374
+ map.setLayoutProperty(id, "visibility", visible ? "visible" : "none");
1324
1375
  }, [map, id, visible, layerAdded]);
1325
1376
  React6.useEffect(() => {
1326
1377
  if (!map || !layerAdded) return;
1327
- try {
1328
- Object.entries(paint).forEach(([key, value]) => {
1329
- map.setPaintProperty(id, key, value);
1330
- });
1331
- } catch {
1332
- }
1378
+ if (!map.getLayer(id)) return;
1379
+ Object.entries(paint).forEach(([key, value]) => {
1380
+ map.setPaintProperty(id, key, value);
1381
+ });
1333
1382
  }, [map, id, paint, layerAdded]);
1334
1383
  React6.useEffect(() => {
1335
1384
  if (!map || !layerAdded || !filter) return;
1336
- try {
1337
- map.setFilter(id, filter);
1338
- } catch {
1339
- }
1385
+ if (!map.getLayer(id)) return;
1386
+ map.setFilter(id, filter);
1340
1387
  }, [map, id, filter, layerAdded]);
1341
1388
  React6.useEffect(() => {
1342
1389
  if (!map || !layerAdded) return;
@@ -1454,8 +1501,6 @@ function useLayer({
1454
1501
  }, [map, id, source, sourceLayer, onClick, onHover, hoverThrottleMs, layerAdded]);
1455
1502
  return { layerAdded };
1456
1503
  }
1457
-
1458
- // src/components/layers/FillLayer.tsx
1459
1504
  var FillLayer = ({
1460
1505
  id,
1461
1506
  source,
@@ -1476,17 +1521,28 @@ var FillLayer = ({
1476
1521
  fillTranslate,
1477
1522
  fillAntialias
1478
1523
  }) => {
1479
- const paint = {};
1480
- const layout = {};
1481
- if (fillColor !== void 0) paint["fill-color"] = fillColor;
1482
- if (fillOpacity !== void 0) paint["fill-opacity"] = fillOpacity;
1483
- if (fillOutlineColor !== void 0) paint["fill-outline-color"] = fillOutlineColor;
1484
- if (fillPattern !== void 0) paint["fill-pattern"] = fillPattern;
1485
- if (fillTranslate !== void 0) paint["fill-translate"] = fillTranslate;
1486
- if (fillAntialias !== void 0) paint["fill-antialias"] = fillAntialias;
1487
- if (opacity !== void 0 && fillOpacity === void 0) {
1488
- paint["fill-opacity"] = opacity;
1489
- }
1524
+ const paint = React6.useMemo(() => {
1525
+ const p = {};
1526
+ if (fillColor !== void 0) p["fill-color"] = fillColor;
1527
+ if (fillOpacity !== void 0) p["fill-opacity"] = fillOpacity;
1528
+ if (fillOutlineColor !== void 0) p["fill-outline-color"] = fillOutlineColor;
1529
+ if (fillPattern !== void 0) p["fill-pattern"] = fillPattern;
1530
+ if (fillTranslate !== void 0) p["fill-translate"] = fillTranslate;
1531
+ if (fillAntialias !== void 0) p["fill-antialias"] = fillAntialias;
1532
+ if (opacity !== void 0 && fillOpacity === void 0) {
1533
+ p["fill-opacity"] = opacity;
1534
+ }
1535
+ return p;
1536
+ }, [
1537
+ fillColor,
1538
+ fillOpacity,
1539
+ fillOutlineColor,
1540
+ fillPattern,
1541
+ fillTranslate,
1542
+ fillAntialias,
1543
+ opacity
1544
+ ]);
1545
+ const layout = React6.useMemo(() => ({}), []);
1490
1546
  useLayer({
1491
1547
  id,
1492
1548
  source,
@@ -1506,8 +1562,6 @@ var FillLayer = ({
1506
1562
  return null;
1507
1563
  };
1508
1564
  FillLayer.displayName = "FillLayer";
1509
-
1510
- // src/components/layers/LineLayer.tsx
1511
1565
  var LineLayer = ({
1512
1566
  id,
1513
1567
  source,
@@ -1532,21 +1586,37 @@ var LineLayer = ({
1532
1586
  lineOffset,
1533
1587
  lineGradient
1534
1588
  }) => {
1535
- const paint = {};
1536
- const layout = {};
1537
- if (lineColor !== void 0) paint["line-color"] = lineColor;
1538
- if (lineWidth !== void 0) paint["line-width"] = lineWidth;
1539
- if (lineOpacity !== void 0) paint["line-opacity"] = lineOpacity;
1540
- if (lineBlur !== void 0) paint["line-blur"] = lineBlur;
1541
- if (lineDasharray !== void 0) paint["line-dasharray"] = lineDasharray;
1542
- if (lineGapWidth !== void 0) paint["line-gap-width"] = lineGapWidth;
1543
- if (lineOffset !== void 0) paint["line-offset"] = lineOffset;
1544
- if (lineGradient !== void 0) paint["line-gradient"] = lineGradient;
1545
- if (lineCap !== void 0) layout["line-cap"] = lineCap;
1546
- if (lineJoin !== void 0) layout["line-join"] = lineJoin;
1547
- if (opacity !== void 0 && lineOpacity === void 0) {
1548
- paint["line-opacity"] = opacity;
1549
- }
1589
+ const paint = React6.useMemo(() => {
1590
+ const p = {};
1591
+ if (lineColor !== void 0) p["line-color"] = lineColor;
1592
+ if (lineWidth !== void 0) p["line-width"] = lineWidth;
1593
+ if (lineOpacity !== void 0) p["line-opacity"] = lineOpacity;
1594
+ if (lineBlur !== void 0) p["line-blur"] = lineBlur;
1595
+ if (lineDasharray !== void 0) p["line-dasharray"] = lineDasharray;
1596
+ if (lineGapWidth !== void 0) p["line-gap-width"] = lineGapWidth;
1597
+ if (lineOffset !== void 0) p["line-offset"] = lineOffset;
1598
+ if (lineGradient !== void 0) p["line-gradient"] = lineGradient;
1599
+ if (opacity !== void 0 && lineOpacity === void 0) {
1600
+ p["line-opacity"] = opacity;
1601
+ }
1602
+ return p;
1603
+ }, [
1604
+ lineColor,
1605
+ lineWidth,
1606
+ lineOpacity,
1607
+ lineBlur,
1608
+ lineDasharray,
1609
+ lineGapWidth,
1610
+ lineOffset,
1611
+ lineGradient,
1612
+ opacity
1613
+ ]);
1614
+ const layout = React6.useMemo(() => {
1615
+ const l = {};
1616
+ if (lineCap !== void 0) l["line-cap"] = lineCap;
1617
+ if (lineJoin !== void 0) l["line-join"] = lineJoin;
1618
+ return l;
1619
+ }, [lineCap, lineJoin]);
1550
1620
  useLayer({
1551
1621
  id,
1552
1622
  source,
@@ -1566,8 +1636,6 @@ var LineLayer = ({
1566
1636
  return null;
1567
1637
  };
1568
1638
  LineLayer.displayName = "LineLayer";
1569
-
1570
- // src/components/layers/CircleLayer.tsx
1571
1639
  var CircleLayer = ({
1572
1640
  id,
1573
1641
  source,
@@ -1592,21 +1660,36 @@ var CircleLayer = ({
1592
1660
  circlePitchScale,
1593
1661
  circleTranslate
1594
1662
  }) => {
1595
- const paint = {};
1596
- const layout = {};
1597
- if (circleRadius !== void 0) paint["circle-radius"] = circleRadius;
1598
- if (circleColor !== void 0) paint["circle-color"] = circleColor;
1599
- if (circleOpacity !== void 0) paint["circle-opacity"] = circleOpacity;
1600
- if (circleStrokeWidth !== void 0) paint["circle-stroke-width"] = circleStrokeWidth;
1601
- if (circleStrokeColor !== void 0) paint["circle-stroke-color"] = circleStrokeColor;
1602
- if (circleStrokeOpacity !== void 0) paint["circle-stroke-opacity"] = circleStrokeOpacity;
1603
- if (circleBlur !== void 0) paint["circle-blur"] = circleBlur;
1604
- if (circlePitchAlignment !== void 0) paint["circle-pitch-alignment"] = circlePitchAlignment;
1605
- if (circlePitchScale !== void 0) paint["circle-pitch-scale"] = circlePitchScale;
1606
- if (circleTranslate !== void 0) paint["circle-translate"] = circleTranslate;
1607
- if (opacity !== void 0 && circleOpacity === void 0) {
1608
- paint["circle-opacity"] = opacity;
1609
- }
1663
+ const paint = React6.useMemo(() => {
1664
+ const p = {};
1665
+ if (circleRadius !== void 0) p["circle-radius"] = circleRadius;
1666
+ if (circleColor !== void 0) p["circle-color"] = circleColor;
1667
+ if (circleOpacity !== void 0) p["circle-opacity"] = circleOpacity;
1668
+ if (circleStrokeWidth !== void 0) p["circle-stroke-width"] = circleStrokeWidth;
1669
+ if (circleStrokeColor !== void 0) p["circle-stroke-color"] = circleStrokeColor;
1670
+ if (circleStrokeOpacity !== void 0) p["circle-stroke-opacity"] = circleStrokeOpacity;
1671
+ if (circleBlur !== void 0) p["circle-blur"] = circleBlur;
1672
+ if (circlePitchAlignment !== void 0) p["circle-pitch-alignment"] = circlePitchAlignment;
1673
+ if (circlePitchScale !== void 0) p["circle-pitch-scale"] = circlePitchScale;
1674
+ if (circleTranslate !== void 0) p["circle-translate"] = circleTranslate;
1675
+ if (opacity !== void 0 && circleOpacity === void 0) {
1676
+ p["circle-opacity"] = opacity;
1677
+ }
1678
+ return p;
1679
+ }, [
1680
+ circleRadius,
1681
+ circleColor,
1682
+ circleOpacity,
1683
+ circleStrokeWidth,
1684
+ circleStrokeColor,
1685
+ circleStrokeOpacity,
1686
+ circleBlur,
1687
+ circlePitchAlignment,
1688
+ circlePitchScale,
1689
+ circleTranslate,
1690
+ opacity
1691
+ ]);
1692
+ const layout = React6.useMemo(() => ({}), []);
1610
1693
  useLayer({
1611
1694
  id,
1612
1695
  source,
@@ -1626,8 +1709,6 @@ var CircleLayer = ({
1626
1709
  return null;
1627
1710
  };
1628
1711
  CircleLayer.displayName = "CircleLayer";
1629
-
1630
- // src/components/layers/SymbolLayer.tsx
1631
1712
  var SymbolLayer = ({
1632
1713
  id,
1633
1714
  source,
@@ -1668,34 +1749,68 @@ var SymbolLayer = ({
1668
1749
  symbolSpacing,
1669
1750
  symbolSortKey
1670
1751
  }) => {
1671
- const paint = {};
1672
- const layout = {};
1673
- if (iconOpacity !== void 0) paint["icon-opacity"] = iconOpacity;
1674
- if (iconColor !== void 0) paint["icon-color"] = iconColor;
1675
- if (iconHaloColor !== void 0) paint["icon-halo-color"] = iconHaloColor;
1676
- if (iconHaloWidth !== void 0) paint["icon-halo-width"] = iconHaloWidth;
1677
- if (textColor !== void 0) paint["text-color"] = textColor;
1678
- if (textOpacity !== void 0) paint["text-opacity"] = textOpacity;
1679
- if (textHaloColor !== void 0) paint["text-halo-color"] = textHaloColor;
1680
- if (textHaloWidth !== void 0) paint["text-halo-width"] = textHaloWidth;
1681
- if (iconImage !== void 0) layout["icon-image"] = iconImage;
1682
- if (iconSize !== void 0) layout["icon-size"] = iconSize;
1683
- if (iconRotate !== void 0) layout["icon-rotate"] = iconRotate;
1684
- if (iconOffset !== void 0) layout["icon-offset"] = iconOffset;
1685
- if (iconAnchor !== void 0) layout["icon-anchor"] = iconAnchor;
1686
- if (iconAllowOverlap !== void 0) layout["icon-allow-overlap"] = iconAllowOverlap;
1687
- if (iconIgnorePlacement !== void 0) layout["icon-ignore-placement"] = iconIgnorePlacement;
1688
- if (textField !== void 0) layout["text-field"] = textField;
1689
- if (textFont !== void 0) layout["text-font"] = textFont;
1690
- if (textSize !== void 0) layout["text-size"] = textSize;
1691
- if (textAnchor !== void 0) layout["text-anchor"] = textAnchor;
1692
- if (textOffset !== void 0) layout["text-offset"] = textOffset;
1693
- if (textRotate !== void 0) layout["text-rotate"] = textRotate;
1694
- if (textAllowOverlap !== void 0) layout["text-allow-overlap"] = textAllowOverlap;
1695
- if (textIgnorePlacement !== void 0) layout["text-ignore-placement"] = textIgnorePlacement;
1696
- if (symbolPlacement !== void 0) layout["symbol-placement"] = symbolPlacement;
1697
- if (symbolSpacing !== void 0) layout["symbol-spacing"] = symbolSpacing;
1698
- if (symbolSortKey !== void 0) layout["symbol-sort-key"] = symbolSortKey;
1752
+ const paint = React6.useMemo(() => {
1753
+ const p = {};
1754
+ if (iconOpacity !== void 0) p["icon-opacity"] = iconOpacity;
1755
+ if (iconColor !== void 0) p["icon-color"] = iconColor;
1756
+ if (iconHaloColor !== void 0) p["icon-halo-color"] = iconHaloColor;
1757
+ if (iconHaloWidth !== void 0) p["icon-halo-width"] = iconHaloWidth;
1758
+ if (textColor !== void 0) p["text-color"] = textColor;
1759
+ if (textOpacity !== void 0) p["text-opacity"] = textOpacity;
1760
+ if (textHaloColor !== void 0) p["text-halo-color"] = textHaloColor;
1761
+ if (textHaloWidth !== void 0) p["text-halo-width"] = textHaloWidth;
1762
+ return p;
1763
+ }, [
1764
+ iconOpacity,
1765
+ iconColor,
1766
+ iconHaloColor,
1767
+ iconHaloWidth,
1768
+ textColor,
1769
+ textOpacity,
1770
+ textHaloColor,
1771
+ textHaloWidth
1772
+ ]);
1773
+ const layout = React6.useMemo(() => {
1774
+ const l = {};
1775
+ if (iconImage !== void 0) l["icon-image"] = iconImage;
1776
+ if (iconSize !== void 0) l["icon-size"] = iconSize;
1777
+ if (iconRotate !== void 0) l["icon-rotate"] = iconRotate;
1778
+ if (iconOffset !== void 0) l["icon-offset"] = iconOffset;
1779
+ if (iconAnchor !== void 0) l["icon-anchor"] = iconAnchor;
1780
+ if (iconAllowOverlap !== void 0) l["icon-allow-overlap"] = iconAllowOverlap;
1781
+ if (iconIgnorePlacement !== void 0) l["icon-ignore-placement"] = iconIgnorePlacement;
1782
+ if (textField !== void 0) l["text-field"] = textField;
1783
+ if (textFont !== void 0) l["text-font"] = textFont;
1784
+ if (textSize !== void 0) l["text-size"] = textSize;
1785
+ if (textAnchor !== void 0) l["text-anchor"] = textAnchor;
1786
+ if (textOffset !== void 0) l["text-offset"] = textOffset;
1787
+ if (textRotate !== void 0) l["text-rotate"] = textRotate;
1788
+ if (textAllowOverlap !== void 0) l["text-allow-overlap"] = textAllowOverlap;
1789
+ if (textIgnorePlacement !== void 0) l["text-ignore-placement"] = textIgnorePlacement;
1790
+ if (symbolPlacement !== void 0) l["symbol-placement"] = symbolPlacement;
1791
+ if (symbolSpacing !== void 0) l["symbol-spacing"] = symbolSpacing;
1792
+ if (symbolSortKey !== void 0) l["symbol-sort-key"] = symbolSortKey;
1793
+ return l;
1794
+ }, [
1795
+ iconImage,
1796
+ iconSize,
1797
+ iconRotate,
1798
+ iconOffset,
1799
+ iconAnchor,
1800
+ iconAllowOverlap,
1801
+ iconIgnorePlacement,
1802
+ textField,
1803
+ textFont,
1804
+ textSize,
1805
+ textAnchor,
1806
+ textOffset,
1807
+ textRotate,
1808
+ textAllowOverlap,
1809
+ textIgnorePlacement,
1810
+ symbolPlacement,
1811
+ symbolSpacing,
1812
+ symbolSortKey
1813
+ ]);
1699
1814
  useLayer({
1700
1815
  id,
1701
1816
  source,
@@ -1715,8 +1830,6 @@ var SymbolLayer = ({
1715
1830
  return null;
1716
1831
  };
1717
1832
  SymbolLayer.displayName = "SymbolLayer";
1718
-
1719
- // src/components/layers/FillExtrusionLayer.tsx
1720
1833
  var FillExtrusionLayer = ({
1721
1834
  id,
1722
1835
  source,
@@ -1738,21 +1851,33 @@ var FillExtrusionLayer = ({
1738
1851
  fillExtrusionTranslate,
1739
1852
  fillExtrusionVerticalGradient
1740
1853
  }) => {
1741
- const paint = {};
1742
- const layout = {};
1743
- if (fillExtrusionHeight !== void 0) paint["fill-extrusion-height"] = fillExtrusionHeight;
1744
- if (fillExtrusionBase !== void 0) paint["fill-extrusion-base"] = fillExtrusionBase;
1745
- if (fillExtrusionColor !== void 0) paint["fill-extrusion-color"] = fillExtrusionColor;
1746
- if (fillExtrusionOpacity !== void 0) paint["fill-extrusion-opacity"] = fillExtrusionOpacity;
1747
- if (fillExtrusionPattern !== void 0) paint["fill-extrusion-pattern"] = fillExtrusionPattern;
1748
- if (fillExtrusionTranslate !== void 0)
1749
- paint["fill-extrusion-translate"] = fillExtrusionTranslate;
1750
- if (fillExtrusionVerticalGradient !== void 0) {
1751
- paint["fill-extrusion-vertical-gradient"] = fillExtrusionVerticalGradient;
1752
- }
1753
- if (opacity !== void 0 && fillExtrusionOpacity === void 0) {
1754
- paint["fill-extrusion-opacity"] = opacity;
1755
- }
1854
+ const paint = React6.useMemo(() => {
1855
+ const p = {};
1856
+ if (fillExtrusionHeight !== void 0) p["fill-extrusion-height"] = fillExtrusionHeight;
1857
+ if (fillExtrusionBase !== void 0) p["fill-extrusion-base"] = fillExtrusionBase;
1858
+ if (fillExtrusionColor !== void 0) p["fill-extrusion-color"] = fillExtrusionColor;
1859
+ if (fillExtrusionOpacity !== void 0) p["fill-extrusion-opacity"] = fillExtrusionOpacity;
1860
+ if (fillExtrusionPattern !== void 0) p["fill-extrusion-pattern"] = fillExtrusionPattern;
1861
+ if (fillExtrusionTranslate !== void 0)
1862
+ p["fill-extrusion-translate"] = fillExtrusionTranslate;
1863
+ if (fillExtrusionVerticalGradient !== void 0) {
1864
+ p["fill-extrusion-vertical-gradient"] = fillExtrusionVerticalGradient;
1865
+ }
1866
+ if (opacity !== void 0 && fillExtrusionOpacity === void 0) {
1867
+ p["fill-extrusion-opacity"] = opacity;
1868
+ }
1869
+ return p;
1870
+ }, [
1871
+ fillExtrusionHeight,
1872
+ fillExtrusionBase,
1873
+ fillExtrusionColor,
1874
+ fillExtrusionOpacity,
1875
+ fillExtrusionPattern,
1876
+ fillExtrusionTranslate,
1877
+ fillExtrusionVerticalGradient,
1878
+ opacity
1879
+ ]);
1880
+ const layout = React6.useMemo(() => ({}), []);
1756
1881
  useLayer({
1757
1882
  id,
1758
1883
  source,
@@ -1772,8 +1897,6 @@ var FillExtrusionLayer = ({
1772
1897
  return null;
1773
1898
  };
1774
1899
  FillExtrusionLayer.displayName = "FillExtrusionLayer";
1775
-
1776
- // src/components/layers/HeatmapLayer.tsx
1777
1900
  var HeatmapLayer = ({
1778
1901
  id,
1779
1902
  source,
@@ -1793,16 +1916,19 @@ var HeatmapLayer = ({
1793
1916
  heatmapRadius,
1794
1917
  heatmapOpacity
1795
1918
  }) => {
1796
- const paint = {};
1797
- const layout = {};
1798
- if (heatmapIntensity !== void 0) paint["heatmap-intensity"] = heatmapIntensity;
1799
- if (heatmapWeight !== void 0) paint["heatmap-weight"] = heatmapWeight;
1800
- if (heatmapColor !== void 0) paint["heatmap-color"] = heatmapColor;
1801
- if (heatmapRadius !== void 0) paint["heatmap-radius"] = heatmapRadius;
1802
- if (heatmapOpacity !== void 0) paint["heatmap-opacity"] = heatmapOpacity;
1803
- if (opacity !== void 0 && heatmapOpacity === void 0) {
1804
- paint["heatmap-opacity"] = opacity;
1805
- }
1919
+ const paint = React6.useMemo(() => {
1920
+ const p = {};
1921
+ if (heatmapIntensity !== void 0) p["heatmap-intensity"] = heatmapIntensity;
1922
+ if (heatmapWeight !== void 0) p["heatmap-weight"] = heatmapWeight;
1923
+ if (heatmapColor !== void 0) p["heatmap-color"] = heatmapColor;
1924
+ if (heatmapRadius !== void 0) p["heatmap-radius"] = heatmapRadius;
1925
+ if (heatmapOpacity !== void 0) p["heatmap-opacity"] = heatmapOpacity;
1926
+ if (opacity !== void 0 && heatmapOpacity === void 0) {
1927
+ p["heatmap-opacity"] = opacity;
1928
+ }
1929
+ return p;
1930
+ }, [heatmapIntensity, heatmapWeight, heatmapColor, heatmapRadius, heatmapOpacity, opacity]);
1931
+ const layout = React6.useMemo(() => ({}), []);
1806
1932
  useLayer({
1807
1933
  id,
1808
1934
  source,
@@ -2236,6 +2362,200 @@ var CoordinateDisplay = ({
2236
2362
  );
2237
2363
  };
2238
2364
  CoordinateDisplay.displayName = "CoordinateDisplay";
2365
+ var switcherIdCounter = 0;
2366
+ var BasemapSwitcher = ({
2367
+ basemaps,
2368
+ extraBasemaps,
2369
+ apiKeys,
2370
+ defaultBasemapId,
2371
+ activeBasemapId,
2372
+ onBasemapChange,
2373
+ columns = 3,
2374
+ thumbnailSize = 64,
2375
+ position = "bottom-right",
2376
+ class: className
2377
+ }) => {
2378
+ const { controlOffsets, registerControl, unregisterControl, setMapStyle } = useMap();
2379
+ const [isOpen, setIsOpen] = React6.useState(false);
2380
+ const [internalActiveId, setInternalActiveId] = React6.useState(
2381
+ defaultBasemapId
2382
+ );
2383
+ const [customControlOffset, setCustomControlOffset] = React6.useState(0);
2384
+ const containerRef = React6.useRef(null);
2385
+ const panelRef = React6.useRef(null);
2386
+ const switcherIdRef = React6.useRef(`basemap-switcher-${++switcherIdCounter}`);
2387
+ const sourceBasemaps = basemaps ?? FREE_BASEMAPS;
2388
+ const availableBasemaps = React6.useMemo(() => {
2389
+ const available = getAvailableBasemaps(sourceBasemaps, apiKeys);
2390
+ if (extraBasemaps?.length) {
2391
+ return [...available, ...getAvailableBasemaps(extraBasemaps, apiKeys)];
2392
+ }
2393
+ return available;
2394
+ }, [sourceBasemaps, extraBasemaps, apiKeys]);
2395
+ const currentActiveId = activeBasemapId ?? internalActiveId ?? availableBasemaps[0]?.id;
2396
+ React6.useEffect(() => {
2397
+ if (!containerRef.current || !registerControl) return;
2398
+ const updatePosition = () => {
2399
+ if (!containerRef.current) return;
2400
+ const height = containerRef.current.offsetHeight;
2401
+ const offset = registerControl(switcherIdRef.current, position, height);
2402
+ setCustomControlOffset(offset);
2403
+ };
2404
+ updatePosition();
2405
+ const observer = new ResizeObserver(updatePosition);
2406
+ observer.observe(containerRef.current);
2407
+ return () => {
2408
+ observer.disconnect();
2409
+ unregisterControl?.(switcherIdRef.current, position);
2410
+ };
2411
+ }, [position, registerControl, unregisterControl]);
2412
+ React6.useEffect(() => {
2413
+ if (!isOpen) return;
2414
+ const handleMouseDown = (e) => {
2415
+ if (containerRef.current && !containerRef.current.contains(e.target)) {
2416
+ setIsOpen(false);
2417
+ }
2418
+ };
2419
+ document.addEventListener("mousedown", handleMouseDown);
2420
+ return () => document.removeEventListener("mousedown", handleMouseDown);
2421
+ }, [isOpen]);
2422
+ React6.useEffect(() => {
2423
+ if (!isOpen) return;
2424
+ const handleKeyDown = (e) => {
2425
+ if (e.key === "Escape") {
2426
+ setIsOpen(false);
2427
+ }
2428
+ };
2429
+ document.addEventListener("keydown", handleKeyDown);
2430
+ return () => document.removeEventListener("keydown", handleKeyDown);
2431
+ }, [isOpen]);
2432
+ const handleSelect = (basemap) => {
2433
+ const style = resolveBasemapStyle(basemap, apiKeys);
2434
+ if (!style) return;
2435
+ if (!activeBasemapId) {
2436
+ setInternalActiveId(basemap.id);
2437
+ }
2438
+ setMapStyle?.(style);
2439
+ onBasemapChange?.(basemap);
2440
+ setIsOpen(false);
2441
+ };
2442
+ const verticalOffsetStyle = React6.useMemo(() => {
2443
+ return computeVerticalOffsetStyle(position, customControlOffset);
2444
+ }, [customControlOffset, position]);
2445
+ const hasControlsAtPosition = (controlOffsets?.[position] ?? 0) > 0;
2446
+ const computedPositionClasses = React6.useMemo(() => {
2447
+ return computePositionClasses(position, hasControlsAtPosition);
2448
+ }, [position, hasControlsAtPosition]);
2449
+ const isTop = position.startsWith("top");
2450
+ return /* @__PURE__ */ jsxs(
2451
+ "div",
2452
+ {
2453
+ ref: containerRef,
2454
+ className: cn("absolute z-10", computedPositionClasses, className),
2455
+ style: verticalOffsetStyle,
2456
+ children: [
2457
+ isOpen && /* @__PURE__ */ jsx(
2458
+ "div",
2459
+ {
2460
+ ref: panelRef,
2461
+ className: cn(
2462
+ "absolute classic-basemap-panel-enter",
2463
+ "bg-card rounded-lg shadow-lg border border-black dark:border-gray-400",
2464
+ "p-2",
2465
+ isTop ? "top-full mt-1" : "bottom-full mb-1",
2466
+ position.includes("right") ? "right-0" : "left-0"
2467
+ ),
2468
+ style: {
2469
+ width: columns * (thumbnailSize + 12) + 16
2470
+ },
2471
+ children: /* @__PURE__ */ jsx(
2472
+ "div",
2473
+ {
2474
+ role: "listbox",
2475
+ "aria-label": "Select basemap",
2476
+ className: "grid gap-1.5",
2477
+ style: {
2478
+ gridTemplateColumns: `repeat(${columns}, 1fr)`
2479
+ },
2480
+ children: availableBasemaps.map((basemap) => {
2481
+ const isActive = basemap.id === currentActiveId;
2482
+ const thumbUrl = resolveBasemapThumbnail(basemap, apiKeys);
2483
+ return /* @__PURE__ */ jsxs(
2484
+ "button",
2485
+ {
2486
+ type: "button",
2487
+ role: "option",
2488
+ "aria-selected": isActive,
2489
+ className: cn(
2490
+ "flex flex-col items-center gap-1 p-1 rounded cursor-pointer",
2491
+ "hover:bg-muted transition-colors",
2492
+ isActive && "ring-2 ring-primary"
2493
+ ),
2494
+ onClick: () => handleSelect(basemap),
2495
+ title: basemap.name,
2496
+ children: [
2497
+ /* @__PURE__ */ jsx(
2498
+ "img",
2499
+ {
2500
+ src: thumbUrl,
2501
+ alt: basemap.name,
2502
+ loading: "lazy",
2503
+ className: "rounded object-cover",
2504
+ style: {
2505
+ width: thumbnailSize,
2506
+ height: thumbnailSize
2507
+ }
2508
+ }
2509
+ ),
2510
+ /* @__PURE__ */ jsx("span", { className: "text-[10px] text-foreground truncate w-full text-center leading-tight", children: basemap.label ?? basemap.name })
2511
+ ]
2512
+ },
2513
+ basemap.id
2514
+ );
2515
+ })
2516
+ }
2517
+ )
2518
+ }
2519
+ ),
2520
+ /* @__PURE__ */ jsx(
2521
+ "button",
2522
+ {
2523
+ type: "button",
2524
+ className: cn(
2525
+ "w-[40px] h-[40px] flex items-center justify-center",
2526
+ "bg-card rounded shadow-lg border border-black dark:border-gray-400",
2527
+ "hover:bg-muted transition-colors cursor-pointer",
2528
+ "text-foreground"
2529
+ ),
2530
+ onClick: () => setIsOpen(!isOpen),
2531
+ "aria-label": "Switch basemap",
2532
+ "aria-expanded": isOpen,
2533
+ "aria-haspopup": "true",
2534
+ children: /* @__PURE__ */ jsxs(
2535
+ "svg",
2536
+ {
2537
+ width: "20",
2538
+ height: "20",
2539
+ viewBox: "0 0 24 24",
2540
+ fill: "none",
2541
+ stroke: "currentColor",
2542
+ strokeWidth: "2",
2543
+ strokeLinecap: "round",
2544
+ strokeLinejoin: "round",
2545
+ children: [
2546
+ /* @__PURE__ */ jsx("path", { d: "M12 2L2 7l10 5 10-5-10-5z" }),
2547
+ /* @__PURE__ */ jsx("path", { d: "M2 17l10 5 10-5" }),
2548
+ /* @__PURE__ */ jsx("path", { d: "M2 12l10 5 10-5" })
2549
+ ]
2550
+ }
2551
+ )
2552
+ }
2553
+ )
2554
+ ]
2555
+ }
2556
+ );
2557
+ };
2558
+ BasemapSwitcher.displayName = "BasemapSwitcher";
2239
2559
  var DeckOverlay = ({
2240
2560
  layers = [],
2241
2561
  onHover,
@@ -2250,9 +2570,11 @@ var DeckOverlay = ({
2250
2570
  const MapboxOverlayRef = React6.useRef(null);
2251
2571
  React6.useEffect(() => {
2252
2572
  if (!map || !loaded) return;
2573
+ let cancelled = false;
2253
2574
  const initOverlay = async () => {
2254
2575
  try {
2255
2576
  const deckMapbox = await import('@deck.gl/mapbox');
2577
+ if (cancelled) return;
2256
2578
  const MapboxOverlay = deckMapbox.MapboxOverlay;
2257
2579
  MapboxOverlayRef.current = MapboxOverlay;
2258
2580
  const overlay = new MapboxOverlay({
@@ -2267,6 +2589,7 @@ var DeckOverlay = ({
2267
2589
  map.addControl(overlay);
2268
2590
  overlayRef.current = overlay;
2269
2591
  } catch (err) {
2592
+ if (cancelled) return;
2270
2593
  console.warn(
2271
2594
  "[maps-react] Deck.gl is not available. Install @deck.gl/core, @deck.gl/layers, and @deck.gl/mapbox to use DeckOverlay.",
2272
2595
  err
@@ -2275,6 +2598,7 @@ var DeckOverlay = ({
2275
2598
  };
2276
2599
  initOverlay();
2277
2600
  return () => {
2601
+ cancelled = true;
2278
2602
  if (overlayRef.current && map) {
2279
2603
  try {
2280
2604
  map.removeControl(overlayRef.current);
@@ -2306,4 +2630,4 @@ var DeckOverlay = ({
2306
2630
  };
2307
2631
  DeckOverlay.displayName = "DeckOverlay";
2308
2632
 
2309
- export { CircleLayer, CoordinateDisplay, DeckOverlay, FillExtrusionLayer, FillLayer, HeatmapLayer, Legend, LegendGroup, LineLayer, Map, MapContainer, MapContext, MapEmpty, MapError, MapSkeleton, Marker, Popup, PopupCard, PopupContent, PopupFooter, PopupHeader, Source, SymbolLayer, cn, useLayer, useMap, useMapInstance, useMapTheme, useReducedMotion };
2633
+ export { BasemapSwitcher, CircleLayer, CoordinateDisplay, DeckOverlay, FillExtrusionLayer, FillLayer, HeatmapLayer, Legend, LegendGroup, LineLayer, Map, MapContainer, MapContext, MapEmpty, MapError, MapSkeleton, Marker, Popup, PopupCard, PopupContent, PopupFooter, PopupHeader, Source, SymbolLayer, cn, useLayer, useMap, useMapInstance, useMapTheme, useReducedMotion };