@classic-homes/maps-react 0.1.2 → 0.1.3

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
@@ -272,11 +272,7 @@ function useReducedMotion() {
272
272
  }, []);
273
273
  return prefersReducedMotion2;
274
274
  }
275
- var MapContext = React6.createContext({
276
- map: null,
277
- loaded: false,
278
- controlOffsets: {}
279
- });
275
+ var MapContext = React6.createContext(null);
280
276
  function useMap() {
281
277
  const context = React6.useContext(MapContext);
282
278
  if (!context) {
@@ -355,6 +351,10 @@ var Map = React6.forwardRef(
355
351
  const [, forceUpdate] = React6.useReducer((x) => x + 1, 0);
356
352
  const prefersReducedMotion2 = useReducedMotion();
357
353
  const { style: themeStyle } = useMapTheme(themePref);
354
+ const onLoadRef = React6.useRef(onLoad);
355
+ onLoadRef.current = onLoad;
356
+ const onErrorRef = React6.useRef(onError);
357
+ onErrorRef.current = onError;
358
358
  const mapStyle = customStyle || themeStyle;
359
359
  const controlOffsets = React6.useMemo(() => {
360
360
  const offsets = {
@@ -483,12 +483,15 @@ var Map = React6.forwardRef(
483
483
  animate: animation && !prefersReducedMotion2
484
484
  });
485
485
  }
486
- onLoad?.({ type: "load", loaded: true });
486
+ onLoadRef.current?.({ type: "load", loaded: true });
487
487
  });
488
488
  map.on("error", (e) => {
489
489
  const errorMessage = e.error?.message || "Map error";
490
- setMapError(errorMessage);
491
- onError?.({ type: "error", message: errorMessage, error: e.error });
490
+ const isTransient = errorMessage.includes("non-existing layer") || errorMessage.includes("Cannot filter");
491
+ if (!isTransient) {
492
+ setMapError(errorMessage);
493
+ }
494
+ onErrorRef.current?.({ type: "error", message: errorMessage, error: e.error });
492
495
  });
493
496
  return () => {
494
497
  map.remove();
@@ -498,11 +501,16 @@ var Map = React6.forwardRef(
498
501
  } catch (err) {
499
502
  const errorMessage = err instanceof Error ? err.message : "Failed to initialize map";
500
503
  setMapError(errorMessage);
501
- onError?.({ type: "error", message: errorMessage, error: err });
504
+ onErrorRef.current?.({ type: "error", message: errorMessage, error: err });
502
505
  }
503
506
  }, []);
507
+ const styleInitialized = React6.useRef(false);
504
508
  React6.useEffect(() => {
505
509
  if (!mapRef.current || !mapLoaded) return;
510
+ if (!styleInitialized.current) {
511
+ styleInitialized.current = true;
512
+ return;
513
+ }
506
514
  mapRef.current.setStyle(mapStyle);
507
515
  }, [mapStyle, mapLoaded]);
508
516
  React6.useEffect(() => {
@@ -693,7 +701,7 @@ var Source = ({
693
701
  return;
694
702
  }
695
703
  const prefersReducedMotion2 = typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
696
- requestAnimationFrame(() => {
704
+ const rafHandle = requestAnimationFrame(() => {
697
705
  if (cancelledRef.current || initialFitDone.current) return;
698
706
  try {
699
707
  const centerLng = (swLng + neLng) / 2;
@@ -716,6 +724,7 @@ var Source = ({
716
724
  console.warn("[maps-react] Source: fitBounds failed", err);
717
725
  }
718
726
  });
727
+ return rafHandle;
719
728
  },
720
729
  [map]
721
730
  );
@@ -791,18 +800,21 @@ var Source = ({
791
800
  return;
792
801
  }
793
802
  const cancelledRef = { current: false };
803
+ const rafHandles = [];
794
804
  const handleSourceData = (e) => {
795
805
  if (cancelledRef.current) return;
796
806
  if (e.sourceId === id && e.isSourceLoaded) {
797
807
  map.off("sourcedata", handleSourceData);
798
- performFitBounds(cancelledRef);
808
+ const h = performFitBounds(cancelledRef);
809
+ if (h !== void 0) rafHandles.push(h);
799
810
  }
800
811
  };
801
812
  map.on("sourcedata", handleSourceData);
802
813
  const handleIdle = () => {
803
814
  if (cancelledRef.current) return;
804
815
  map.off("idle", handleIdle);
805
- performFitBounds(cancelledRef);
816
+ const h = performFitBounds(cancelledRef);
817
+ if (h !== void 0) rafHandles.push(h);
806
818
  };
807
819
  map.once("idle", handleIdle);
808
820
  map.addSource(id, sourceConfig);
@@ -811,12 +823,16 @@ var Source = ({
811
823
  if (source && map.isSourceLoaded(id)) {
812
824
  map.off("sourcedata", handleSourceData);
813
825
  map.off("idle", handleIdle);
814
- performFitBounds(cancelledRef);
826
+ const h = performFitBounds(cancelledRef);
827
+ if (h !== void 0) rafHandles.push(h);
815
828
  }
816
829
  const cleanupListeners = () => {
817
830
  cancelledRef.current = true;
818
831
  map.off("sourcedata", handleSourceData);
819
832
  map.off("idle", handleIdle);
833
+ for (const h of rafHandles) {
834
+ cancelAnimationFrame(h);
835
+ }
820
836
  };
821
837
  return () => {
822
838
  cleanupListeners();
@@ -899,6 +915,12 @@ var Marker = React6.forwardRef(
899
915
  const originalLngLatRef = React6.useRef();
900
916
  const clickHandlerRef = React6.useRef(null);
901
917
  const [mounted, setMounted] = React6.useState(false);
918
+ const onClickRef = React6.useRef(onClick);
919
+ onClickRef.current = onClick;
920
+ const onDragRef = React6.useRef(onDrag);
921
+ onDragRef.current = onDrag;
922
+ const onDragEndRef = React6.useRef(onDragEnd);
923
+ onDragEndRef.current = onDragEnd;
902
924
  React6.useEffect(() => {
903
925
  setMounted(true);
904
926
  return () => setMounted(false);
@@ -940,12 +962,13 @@ var Marker = React6.forwardRef(
940
962
  ref.current = marker;
941
963
  }
942
964
  }
943
- if (onClick) {
965
+ {
944
966
  const element = marker.getElement();
945
967
  const handleClick = (e) => {
968
+ if (!onClickRef.current) return;
946
969
  e.stopPropagation();
947
970
  const lngLat = marker.getLngLat();
948
- onClick({
971
+ onClickRef.current({
949
972
  type: "click",
950
973
  markerId: id || "",
951
974
  lngLat: [lngLat.lng, lngLat.lat],
@@ -961,26 +984,22 @@ var Marker = React6.forwardRef(
961
984
  originalLngLatRef.current = [lngLat.lng, lngLat.lat];
962
985
  });
963
986
  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
- }
987
+ const lngLat = marker.getLngLat();
988
+ onDragRef.current?.({
989
+ type: "drag",
990
+ markerId: id || "",
991
+ lngLat: [lngLat.lng, lngLat.lat],
992
+ originalLngLat: originalLngLatRef.current
993
+ });
973
994
  });
974
995
  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
- }
996
+ const lngLat = marker.getLngLat();
997
+ onDragEndRef.current?.({
998
+ type: "dragend",
999
+ markerId: id || "",
1000
+ lngLat: [lngLat.lng, lngLat.lat],
1001
+ originalLngLat: originalLngLatRef.current
1002
+ });
984
1003
  });
985
1004
  }
986
1005
  return () => {
@@ -1070,8 +1089,14 @@ var Popup = React6.forwardRef(
1070
1089
  }, ref) => {
1071
1090
  const { map, loaded } = useMap();
1072
1091
  const popupRef = React6.useRef(null);
1092
+ const onOpenRef = React6.useRef(onOpen);
1093
+ onOpenRef.current = onOpen;
1094
+ const onCloseRef = React6.useRef(onClose);
1095
+ onCloseRef.current = onClose;
1096
+ const coordinatesRef = React6.useRef(coordinates);
1097
+ coordinatesRef.current = coordinates;
1073
1098
  const containerRef = React6.useRef(null);
1074
- if (!containerRef.current) {
1099
+ if (!containerRef.current && typeof document !== "undefined") {
1075
1100
  containerRef.current = document.createElement("div");
1076
1101
  containerRef.current.className = "maplibregl-popup-content-wrapper";
1077
1102
  }
@@ -1094,23 +1119,16 @@ var Popup = React6.forwardRef(
1094
1119
  });
1095
1120
  popup.setDOMContent(containerRef.current);
1096
1121
  popupRef.current = popup;
1097
- if (ref) {
1098
- if (typeof ref === "function") {
1099
- ref(popup);
1100
- } else {
1101
- ref.current = popup;
1102
- }
1103
- }
1104
1122
  popup.on("open", () => {
1105
- onOpen?.({
1123
+ onOpenRef.current?.({
1106
1124
  type: "open",
1107
- lngLat: coordinates
1125
+ lngLat: coordinatesRef.current
1108
1126
  });
1109
1127
  });
1110
1128
  popup.on("close", () => {
1111
- onClose?.({
1129
+ onCloseRef.current?.({
1112
1130
  type: "close",
1113
- lngLat: coordinates
1131
+ lngLat: coordinatesRef.current
1114
1132
  });
1115
1133
  });
1116
1134
  return () => {
@@ -1126,12 +1144,16 @@ var Popup = React6.forwardRef(
1126
1144
  anchor,
1127
1145
  offset,
1128
1146
  maxWidth,
1129
- focusAfterOpen,
1130
- ref,
1131
- onOpen,
1132
- onClose,
1133
- coordinates
1147
+ focusAfterOpen
1134
1148
  ]);
1149
+ React6.useEffect(() => {
1150
+ if (!popupRef.current || !ref) return;
1151
+ if (typeof ref === "function") {
1152
+ ref(popupRef.current);
1153
+ } else {
1154
+ ref.current = popupRef.current;
1155
+ }
1156
+ }, [ref]);
1135
1157
  React6.useEffect(() => {
1136
1158
  if (popupRef.current) {
1137
1159
  popupRef.current.setLngLat(coordinates);
@@ -1139,10 +1161,11 @@ var Popup = React6.forwardRef(
1139
1161
  }, [coordinates]);
1140
1162
  React6.useEffect(() => {
1141
1163
  if (!map || !popupRef.current || !contentReady) return;
1164
+ let rafHandle;
1142
1165
  if (open) {
1143
1166
  popupRef.current.setLngLat(coordinates).addTo(map);
1144
1167
  if (autoPan) {
1145
- requestAnimationFrame(() => {
1168
+ rafHandle = requestAnimationFrame(() => {
1146
1169
  if (popupRef.current && map) {
1147
1170
  panToFitPopup(map, popupRef.current, normalizePadding(autoPanPadding));
1148
1171
  }
@@ -1151,7 +1174,13 @@ var Popup = React6.forwardRef(
1151
1174
  } else {
1152
1175
  popupRef.current.remove();
1153
1176
  }
1177
+ return () => {
1178
+ if (rafHandle !== void 0) {
1179
+ cancelAnimationFrame(rafHandle);
1180
+ }
1181
+ };
1154
1182
  }, [map, open, coordinates, autoPan, autoPanPadding, contentReady]);
1183
+ if (!containerRef.current) return null;
1155
1184
  return ReactDOM.createPortal(
1156
1185
  /* @__PURE__ */ jsx("div", { ref: contentCallbackRef, children }),
1157
1186
  containerRef.current
@@ -1270,7 +1299,7 @@ function useLayer({
1270
1299
  }
1271
1300
  addLayer();
1272
1301
  function addLayer() {
1273
- if (layerAdded || map.getLayer(id)) {
1302
+ if (map.getLayer(id)) {
1274
1303
  setLayerAdded(true);
1275
1304
  return;
1276
1305
  }
@@ -1304,7 +1333,7 @@ function useLayer({
1304
1333
  }
1305
1334
  }
1306
1335
  return () => {
1307
- if (map && layerAdded) {
1336
+ if (map) {
1308
1337
  try {
1309
1338
  if (map.getLayer(id)) {
1310
1339
  map.removeLayer(id);
@@ -1314,29 +1343,23 @@ function useLayer({
1314
1343
  setLayerAdded(false);
1315
1344
  }
1316
1345
  };
1317
- }, [map, loaded, id, source, sourceLayer, type, beforeId, layerAdded]);
1346
+ }, [map, loaded, id, source, sourceLayer, type, beforeId]);
1318
1347
  React6.useEffect(() => {
1319
1348
  if (!map || !layerAdded) return;
1320
- try {
1321
- map.setLayoutProperty(id, "visibility", visible ? "visible" : "none");
1322
- } catch {
1323
- }
1349
+ if (!map.getLayer(id)) return;
1350
+ map.setLayoutProperty(id, "visibility", visible ? "visible" : "none");
1324
1351
  }, [map, id, visible, layerAdded]);
1325
1352
  React6.useEffect(() => {
1326
1353
  if (!map || !layerAdded) return;
1327
- try {
1328
- Object.entries(paint).forEach(([key, value]) => {
1329
- map.setPaintProperty(id, key, value);
1330
- });
1331
- } catch {
1332
- }
1354
+ if (!map.getLayer(id)) return;
1355
+ Object.entries(paint).forEach(([key, value]) => {
1356
+ map.setPaintProperty(id, key, value);
1357
+ });
1333
1358
  }, [map, id, paint, layerAdded]);
1334
1359
  React6.useEffect(() => {
1335
1360
  if (!map || !layerAdded || !filter) return;
1336
- try {
1337
- map.setFilter(id, filter);
1338
- } catch {
1339
- }
1361
+ if (!map.getLayer(id)) return;
1362
+ map.setFilter(id, filter);
1340
1363
  }, [map, id, filter, layerAdded]);
1341
1364
  React6.useEffect(() => {
1342
1365
  if (!map || !layerAdded) return;
@@ -1454,8 +1477,6 @@ function useLayer({
1454
1477
  }, [map, id, source, sourceLayer, onClick, onHover, hoverThrottleMs, layerAdded]);
1455
1478
  return { layerAdded };
1456
1479
  }
1457
-
1458
- // src/components/layers/FillLayer.tsx
1459
1480
  var FillLayer = ({
1460
1481
  id,
1461
1482
  source,
@@ -1476,17 +1497,28 @@ var FillLayer = ({
1476
1497
  fillTranslate,
1477
1498
  fillAntialias
1478
1499
  }) => {
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
- }
1500
+ const paint = React6.useMemo(() => {
1501
+ const p = {};
1502
+ if (fillColor !== void 0) p["fill-color"] = fillColor;
1503
+ if (fillOpacity !== void 0) p["fill-opacity"] = fillOpacity;
1504
+ if (fillOutlineColor !== void 0) p["fill-outline-color"] = fillOutlineColor;
1505
+ if (fillPattern !== void 0) p["fill-pattern"] = fillPattern;
1506
+ if (fillTranslate !== void 0) p["fill-translate"] = fillTranslate;
1507
+ if (fillAntialias !== void 0) p["fill-antialias"] = fillAntialias;
1508
+ if (opacity !== void 0 && fillOpacity === void 0) {
1509
+ p["fill-opacity"] = opacity;
1510
+ }
1511
+ return p;
1512
+ }, [
1513
+ fillColor,
1514
+ fillOpacity,
1515
+ fillOutlineColor,
1516
+ fillPattern,
1517
+ fillTranslate,
1518
+ fillAntialias,
1519
+ opacity
1520
+ ]);
1521
+ const layout = React6.useMemo(() => ({}), []);
1490
1522
  useLayer({
1491
1523
  id,
1492
1524
  source,
@@ -1506,8 +1538,6 @@ var FillLayer = ({
1506
1538
  return null;
1507
1539
  };
1508
1540
  FillLayer.displayName = "FillLayer";
1509
-
1510
- // src/components/layers/LineLayer.tsx
1511
1541
  var LineLayer = ({
1512
1542
  id,
1513
1543
  source,
@@ -1532,21 +1562,37 @@ var LineLayer = ({
1532
1562
  lineOffset,
1533
1563
  lineGradient
1534
1564
  }) => {
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
- }
1565
+ const paint = React6.useMemo(() => {
1566
+ const p = {};
1567
+ if (lineColor !== void 0) p["line-color"] = lineColor;
1568
+ if (lineWidth !== void 0) p["line-width"] = lineWidth;
1569
+ if (lineOpacity !== void 0) p["line-opacity"] = lineOpacity;
1570
+ if (lineBlur !== void 0) p["line-blur"] = lineBlur;
1571
+ if (lineDasharray !== void 0) p["line-dasharray"] = lineDasharray;
1572
+ if (lineGapWidth !== void 0) p["line-gap-width"] = lineGapWidth;
1573
+ if (lineOffset !== void 0) p["line-offset"] = lineOffset;
1574
+ if (lineGradient !== void 0) p["line-gradient"] = lineGradient;
1575
+ if (opacity !== void 0 && lineOpacity === void 0) {
1576
+ p["line-opacity"] = opacity;
1577
+ }
1578
+ return p;
1579
+ }, [
1580
+ lineColor,
1581
+ lineWidth,
1582
+ lineOpacity,
1583
+ lineBlur,
1584
+ lineDasharray,
1585
+ lineGapWidth,
1586
+ lineOffset,
1587
+ lineGradient,
1588
+ opacity
1589
+ ]);
1590
+ const layout = React6.useMemo(() => {
1591
+ const l = {};
1592
+ if (lineCap !== void 0) l["line-cap"] = lineCap;
1593
+ if (lineJoin !== void 0) l["line-join"] = lineJoin;
1594
+ return l;
1595
+ }, [lineCap, lineJoin]);
1550
1596
  useLayer({
1551
1597
  id,
1552
1598
  source,
@@ -1566,8 +1612,6 @@ var LineLayer = ({
1566
1612
  return null;
1567
1613
  };
1568
1614
  LineLayer.displayName = "LineLayer";
1569
-
1570
- // src/components/layers/CircleLayer.tsx
1571
1615
  var CircleLayer = ({
1572
1616
  id,
1573
1617
  source,
@@ -1592,21 +1636,36 @@ var CircleLayer = ({
1592
1636
  circlePitchScale,
1593
1637
  circleTranslate
1594
1638
  }) => {
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
- }
1639
+ const paint = React6.useMemo(() => {
1640
+ const p = {};
1641
+ if (circleRadius !== void 0) p["circle-radius"] = circleRadius;
1642
+ if (circleColor !== void 0) p["circle-color"] = circleColor;
1643
+ if (circleOpacity !== void 0) p["circle-opacity"] = circleOpacity;
1644
+ if (circleStrokeWidth !== void 0) p["circle-stroke-width"] = circleStrokeWidth;
1645
+ if (circleStrokeColor !== void 0) p["circle-stroke-color"] = circleStrokeColor;
1646
+ if (circleStrokeOpacity !== void 0) p["circle-stroke-opacity"] = circleStrokeOpacity;
1647
+ if (circleBlur !== void 0) p["circle-blur"] = circleBlur;
1648
+ if (circlePitchAlignment !== void 0) p["circle-pitch-alignment"] = circlePitchAlignment;
1649
+ if (circlePitchScale !== void 0) p["circle-pitch-scale"] = circlePitchScale;
1650
+ if (circleTranslate !== void 0) p["circle-translate"] = circleTranslate;
1651
+ if (opacity !== void 0 && circleOpacity === void 0) {
1652
+ p["circle-opacity"] = opacity;
1653
+ }
1654
+ return p;
1655
+ }, [
1656
+ circleRadius,
1657
+ circleColor,
1658
+ circleOpacity,
1659
+ circleStrokeWidth,
1660
+ circleStrokeColor,
1661
+ circleStrokeOpacity,
1662
+ circleBlur,
1663
+ circlePitchAlignment,
1664
+ circlePitchScale,
1665
+ circleTranslate,
1666
+ opacity
1667
+ ]);
1668
+ const layout = React6.useMemo(() => ({}), []);
1610
1669
  useLayer({
1611
1670
  id,
1612
1671
  source,
@@ -1626,8 +1685,6 @@ var CircleLayer = ({
1626
1685
  return null;
1627
1686
  };
1628
1687
  CircleLayer.displayName = "CircleLayer";
1629
-
1630
- // src/components/layers/SymbolLayer.tsx
1631
1688
  var SymbolLayer = ({
1632
1689
  id,
1633
1690
  source,
@@ -1668,34 +1725,68 @@ var SymbolLayer = ({
1668
1725
  symbolSpacing,
1669
1726
  symbolSortKey
1670
1727
  }) => {
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;
1728
+ const paint = React6.useMemo(() => {
1729
+ const p = {};
1730
+ if (iconOpacity !== void 0) p["icon-opacity"] = iconOpacity;
1731
+ if (iconColor !== void 0) p["icon-color"] = iconColor;
1732
+ if (iconHaloColor !== void 0) p["icon-halo-color"] = iconHaloColor;
1733
+ if (iconHaloWidth !== void 0) p["icon-halo-width"] = iconHaloWidth;
1734
+ if (textColor !== void 0) p["text-color"] = textColor;
1735
+ if (textOpacity !== void 0) p["text-opacity"] = textOpacity;
1736
+ if (textHaloColor !== void 0) p["text-halo-color"] = textHaloColor;
1737
+ if (textHaloWidth !== void 0) p["text-halo-width"] = textHaloWidth;
1738
+ return p;
1739
+ }, [
1740
+ iconOpacity,
1741
+ iconColor,
1742
+ iconHaloColor,
1743
+ iconHaloWidth,
1744
+ textColor,
1745
+ textOpacity,
1746
+ textHaloColor,
1747
+ textHaloWidth
1748
+ ]);
1749
+ const layout = React6.useMemo(() => {
1750
+ const l = {};
1751
+ if (iconImage !== void 0) l["icon-image"] = iconImage;
1752
+ if (iconSize !== void 0) l["icon-size"] = iconSize;
1753
+ if (iconRotate !== void 0) l["icon-rotate"] = iconRotate;
1754
+ if (iconOffset !== void 0) l["icon-offset"] = iconOffset;
1755
+ if (iconAnchor !== void 0) l["icon-anchor"] = iconAnchor;
1756
+ if (iconAllowOverlap !== void 0) l["icon-allow-overlap"] = iconAllowOverlap;
1757
+ if (iconIgnorePlacement !== void 0) l["icon-ignore-placement"] = iconIgnorePlacement;
1758
+ if (textField !== void 0) l["text-field"] = textField;
1759
+ if (textFont !== void 0) l["text-font"] = textFont;
1760
+ if (textSize !== void 0) l["text-size"] = textSize;
1761
+ if (textAnchor !== void 0) l["text-anchor"] = textAnchor;
1762
+ if (textOffset !== void 0) l["text-offset"] = textOffset;
1763
+ if (textRotate !== void 0) l["text-rotate"] = textRotate;
1764
+ if (textAllowOverlap !== void 0) l["text-allow-overlap"] = textAllowOverlap;
1765
+ if (textIgnorePlacement !== void 0) l["text-ignore-placement"] = textIgnorePlacement;
1766
+ if (symbolPlacement !== void 0) l["symbol-placement"] = symbolPlacement;
1767
+ if (symbolSpacing !== void 0) l["symbol-spacing"] = symbolSpacing;
1768
+ if (symbolSortKey !== void 0) l["symbol-sort-key"] = symbolSortKey;
1769
+ return l;
1770
+ }, [
1771
+ iconImage,
1772
+ iconSize,
1773
+ iconRotate,
1774
+ iconOffset,
1775
+ iconAnchor,
1776
+ iconAllowOverlap,
1777
+ iconIgnorePlacement,
1778
+ textField,
1779
+ textFont,
1780
+ textSize,
1781
+ textAnchor,
1782
+ textOffset,
1783
+ textRotate,
1784
+ textAllowOverlap,
1785
+ textIgnorePlacement,
1786
+ symbolPlacement,
1787
+ symbolSpacing,
1788
+ symbolSortKey
1789
+ ]);
1699
1790
  useLayer({
1700
1791
  id,
1701
1792
  source,
@@ -1715,8 +1806,6 @@ var SymbolLayer = ({
1715
1806
  return null;
1716
1807
  };
1717
1808
  SymbolLayer.displayName = "SymbolLayer";
1718
-
1719
- // src/components/layers/FillExtrusionLayer.tsx
1720
1809
  var FillExtrusionLayer = ({
1721
1810
  id,
1722
1811
  source,
@@ -1738,21 +1827,33 @@ var FillExtrusionLayer = ({
1738
1827
  fillExtrusionTranslate,
1739
1828
  fillExtrusionVerticalGradient
1740
1829
  }) => {
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
- }
1830
+ const paint = React6.useMemo(() => {
1831
+ const p = {};
1832
+ if (fillExtrusionHeight !== void 0) p["fill-extrusion-height"] = fillExtrusionHeight;
1833
+ if (fillExtrusionBase !== void 0) p["fill-extrusion-base"] = fillExtrusionBase;
1834
+ if (fillExtrusionColor !== void 0) p["fill-extrusion-color"] = fillExtrusionColor;
1835
+ if (fillExtrusionOpacity !== void 0) p["fill-extrusion-opacity"] = fillExtrusionOpacity;
1836
+ if (fillExtrusionPattern !== void 0) p["fill-extrusion-pattern"] = fillExtrusionPattern;
1837
+ if (fillExtrusionTranslate !== void 0)
1838
+ p["fill-extrusion-translate"] = fillExtrusionTranslate;
1839
+ if (fillExtrusionVerticalGradient !== void 0) {
1840
+ p["fill-extrusion-vertical-gradient"] = fillExtrusionVerticalGradient;
1841
+ }
1842
+ if (opacity !== void 0 && fillExtrusionOpacity === void 0) {
1843
+ p["fill-extrusion-opacity"] = opacity;
1844
+ }
1845
+ return p;
1846
+ }, [
1847
+ fillExtrusionHeight,
1848
+ fillExtrusionBase,
1849
+ fillExtrusionColor,
1850
+ fillExtrusionOpacity,
1851
+ fillExtrusionPattern,
1852
+ fillExtrusionTranslate,
1853
+ fillExtrusionVerticalGradient,
1854
+ opacity
1855
+ ]);
1856
+ const layout = React6.useMemo(() => ({}), []);
1756
1857
  useLayer({
1757
1858
  id,
1758
1859
  source,
@@ -1772,8 +1873,6 @@ var FillExtrusionLayer = ({
1772
1873
  return null;
1773
1874
  };
1774
1875
  FillExtrusionLayer.displayName = "FillExtrusionLayer";
1775
-
1776
- // src/components/layers/HeatmapLayer.tsx
1777
1876
  var HeatmapLayer = ({
1778
1877
  id,
1779
1878
  source,
@@ -1793,16 +1892,19 @@ var HeatmapLayer = ({
1793
1892
  heatmapRadius,
1794
1893
  heatmapOpacity
1795
1894
  }) => {
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
- }
1895
+ const paint = React6.useMemo(() => {
1896
+ const p = {};
1897
+ if (heatmapIntensity !== void 0) p["heatmap-intensity"] = heatmapIntensity;
1898
+ if (heatmapWeight !== void 0) p["heatmap-weight"] = heatmapWeight;
1899
+ if (heatmapColor !== void 0) p["heatmap-color"] = heatmapColor;
1900
+ if (heatmapRadius !== void 0) p["heatmap-radius"] = heatmapRadius;
1901
+ if (heatmapOpacity !== void 0) p["heatmap-opacity"] = heatmapOpacity;
1902
+ if (opacity !== void 0 && heatmapOpacity === void 0) {
1903
+ p["heatmap-opacity"] = opacity;
1904
+ }
1905
+ return p;
1906
+ }, [heatmapIntensity, heatmapWeight, heatmapColor, heatmapRadius, heatmapOpacity, opacity]);
1907
+ const layout = React6.useMemo(() => ({}), []);
1806
1908
  useLayer({
1807
1909
  id,
1808
1910
  source,
@@ -2250,9 +2352,11 @@ var DeckOverlay = ({
2250
2352
  const MapboxOverlayRef = React6.useRef(null);
2251
2353
  React6.useEffect(() => {
2252
2354
  if (!map || !loaded) return;
2355
+ let cancelled = false;
2253
2356
  const initOverlay = async () => {
2254
2357
  try {
2255
2358
  const deckMapbox = await import('@deck.gl/mapbox');
2359
+ if (cancelled) return;
2256
2360
  const MapboxOverlay = deckMapbox.MapboxOverlay;
2257
2361
  MapboxOverlayRef.current = MapboxOverlay;
2258
2362
  const overlay = new MapboxOverlay({
@@ -2267,6 +2371,7 @@ var DeckOverlay = ({
2267
2371
  map.addControl(overlay);
2268
2372
  overlayRef.current = overlay;
2269
2373
  } catch (err) {
2374
+ if (cancelled) return;
2270
2375
  console.warn(
2271
2376
  "[maps-react] Deck.gl is not available. Install @deck.gl/core, @deck.gl/layers, and @deck.gl/mapbox to use DeckOverlay.",
2272
2377
  err
@@ -2275,6 +2380,7 @@ var DeckOverlay = ({
2275
2380
  };
2276
2381
  initOverlay();
2277
2382
  return () => {
2383
+ cancelled = true;
2278
2384
  if (overlayRef.current && map) {
2279
2385
  try {
2280
2386
  map.removeControl(overlayRef.current);