@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.cjs +524 -179
- package/dist/index.d.cts +16 -5
- package/dist/index.d.ts +16 -5
- package/dist/index.js +506 -182
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -11,6 +11,7 @@ require('@classic-homes/maps-core/styles/marker.css');
|
|
|
11
11
|
var mapsCore = require('@classic-homes/maps-core');
|
|
12
12
|
var ReactDOM = require('react-dom');
|
|
13
13
|
var classVarianceAuthority = require('class-variance-authority');
|
|
14
|
+
require('@classic-homes/maps-core/styles/basemap-switcher.css');
|
|
14
15
|
|
|
15
16
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
16
17
|
|
|
@@ -296,11 +297,7 @@ function useReducedMotion() {
|
|
|
296
297
|
}, []);
|
|
297
298
|
return prefersReducedMotion2;
|
|
298
299
|
}
|
|
299
|
-
var MapContext = React6__namespace.createContext(
|
|
300
|
-
map: null,
|
|
301
|
-
loaded: false,
|
|
302
|
-
controlOffsets: {}
|
|
303
|
-
});
|
|
300
|
+
var MapContext = React6__namespace.createContext(null);
|
|
304
301
|
function useMap() {
|
|
305
302
|
const context = React6__namespace.useContext(MapContext);
|
|
306
303
|
if (!context) {
|
|
@@ -370,6 +367,14 @@ var Map = React6__namespace.forwardRef(
|
|
|
370
367
|
const mapRef = React6__namespace.useRef(null);
|
|
371
368
|
const [mapLoaded, setMapLoaded] = React6__namespace.useState(false);
|
|
372
369
|
const [mapError, setMapError] = React6__namespace.useState(null);
|
|
370
|
+
const [styleVersion, setStyleVersion] = React6__namespace.useState(0);
|
|
371
|
+
const activeStyleOverrideRef = React6__namespace.useRef(
|
|
372
|
+
null
|
|
373
|
+
);
|
|
374
|
+
const setMapStyle = React6__namespace.useCallback((style) => {
|
|
375
|
+
activeStyleOverrideRef.current = style;
|
|
376
|
+
mapRef.current?.setStyle(style);
|
|
377
|
+
}, []);
|
|
373
378
|
const customControlRegistryRef = React6__namespace.useRef({
|
|
374
379
|
"top-left": [],
|
|
375
380
|
"top-right": [],
|
|
@@ -379,6 +384,10 @@ var Map = React6__namespace.forwardRef(
|
|
|
379
384
|
const [, forceUpdate] = React6__namespace.useReducer((x) => x + 1, 0);
|
|
380
385
|
const prefersReducedMotion2 = useReducedMotion();
|
|
381
386
|
const { style: themeStyle } = useMapTheme(themePref);
|
|
387
|
+
const onLoadRef = React6__namespace.useRef(onLoad);
|
|
388
|
+
onLoadRef.current = onLoad;
|
|
389
|
+
const onErrorRef = React6__namespace.useRef(onError);
|
|
390
|
+
onErrorRef.current = onError;
|
|
382
391
|
const mapStyle = customStyle || themeStyle;
|
|
383
392
|
const controlOffsets = React6__namespace.useMemo(() => {
|
|
384
393
|
const offsets = {
|
|
@@ -474,6 +483,9 @@ var Map = React6__namespace.forwardRef(
|
|
|
474
483
|
attributionControl: attributionControl ? { customAttribution } : false
|
|
475
484
|
});
|
|
476
485
|
mapRef.current = map;
|
|
486
|
+
map.on("style.load", () => {
|
|
487
|
+
setStyleVersion((v) => v + 1);
|
|
488
|
+
});
|
|
477
489
|
if (navigationControl) {
|
|
478
490
|
map.addControl(
|
|
479
491
|
new maplibregl__default.default.NavigationControl({
|
|
@@ -507,12 +519,15 @@ var Map = React6__namespace.forwardRef(
|
|
|
507
519
|
animate: animation && !prefersReducedMotion2
|
|
508
520
|
});
|
|
509
521
|
}
|
|
510
|
-
|
|
522
|
+
onLoadRef.current?.({ type: "load", loaded: true });
|
|
511
523
|
});
|
|
512
524
|
map.on("error", (e) => {
|
|
513
525
|
const errorMessage = e.error?.message || "Map error";
|
|
514
|
-
|
|
515
|
-
|
|
526
|
+
const isTransient = errorMessage.includes("non-existing layer") || errorMessage.includes("Cannot filter");
|
|
527
|
+
if (!isTransient) {
|
|
528
|
+
setMapError(errorMessage);
|
|
529
|
+
}
|
|
530
|
+
onErrorRef.current?.({ type: "error", message: errorMessage, error: e.error });
|
|
516
531
|
});
|
|
517
532
|
return () => {
|
|
518
533
|
map.remove();
|
|
@@ -522,13 +537,24 @@ var Map = React6__namespace.forwardRef(
|
|
|
522
537
|
} catch (err) {
|
|
523
538
|
const errorMessage = err instanceof Error ? err.message : "Failed to initialize map";
|
|
524
539
|
setMapError(errorMessage);
|
|
525
|
-
|
|
540
|
+
onErrorRef.current?.({ type: "error", message: errorMessage, error: err });
|
|
526
541
|
}
|
|
527
542
|
}, []);
|
|
543
|
+
const styleInitialized = React6__namespace.useRef(false);
|
|
528
544
|
React6__namespace.useEffect(() => {
|
|
529
545
|
if (!mapRef.current || !mapLoaded) return;
|
|
546
|
+
if (!styleInitialized.current) {
|
|
547
|
+
styleInitialized.current = true;
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
if (activeStyleOverrideRef.current) return;
|
|
530
551
|
mapRef.current.setStyle(mapStyle);
|
|
531
552
|
}, [mapStyle, mapLoaded]);
|
|
553
|
+
React6__namespace.useEffect(() => {
|
|
554
|
+
if (customStyle) {
|
|
555
|
+
activeStyleOverrideRef.current = null;
|
|
556
|
+
}
|
|
557
|
+
}, [customStyle]);
|
|
532
558
|
React6__namespace.useEffect(() => {
|
|
533
559
|
const map = mapRef.current;
|
|
534
560
|
if (!map || !mapLoaded) return;
|
|
@@ -649,7 +675,9 @@ var Map = React6__namespace.forwardRef(
|
|
|
649
675
|
controlOffsets,
|
|
650
676
|
registerControl,
|
|
651
677
|
unregisterControl,
|
|
652
|
-
getCustomControlOffset
|
|
678
|
+
getCustomControlOffset,
|
|
679
|
+
styleVersion,
|
|
680
|
+
setMapStyle
|
|
653
681
|
},
|
|
654
682
|
children: [
|
|
655
683
|
/* @__PURE__ */ jsxRuntime.jsx("div", { ref: containerRef, className: "absolute inset-0" }),
|
|
@@ -681,7 +709,7 @@ var Source = ({
|
|
|
681
709
|
fitBoundsAnimate = true,
|
|
682
710
|
children
|
|
683
711
|
}) => {
|
|
684
|
-
const { map, loaded } = useMap();
|
|
712
|
+
const { map, loaded, styleVersion } = useMap();
|
|
685
713
|
const sourceAdded = React6__namespace.useRef(false);
|
|
686
714
|
const initialFitDone = React6__namespace.useRef(false);
|
|
687
715
|
const fitBoundsParamsRef = React6__namespace.useRef({
|
|
@@ -717,7 +745,7 @@ var Source = ({
|
|
|
717
745
|
return;
|
|
718
746
|
}
|
|
719
747
|
const prefersReducedMotion2 = typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
720
|
-
requestAnimationFrame(() => {
|
|
748
|
+
const rafHandle = requestAnimationFrame(() => {
|
|
721
749
|
if (cancelledRef.current || initialFitDone.current) return;
|
|
722
750
|
try {
|
|
723
751
|
const centerLng = (swLng + neLng) / 2;
|
|
@@ -740,6 +768,7 @@ var Source = ({
|
|
|
740
768
|
console.warn("[maps-react] Source: fitBounds failed", err);
|
|
741
769
|
}
|
|
742
770
|
});
|
|
771
|
+
return rafHandle;
|
|
743
772
|
},
|
|
744
773
|
[map]
|
|
745
774
|
);
|
|
@@ -815,18 +844,21 @@ var Source = ({
|
|
|
815
844
|
return;
|
|
816
845
|
}
|
|
817
846
|
const cancelledRef = { current: false };
|
|
847
|
+
const rafHandles = [];
|
|
818
848
|
const handleSourceData = (e) => {
|
|
819
849
|
if (cancelledRef.current) return;
|
|
820
850
|
if (e.sourceId === id && e.isSourceLoaded) {
|
|
821
851
|
map.off("sourcedata", handleSourceData);
|
|
822
|
-
performFitBounds(cancelledRef);
|
|
852
|
+
const h = performFitBounds(cancelledRef);
|
|
853
|
+
if (h !== void 0) rafHandles.push(h);
|
|
823
854
|
}
|
|
824
855
|
};
|
|
825
856
|
map.on("sourcedata", handleSourceData);
|
|
826
857
|
const handleIdle = () => {
|
|
827
858
|
if (cancelledRef.current) return;
|
|
828
859
|
map.off("idle", handleIdle);
|
|
829
|
-
performFitBounds(cancelledRef);
|
|
860
|
+
const h = performFitBounds(cancelledRef);
|
|
861
|
+
if (h !== void 0) rafHandles.push(h);
|
|
830
862
|
};
|
|
831
863
|
map.once("idle", handleIdle);
|
|
832
864
|
map.addSource(id, sourceConfig);
|
|
@@ -835,12 +867,16 @@ var Source = ({
|
|
|
835
867
|
if (source && map.isSourceLoaded(id)) {
|
|
836
868
|
map.off("sourcedata", handleSourceData);
|
|
837
869
|
map.off("idle", handleIdle);
|
|
838
|
-
performFitBounds(cancelledRef);
|
|
870
|
+
const h = performFitBounds(cancelledRef);
|
|
871
|
+
if (h !== void 0) rafHandles.push(h);
|
|
839
872
|
}
|
|
840
873
|
const cleanupListeners = () => {
|
|
841
874
|
cancelledRef.current = true;
|
|
842
875
|
map.off("sourcedata", handleSourceData);
|
|
843
876
|
map.off("idle", handleIdle);
|
|
877
|
+
for (const h of rafHandles) {
|
|
878
|
+
cancelAnimationFrame(h);
|
|
879
|
+
}
|
|
844
880
|
};
|
|
845
881
|
return () => {
|
|
846
882
|
cleanupListeners();
|
|
@@ -862,7 +898,6 @@ var Source = ({
|
|
|
862
898
|
} catch {
|
|
863
899
|
}
|
|
864
900
|
sourceAdded.current = false;
|
|
865
|
-
initialFitDone.current = false;
|
|
866
901
|
}
|
|
867
902
|
};
|
|
868
903
|
} catch (err) {
|
|
@@ -882,8 +917,10 @@ var Source = ({
|
|
|
882
917
|
clusterMaxZoom,
|
|
883
918
|
generateId,
|
|
884
919
|
promoteId,
|
|
885
|
-
performFitBounds
|
|
920
|
+
performFitBounds,
|
|
886
921
|
// stable due to using ref for params
|
|
922
|
+
styleVersion
|
|
923
|
+
// re-add source after basemap style changes
|
|
887
924
|
]);
|
|
888
925
|
React6__namespace.useEffect(() => {
|
|
889
926
|
if (!map || !loaded || !sourceAdded.current || type !== "geojson") return;
|
|
@@ -923,6 +960,12 @@ var Marker = React6__namespace.forwardRef(
|
|
|
923
960
|
const originalLngLatRef = React6__namespace.useRef();
|
|
924
961
|
const clickHandlerRef = React6__namespace.useRef(null);
|
|
925
962
|
const [mounted, setMounted] = React6__namespace.useState(false);
|
|
963
|
+
const onClickRef = React6__namespace.useRef(onClick);
|
|
964
|
+
onClickRef.current = onClick;
|
|
965
|
+
const onDragRef = React6__namespace.useRef(onDrag);
|
|
966
|
+
onDragRef.current = onDrag;
|
|
967
|
+
const onDragEndRef = React6__namespace.useRef(onDragEnd);
|
|
968
|
+
onDragEndRef.current = onDragEnd;
|
|
926
969
|
React6__namespace.useEffect(() => {
|
|
927
970
|
setMounted(true);
|
|
928
971
|
return () => setMounted(false);
|
|
@@ -964,12 +1007,13 @@ var Marker = React6__namespace.forwardRef(
|
|
|
964
1007
|
ref.current = marker;
|
|
965
1008
|
}
|
|
966
1009
|
}
|
|
967
|
-
|
|
1010
|
+
{
|
|
968
1011
|
const element = marker.getElement();
|
|
969
1012
|
const handleClick = (e) => {
|
|
1013
|
+
if (!onClickRef.current) return;
|
|
970
1014
|
e.stopPropagation();
|
|
971
1015
|
const lngLat = marker.getLngLat();
|
|
972
|
-
|
|
1016
|
+
onClickRef.current({
|
|
973
1017
|
type: "click",
|
|
974
1018
|
markerId: id || "",
|
|
975
1019
|
lngLat: [lngLat.lng, lngLat.lat],
|
|
@@ -985,26 +1029,22 @@ var Marker = React6__namespace.forwardRef(
|
|
|
985
1029
|
originalLngLatRef.current = [lngLat.lng, lngLat.lat];
|
|
986
1030
|
});
|
|
987
1031
|
marker.on("drag", () => {
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
});
|
|
996
|
-
}
|
|
1032
|
+
const lngLat = marker.getLngLat();
|
|
1033
|
+
onDragRef.current?.({
|
|
1034
|
+
type: "drag",
|
|
1035
|
+
markerId: id || "",
|
|
1036
|
+
lngLat: [lngLat.lng, lngLat.lat],
|
|
1037
|
+
originalLngLat: originalLngLatRef.current
|
|
1038
|
+
});
|
|
997
1039
|
});
|
|
998
1040
|
marker.on("dragend", () => {
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
});
|
|
1007
|
-
}
|
|
1041
|
+
const lngLat = marker.getLngLat();
|
|
1042
|
+
onDragEndRef.current?.({
|
|
1043
|
+
type: "dragend",
|
|
1044
|
+
markerId: id || "",
|
|
1045
|
+
lngLat: [lngLat.lng, lngLat.lat],
|
|
1046
|
+
originalLngLat: originalLngLatRef.current
|
|
1047
|
+
});
|
|
1008
1048
|
});
|
|
1009
1049
|
}
|
|
1010
1050
|
return () => {
|
|
@@ -1094,8 +1134,14 @@ var Popup = React6__namespace.forwardRef(
|
|
|
1094
1134
|
}, ref) => {
|
|
1095
1135
|
const { map, loaded } = useMap();
|
|
1096
1136
|
const popupRef = React6__namespace.useRef(null);
|
|
1137
|
+
const onOpenRef = React6__namespace.useRef(onOpen);
|
|
1138
|
+
onOpenRef.current = onOpen;
|
|
1139
|
+
const onCloseRef = React6__namespace.useRef(onClose);
|
|
1140
|
+
onCloseRef.current = onClose;
|
|
1141
|
+
const coordinatesRef = React6__namespace.useRef(coordinates);
|
|
1142
|
+
coordinatesRef.current = coordinates;
|
|
1097
1143
|
const containerRef = React6__namespace.useRef(null);
|
|
1098
|
-
if (!containerRef.current) {
|
|
1144
|
+
if (!containerRef.current && typeof document !== "undefined") {
|
|
1099
1145
|
containerRef.current = document.createElement("div");
|
|
1100
1146
|
containerRef.current.className = "maplibregl-popup-content-wrapper";
|
|
1101
1147
|
}
|
|
@@ -1118,23 +1164,16 @@ var Popup = React6__namespace.forwardRef(
|
|
|
1118
1164
|
});
|
|
1119
1165
|
popup.setDOMContent(containerRef.current);
|
|
1120
1166
|
popupRef.current = popup;
|
|
1121
|
-
if (ref) {
|
|
1122
|
-
if (typeof ref === "function") {
|
|
1123
|
-
ref(popup);
|
|
1124
|
-
} else {
|
|
1125
|
-
ref.current = popup;
|
|
1126
|
-
}
|
|
1127
|
-
}
|
|
1128
1167
|
popup.on("open", () => {
|
|
1129
|
-
|
|
1168
|
+
onOpenRef.current?.({
|
|
1130
1169
|
type: "open",
|
|
1131
|
-
lngLat:
|
|
1170
|
+
lngLat: coordinatesRef.current
|
|
1132
1171
|
});
|
|
1133
1172
|
});
|
|
1134
1173
|
popup.on("close", () => {
|
|
1135
|
-
|
|
1174
|
+
onCloseRef.current?.({
|
|
1136
1175
|
type: "close",
|
|
1137
|
-
lngLat:
|
|
1176
|
+
lngLat: coordinatesRef.current
|
|
1138
1177
|
});
|
|
1139
1178
|
});
|
|
1140
1179
|
return () => {
|
|
@@ -1150,12 +1189,16 @@ var Popup = React6__namespace.forwardRef(
|
|
|
1150
1189
|
anchor,
|
|
1151
1190
|
offset,
|
|
1152
1191
|
maxWidth,
|
|
1153
|
-
focusAfterOpen
|
|
1154
|
-
ref,
|
|
1155
|
-
onOpen,
|
|
1156
|
-
onClose,
|
|
1157
|
-
coordinates
|
|
1192
|
+
focusAfterOpen
|
|
1158
1193
|
]);
|
|
1194
|
+
React6__namespace.useEffect(() => {
|
|
1195
|
+
if (!popupRef.current || !ref) return;
|
|
1196
|
+
if (typeof ref === "function") {
|
|
1197
|
+
ref(popupRef.current);
|
|
1198
|
+
} else {
|
|
1199
|
+
ref.current = popupRef.current;
|
|
1200
|
+
}
|
|
1201
|
+
}, [ref]);
|
|
1159
1202
|
React6__namespace.useEffect(() => {
|
|
1160
1203
|
if (popupRef.current) {
|
|
1161
1204
|
popupRef.current.setLngLat(coordinates);
|
|
@@ -1163,10 +1206,11 @@ var Popup = React6__namespace.forwardRef(
|
|
|
1163
1206
|
}, [coordinates]);
|
|
1164
1207
|
React6__namespace.useEffect(() => {
|
|
1165
1208
|
if (!map || !popupRef.current || !contentReady) return;
|
|
1209
|
+
let rafHandle;
|
|
1166
1210
|
if (open) {
|
|
1167
1211
|
popupRef.current.setLngLat(coordinates).addTo(map);
|
|
1168
1212
|
if (autoPan) {
|
|
1169
|
-
requestAnimationFrame(() => {
|
|
1213
|
+
rafHandle = requestAnimationFrame(() => {
|
|
1170
1214
|
if (popupRef.current && map) {
|
|
1171
1215
|
panToFitPopup(map, popupRef.current, normalizePadding(autoPanPadding));
|
|
1172
1216
|
}
|
|
@@ -1175,7 +1219,13 @@ var Popup = React6__namespace.forwardRef(
|
|
|
1175
1219
|
} else {
|
|
1176
1220
|
popupRef.current.remove();
|
|
1177
1221
|
}
|
|
1222
|
+
return () => {
|
|
1223
|
+
if (rafHandle !== void 0) {
|
|
1224
|
+
cancelAnimationFrame(rafHandle);
|
|
1225
|
+
}
|
|
1226
|
+
};
|
|
1178
1227
|
}, [map, open, coordinates, autoPan, autoPanPadding, contentReady]);
|
|
1228
|
+
if (!containerRef.current) return null;
|
|
1179
1229
|
return ReactDOM__namespace.createPortal(
|
|
1180
1230
|
/* @__PURE__ */ jsxRuntime.jsx("div", { ref: contentCallbackRef, children }),
|
|
1181
1231
|
containerRef.current
|
|
@@ -1263,11 +1313,14 @@ function useLayer({
|
|
|
1263
1313
|
onHover,
|
|
1264
1314
|
hoverThrottleMs = 0
|
|
1265
1315
|
}) {
|
|
1266
|
-
const { map, loaded } = useMap();
|
|
1316
|
+
const { map, loaded, styleVersion } = useMap();
|
|
1267
1317
|
const [layerAdded, setLayerAdded] = React6__namespace.useState(false);
|
|
1268
1318
|
const hoveredFeatureId = React6__namespace.useRef(null);
|
|
1269
1319
|
const lastHoverCallTime = React6__namespace.useRef(0);
|
|
1270
1320
|
const lastMousePosition = React6__namespace.useRef(null);
|
|
1321
|
+
React6__namespace.useEffect(() => {
|
|
1322
|
+
hoveredFeatureId.current = null;
|
|
1323
|
+
}, [styleVersion]);
|
|
1271
1324
|
React6__namespace.useEffect(() => {
|
|
1272
1325
|
if (!map || !loaded) return;
|
|
1273
1326
|
if (!map.getSource(source)) {
|
|
@@ -1294,7 +1347,7 @@ function useLayer({
|
|
|
1294
1347
|
}
|
|
1295
1348
|
addLayer();
|
|
1296
1349
|
function addLayer() {
|
|
1297
|
-
if (
|
|
1350
|
+
if (map.getLayer(id)) {
|
|
1298
1351
|
setLayerAdded(true);
|
|
1299
1352
|
return;
|
|
1300
1353
|
}
|
|
@@ -1328,7 +1381,7 @@ function useLayer({
|
|
|
1328
1381
|
}
|
|
1329
1382
|
}
|
|
1330
1383
|
return () => {
|
|
1331
|
-
if (map
|
|
1384
|
+
if (map) {
|
|
1332
1385
|
try {
|
|
1333
1386
|
if (map.getLayer(id)) {
|
|
1334
1387
|
map.removeLayer(id);
|
|
@@ -1338,29 +1391,23 @@ function useLayer({
|
|
|
1338
1391
|
setLayerAdded(false);
|
|
1339
1392
|
}
|
|
1340
1393
|
};
|
|
1341
|
-
}, [map, loaded, id, source, sourceLayer, type, beforeId,
|
|
1394
|
+
}, [map, loaded, id, source, sourceLayer, type, beforeId, styleVersion]);
|
|
1342
1395
|
React6__namespace.useEffect(() => {
|
|
1343
1396
|
if (!map || !layerAdded) return;
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
} catch {
|
|
1347
|
-
}
|
|
1397
|
+
if (!map.getLayer(id)) return;
|
|
1398
|
+
map.setLayoutProperty(id, "visibility", visible ? "visible" : "none");
|
|
1348
1399
|
}, [map, id, visible, layerAdded]);
|
|
1349
1400
|
React6__namespace.useEffect(() => {
|
|
1350
1401
|
if (!map || !layerAdded) return;
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
} catch {
|
|
1356
|
-
}
|
|
1402
|
+
if (!map.getLayer(id)) return;
|
|
1403
|
+
Object.entries(paint).forEach(([key, value]) => {
|
|
1404
|
+
map.setPaintProperty(id, key, value);
|
|
1405
|
+
});
|
|
1357
1406
|
}, [map, id, paint, layerAdded]);
|
|
1358
1407
|
React6__namespace.useEffect(() => {
|
|
1359
1408
|
if (!map || !layerAdded || !filter) return;
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
} catch {
|
|
1363
|
-
}
|
|
1409
|
+
if (!map.getLayer(id)) return;
|
|
1410
|
+
map.setFilter(id, filter);
|
|
1364
1411
|
}, [map, id, filter, layerAdded]);
|
|
1365
1412
|
React6__namespace.useEffect(() => {
|
|
1366
1413
|
if (!map || !layerAdded) return;
|
|
@@ -1478,8 +1525,6 @@ function useLayer({
|
|
|
1478
1525
|
}, [map, id, source, sourceLayer, onClick, onHover, hoverThrottleMs, layerAdded]);
|
|
1479
1526
|
return { layerAdded };
|
|
1480
1527
|
}
|
|
1481
|
-
|
|
1482
|
-
// src/components/layers/FillLayer.tsx
|
|
1483
1528
|
var FillLayer = ({
|
|
1484
1529
|
id,
|
|
1485
1530
|
source,
|
|
@@ -1500,17 +1545,28 @@ var FillLayer = ({
|
|
|
1500
1545
|
fillTranslate,
|
|
1501
1546
|
fillAntialias
|
|
1502
1547
|
}) => {
|
|
1503
|
-
const paint = {
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1548
|
+
const paint = React6__namespace.useMemo(() => {
|
|
1549
|
+
const p = {};
|
|
1550
|
+
if (fillColor !== void 0) p["fill-color"] = fillColor;
|
|
1551
|
+
if (fillOpacity !== void 0) p["fill-opacity"] = fillOpacity;
|
|
1552
|
+
if (fillOutlineColor !== void 0) p["fill-outline-color"] = fillOutlineColor;
|
|
1553
|
+
if (fillPattern !== void 0) p["fill-pattern"] = fillPattern;
|
|
1554
|
+
if (fillTranslate !== void 0) p["fill-translate"] = fillTranslate;
|
|
1555
|
+
if (fillAntialias !== void 0) p["fill-antialias"] = fillAntialias;
|
|
1556
|
+
if (opacity !== void 0 && fillOpacity === void 0) {
|
|
1557
|
+
p["fill-opacity"] = opacity;
|
|
1558
|
+
}
|
|
1559
|
+
return p;
|
|
1560
|
+
}, [
|
|
1561
|
+
fillColor,
|
|
1562
|
+
fillOpacity,
|
|
1563
|
+
fillOutlineColor,
|
|
1564
|
+
fillPattern,
|
|
1565
|
+
fillTranslate,
|
|
1566
|
+
fillAntialias,
|
|
1567
|
+
opacity
|
|
1568
|
+
]);
|
|
1569
|
+
const layout = React6__namespace.useMemo(() => ({}), []);
|
|
1514
1570
|
useLayer({
|
|
1515
1571
|
id,
|
|
1516
1572
|
source,
|
|
@@ -1530,8 +1586,6 @@ var FillLayer = ({
|
|
|
1530
1586
|
return null;
|
|
1531
1587
|
};
|
|
1532
1588
|
FillLayer.displayName = "FillLayer";
|
|
1533
|
-
|
|
1534
|
-
// src/components/layers/LineLayer.tsx
|
|
1535
1589
|
var LineLayer = ({
|
|
1536
1590
|
id,
|
|
1537
1591
|
source,
|
|
@@ -1556,21 +1610,37 @@ var LineLayer = ({
|
|
|
1556
1610
|
lineOffset,
|
|
1557
1611
|
lineGradient
|
|
1558
1612
|
}) => {
|
|
1559
|
-
const paint = {
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
}
|
|
1613
|
+
const paint = React6__namespace.useMemo(() => {
|
|
1614
|
+
const p = {};
|
|
1615
|
+
if (lineColor !== void 0) p["line-color"] = lineColor;
|
|
1616
|
+
if (lineWidth !== void 0) p["line-width"] = lineWidth;
|
|
1617
|
+
if (lineOpacity !== void 0) p["line-opacity"] = lineOpacity;
|
|
1618
|
+
if (lineBlur !== void 0) p["line-blur"] = lineBlur;
|
|
1619
|
+
if (lineDasharray !== void 0) p["line-dasharray"] = lineDasharray;
|
|
1620
|
+
if (lineGapWidth !== void 0) p["line-gap-width"] = lineGapWidth;
|
|
1621
|
+
if (lineOffset !== void 0) p["line-offset"] = lineOffset;
|
|
1622
|
+
if (lineGradient !== void 0) p["line-gradient"] = lineGradient;
|
|
1623
|
+
if (opacity !== void 0 && lineOpacity === void 0) {
|
|
1624
|
+
p["line-opacity"] = opacity;
|
|
1625
|
+
}
|
|
1626
|
+
return p;
|
|
1627
|
+
}, [
|
|
1628
|
+
lineColor,
|
|
1629
|
+
lineWidth,
|
|
1630
|
+
lineOpacity,
|
|
1631
|
+
lineBlur,
|
|
1632
|
+
lineDasharray,
|
|
1633
|
+
lineGapWidth,
|
|
1634
|
+
lineOffset,
|
|
1635
|
+
lineGradient,
|
|
1636
|
+
opacity
|
|
1637
|
+
]);
|
|
1638
|
+
const layout = React6__namespace.useMemo(() => {
|
|
1639
|
+
const l = {};
|
|
1640
|
+
if (lineCap !== void 0) l["line-cap"] = lineCap;
|
|
1641
|
+
if (lineJoin !== void 0) l["line-join"] = lineJoin;
|
|
1642
|
+
return l;
|
|
1643
|
+
}, [lineCap, lineJoin]);
|
|
1574
1644
|
useLayer({
|
|
1575
1645
|
id,
|
|
1576
1646
|
source,
|
|
@@ -1590,8 +1660,6 @@ var LineLayer = ({
|
|
|
1590
1660
|
return null;
|
|
1591
1661
|
};
|
|
1592
1662
|
LineLayer.displayName = "LineLayer";
|
|
1593
|
-
|
|
1594
|
-
// src/components/layers/CircleLayer.tsx
|
|
1595
1663
|
var CircleLayer = ({
|
|
1596
1664
|
id,
|
|
1597
1665
|
source,
|
|
@@ -1616,21 +1684,36 @@ var CircleLayer = ({
|
|
|
1616
1684
|
circlePitchScale,
|
|
1617
1685
|
circleTranslate
|
|
1618
1686
|
}) => {
|
|
1619
|
-
const paint = {
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1687
|
+
const paint = React6__namespace.useMemo(() => {
|
|
1688
|
+
const p = {};
|
|
1689
|
+
if (circleRadius !== void 0) p["circle-radius"] = circleRadius;
|
|
1690
|
+
if (circleColor !== void 0) p["circle-color"] = circleColor;
|
|
1691
|
+
if (circleOpacity !== void 0) p["circle-opacity"] = circleOpacity;
|
|
1692
|
+
if (circleStrokeWidth !== void 0) p["circle-stroke-width"] = circleStrokeWidth;
|
|
1693
|
+
if (circleStrokeColor !== void 0) p["circle-stroke-color"] = circleStrokeColor;
|
|
1694
|
+
if (circleStrokeOpacity !== void 0) p["circle-stroke-opacity"] = circleStrokeOpacity;
|
|
1695
|
+
if (circleBlur !== void 0) p["circle-blur"] = circleBlur;
|
|
1696
|
+
if (circlePitchAlignment !== void 0) p["circle-pitch-alignment"] = circlePitchAlignment;
|
|
1697
|
+
if (circlePitchScale !== void 0) p["circle-pitch-scale"] = circlePitchScale;
|
|
1698
|
+
if (circleTranslate !== void 0) p["circle-translate"] = circleTranslate;
|
|
1699
|
+
if (opacity !== void 0 && circleOpacity === void 0) {
|
|
1700
|
+
p["circle-opacity"] = opacity;
|
|
1701
|
+
}
|
|
1702
|
+
return p;
|
|
1703
|
+
}, [
|
|
1704
|
+
circleRadius,
|
|
1705
|
+
circleColor,
|
|
1706
|
+
circleOpacity,
|
|
1707
|
+
circleStrokeWidth,
|
|
1708
|
+
circleStrokeColor,
|
|
1709
|
+
circleStrokeOpacity,
|
|
1710
|
+
circleBlur,
|
|
1711
|
+
circlePitchAlignment,
|
|
1712
|
+
circlePitchScale,
|
|
1713
|
+
circleTranslate,
|
|
1714
|
+
opacity
|
|
1715
|
+
]);
|
|
1716
|
+
const layout = React6__namespace.useMemo(() => ({}), []);
|
|
1634
1717
|
useLayer({
|
|
1635
1718
|
id,
|
|
1636
1719
|
source,
|
|
@@ -1650,8 +1733,6 @@ var CircleLayer = ({
|
|
|
1650
1733
|
return null;
|
|
1651
1734
|
};
|
|
1652
1735
|
CircleLayer.displayName = "CircleLayer";
|
|
1653
|
-
|
|
1654
|
-
// src/components/layers/SymbolLayer.tsx
|
|
1655
1736
|
var SymbolLayer = ({
|
|
1656
1737
|
id,
|
|
1657
1738
|
source,
|
|
@@ -1692,34 +1773,68 @@ var SymbolLayer = ({
|
|
|
1692
1773
|
symbolSpacing,
|
|
1693
1774
|
symbolSortKey
|
|
1694
1775
|
}) => {
|
|
1695
|
-
const paint = {
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1776
|
+
const paint = React6__namespace.useMemo(() => {
|
|
1777
|
+
const p = {};
|
|
1778
|
+
if (iconOpacity !== void 0) p["icon-opacity"] = iconOpacity;
|
|
1779
|
+
if (iconColor !== void 0) p["icon-color"] = iconColor;
|
|
1780
|
+
if (iconHaloColor !== void 0) p["icon-halo-color"] = iconHaloColor;
|
|
1781
|
+
if (iconHaloWidth !== void 0) p["icon-halo-width"] = iconHaloWidth;
|
|
1782
|
+
if (textColor !== void 0) p["text-color"] = textColor;
|
|
1783
|
+
if (textOpacity !== void 0) p["text-opacity"] = textOpacity;
|
|
1784
|
+
if (textHaloColor !== void 0) p["text-halo-color"] = textHaloColor;
|
|
1785
|
+
if (textHaloWidth !== void 0) p["text-halo-width"] = textHaloWidth;
|
|
1786
|
+
return p;
|
|
1787
|
+
}, [
|
|
1788
|
+
iconOpacity,
|
|
1789
|
+
iconColor,
|
|
1790
|
+
iconHaloColor,
|
|
1791
|
+
iconHaloWidth,
|
|
1792
|
+
textColor,
|
|
1793
|
+
textOpacity,
|
|
1794
|
+
textHaloColor,
|
|
1795
|
+
textHaloWidth
|
|
1796
|
+
]);
|
|
1797
|
+
const layout = React6__namespace.useMemo(() => {
|
|
1798
|
+
const l = {};
|
|
1799
|
+
if (iconImage !== void 0) l["icon-image"] = iconImage;
|
|
1800
|
+
if (iconSize !== void 0) l["icon-size"] = iconSize;
|
|
1801
|
+
if (iconRotate !== void 0) l["icon-rotate"] = iconRotate;
|
|
1802
|
+
if (iconOffset !== void 0) l["icon-offset"] = iconOffset;
|
|
1803
|
+
if (iconAnchor !== void 0) l["icon-anchor"] = iconAnchor;
|
|
1804
|
+
if (iconAllowOverlap !== void 0) l["icon-allow-overlap"] = iconAllowOverlap;
|
|
1805
|
+
if (iconIgnorePlacement !== void 0) l["icon-ignore-placement"] = iconIgnorePlacement;
|
|
1806
|
+
if (textField !== void 0) l["text-field"] = textField;
|
|
1807
|
+
if (textFont !== void 0) l["text-font"] = textFont;
|
|
1808
|
+
if (textSize !== void 0) l["text-size"] = textSize;
|
|
1809
|
+
if (textAnchor !== void 0) l["text-anchor"] = textAnchor;
|
|
1810
|
+
if (textOffset !== void 0) l["text-offset"] = textOffset;
|
|
1811
|
+
if (textRotate !== void 0) l["text-rotate"] = textRotate;
|
|
1812
|
+
if (textAllowOverlap !== void 0) l["text-allow-overlap"] = textAllowOverlap;
|
|
1813
|
+
if (textIgnorePlacement !== void 0) l["text-ignore-placement"] = textIgnorePlacement;
|
|
1814
|
+
if (symbolPlacement !== void 0) l["symbol-placement"] = symbolPlacement;
|
|
1815
|
+
if (symbolSpacing !== void 0) l["symbol-spacing"] = symbolSpacing;
|
|
1816
|
+
if (symbolSortKey !== void 0) l["symbol-sort-key"] = symbolSortKey;
|
|
1817
|
+
return l;
|
|
1818
|
+
}, [
|
|
1819
|
+
iconImage,
|
|
1820
|
+
iconSize,
|
|
1821
|
+
iconRotate,
|
|
1822
|
+
iconOffset,
|
|
1823
|
+
iconAnchor,
|
|
1824
|
+
iconAllowOverlap,
|
|
1825
|
+
iconIgnorePlacement,
|
|
1826
|
+
textField,
|
|
1827
|
+
textFont,
|
|
1828
|
+
textSize,
|
|
1829
|
+
textAnchor,
|
|
1830
|
+
textOffset,
|
|
1831
|
+
textRotate,
|
|
1832
|
+
textAllowOverlap,
|
|
1833
|
+
textIgnorePlacement,
|
|
1834
|
+
symbolPlacement,
|
|
1835
|
+
symbolSpacing,
|
|
1836
|
+
symbolSortKey
|
|
1837
|
+
]);
|
|
1723
1838
|
useLayer({
|
|
1724
1839
|
id,
|
|
1725
1840
|
source,
|
|
@@ -1739,8 +1854,6 @@ var SymbolLayer = ({
|
|
|
1739
1854
|
return null;
|
|
1740
1855
|
};
|
|
1741
1856
|
SymbolLayer.displayName = "SymbolLayer";
|
|
1742
|
-
|
|
1743
|
-
// src/components/layers/FillExtrusionLayer.tsx
|
|
1744
1857
|
var FillExtrusionLayer = ({
|
|
1745
1858
|
id,
|
|
1746
1859
|
source,
|
|
@@ -1762,21 +1875,33 @@ var FillExtrusionLayer = ({
|
|
|
1762
1875
|
fillExtrusionTranslate,
|
|
1763
1876
|
fillExtrusionVerticalGradient
|
|
1764
1877
|
}) => {
|
|
1765
|
-
const paint = {
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1878
|
+
const paint = React6__namespace.useMemo(() => {
|
|
1879
|
+
const p = {};
|
|
1880
|
+
if (fillExtrusionHeight !== void 0) p["fill-extrusion-height"] = fillExtrusionHeight;
|
|
1881
|
+
if (fillExtrusionBase !== void 0) p["fill-extrusion-base"] = fillExtrusionBase;
|
|
1882
|
+
if (fillExtrusionColor !== void 0) p["fill-extrusion-color"] = fillExtrusionColor;
|
|
1883
|
+
if (fillExtrusionOpacity !== void 0) p["fill-extrusion-opacity"] = fillExtrusionOpacity;
|
|
1884
|
+
if (fillExtrusionPattern !== void 0) p["fill-extrusion-pattern"] = fillExtrusionPattern;
|
|
1885
|
+
if (fillExtrusionTranslate !== void 0)
|
|
1886
|
+
p["fill-extrusion-translate"] = fillExtrusionTranslate;
|
|
1887
|
+
if (fillExtrusionVerticalGradient !== void 0) {
|
|
1888
|
+
p["fill-extrusion-vertical-gradient"] = fillExtrusionVerticalGradient;
|
|
1889
|
+
}
|
|
1890
|
+
if (opacity !== void 0 && fillExtrusionOpacity === void 0) {
|
|
1891
|
+
p["fill-extrusion-opacity"] = opacity;
|
|
1892
|
+
}
|
|
1893
|
+
return p;
|
|
1894
|
+
}, [
|
|
1895
|
+
fillExtrusionHeight,
|
|
1896
|
+
fillExtrusionBase,
|
|
1897
|
+
fillExtrusionColor,
|
|
1898
|
+
fillExtrusionOpacity,
|
|
1899
|
+
fillExtrusionPattern,
|
|
1900
|
+
fillExtrusionTranslate,
|
|
1901
|
+
fillExtrusionVerticalGradient,
|
|
1902
|
+
opacity
|
|
1903
|
+
]);
|
|
1904
|
+
const layout = React6__namespace.useMemo(() => ({}), []);
|
|
1780
1905
|
useLayer({
|
|
1781
1906
|
id,
|
|
1782
1907
|
source,
|
|
@@ -1796,8 +1921,6 @@ var FillExtrusionLayer = ({
|
|
|
1796
1921
|
return null;
|
|
1797
1922
|
};
|
|
1798
1923
|
FillExtrusionLayer.displayName = "FillExtrusionLayer";
|
|
1799
|
-
|
|
1800
|
-
// src/components/layers/HeatmapLayer.tsx
|
|
1801
1924
|
var HeatmapLayer = ({
|
|
1802
1925
|
id,
|
|
1803
1926
|
source,
|
|
@@ -1817,16 +1940,19 @@ var HeatmapLayer = ({
|
|
|
1817
1940
|
heatmapRadius,
|
|
1818
1941
|
heatmapOpacity
|
|
1819
1942
|
}) => {
|
|
1820
|
-
const paint = {
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1943
|
+
const paint = React6__namespace.useMemo(() => {
|
|
1944
|
+
const p = {};
|
|
1945
|
+
if (heatmapIntensity !== void 0) p["heatmap-intensity"] = heatmapIntensity;
|
|
1946
|
+
if (heatmapWeight !== void 0) p["heatmap-weight"] = heatmapWeight;
|
|
1947
|
+
if (heatmapColor !== void 0) p["heatmap-color"] = heatmapColor;
|
|
1948
|
+
if (heatmapRadius !== void 0) p["heatmap-radius"] = heatmapRadius;
|
|
1949
|
+
if (heatmapOpacity !== void 0) p["heatmap-opacity"] = heatmapOpacity;
|
|
1950
|
+
if (opacity !== void 0 && heatmapOpacity === void 0) {
|
|
1951
|
+
p["heatmap-opacity"] = opacity;
|
|
1952
|
+
}
|
|
1953
|
+
return p;
|
|
1954
|
+
}, [heatmapIntensity, heatmapWeight, heatmapColor, heatmapRadius, heatmapOpacity, opacity]);
|
|
1955
|
+
const layout = React6__namespace.useMemo(() => ({}), []);
|
|
1830
1956
|
useLayer({
|
|
1831
1957
|
id,
|
|
1832
1958
|
source,
|
|
@@ -2260,6 +2386,200 @@ var CoordinateDisplay = ({
|
|
|
2260
2386
|
);
|
|
2261
2387
|
};
|
|
2262
2388
|
CoordinateDisplay.displayName = "CoordinateDisplay";
|
|
2389
|
+
var switcherIdCounter = 0;
|
|
2390
|
+
var BasemapSwitcher = ({
|
|
2391
|
+
basemaps,
|
|
2392
|
+
extraBasemaps,
|
|
2393
|
+
apiKeys,
|
|
2394
|
+
defaultBasemapId,
|
|
2395
|
+
activeBasemapId,
|
|
2396
|
+
onBasemapChange,
|
|
2397
|
+
columns = 3,
|
|
2398
|
+
thumbnailSize = 64,
|
|
2399
|
+
position = "bottom-right",
|
|
2400
|
+
class: className
|
|
2401
|
+
}) => {
|
|
2402
|
+
const { controlOffsets, registerControl, unregisterControl, setMapStyle } = useMap();
|
|
2403
|
+
const [isOpen, setIsOpen] = React6__namespace.useState(false);
|
|
2404
|
+
const [internalActiveId, setInternalActiveId] = React6__namespace.useState(
|
|
2405
|
+
defaultBasemapId
|
|
2406
|
+
);
|
|
2407
|
+
const [customControlOffset, setCustomControlOffset] = React6__namespace.useState(0);
|
|
2408
|
+
const containerRef = React6__namespace.useRef(null);
|
|
2409
|
+
const panelRef = React6__namespace.useRef(null);
|
|
2410
|
+
const switcherIdRef = React6__namespace.useRef(`basemap-switcher-${++switcherIdCounter}`);
|
|
2411
|
+
const sourceBasemaps = basemaps ?? mapsCore.FREE_BASEMAPS;
|
|
2412
|
+
const availableBasemaps = React6__namespace.useMemo(() => {
|
|
2413
|
+
const available = mapsCore.getAvailableBasemaps(sourceBasemaps, apiKeys);
|
|
2414
|
+
if (extraBasemaps?.length) {
|
|
2415
|
+
return [...available, ...mapsCore.getAvailableBasemaps(extraBasemaps, apiKeys)];
|
|
2416
|
+
}
|
|
2417
|
+
return available;
|
|
2418
|
+
}, [sourceBasemaps, extraBasemaps, apiKeys]);
|
|
2419
|
+
const currentActiveId = activeBasemapId ?? internalActiveId ?? availableBasemaps[0]?.id;
|
|
2420
|
+
React6__namespace.useEffect(() => {
|
|
2421
|
+
if (!containerRef.current || !registerControl) return;
|
|
2422
|
+
const updatePosition = () => {
|
|
2423
|
+
if (!containerRef.current) return;
|
|
2424
|
+
const height = containerRef.current.offsetHeight;
|
|
2425
|
+
const offset = registerControl(switcherIdRef.current, position, height);
|
|
2426
|
+
setCustomControlOffset(offset);
|
|
2427
|
+
};
|
|
2428
|
+
updatePosition();
|
|
2429
|
+
const observer = new ResizeObserver(updatePosition);
|
|
2430
|
+
observer.observe(containerRef.current);
|
|
2431
|
+
return () => {
|
|
2432
|
+
observer.disconnect();
|
|
2433
|
+
unregisterControl?.(switcherIdRef.current, position);
|
|
2434
|
+
};
|
|
2435
|
+
}, [position, registerControl, unregisterControl]);
|
|
2436
|
+
React6__namespace.useEffect(() => {
|
|
2437
|
+
if (!isOpen) return;
|
|
2438
|
+
const handleMouseDown = (e) => {
|
|
2439
|
+
if (containerRef.current && !containerRef.current.contains(e.target)) {
|
|
2440
|
+
setIsOpen(false);
|
|
2441
|
+
}
|
|
2442
|
+
};
|
|
2443
|
+
document.addEventListener("mousedown", handleMouseDown);
|
|
2444
|
+
return () => document.removeEventListener("mousedown", handleMouseDown);
|
|
2445
|
+
}, [isOpen]);
|
|
2446
|
+
React6__namespace.useEffect(() => {
|
|
2447
|
+
if (!isOpen) return;
|
|
2448
|
+
const handleKeyDown = (e) => {
|
|
2449
|
+
if (e.key === "Escape") {
|
|
2450
|
+
setIsOpen(false);
|
|
2451
|
+
}
|
|
2452
|
+
};
|
|
2453
|
+
document.addEventListener("keydown", handleKeyDown);
|
|
2454
|
+
return () => document.removeEventListener("keydown", handleKeyDown);
|
|
2455
|
+
}, [isOpen]);
|
|
2456
|
+
const handleSelect = (basemap) => {
|
|
2457
|
+
const style = mapsCore.resolveBasemapStyle(basemap, apiKeys);
|
|
2458
|
+
if (!style) return;
|
|
2459
|
+
if (!activeBasemapId) {
|
|
2460
|
+
setInternalActiveId(basemap.id);
|
|
2461
|
+
}
|
|
2462
|
+
setMapStyle?.(style);
|
|
2463
|
+
onBasemapChange?.(basemap);
|
|
2464
|
+
setIsOpen(false);
|
|
2465
|
+
};
|
|
2466
|
+
const verticalOffsetStyle = React6__namespace.useMemo(() => {
|
|
2467
|
+
return mapsCore.computeVerticalOffsetStyle(position, customControlOffset);
|
|
2468
|
+
}, [customControlOffset, position]);
|
|
2469
|
+
const hasControlsAtPosition = (controlOffsets?.[position] ?? 0) > 0;
|
|
2470
|
+
const computedPositionClasses = React6__namespace.useMemo(() => {
|
|
2471
|
+
return mapsCore.computePositionClasses(position, hasControlsAtPosition);
|
|
2472
|
+
}, [position, hasControlsAtPosition]);
|
|
2473
|
+
const isTop = position.startsWith("top");
|
|
2474
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2475
|
+
"div",
|
|
2476
|
+
{
|
|
2477
|
+
ref: containerRef,
|
|
2478
|
+
className: cn("absolute z-10", computedPositionClasses, className),
|
|
2479
|
+
style: verticalOffsetStyle,
|
|
2480
|
+
children: [
|
|
2481
|
+
isOpen && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2482
|
+
"div",
|
|
2483
|
+
{
|
|
2484
|
+
ref: panelRef,
|
|
2485
|
+
className: cn(
|
|
2486
|
+
"absolute classic-basemap-panel-enter",
|
|
2487
|
+
"bg-card rounded-lg shadow-lg border border-black dark:border-gray-400",
|
|
2488
|
+
"p-2",
|
|
2489
|
+
isTop ? "top-full mt-1" : "bottom-full mb-1",
|
|
2490
|
+
position.includes("right") ? "right-0" : "left-0"
|
|
2491
|
+
),
|
|
2492
|
+
style: {
|
|
2493
|
+
width: columns * (thumbnailSize + 12) + 16
|
|
2494
|
+
},
|
|
2495
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2496
|
+
"div",
|
|
2497
|
+
{
|
|
2498
|
+
role: "listbox",
|
|
2499
|
+
"aria-label": "Select basemap",
|
|
2500
|
+
className: "grid gap-1.5",
|
|
2501
|
+
style: {
|
|
2502
|
+
gridTemplateColumns: `repeat(${columns}, 1fr)`
|
|
2503
|
+
},
|
|
2504
|
+
children: availableBasemaps.map((basemap) => {
|
|
2505
|
+
const isActive = basemap.id === currentActiveId;
|
|
2506
|
+
const thumbUrl = mapsCore.resolveBasemapThumbnail(basemap, apiKeys);
|
|
2507
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2508
|
+
"button",
|
|
2509
|
+
{
|
|
2510
|
+
type: "button",
|
|
2511
|
+
role: "option",
|
|
2512
|
+
"aria-selected": isActive,
|
|
2513
|
+
className: cn(
|
|
2514
|
+
"flex flex-col items-center gap-1 p-1 rounded cursor-pointer",
|
|
2515
|
+
"hover:bg-muted transition-colors",
|
|
2516
|
+
isActive && "ring-2 ring-primary"
|
|
2517
|
+
),
|
|
2518
|
+
onClick: () => handleSelect(basemap),
|
|
2519
|
+
title: basemap.name,
|
|
2520
|
+
children: [
|
|
2521
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2522
|
+
"img",
|
|
2523
|
+
{
|
|
2524
|
+
src: thumbUrl,
|
|
2525
|
+
alt: basemap.name,
|
|
2526
|
+
loading: "lazy",
|
|
2527
|
+
className: "rounded object-cover",
|
|
2528
|
+
style: {
|
|
2529
|
+
width: thumbnailSize,
|
|
2530
|
+
height: thumbnailSize
|
|
2531
|
+
}
|
|
2532
|
+
}
|
|
2533
|
+
),
|
|
2534
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-[10px] text-foreground truncate w-full text-center leading-tight", children: basemap.label ?? basemap.name })
|
|
2535
|
+
]
|
|
2536
|
+
},
|
|
2537
|
+
basemap.id
|
|
2538
|
+
);
|
|
2539
|
+
})
|
|
2540
|
+
}
|
|
2541
|
+
)
|
|
2542
|
+
}
|
|
2543
|
+
),
|
|
2544
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2545
|
+
"button",
|
|
2546
|
+
{
|
|
2547
|
+
type: "button",
|
|
2548
|
+
className: cn(
|
|
2549
|
+
"w-[40px] h-[40px] flex items-center justify-center",
|
|
2550
|
+
"bg-card rounded shadow-lg border border-black dark:border-gray-400",
|
|
2551
|
+
"hover:bg-muted transition-colors cursor-pointer",
|
|
2552
|
+
"text-foreground"
|
|
2553
|
+
),
|
|
2554
|
+
onClick: () => setIsOpen(!isOpen),
|
|
2555
|
+
"aria-label": "Switch basemap",
|
|
2556
|
+
"aria-expanded": isOpen,
|
|
2557
|
+
"aria-haspopup": "true",
|
|
2558
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2559
|
+
"svg",
|
|
2560
|
+
{
|
|
2561
|
+
width: "20",
|
|
2562
|
+
height: "20",
|
|
2563
|
+
viewBox: "0 0 24 24",
|
|
2564
|
+
fill: "none",
|
|
2565
|
+
stroke: "currentColor",
|
|
2566
|
+
strokeWidth: "2",
|
|
2567
|
+
strokeLinecap: "round",
|
|
2568
|
+
strokeLinejoin: "round",
|
|
2569
|
+
children: [
|
|
2570
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M12 2L2 7l10 5 10-5-10-5z" }),
|
|
2571
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M2 17l10 5 10-5" }),
|
|
2572
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M2 12l10 5 10-5" })
|
|
2573
|
+
]
|
|
2574
|
+
}
|
|
2575
|
+
)
|
|
2576
|
+
}
|
|
2577
|
+
)
|
|
2578
|
+
]
|
|
2579
|
+
}
|
|
2580
|
+
);
|
|
2581
|
+
};
|
|
2582
|
+
BasemapSwitcher.displayName = "BasemapSwitcher";
|
|
2263
2583
|
var DeckOverlay = ({
|
|
2264
2584
|
layers = [],
|
|
2265
2585
|
onHover,
|
|
@@ -2274,9 +2594,11 @@ var DeckOverlay = ({
|
|
|
2274
2594
|
const MapboxOverlayRef = React6__namespace.useRef(null);
|
|
2275
2595
|
React6__namespace.useEffect(() => {
|
|
2276
2596
|
if (!map || !loaded) return;
|
|
2597
|
+
let cancelled = false;
|
|
2277
2598
|
const initOverlay = async () => {
|
|
2278
2599
|
try {
|
|
2279
2600
|
const deckMapbox = await import('@deck.gl/mapbox');
|
|
2601
|
+
if (cancelled) return;
|
|
2280
2602
|
const MapboxOverlay = deckMapbox.MapboxOverlay;
|
|
2281
2603
|
MapboxOverlayRef.current = MapboxOverlay;
|
|
2282
2604
|
const overlay = new MapboxOverlay({
|
|
@@ -2291,6 +2613,7 @@ var DeckOverlay = ({
|
|
|
2291
2613
|
map.addControl(overlay);
|
|
2292
2614
|
overlayRef.current = overlay;
|
|
2293
2615
|
} catch (err) {
|
|
2616
|
+
if (cancelled) return;
|
|
2294
2617
|
console.warn(
|
|
2295
2618
|
"[maps-react] Deck.gl is not available. Install @deck.gl/core, @deck.gl/layers, and @deck.gl/mapbox to use DeckOverlay.",
|
|
2296
2619
|
err
|
|
@@ -2299,6 +2622,7 @@ var DeckOverlay = ({
|
|
|
2299
2622
|
};
|
|
2300
2623
|
initOverlay();
|
|
2301
2624
|
return () => {
|
|
2625
|
+
cancelled = true;
|
|
2302
2626
|
if (overlayRef.current && map) {
|
|
2303
2627
|
try {
|
|
2304
2628
|
map.removeControl(overlayRef.current);
|
|
@@ -2330,6 +2654,18 @@ var DeckOverlay = ({
|
|
|
2330
2654
|
};
|
|
2331
2655
|
DeckOverlay.displayName = "DeckOverlay";
|
|
2332
2656
|
|
|
2657
|
+
Object.defineProperty(exports, "BUILTIN_BASEMAPS", {
|
|
2658
|
+
enumerable: true,
|
|
2659
|
+
get: function () { return mapsCore.BUILTIN_BASEMAPS; }
|
|
2660
|
+
});
|
|
2661
|
+
Object.defineProperty(exports, "FREE_BASEMAPS", {
|
|
2662
|
+
enumerable: true,
|
|
2663
|
+
get: function () { return mapsCore.FREE_BASEMAPS; }
|
|
2664
|
+
});
|
|
2665
|
+
Object.defineProperty(exports, "OSM_STANDARD", {
|
|
2666
|
+
enumerable: true,
|
|
2667
|
+
get: function () { return mapsCore.OSM_STANDARD; }
|
|
2668
|
+
});
|
|
2333
2669
|
Object.defineProperty(exports, "THEME_DARK", {
|
|
2334
2670
|
enumerable: true,
|
|
2335
2671
|
get: function () { return mapsCore.THEME_DARK; }
|
|
@@ -2402,6 +2738,10 @@ Object.defineProperty(exports, "generateMapDescription", {
|
|
|
2402
2738
|
enumerable: true,
|
|
2403
2739
|
get: function () { return mapsCore.generateMapDescription; }
|
|
2404
2740
|
});
|
|
2741
|
+
Object.defineProperty(exports, "getAvailableBasemaps", {
|
|
2742
|
+
enumerable: true,
|
|
2743
|
+
get: function () { return mapsCore.getAvailableBasemaps; }
|
|
2744
|
+
});
|
|
2405
2745
|
Object.defineProperty(exports, "getClusterBounds", {
|
|
2406
2746
|
enumerable: true,
|
|
2407
2747
|
get: function () { return mapsCore.getClusterBounds; }
|
|
@@ -2446,10 +2786,15 @@ Object.defineProperty(exports, "loadGeoJSON", {
|
|
|
2446
2786
|
enumerable: true,
|
|
2447
2787
|
get: function () { return mapsCore.loadGeoJSON; }
|
|
2448
2788
|
});
|
|
2789
|
+
Object.defineProperty(exports, "resolveBasemapStyle", {
|
|
2790
|
+
enumerable: true,
|
|
2791
|
+
get: function () { return mapsCore.resolveBasemapStyle; }
|
|
2792
|
+
});
|
|
2449
2793
|
Object.defineProperty(exports, "validateGeoJSON", {
|
|
2450
2794
|
enumerable: true,
|
|
2451
2795
|
get: function () { return mapsCore.validateGeoJSON; }
|
|
2452
2796
|
});
|
|
2797
|
+
exports.BasemapSwitcher = BasemapSwitcher;
|
|
2453
2798
|
exports.CircleLayer = CircleLayer;
|
|
2454
2799
|
exports.CoordinateDisplay = CoordinateDisplay;
|
|
2455
2800
|
exports.DeckOverlay = DeckOverlay;
|