@classic-homes/maps-react 0.1.4 → 0.2.1
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 +819 -145
- package/dist/index.d.cts +10 -3
- package/dist/index.d.ts +10 -3
- package/dist/index.js +730 -141
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as React25 from 'react';
|
|
2
2
|
import { useState, useEffect, useCallback } from 'react';
|
|
3
3
|
import { clsx } from 'clsx';
|
|
4
4
|
import { twMerge } from 'tailwind-merge';
|
|
@@ -7,17 +7,19 @@ 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, 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';
|
|
10
|
+
import { generateMapDescription, applyMarkerProtection, applyMarkerChildProtection, removeMarkerProtection, darkBasicStyle, lightBasicStyle, darkTheme, lightTheme, THEME_DARK, THEME_LIGHT, calculateBounds, computeVerticalOffsetStyle, computePositionClasses, formatCoordinates, getAvailableBasemaps, FREE_BASEMAPS, resolveBasemapThumbnail, createInitialLayerStates, getLayerCategories, searchLayers, groupLayersByCategory, toggleLayerVisibility, setLayerOpacity, getLayerStatesArray, reorderLayers, CATEGORY_META, resolveBasemapStyle, getLayerStyleForTheme, resolveLayerSourceUrl } from '@classic-homes/maps-core';
|
|
11
|
+
export { BIKE_LANES, BUILTIN_BASEMAPS, BUILTIN_OVERLAY_LAYERS, CATEGORY_META, CITY_LIMITS, FLOOD_ZONES, FREE_BASEMAPS, OSM_STANDARD, PARKS, SCHOOL_DISTRICTS, SPORTS_FACILITIES, THEME_DARK, THEME_LIGHT, TRAILS, TRANSIT_ROUTES, WATERSHEDS, ZONING_DISTRICTS, calculateBounds, calculateCentroid, combineBounds, countFeaturesByType, createHoverExpression, createInitialLayerStates, createSelectionExpression, darkBasicStyle, darkTheme, expandCluster, expandClusterToBounds, extendBounds, filterByGeometryType, formatArea, formatCoordinates, formatDistance, generateMapDescription, getAvailableBasemaps, getClusterBounds, getClusterChildren, getClusterExpansionZoom, getClusterLeaves, getHighlightStyle, getLayerCategories, getLayerStyleForTheme, getLayersByCategory, getSelectionStyle, groupLayersByCategory, isClusterFeature, isValidBounds, lightBasicStyle, lightTheme, loadGeoJSON, resolveBasemapStyle, resolveLayerSourceUrl, searchLayers, setLayerOpacity, toggleLayerVisibility, validateGeoJSON } from '@classic-homes/maps-core';
|
|
12
12
|
import * as ReactDOM from 'react-dom';
|
|
13
13
|
import { cva } from 'class-variance-authority';
|
|
14
14
|
import '@classic-homes/maps-core/styles/basemap-switcher.css';
|
|
15
|
+
import '@classic-homes/maps-core/styles/layer-manager.css';
|
|
16
|
+
import { Switch } from '@classic-homes/theme-react';
|
|
15
17
|
|
|
16
18
|
// src/components/base/MapContainer.tsx
|
|
17
19
|
function cn(...inputs) {
|
|
18
20
|
return twMerge(clsx(inputs));
|
|
19
21
|
}
|
|
20
|
-
var MapSkeleton =
|
|
22
|
+
var MapSkeleton = React25.forwardRef(
|
|
21
23
|
({ height = 400, className, ...props }, ref) => {
|
|
22
24
|
const heightStyle = typeof height === "number" ? `${height}px` : height;
|
|
23
25
|
return /* @__PURE__ */ jsxs(
|
|
@@ -71,7 +73,7 @@ var MapSkeleton = React6.forwardRef(
|
|
|
71
73
|
}
|
|
72
74
|
);
|
|
73
75
|
MapSkeleton.displayName = "MapSkeleton";
|
|
74
|
-
var MapError =
|
|
76
|
+
var MapError = React25.forwardRef(
|
|
75
77
|
({ message = "Failed to load map", height = 400, onRetry, className, ...props }, ref) => {
|
|
76
78
|
const heightStyle = typeof height === "number" ? `${height}px` : height;
|
|
77
79
|
return /* @__PURE__ */ jsx(
|
|
@@ -92,6 +94,8 @@ var MapError = React6.forwardRef(
|
|
|
92
94
|
{
|
|
93
95
|
className: "h-10 w-10 text-destructive",
|
|
94
96
|
xmlns: "http://www.w3.org/2000/svg",
|
|
97
|
+
width: "40",
|
|
98
|
+
height: "40",
|
|
95
99
|
fill: "none",
|
|
96
100
|
viewBox: "0 0 24 24",
|
|
97
101
|
stroke: "currentColor",
|
|
@@ -125,7 +129,7 @@ var MapError = React6.forwardRef(
|
|
|
125
129
|
}
|
|
126
130
|
);
|
|
127
131
|
MapError.displayName = "MapError";
|
|
128
|
-
var MapEmpty =
|
|
132
|
+
var MapEmpty = React25.forwardRef(
|
|
129
133
|
({ message = "No map data to display", height = 400, className, ...props }, ref) => {
|
|
130
134
|
const heightStyle = typeof height === "number" ? `${height}px` : height;
|
|
131
135
|
return /* @__PURE__ */ jsx(
|
|
@@ -168,7 +172,7 @@ var MapEmpty = React6.forwardRef(
|
|
|
168
172
|
}
|
|
169
173
|
);
|
|
170
174
|
MapEmpty.displayName = "MapEmpty";
|
|
171
|
-
var MapContainer =
|
|
175
|
+
var MapContainer = React25.forwardRef(
|
|
172
176
|
({
|
|
173
177
|
title,
|
|
174
178
|
description,
|
|
@@ -273,9 +277,9 @@ function useReducedMotion() {
|
|
|
273
277
|
}, []);
|
|
274
278
|
return prefersReducedMotion2;
|
|
275
279
|
}
|
|
276
|
-
var MapContext =
|
|
280
|
+
var MapContext = React25.createContext(null);
|
|
277
281
|
function useMap() {
|
|
278
|
-
const context =
|
|
282
|
+
const context = React25.useContext(MapContext);
|
|
279
283
|
if (!context) {
|
|
280
284
|
throw new Error("useMap must be used within a Map component");
|
|
281
285
|
}
|
|
@@ -285,7 +289,7 @@ function useMapInstance() {
|
|
|
285
289
|
const { map, loaded } = useMap();
|
|
286
290
|
return loaded ? map : null;
|
|
287
291
|
}
|
|
288
|
-
var
|
|
292
|
+
var Map2 = React25.forwardRef(
|
|
289
293
|
({
|
|
290
294
|
// Base props
|
|
291
295
|
title,
|
|
@@ -339,33 +343,33 @@ var Map = React6.forwardRef(
|
|
|
339
343
|
onZoom,
|
|
340
344
|
onError
|
|
341
345
|
}, ref) => {
|
|
342
|
-
const containerRef =
|
|
343
|
-
const mapRef =
|
|
344
|
-
const [mapLoaded, setMapLoaded] =
|
|
345
|
-
const [mapError, setMapError] =
|
|
346
|
-
const [styleVersion, setStyleVersion] =
|
|
347
|
-
const activeStyleOverrideRef =
|
|
346
|
+
const containerRef = React25.useRef(null);
|
|
347
|
+
const mapRef = React25.useRef(null);
|
|
348
|
+
const [mapLoaded, setMapLoaded] = React25.useState(false);
|
|
349
|
+
const [mapError, setMapError] = React25.useState(null);
|
|
350
|
+
const [styleVersion, setStyleVersion] = React25.useState(0);
|
|
351
|
+
const activeStyleOverrideRef = React25.useRef(
|
|
348
352
|
null
|
|
349
353
|
);
|
|
350
|
-
const setMapStyle =
|
|
354
|
+
const setMapStyle = React25.useCallback((style) => {
|
|
351
355
|
activeStyleOverrideRef.current = style;
|
|
352
356
|
mapRef.current?.setStyle(style);
|
|
353
357
|
}, []);
|
|
354
|
-
const customControlRegistryRef =
|
|
358
|
+
const customControlRegistryRef = React25.useRef({
|
|
355
359
|
"top-left": [],
|
|
356
360
|
"top-right": [],
|
|
357
361
|
"bottom-left": [],
|
|
358
362
|
"bottom-right": []
|
|
359
363
|
});
|
|
360
|
-
const [, forceUpdate] =
|
|
364
|
+
const [, forceUpdate] = React25.useReducer((x) => x + 1, 0);
|
|
361
365
|
const prefersReducedMotion2 = useReducedMotion();
|
|
362
366
|
const { style: themeStyle } = useMapTheme(themePref);
|
|
363
|
-
const onLoadRef =
|
|
367
|
+
const onLoadRef = React25.useRef(onLoad);
|
|
364
368
|
onLoadRef.current = onLoad;
|
|
365
|
-
const onErrorRef =
|
|
369
|
+
const onErrorRef = React25.useRef(onError);
|
|
366
370
|
onErrorRef.current = onError;
|
|
367
371
|
const mapStyle = customStyle || themeStyle;
|
|
368
|
-
const controlOffsets =
|
|
372
|
+
const controlOffsets = React25.useMemo(() => {
|
|
369
373
|
const offsets = {
|
|
370
374
|
"top-left": 0,
|
|
371
375
|
"top-right": 0,
|
|
@@ -384,6 +388,9 @@ var Map = React6.forwardRef(
|
|
|
384
388
|
if (geolocateControl) {
|
|
385
389
|
offsets[geolocateControlPosition] += 38;
|
|
386
390
|
}
|
|
391
|
+
if (attributionControl) {
|
|
392
|
+
offsets["bottom-right"] += 32;
|
|
393
|
+
}
|
|
387
394
|
return offsets;
|
|
388
395
|
}, [
|
|
389
396
|
navigationControl,
|
|
@@ -393,9 +400,10 @@ var Map = React6.forwardRef(
|
|
|
393
400
|
fullscreenControl,
|
|
394
401
|
fullscreenControlPosition,
|
|
395
402
|
geolocateControl,
|
|
396
|
-
geolocateControlPosition
|
|
403
|
+
geolocateControlPosition,
|
|
404
|
+
attributionControl
|
|
397
405
|
]);
|
|
398
|
-
const registerControl =
|
|
406
|
+
const registerControl = React25.useCallback(
|
|
399
407
|
(id, position, height2) => {
|
|
400
408
|
const registry = customControlRegistryRef.current;
|
|
401
409
|
const positionControls = registry[position] || [];
|
|
@@ -416,13 +424,13 @@ var Map = React6.forwardRef(
|
|
|
416
424
|
},
|
|
417
425
|
[]
|
|
418
426
|
);
|
|
419
|
-
const unregisterControl =
|
|
427
|
+
const unregisterControl = React25.useCallback((id, position) => {
|
|
420
428
|
const registry = customControlRegistryRef.current;
|
|
421
429
|
const positionControls = registry[position] || [];
|
|
422
430
|
registry[position] = positionControls.filter((c) => c.id !== id);
|
|
423
431
|
forceUpdate();
|
|
424
432
|
}, []);
|
|
425
|
-
const getCustomControlOffset =
|
|
433
|
+
const getCustomControlOffset = React25.useCallback((id, position) => {
|
|
426
434
|
const registry = customControlRegistryRef.current;
|
|
427
435
|
const positionControls = registry[position] || [];
|
|
428
436
|
let offset = 0;
|
|
@@ -436,7 +444,7 @@ var Map = React6.forwardRef(
|
|
|
436
444
|
center,
|
|
437
445
|
zoom
|
|
438
446
|
});
|
|
439
|
-
|
|
447
|
+
React25.useEffect(() => {
|
|
440
448
|
if (!containerRef.current || mapRef.current) return;
|
|
441
449
|
try {
|
|
442
450
|
const map = new maplibregl.Map({
|
|
@@ -516,8 +524,8 @@ var Map = React6.forwardRef(
|
|
|
516
524
|
onErrorRef.current?.({ type: "error", message: errorMessage, error: err });
|
|
517
525
|
}
|
|
518
526
|
}, []);
|
|
519
|
-
const styleInitialized =
|
|
520
|
-
|
|
527
|
+
const styleInitialized = React25.useRef(false);
|
|
528
|
+
React25.useEffect(() => {
|
|
521
529
|
if (!mapRef.current || !mapLoaded) return;
|
|
522
530
|
if (!styleInitialized.current) {
|
|
523
531
|
styleInitialized.current = true;
|
|
@@ -526,12 +534,12 @@ var Map = React6.forwardRef(
|
|
|
526
534
|
if (activeStyleOverrideRef.current) return;
|
|
527
535
|
mapRef.current.setStyle(mapStyle);
|
|
528
536
|
}, [mapStyle, mapLoaded]);
|
|
529
|
-
|
|
537
|
+
React25.useEffect(() => {
|
|
530
538
|
if (customStyle) {
|
|
531
539
|
activeStyleOverrideRef.current = null;
|
|
532
540
|
}
|
|
533
541
|
}, [customStyle]);
|
|
534
|
-
|
|
542
|
+
React25.useEffect(() => {
|
|
535
543
|
const map = mapRef.current;
|
|
536
544
|
if (!map || !mapLoaded) return;
|
|
537
545
|
const createEventParams = (e) => ({
|
|
@@ -665,7 +673,7 @@ var Map = React6.forwardRef(
|
|
|
665
673
|
);
|
|
666
674
|
}
|
|
667
675
|
);
|
|
668
|
-
|
|
676
|
+
Map2.displayName = "Map";
|
|
669
677
|
var Source = ({
|
|
670
678
|
id,
|
|
671
679
|
type,
|
|
@@ -686,9 +694,9 @@ var Source = ({
|
|
|
686
694
|
children
|
|
687
695
|
}) => {
|
|
688
696
|
const { map, loaded, styleVersion } = useMap();
|
|
689
|
-
const sourceAdded =
|
|
690
|
-
const initialFitDone =
|
|
691
|
-
const fitBoundsParamsRef =
|
|
697
|
+
const sourceAdded = React25.useRef(false);
|
|
698
|
+
const initialFitDone = React25.useRef(false);
|
|
699
|
+
const fitBoundsParamsRef = React25.useRef({
|
|
692
700
|
shouldFitBounds,
|
|
693
701
|
data,
|
|
694
702
|
fitBoundsPadding,
|
|
@@ -704,7 +712,7 @@ var Source = ({
|
|
|
704
712
|
fitBoundsAnimate,
|
|
705
713
|
type
|
|
706
714
|
};
|
|
707
|
-
const performFitBounds =
|
|
715
|
+
const performFitBounds = React25.useCallback(
|
|
708
716
|
(cancelledRef) => {
|
|
709
717
|
const params = fitBoundsParamsRef.current;
|
|
710
718
|
if (cancelledRef.current || !params.shouldFitBounds || initialFitDone.current) return;
|
|
@@ -748,7 +756,7 @@ var Source = ({
|
|
|
748
756
|
},
|
|
749
757
|
[map]
|
|
750
758
|
);
|
|
751
|
-
|
|
759
|
+
React25.useEffect(() => {
|
|
752
760
|
if (!map || !loaded || sourceAdded.current) return;
|
|
753
761
|
if (map.getSource(id)) {
|
|
754
762
|
sourceAdded.current = true;
|
|
@@ -898,24 +906,39 @@ var Source = ({
|
|
|
898
906
|
styleVersion
|
|
899
907
|
// re-add source after basemap style changes
|
|
900
908
|
]);
|
|
901
|
-
|
|
909
|
+
React25.useEffect(() => {
|
|
902
910
|
if (!map || !loaded || !sourceAdded.current || type !== "geojson") return;
|
|
903
911
|
const source = map.getSource(id);
|
|
904
912
|
if (!source) return;
|
|
913
|
+
let cancelled = false;
|
|
905
914
|
try {
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
915
|
+
const newData = typeof data === "string" ? data : data && typeof data === "object" ? data : null;
|
|
916
|
+
if (!newData) return;
|
|
917
|
+
const handleSourceData = (e) => {
|
|
918
|
+
if (cancelled) return;
|
|
919
|
+
if (e.sourceId === id && e.isSourceLoaded) {
|
|
920
|
+
map.off("sourcedata", handleSourceData);
|
|
921
|
+
map.triggerRepaint();
|
|
922
|
+
}
|
|
923
|
+
};
|
|
924
|
+
if (cluster) {
|
|
925
|
+
map.on("sourcedata", handleSourceData);
|
|
910
926
|
}
|
|
927
|
+
source.setData(newData);
|
|
928
|
+
return () => {
|
|
929
|
+
cancelled = true;
|
|
930
|
+
if (cluster) {
|
|
931
|
+
map.off("sourcedata", handleSourceData);
|
|
932
|
+
}
|
|
933
|
+
};
|
|
911
934
|
} catch (err) {
|
|
912
935
|
console.error(`[maps-react] Failed to update source "${id}" data:`, err);
|
|
913
936
|
}
|
|
914
|
-
}, [map, loaded, id, type, data]);
|
|
937
|
+
}, [map, loaded, id, type, data, cluster]);
|
|
915
938
|
return /* @__PURE__ */ jsx(Fragment, { children });
|
|
916
939
|
};
|
|
917
940
|
Source.displayName = "Source";
|
|
918
|
-
var Marker =
|
|
941
|
+
var Marker = React25.forwardRef(
|
|
919
942
|
({
|
|
920
943
|
id,
|
|
921
944
|
coordinates,
|
|
@@ -931,27 +954,27 @@ var Marker = React6.forwardRef(
|
|
|
931
954
|
children
|
|
932
955
|
}, ref) => {
|
|
933
956
|
const { map, loaded } = useMap();
|
|
934
|
-
const markerRef =
|
|
935
|
-
const elementRef =
|
|
936
|
-
const originalLngLatRef =
|
|
937
|
-
const clickHandlerRef =
|
|
938
|
-
const [mounted, setMounted] =
|
|
939
|
-
const onClickRef =
|
|
957
|
+
const markerRef = React25.useRef(null);
|
|
958
|
+
const elementRef = React25.useRef(null);
|
|
959
|
+
const originalLngLatRef = React25.useRef();
|
|
960
|
+
const clickHandlerRef = React25.useRef(null);
|
|
961
|
+
const [mounted, setMounted] = React25.useState(false);
|
|
962
|
+
const onClickRef = React25.useRef(onClick);
|
|
940
963
|
onClickRef.current = onClick;
|
|
941
|
-
const onDragRef =
|
|
964
|
+
const onDragRef = React25.useRef(onDrag);
|
|
942
965
|
onDragRef.current = onDrag;
|
|
943
|
-
const onDragEndRef =
|
|
966
|
+
const onDragEndRef = React25.useRef(onDragEnd);
|
|
944
967
|
onDragEndRef.current = onDragEnd;
|
|
945
|
-
|
|
968
|
+
React25.useEffect(() => {
|
|
946
969
|
setMounted(true);
|
|
947
970
|
return () => setMounted(false);
|
|
948
971
|
}, []);
|
|
949
|
-
|
|
972
|
+
React25.useEffect(() => {
|
|
950
973
|
if (children && !elementRef.current) {
|
|
951
974
|
elementRef.current = document.createElement("div");
|
|
952
975
|
}
|
|
953
976
|
}, [children]);
|
|
954
|
-
|
|
977
|
+
React25.useEffect(() => {
|
|
955
978
|
if (!map || !loaded || !mounted) return;
|
|
956
979
|
if (markerRef.current) return;
|
|
957
980
|
const markerOptions = {
|
|
@@ -1035,17 +1058,17 @@ var Marker = React6.forwardRef(
|
|
|
1035
1058
|
}
|
|
1036
1059
|
};
|
|
1037
1060
|
}, [map, loaded, mounted]);
|
|
1038
|
-
|
|
1061
|
+
React25.useEffect(() => {
|
|
1039
1062
|
if (markerRef.current) {
|
|
1040
1063
|
markerRef.current.setLngLat(coordinates);
|
|
1041
1064
|
}
|
|
1042
1065
|
}, [coordinates]);
|
|
1043
|
-
|
|
1066
|
+
React25.useEffect(() => {
|
|
1044
1067
|
if (markerRef.current) {
|
|
1045
1068
|
markerRef.current.setDraggable(draggable);
|
|
1046
1069
|
}
|
|
1047
1070
|
}, [draggable]);
|
|
1048
|
-
|
|
1071
|
+
React25.useEffect(() => {
|
|
1049
1072
|
if (markerRef.current && rotation !== void 0) {
|
|
1050
1073
|
markerRef.current.setRotation(rotation);
|
|
1051
1074
|
}
|
|
@@ -1091,7 +1114,7 @@ function panToFitPopup(map, popup, padding) {
|
|
|
1091
1114
|
});
|
|
1092
1115
|
}
|
|
1093
1116
|
}
|
|
1094
|
-
var Popup =
|
|
1117
|
+
var Popup = React25.forwardRef(
|
|
1095
1118
|
({
|
|
1096
1119
|
coordinates,
|
|
1097
1120
|
closeButton = true,
|
|
@@ -1109,25 +1132,25 @@ var Popup = React6.forwardRef(
|
|
|
1109
1132
|
children
|
|
1110
1133
|
}, ref) => {
|
|
1111
1134
|
const { map, loaded } = useMap();
|
|
1112
|
-
const popupRef =
|
|
1113
|
-
const onOpenRef =
|
|
1135
|
+
const popupRef = React25.useRef(null);
|
|
1136
|
+
const onOpenRef = React25.useRef(onOpen);
|
|
1114
1137
|
onOpenRef.current = onOpen;
|
|
1115
|
-
const onCloseRef =
|
|
1138
|
+
const onCloseRef = React25.useRef(onClose);
|
|
1116
1139
|
onCloseRef.current = onClose;
|
|
1117
|
-
const coordinatesRef =
|
|
1140
|
+
const coordinatesRef = React25.useRef(coordinates);
|
|
1118
1141
|
coordinatesRef.current = coordinates;
|
|
1119
|
-
const containerRef =
|
|
1142
|
+
const containerRef = React25.useRef(null);
|
|
1120
1143
|
if (!containerRef.current && typeof document !== "undefined") {
|
|
1121
1144
|
containerRef.current = document.createElement("div");
|
|
1122
1145
|
containerRef.current.className = "maplibregl-popup-content-wrapper";
|
|
1123
1146
|
}
|
|
1124
|
-
const [contentReady, setContentReady] =
|
|
1125
|
-
const contentCallbackRef =
|
|
1147
|
+
const [contentReady, setContentReady] = React25.useState(false);
|
|
1148
|
+
const contentCallbackRef = React25.useCallback((node) => {
|
|
1126
1149
|
if (node && containerRef.current) {
|
|
1127
1150
|
setContentReady(true);
|
|
1128
1151
|
}
|
|
1129
1152
|
}, []);
|
|
1130
|
-
|
|
1153
|
+
React25.useEffect(() => {
|
|
1131
1154
|
if (!map || !loaded || !containerRef.current) return;
|
|
1132
1155
|
const popup = new maplibregl.Popup({
|
|
1133
1156
|
closeButton,
|
|
@@ -1167,7 +1190,7 @@ var Popup = React6.forwardRef(
|
|
|
1167
1190
|
maxWidth,
|
|
1168
1191
|
focusAfterOpen
|
|
1169
1192
|
]);
|
|
1170
|
-
|
|
1193
|
+
React25.useEffect(() => {
|
|
1171
1194
|
if (!popupRef.current || !ref) return;
|
|
1172
1195
|
if (typeof ref === "function") {
|
|
1173
1196
|
ref(popupRef.current);
|
|
@@ -1175,12 +1198,12 @@ var Popup = React6.forwardRef(
|
|
|
1175
1198
|
ref.current = popupRef.current;
|
|
1176
1199
|
}
|
|
1177
1200
|
}, [ref]);
|
|
1178
|
-
|
|
1201
|
+
React25.useEffect(() => {
|
|
1179
1202
|
if (popupRef.current) {
|
|
1180
1203
|
popupRef.current.setLngLat(coordinates);
|
|
1181
1204
|
}
|
|
1182
1205
|
}, [coordinates]);
|
|
1183
|
-
|
|
1206
|
+
React25.useEffect(() => {
|
|
1184
1207
|
if (!map || !popupRef.current || !contentReady) return;
|
|
1185
1208
|
let rafHandle;
|
|
1186
1209
|
if (open) {
|
|
@@ -1209,7 +1232,7 @@ var Popup = React6.forwardRef(
|
|
|
1209
1232
|
}
|
|
1210
1233
|
);
|
|
1211
1234
|
Popup.displayName = "Popup";
|
|
1212
|
-
var PopupCard =
|
|
1235
|
+
var PopupCard = React25.forwardRef(
|
|
1213
1236
|
({ className, children, ...props }, ref) => {
|
|
1214
1237
|
return /* @__PURE__ */ jsx("div", { ref, className: cn("bg-popover text-popover-foreground", className), ...props, children });
|
|
1215
1238
|
}
|
|
@@ -1229,7 +1252,7 @@ var badgeVariants = cva("text-xs px-1.5 py-0.5 rounded font-medium flex-shrink-0
|
|
|
1229
1252
|
badgeVariant: "secondary"
|
|
1230
1253
|
}
|
|
1231
1254
|
});
|
|
1232
|
-
var PopupHeader =
|
|
1255
|
+
var PopupHeader = React25.forwardRef(
|
|
1233
1256
|
({ className, title, badge, badgeVariant, ...props }, ref) => {
|
|
1234
1257
|
return /* @__PURE__ */ jsxs(
|
|
1235
1258
|
"div",
|
|
@@ -1249,13 +1272,13 @@ var PopupHeader = React6.forwardRef(
|
|
|
1249
1272
|
}
|
|
1250
1273
|
);
|
|
1251
1274
|
PopupHeader.displayName = "PopupHeader";
|
|
1252
|
-
var PopupContent =
|
|
1275
|
+
var PopupContent = React25.forwardRef(
|
|
1253
1276
|
({ className, children, ...props }, ref) => {
|
|
1254
1277
|
return /* @__PURE__ */ jsx("div", { ref, className: cn("px-4 py-3 text-sm", className), ...props, children });
|
|
1255
1278
|
}
|
|
1256
1279
|
);
|
|
1257
1280
|
PopupContent.displayName = "PopupContent";
|
|
1258
|
-
var PopupFooter =
|
|
1281
|
+
var PopupFooter = React25.forwardRef(
|
|
1259
1282
|
({ className, children, ...props }, ref) => {
|
|
1260
1283
|
return /* @__PURE__ */ jsx(
|
|
1261
1284
|
"div",
|
|
@@ -1290,14 +1313,14 @@ function useLayer({
|
|
|
1290
1313
|
hoverThrottleMs = 0
|
|
1291
1314
|
}) {
|
|
1292
1315
|
const { map, loaded, styleVersion } = useMap();
|
|
1293
|
-
const [layerAdded, setLayerAdded] =
|
|
1294
|
-
const hoveredFeatureId =
|
|
1295
|
-
const lastHoverCallTime =
|
|
1296
|
-
const lastMousePosition =
|
|
1297
|
-
|
|
1316
|
+
const [layerAdded, setLayerAdded] = React25.useState(false);
|
|
1317
|
+
const hoveredFeatureId = React25.useRef(null);
|
|
1318
|
+
const lastHoverCallTime = React25.useRef(0);
|
|
1319
|
+
const lastMousePosition = React25.useRef(null);
|
|
1320
|
+
React25.useEffect(() => {
|
|
1298
1321
|
hoveredFeatureId.current = null;
|
|
1299
1322
|
}, [styleVersion]);
|
|
1300
|
-
|
|
1323
|
+
React25.useEffect(() => {
|
|
1301
1324
|
if (!map || !loaded) return;
|
|
1302
1325
|
if (!map.getSource(source)) {
|
|
1303
1326
|
let timeoutId = null;
|
|
@@ -1368,24 +1391,24 @@ function useLayer({
|
|
|
1368
1391
|
}
|
|
1369
1392
|
};
|
|
1370
1393
|
}, [map, loaded, id, source, sourceLayer, type, beforeId, styleVersion]);
|
|
1371
|
-
|
|
1394
|
+
React25.useEffect(() => {
|
|
1372
1395
|
if (!map || !layerAdded) return;
|
|
1373
1396
|
if (!map.getLayer(id)) return;
|
|
1374
1397
|
map.setLayoutProperty(id, "visibility", visible ? "visible" : "none");
|
|
1375
1398
|
}, [map, id, visible, layerAdded]);
|
|
1376
|
-
|
|
1399
|
+
React25.useEffect(() => {
|
|
1377
1400
|
if (!map || !layerAdded) return;
|
|
1378
1401
|
if (!map.getLayer(id)) return;
|
|
1379
1402
|
Object.entries(paint).forEach(([key, value]) => {
|
|
1380
1403
|
map.setPaintProperty(id, key, value);
|
|
1381
1404
|
});
|
|
1382
1405
|
}, [map, id, paint, layerAdded]);
|
|
1383
|
-
|
|
1406
|
+
React25.useEffect(() => {
|
|
1384
1407
|
if (!map || !layerAdded || !filter) return;
|
|
1385
1408
|
if (!map.getLayer(id)) return;
|
|
1386
1409
|
map.setFilter(id, filter);
|
|
1387
1410
|
}, [map, id, filter, layerAdded]);
|
|
1388
|
-
|
|
1411
|
+
React25.useEffect(() => {
|
|
1389
1412
|
if (!map || !layerAdded) return;
|
|
1390
1413
|
const createFeatureParams = (e) => {
|
|
1391
1414
|
const feature = e.features?.[0];
|
|
@@ -1521,7 +1544,7 @@ var FillLayer = ({
|
|
|
1521
1544
|
fillTranslate,
|
|
1522
1545
|
fillAntialias
|
|
1523
1546
|
}) => {
|
|
1524
|
-
const paint =
|
|
1547
|
+
const paint = React25.useMemo(() => {
|
|
1525
1548
|
const p = {};
|
|
1526
1549
|
if (fillColor !== void 0) p["fill-color"] = fillColor;
|
|
1527
1550
|
if (fillOpacity !== void 0) p["fill-opacity"] = fillOpacity;
|
|
@@ -1542,7 +1565,7 @@ var FillLayer = ({
|
|
|
1542
1565
|
fillAntialias,
|
|
1543
1566
|
opacity
|
|
1544
1567
|
]);
|
|
1545
|
-
const layout =
|
|
1568
|
+
const layout = React25.useMemo(() => ({}), []);
|
|
1546
1569
|
useLayer({
|
|
1547
1570
|
id,
|
|
1548
1571
|
source,
|
|
@@ -1586,7 +1609,7 @@ var LineLayer = ({
|
|
|
1586
1609
|
lineOffset,
|
|
1587
1610
|
lineGradient
|
|
1588
1611
|
}) => {
|
|
1589
|
-
const paint =
|
|
1612
|
+
const paint = React25.useMemo(() => {
|
|
1590
1613
|
const p = {};
|
|
1591
1614
|
if (lineColor !== void 0) p["line-color"] = lineColor;
|
|
1592
1615
|
if (lineWidth !== void 0) p["line-width"] = lineWidth;
|
|
@@ -1611,7 +1634,7 @@ var LineLayer = ({
|
|
|
1611
1634
|
lineGradient,
|
|
1612
1635
|
opacity
|
|
1613
1636
|
]);
|
|
1614
|
-
const layout =
|
|
1637
|
+
const layout = React25.useMemo(() => {
|
|
1615
1638
|
const l = {};
|
|
1616
1639
|
if (lineCap !== void 0) l["line-cap"] = lineCap;
|
|
1617
1640
|
if (lineJoin !== void 0) l["line-join"] = lineJoin;
|
|
@@ -1660,7 +1683,7 @@ var CircleLayer = ({
|
|
|
1660
1683
|
circlePitchScale,
|
|
1661
1684
|
circleTranslate
|
|
1662
1685
|
}) => {
|
|
1663
|
-
const paint =
|
|
1686
|
+
const paint = React25.useMemo(() => {
|
|
1664
1687
|
const p = {};
|
|
1665
1688
|
if (circleRadius !== void 0) p["circle-radius"] = circleRadius;
|
|
1666
1689
|
if (circleColor !== void 0) p["circle-color"] = circleColor;
|
|
@@ -1689,7 +1712,7 @@ var CircleLayer = ({
|
|
|
1689
1712
|
circleTranslate,
|
|
1690
1713
|
opacity
|
|
1691
1714
|
]);
|
|
1692
|
-
const layout =
|
|
1715
|
+
const layout = React25.useMemo(() => ({}), []);
|
|
1693
1716
|
useLayer({
|
|
1694
1717
|
id,
|
|
1695
1718
|
source,
|
|
@@ -1749,7 +1772,7 @@ var SymbolLayer = ({
|
|
|
1749
1772
|
symbolSpacing,
|
|
1750
1773
|
symbolSortKey
|
|
1751
1774
|
}) => {
|
|
1752
|
-
const paint =
|
|
1775
|
+
const paint = React25.useMemo(() => {
|
|
1753
1776
|
const p = {};
|
|
1754
1777
|
if (iconOpacity !== void 0) p["icon-opacity"] = iconOpacity;
|
|
1755
1778
|
if (iconColor !== void 0) p["icon-color"] = iconColor;
|
|
@@ -1770,7 +1793,7 @@ var SymbolLayer = ({
|
|
|
1770
1793
|
textHaloColor,
|
|
1771
1794
|
textHaloWidth
|
|
1772
1795
|
]);
|
|
1773
|
-
const layout =
|
|
1796
|
+
const layout = React25.useMemo(() => {
|
|
1774
1797
|
const l = {};
|
|
1775
1798
|
if (iconImage !== void 0) l["icon-image"] = iconImage;
|
|
1776
1799
|
if (iconSize !== void 0) l["icon-size"] = iconSize;
|
|
@@ -1851,7 +1874,7 @@ var FillExtrusionLayer = ({
|
|
|
1851
1874
|
fillExtrusionTranslate,
|
|
1852
1875
|
fillExtrusionVerticalGradient
|
|
1853
1876
|
}) => {
|
|
1854
|
-
const paint =
|
|
1877
|
+
const paint = React25.useMemo(() => {
|
|
1855
1878
|
const p = {};
|
|
1856
1879
|
if (fillExtrusionHeight !== void 0) p["fill-extrusion-height"] = fillExtrusionHeight;
|
|
1857
1880
|
if (fillExtrusionBase !== void 0) p["fill-extrusion-base"] = fillExtrusionBase;
|
|
@@ -1877,7 +1900,7 @@ var FillExtrusionLayer = ({
|
|
|
1877
1900
|
fillExtrusionVerticalGradient,
|
|
1878
1901
|
opacity
|
|
1879
1902
|
]);
|
|
1880
|
-
const layout =
|
|
1903
|
+
const layout = React25.useMemo(() => ({}), []);
|
|
1881
1904
|
useLayer({
|
|
1882
1905
|
id,
|
|
1883
1906
|
source,
|
|
@@ -1916,7 +1939,7 @@ var HeatmapLayer = ({
|
|
|
1916
1939
|
heatmapRadius,
|
|
1917
1940
|
heatmapOpacity
|
|
1918
1941
|
}) => {
|
|
1919
|
-
const paint =
|
|
1942
|
+
const paint = React25.useMemo(() => {
|
|
1920
1943
|
const p = {};
|
|
1921
1944
|
if (heatmapIntensity !== void 0) p["heatmap-intensity"] = heatmapIntensity;
|
|
1922
1945
|
if (heatmapWeight !== void 0) p["heatmap-weight"] = heatmapWeight;
|
|
@@ -1928,7 +1951,7 @@ var HeatmapLayer = ({
|
|
|
1928
1951
|
}
|
|
1929
1952
|
return p;
|
|
1930
1953
|
}, [heatmapIntensity, heatmapWeight, heatmapColor, heatmapRadius, heatmapOpacity, opacity]);
|
|
1931
|
-
const layout =
|
|
1954
|
+
const layout = React25.useMemo(() => ({}), []);
|
|
1932
1955
|
useLayer({
|
|
1933
1956
|
id,
|
|
1934
1957
|
source,
|
|
@@ -1963,11 +1986,11 @@ var Legend = ({
|
|
|
1963
1986
|
onItemClick
|
|
1964
1987
|
}) => {
|
|
1965
1988
|
const { controlOffsets, registerControl, unregisterControl } = useMap();
|
|
1966
|
-
const [isCollapsed, setIsCollapsed] =
|
|
1967
|
-
const [customControlOffset, setCustomControlOffset] =
|
|
1968
|
-
const legendRef =
|
|
1969
|
-
const legendIdRef =
|
|
1970
|
-
|
|
1989
|
+
const [isCollapsed, setIsCollapsed] = React25.useState(initialCollapsed);
|
|
1990
|
+
const [customControlOffset, setCustomControlOffset] = React25.useState(0);
|
|
1991
|
+
const legendRef = React25.useRef(null);
|
|
1992
|
+
const legendIdRef = React25.useRef(`legend-${++legendIdCounter}`);
|
|
1993
|
+
React25.useEffect(() => {
|
|
1971
1994
|
if (!legendRef.current || !registerControl) return;
|
|
1972
1995
|
const updatePosition = () => {
|
|
1973
1996
|
if (!legendRef.current) return;
|
|
@@ -1983,7 +2006,7 @@ var Legend = ({
|
|
|
1983
2006
|
unregisterControl?.(legendIdRef.current, position);
|
|
1984
2007
|
};
|
|
1985
2008
|
}, [position, registerControl, unregisterControl]);
|
|
1986
|
-
const verticalOffsetStyle =
|
|
2009
|
+
const verticalOffsetStyle = React25.useMemo(() => {
|
|
1987
2010
|
return computeVerticalOffsetStyle(position, customControlOffset);
|
|
1988
2011
|
}, [customControlOffset, position]);
|
|
1989
2012
|
const handleItemClick = (item, index) => {
|
|
@@ -1996,13 +2019,13 @@ var Legend = ({
|
|
|
1996
2019
|
setIsCollapsed(!isCollapsed);
|
|
1997
2020
|
}
|
|
1998
2021
|
};
|
|
1999
|
-
const gradientStyle =
|
|
2022
|
+
const gradientStyle = React25.useMemo(() => {
|
|
2000
2023
|
if (type !== "gradient" || gradient.length === 0) return "";
|
|
2001
2024
|
const stops = gradient.map((stop) => `${stop.color} ${stop.position * 100}%`).join(", ");
|
|
2002
2025
|
return `linear-gradient(to right, ${stops})`;
|
|
2003
2026
|
}, [type, gradient]);
|
|
2004
2027
|
const hasControlsAtPosition = (controlOffsets?.[position] ?? 0) > 0;
|
|
2005
|
-
const computedPositionClasses =
|
|
2028
|
+
const computedPositionClasses = React25.useMemo(() => {
|
|
2006
2029
|
return computePositionClasses(position, hasControlsAtPosition);
|
|
2007
2030
|
}, [position, hasControlsAtPosition]);
|
|
2008
2031
|
return /* @__PURE__ */ jsxs(
|
|
@@ -2101,15 +2124,15 @@ var LegendGroup = ({
|
|
|
2101
2124
|
class: className
|
|
2102
2125
|
}) => {
|
|
2103
2126
|
const { controlOffsets, registerControl, unregisterControl } = useMap();
|
|
2104
|
-
const containerRef =
|
|
2105
|
-
const groupIdRef =
|
|
2106
|
-
const [customControlOffset, setCustomControlOffset] =
|
|
2127
|
+
const containerRef = React25.useRef(null);
|
|
2128
|
+
const groupIdRef = React25.useRef(`legend-group-${++legendGroupIdCounter}`);
|
|
2129
|
+
const [customControlOffset, setCustomControlOffset] = React25.useState(0);
|
|
2107
2130
|
const getInitialExpanded = () => {
|
|
2108
2131
|
if (controlledExpanded !== void 0) return controlledExpanded;
|
|
2109
2132
|
if (defaultExpanded) return defaultExpanded;
|
|
2110
2133
|
return legends[0]?.id || null;
|
|
2111
2134
|
};
|
|
2112
|
-
const [internalExpanded, setInternalExpanded] =
|
|
2135
|
+
const [internalExpanded, setInternalExpanded] = React25.useState(getInitialExpanded);
|
|
2113
2136
|
const expandedId = controlledExpanded !== void 0 ? controlledExpanded : internalExpanded;
|
|
2114
2137
|
const handleToggle = (id) => {
|
|
2115
2138
|
const newExpanded = expandedId === id ? allowCollapseAll ? null : id : id;
|
|
@@ -2118,7 +2141,7 @@ var LegendGroup = ({
|
|
|
2118
2141
|
}
|
|
2119
2142
|
onExpandedChange?.(newExpanded);
|
|
2120
2143
|
};
|
|
2121
|
-
|
|
2144
|
+
React25.useEffect(() => {
|
|
2122
2145
|
if (!containerRef.current || !registerControl) return;
|
|
2123
2146
|
const timeoutId = setTimeout(() => {
|
|
2124
2147
|
if (containerRef.current) {
|
|
@@ -2132,11 +2155,11 @@ var LegendGroup = ({
|
|
|
2132
2155
|
unregisterControl?.(groupIdRef.current, position);
|
|
2133
2156
|
};
|
|
2134
2157
|
}, [position, expandedId, registerControl, unregisterControl]);
|
|
2135
|
-
const verticalOffsetStyle =
|
|
2158
|
+
const verticalOffsetStyle = React25.useMemo(() => {
|
|
2136
2159
|
return computeVerticalOffsetStyle(position, customControlOffset);
|
|
2137
2160
|
}, [customControlOffset, position]);
|
|
2138
2161
|
const hasControlsAtPosition = (controlOffsets?.[position] ?? 0) > 0;
|
|
2139
|
-
const computedPositionClasses =
|
|
2162
|
+
const computedPositionClasses = React25.useMemo(() => {
|
|
2140
2163
|
return computePositionClasses(position, hasControlsAtPosition);
|
|
2141
2164
|
}, [position, hasControlsAtPosition]);
|
|
2142
2165
|
const getGradientStyle = (legend) => {
|
|
@@ -2267,13 +2290,13 @@ var CoordinateDisplay = ({
|
|
|
2267
2290
|
class: className
|
|
2268
2291
|
}) => {
|
|
2269
2292
|
const { map, loaded, controlOffsets, registerControl, unregisterControl } = useMap();
|
|
2270
|
-
const [cursorLngLat, setCursorLngLat] =
|
|
2271
|
-
const [currentZoom, setCurrentZoom] =
|
|
2272
|
-
const [currentBearing, setCurrentBearing] =
|
|
2273
|
-
const [customControlOffset, setCustomControlOffset] =
|
|
2274
|
-
const controlRef =
|
|
2275
|
-
const controlIdRef =
|
|
2276
|
-
|
|
2293
|
+
const [cursorLngLat, setCursorLngLat] = React25.useState(null);
|
|
2294
|
+
const [currentZoom, setCurrentZoom] = React25.useState(0);
|
|
2295
|
+
const [currentBearing, setCurrentBearing] = React25.useState(0);
|
|
2296
|
+
const [customControlOffset, setCustomControlOffset] = React25.useState(0);
|
|
2297
|
+
const controlRef = React25.useRef(null);
|
|
2298
|
+
const controlIdRef = React25.useRef(`coord-display-${++coordDisplayIdCounter}`);
|
|
2299
|
+
React25.useEffect(() => {
|
|
2277
2300
|
if (!controlRef.current || !registerControl) return;
|
|
2278
2301
|
const updatePosition = () => {
|
|
2279
2302
|
if (!controlRef.current) return;
|
|
@@ -2289,10 +2312,10 @@ var CoordinateDisplay = ({
|
|
|
2289
2312
|
unregisterControl?.(controlIdRef.current, position);
|
|
2290
2313
|
};
|
|
2291
2314
|
}, [position, registerControl, unregisterControl]);
|
|
2292
|
-
const verticalOffsetStyle =
|
|
2315
|
+
const verticalOffsetStyle = React25.useMemo(() => {
|
|
2293
2316
|
return computeVerticalOffsetStyle(position, customControlOffset);
|
|
2294
2317
|
}, [customControlOffset, position]);
|
|
2295
|
-
const formatCoord =
|
|
2318
|
+
const formatCoord = React25.useCallback(
|
|
2296
2319
|
(lngLat) => {
|
|
2297
2320
|
return formatCoordinates(lngLat, precision, format);
|
|
2298
2321
|
},
|
|
@@ -2306,10 +2329,10 @@ var CoordinateDisplay = ({
|
|
|
2306
2329
|
return `${normalized.toFixed(0)}\xB0`;
|
|
2307
2330
|
};
|
|
2308
2331
|
const hasControlsAtPosition = (controlOffsets?.[position] ?? 0) > 0;
|
|
2309
|
-
const computedPositionClasses =
|
|
2332
|
+
const computedPositionClasses = React25.useMemo(() => {
|
|
2310
2333
|
return computePositionClasses(position, hasControlsAtPosition);
|
|
2311
2334
|
}, [position, hasControlsAtPosition]);
|
|
2312
|
-
|
|
2335
|
+
React25.useEffect(() => {
|
|
2313
2336
|
if (!map || !loaded) return;
|
|
2314
2337
|
setCurrentZoom(map.getZoom());
|
|
2315
2338
|
setCurrentBearing(map.getBearing());
|
|
@@ -2376,16 +2399,16 @@ var BasemapSwitcher = ({
|
|
|
2376
2399
|
class: className
|
|
2377
2400
|
}) => {
|
|
2378
2401
|
const { controlOffsets, registerControl, unregisterControl, setMapStyle } = useMap();
|
|
2379
|
-
const [isOpen, setIsOpen] =
|
|
2380
|
-
const [internalActiveId, setInternalActiveId] =
|
|
2402
|
+
const [isOpen, setIsOpen] = React25.useState(false);
|
|
2403
|
+
const [internalActiveId, setInternalActiveId] = React25.useState(
|
|
2381
2404
|
defaultBasemapId
|
|
2382
2405
|
);
|
|
2383
|
-
const [customControlOffset, setCustomControlOffset] =
|
|
2384
|
-
const containerRef =
|
|
2385
|
-
const panelRef =
|
|
2386
|
-
const switcherIdRef =
|
|
2406
|
+
const [customControlOffset, setCustomControlOffset] = React25.useState(0);
|
|
2407
|
+
const containerRef = React25.useRef(null);
|
|
2408
|
+
const panelRef = React25.useRef(null);
|
|
2409
|
+
const switcherIdRef = React25.useRef(`basemap-switcher-${++switcherIdCounter}`);
|
|
2387
2410
|
const sourceBasemaps = basemaps ?? FREE_BASEMAPS;
|
|
2388
|
-
const availableBasemaps =
|
|
2411
|
+
const availableBasemaps = React25.useMemo(() => {
|
|
2389
2412
|
const available = getAvailableBasemaps(sourceBasemaps, apiKeys);
|
|
2390
2413
|
if (extraBasemaps?.length) {
|
|
2391
2414
|
return [...available, ...getAvailableBasemaps(extraBasemaps, apiKeys)];
|
|
@@ -2393,7 +2416,7 @@ var BasemapSwitcher = ({
|
|
|
2393
2416
|
return available;
|
|
2394
2417
|
}, [sourceBasemaps, extraBasemaps, apiKeys]);
|
|
2395
2418
|
const currentActiveId = activeBasemapId ?? internalActiveId ?? availableBasemaps[0]?.id;
|
|
2396
|
-
|
|
2419
|
+
React25.useEffect(() => {
|
|
2397
2420
|
if (!containerRef.current || !registerControl) return;
|
|
2398
2421
|
const updatePosition = () => {
|
|
2399
2422
|
if (!containerRef.current) return;
|
|
@@ -2409,7 +2432,7 @@ var BasemapSwitcher = ({
|
|
|
2409
2432
|
unregisterControl?.(switcherIdRef.current, position);
|
|
2410
2433
|
};
|
|
2411
2434
|
}, [position, registerControl, unregisterControl]);
|
|
2412
|
-
|
|
2435
|
+
React25.useEffect(() => {
|
|
2413
2436
|
if (!isOpen) return;
|
|
2414
2437
|
const handleMouseDown = (e) => {
|
|
2415
2438
|
if (containerRef.current && !containerRef.current.contains(e.target)) {
|
|
@@ -2419,7 +2442,7 @@ var BasemapSwitcher = ({
|
|
|
2419
2442
|
document.addEventListener("mousedown", handleMouseDown);
|
|
2420
2443
|
return () => document.removeEventListener("mousedown", handleMouseDown);
|
|
2421
2444
|
}, [isOpen]);
|
|
2422
|
-
|
|
2445
|
+
React25.useEffect(() => {
|
|
2423
2446
|
if (!isOpen) return;
|
|
2424
2447
|
const handleKeyDown = (e) => {
|
|
2425
2448
|
if (e.key === "Escape") {
|
|
@@ -2439,11 +2462,11 @@ var BasemapSwitcher = ({
|
|
|
2439
2462
|
onBasemapChange?.(basemap);
|
|
2440
2463
|
setIsOpen(false);
|
|
2441
2464
|
};
|
|
2442
|
-
const verticalOffsetStyle =
|
|
2465
|
+
const verticalOffsetStyle = React25.useMemo(() => {
|
|
2443
2466
|
return computeVerticalOffsetStyle(position, customControlOffset);
|
|
2444
2467
|
}, [customControlOffset, position]);
|
|
2445
2468
|
const hasControlsAtPosition = (controlOffsets?.[position] ?? 0) > 0;
|
|
2446
|
-
const computedPositionClasses =
|
|
2469
|
+
const computedPositionClasses = React25.useMemo(() => {
|
|
2447
2470
|
return computePositionClasses(position, hasControlsAtPosition);
|
|
2448
2471
|
}, [position, hasControlsAtPosition]);
|
|
2449
2472
|
const isTop = position.startsWith("top");
|
|
@@ -2556,6 +2579,572 @@ var BasemapSwitcher = ({
|
|
|
2556
2579
|
);
|
|
2557
2580
|
};
|
|
2558
2581
|
BasemapSwitcher.displayName = "BasemapSwitcher";
|
|
2582
|
+
var managerIdCounter = 0;
|
|
2583
|
+
var LayerManager = ({
|
|
2584
|
+
layers,
|
|
2585
|
+
apiKeys,
|
|
2586
|
+
initialActiveLayers,
|
|
2587
|
+
position = "top-right",
|
|
2588
|
+
showSearch = false,
|
|
2589
|
+
showCategories = false,
|
|
2590
|
+
allowReorder = false,
|
|
2591
|
+
showOpacity = false,
|
|
2592
|
+
collapsible = true,
|
|
2593
|
+
onLayerChange,
|
|
2594
|
+
class: className
|
|
2595
|
+
}) => {
|
|
2596
|
+
const { controlOffsets, registerControl, unregisterControl } = useMap();
|
|
2597
|
+
const { isDark } = useMapTheme();
|
|
2598
|
+
const [isOpen, setIsOpen] = React25.useState(false);
|
|
2599
|
+
const [layerStates, setLayerStates] = React25.useState(
|
|
2600
|
+
() => createInitialLayerStates(layers, initialActiveLayers)
|
|
2601
|
+
);
|
|
2602
|
+
const [searchQuery, setSearchQuery] = React25.useState("");
|
|
2603
|
+
const [activeCategory, setActiveCategory] = React25.useState("all");
|
|
2604
|
+
const [customControlOffset, setCustomControlOffset] = React25.useState(0);
|
|
2605
|
+
const [expandedOpacity, setExpandedOpacity] = React25.useState(null);
|
|
2606
|
+
const [draggedId, setDraggedId] = React25.useState(null);
|
|
2607
|
+
const [dragOver, setDragOver] = React25.useState(null);
|
|
2608
|
+
const containerRef = React25.useRef(null);
|
|
2609
|
+
const managerIdRef = React25.useRef(`layer-manager-${++managerIdCounter}`);
|
|
2610
|
+
const lastLayerIdsRef = React25.useRef(new Set(layers.map((l) => l.id)));
|
|
2611
|
+
React25.useEffect(() => {
|
|
2612
|
+
const currentLayerIds = new Set(layers.map((l) => l.id));
|
|
2613
|
+
const hasNewLayers = layers.some((l) => !lastLayerIdsRef.current.has(l.id));
|
|
2614
|
+
const hasRemovedLayers = Array.from(lastLayerIdsRef.current).some(
|
|
2615
|
+
(id) => !currentLayerIds.has(id)
|
|
2616
|
+
);
|
|
2617
|
+
if (hasNewLayers || hasRemovedLayers) {
|
|
2618
|
+
setLayerStates((prev) => {
|
|
2619
|
+
const newStates = new Map(prev);
|
|
2620
|
+
for (const layer of layers) {
|
|
2621
|
+
if (!newStates.has(layer.id)) {
|
|
2622
|
+
newStates.set(layer.id, {
|
|
2623
|
+
id: layer.id,
|
|
2624
|
+
visible: initialActiveLayers?.includes(layer.id) ?? false,
|
|
2625
|
+
opacity: 1,
|
|
2626
|
+
loading: false,
|
|
2627
|
+
error: null,
|
|
2628
|
+
order: newStates.size
|
|
2629
|
+
});
|
|
2630
|
+
}
|
|
2631
|
+
}
|
|
2632
|
+
for (const id of lastLayerIdsRef.current) {
|
|
2633
|
+
if (!currentLayerIds.has(id)) {
|
|
2634
|
+
newStates.delete(id);
|
|
2635
|
+
}
|
|
2636
|
+
}
|
|
2637
|
+
return newStates;
|
|
2638
|
+
});
|
|
2639
|
+
lastLayerIdsRef.current = currentLayerIds;
|
|
2640
|
+
}
|
|
2641
|
+
}, [layers, initialActiveLayers]);
|
|
2642
|
+
const categories = React25.useMemo(() => getLayerCategories(layers), [layers]);
|
|
2643
|
+
const filteredLayers = React25.useMemo(() => {
|
|
2644
|
+
let result = layers;
|
|
2645
|
+
if (searchQuery) {
|
|
2646
|
+
result = searchLayers(result, searchQuery);
|
|
2647
|
+
}
|
|
2648
|
+
if (activeCategory !== "all") {
|
|
2649
|
+
result = result.filter((l) => l.category === activeCategory);
|
|
2650
|
+
}
|
|
2651
|
+
return [...result].sort((a, b) => {
|
|
2652
|
+
const orderA = layerStates.get(a.id)?.order ?? 0;
|
|
2653
|
+
const orderB = layerStates.get(b.id)?.order ?? 0;
|
|
2654
|
+
return orderA - orderB;
|
|
2655
|
+
});
|
|
2656
|
+
}, [layers, searchQuery, activeCategory, layerStates]);
|
|
2657
|
+
const layerGroups = React25.useMemo(
|
|
2658
|
+
() => showCategories ? groupLayersByCategory(filteredLayers) : null,
|
|
2659
|
+
[filteredLayers, showCategories]
|
|
2660
|
+
);
|
|
2661
|
+
React25.useEffect(() => {
|
|
2662
|
+
if (!containerRef.current || !registerControl) return;
|
|
2663
|
+
const updatePosition = () => {
|
|
2664
|
+
if (!containerRef.current) return;
|
|
2665
|
+
const height = containerRef.current.offsetHeight;
|
|
2666
|
+
const offset = registerControl(managerIdRef.current, position, height);
|
|
2667
|
+
setCustomControlOffset(offset);
|
|
2668
|
+
};
|
|
2669
|
+
updatePosition();
|
|
2670
|
+
const observer = new ResizeObserver(updatePosition);
|
|
2671
|
+
observer.observe(containerRef.current);
|
|
2672
|
+
return () => {
|
|
2673
|
+
observer.disconnect();
|
|
2674
|
+
unregisterControl?.(managerIdRef.current, position);
|
|
2675
|
+
};
|
|
2676
|
+
}, [position, registerControl, unregisterControl]);
|
|
2677
|
+
React25.useEffect(() => {
|
|
2678
|
+
if (!isOpen) return;
|
|
2679
|
+
const handleMouseDown = (e) => {
|
|
2680
|
+
if (containerRef.current && !containerRef.current.contains(e.target)) {
|
|
2681
|
+
setIsOpen(false);
|
|
2682
|
+
}
|
|
2683
|
+
};
|
|
2684
|
+
document.addEventListener("mousedown", handleMouseDown);
|
|
2685
|
+
return () => document.removeEventListener("mousedown", handleMouseDown);
|
|
2686
|
+
}, [isOpen]);
|
|
2687
|
+
React25.useEffect(() => {
|
|
2688
|
+
if (!isOpen) return;
|
|
2689
|
+
const handleKeyDown = (e) => {
|
|
2690
|
+
if (e.key === "Escape") {
|
|
2691
|
+
setIsOpen(false);
|
|
2692
|
+
}
|
|
2693
|
+
};
|
|
2694
|
+
document.addEventListener("keydown", handleKeyDown);
|
|
2695
|
+
return () => document.removeEventListener("keydown", handleKeyDown);
|
|
2696
|
+
}, [isOpen]);
|
|
2697
|
+
const handleToggleLayer = React25.useCallback(
|
|
2698
|
+
(layerId) => {
|
|
2699
|
+
setLayerStates((prev) => {
|
|
2700
|
+
const newStates = toggleLayerVisibility(prev, layerId);
|
|
2701
|
+
const state = newStates.get(layerId);
|
|
2702
|
+
if (state && onLayerChange) {
|
|
2703
|
+
onLayerChange(layerId, state);
|
|
2704
|
+
}
|
|
2705
|
+
return newStates;
|
|
2706
|
+
});
|
|
2707
|
+
},
|
|
2708
|
+
[onLayerChange]
|
|
2709
|
+
);
|
|
2710
|
+
const handleOpacityChange = React25.useCallback(
|
|
2711
|
+
(layerId, opacity) => {
|
|
2712
|
+
setLayerStates((prev) => {
|
|
2713
|
+
const newStates = setLayerOpacity(prev, layerId, opacity);
|
|
2714
|
+
const state = newStates.get(layerId);
|
|
2715
|
+
if (state && onLayerChange) {
|
|
2716
|
+
onLayerChange(layerId, state);
|
|
2717
|
+
}
|
|
2718
|
+
return newStates;
|
|
2719
|
+
});
|
|
2720
|
+
},
|
|
2721
|
+
[onLayerChange]
|
|
2722
|
+
);
|
|
2723
|
+
const handleDragStart = React25.useCallback((e, layerId) => {
|
|
2724
|
+
setDraggedId(layerId);
|
|
2725
|
+
e.dataTransfer.effectAllowed = "move";
|
|
2726
|
+
e.dataTransfer.setData("text/plain", layerId);
|
|
2727
|
+
}, []);
|
|
2728
|
+
const handleDragOver = React25.useCallback(
|
|
2729
|
+
(e, layerId) => {
|
|
2730
|
+
e.preventDefault();
|
|
2731
|
+
e.dataTransfer.dropEffect = "move";
|
|
2732
|
+
if (layerId !== draggedId) {
|
|
2733
|
+
const rect = e.currentTarget.getBoundingClientRect();
|
|
2734
|
+
const relativeY = (e.clientY - rect.top) / rect.height;
|
|
2735
|
+
let position2;
|
|
2736
|
+
if (relativeY < 0.3) {
|
|
2737
|
+
position2 = "above";
|
|
2738
|
+
} else if (relativeY > 0.7) {
|
|
2739
|
+
position2 = "below";
|
|
2740
|
+
} else {
|
|
2741
|
+
position2 = dragOver?.id === layerId ? dragOver.position : "below";
|
|
2742
|
+
}
|
|
2743
|
+
setDragOver({ id: layerId, position: position2 });
|
|
2744
|
+
}
|
|
2745
|
+
},
|
|
2746
|
+
[draggedId, dragOver]
|
|
2747
|
+
);
|
|
2748
|
+
const handleDragLeave = React25.useCallback(() => {
|
|
2749
|
+
setDragOver(null);
|
|
2750
|
+
}, []);
|
|
2751
|
+
const handleDragEnd = React25.useCallback(() => {
|
|
2752
|
+
setDraggedId(null);
|
|
2753
|
+
setDragOver(null);
|
|
2754
|
+
}, []);
|
|
2755
|
+
const handleDrop = React25.useCallback(
|
|
2756
|
+
(e, targetLayerId) => {
|
|
2757
|
+
e.preventDefault();
|
|
2758
|
+
const sourceLayerId = e.dataTransfer.getData("text/plain");
|
|
2759
|
+
if (sourceLayerId && sourceLayerId !== targetLayerId) {
|
|
2760
|
+
const sortedStates = getLayerStatesArray(layerStates);
|
|
2761
|
+
const sourceIndex = sortedStates.findIndex((s) => s.id === sourceLayerId);
|
|
2762
|
+
let targetIndex = sortedStates.findIndex((s) => s.id === targetLayerId);
|
|
2763
|
+
if (targetIndex !== -1) {
|
|
2764
|
+
if (dragOver?.position === "below") {
|
|
2765
|
+
targetIndex += 1;
|
|
2766
|
+
}
|
|
2767
|
+
if (sourceIndex < targetIndex) {
|
|
2768
|
+
targetIndex -= 1;
|
|
2769
|
+
}
|
|
2770
|
+
setLayerStates((prev) => {
|
|
2771
|
+
const newStates = reorderLayers(prev, sourceLayerId, targetIndex);
|
|
2772
|
+
const state = newStates.get(sourceLayerId);
|
|
2773
|
+
if (state && onLayerChange) {
|
|
2774
|
+
onLayerChange(sourceLayerId, state);
|
|
2775
|
+
}
|
|
2776
|
+
return newStates;
|
|
2777
|
+
});
|
|
2778
|
+
}
|
|
2779
|
+
}
|
|
2780
|
+
setDraggedId(null);
|
|
2781
|
+
setDragOver(null);
|
|
2782
|
+
},
|
|
2783
|
+
[layerStates, onLayerChange, dragOver]
|
|
2784
|
+
);
|
|
2785
|
+
const verticalOffsetStyle = React25.useMemo(() => {
|
|
2786
|
+
return computeVerticalOffsetStyle(position, customControlOffset);
|
|
2787
|
+
}, [customControlOffset, position]);
|
|
2788
|
+
const hasControlsAtPosition = (controlOffsets?.[position] ?? 0) > 0;
|
|
2789
|
+
const computedPositionClasses = React25.useMemo(() => {
|
|
2790
|
+
return computePositionClasses(position, hasControlsAtPosition);
|
|
2791
|
+
}, [position, hasControlsAtPosition]);
|
|
2792
|
+
const isTop = position.startsWith("top");
|
|
2793
|
+
const renderLayer = (layer, state) => {
|
|
2794
|
+
if (!state.visible) return null;
|
|
2795
|
+
const theme = isDark ? "dark" : "light";
|
|
2796
|
+
const paint = getLayerStyleForTheme(layer, theme);
|
|
2797
|
+
const sourceUrl = resolveLayerSourceUrl(layer, apiKeys);
|
|
2798
|
+
const sourceId = `lm-source-${layer.id}`;
|
|
2799
|
+
const sourceData = layer.source.type === "geojson-inline" ? layer.source.data : layer.source.type === "geojson-url" && sourceUrl ? sourceUrl : void 0;
|
|
2800
|
+
if (!sourceData && layer.source.type !== "vector-tiles") {
|
|
2801
|
+
return null;
|
|
2802
|
+
}
|
|
2803
|
+
const layerProps = {
|
|
2804
|
+
id: `lm-layer-${layer.id}`,
|
|
2805
|
+
source: sourceId,
|
|
2806
|
+
sourceLayer: layer.source.sourceLayer,
|
|
2807
|
+
visible: state.visible,
|
|
2808
|
+
opacity: state.opacity,
|
|
2809
|
+
minZoom: layer.style.minZoom,
|
|
2810
|
+
maxZoom: layer.style.maxZoom
|
|
2811
|
+
};
|
|
2812
|
+
let layerComponent = null;
|
|
2813
|
+
const baseOpacity = {
|
|
2814
|
+
fill: paint["fill-opacity"] ?? 1,
|
|
2815
|
+
line: paint["line-opacity"] ?? 1,
|
|
2816
|
+
circle: paint["circle-opacity"] ?? 1,
|
|
2817
|
+
icon: paint["icon-opacity"] ?? 1
|
|
2818
|
+
};
|
|
2819
|
+
switch (layer.style.renderType) {
|
|
2820
|
+
case "fill":
|
|
2821
|
+
layerComponent = /* @__PURE__ */ jsx(
|
|
2822
|
+
FillLayer,
|
|
2823
|
+
{
|
|
2824
|
+
...layerProps,
|
|
2825
|
+
fillColor: paint["fill-color"],
|
|
2826
|
+
fillOpacity: baseOpacity.fill * state.opacity,
|
|
2827
|
+
fillOutlineColor: paint["fill-outline-color"]
|
|
2828
|
+
}
|
|
2829
|
+
);
|
|
2830
|
+
break;
|
|
2831
|
+
case "line":
|
|
2832
|
+
layerComponent = /* @__PURE__ */ jsx(
|
|
2833
|
+
LineLayer,
|
|
2834
|
+
{
|
|
2835
|
+
...layerProps,
|
|
2836
|
+
lineColor: paint["line-color"],
|
|
2837
|
+
lineWidth: paint["line-width"],
|
|
2838
|
+
lineOpacity: baseOpacity.line * state.opacity,
|
|
2839
|
+
lineDasharray: paint["line-dasharray"]
|
|
2840
|
+
}
|
|
2841
|
+
);
|
|
2842
|
+
break;
|
|
2843
|
+
case "circle":
|
|
2844
|
+
layerComponent = /* @__PURE__ */ jsx(
|
|
2845
|
+
CircleLayer,
|
|
2846
|
+
{
|
|
2847
|
+
...layerProps,
|
|
2848
|
+
circleColor: paint["circle-color"],
|
|
2849
|
+
circleRadius: paint["circle-radius"],
|
|
2850
|
+
circleOpacity: baseOpacity.circle * state.opacity,
|
|
2851
|
+
circleStrokeWidth: paint["circle-stroke-width"],
|
|
2852
|
+
circleStrokeColor: paint["circle-stroke-color"]
|
|
2853
|
+
}
|
|
2854
|
+
);
|
|
2855
|
+
break;
|
|
2856
|
+
case "symbol":
|
|
2857
|
+
layerComponent = /* @__PURE__ */ jsx(
|
|
2858
|
+
SymbolLayer,
|
|
2859
|
+
{
|
|
2860
|
+
...layerProps,
|
|
2861
|
+
iconImage: paint["icon-image"],
|
|
2862
|
+
iconSize: paint["icon-size"],
|
|
2863
|
+
iconOpacity: baseOpacity.icon * state.opacity,
|
|
2864
|
+
textField: paint["text-field"],
|
|
2865
|
+
textSize: paint["text-size"],
|
|
2866
|
+
textColor: paint["text-color"]
|
|
2867
|
+
}
|
|
2868
|
+
);
|
|
2869
|
+
break;
|
|
2870
|
+
}
|
|
2871
|
+
return /* @__PURE__ */ jsx(
|
|
2872
|
+
Source,
|
|
2873
|
+
{
|
|
2874
|
+
id: sourceId,
|
|
2875
|
+
type: layer.source.type === "vector-tiles" ? "vector" : "geojson",
|
|
2876
|
+
data: layer.source.type !== "vector-tiles" ? sourceData : void 0,
|
|
2877
|
+
url: layer.source.type === "vector-tiles" ? sourceUrl ?? void 0 : void 0,
|
|
2878
|
+
tiles: layer.source.type === "vector-tiles" ? [sourceUrl ?? ""] : void 0,
|
|
2879
|
+
attribution: layer.source.attribution,
|
|
2880
|
+
children: layerComponent
|
|
2881
|
+
},
|
|
2882
|
+
layer.id
|
|
2883
|
+
);
|
|
2884
|
+
};
|
|
2885
|
+
const renderLayerItem = (layer) => {
|
|
2886
|
+
const state = layerStates.get(layer.id);
|
|
2887
|
+
if (!state) return null;
|
|
2888
|
+
const isDragging = draggedId === layer.id;
|
|
2889
|
+
const isDragOver = dragOver?.id === layer.id;
|
|
2890
|
+
const dragOverPosition = isDragOver ? dragOver.position : void 0;
|
|
2891
|
+
return /* @__PURE__ */ jsxs(
|
|
2892
|
+
"div",
|
|
2893
|
+
{
|
|
2894
|
+
className: "classic-layer-item",
|
|
2895
|
+
draggable: allowReorder,
|
|
2896
|
+
onDragStart: allowReorder ? (e) => handleDragStart(e, layer.id) : void 0,
|
|
2897
|
+
onDragOver: allowReorder ? (e) => handleDragOver(e, layer.id) : void 0,
|
|
2898
|
+
onDragLeave: allowReorder ? handleDragLeave : void 0,
|
|
2899
|
+
onDragEnd: allowReorder ? handleDragEnd : void 0,
|
|
2900
|
+
onDrop: allowReorder ? (e) => handleDrop(e, layer.id) : void 0,
|
|
2901
|
+
"data-dragging": isDragging || void 0,
|
|
2902
|
+
"data-drag-over": dragOverPosition,
|
|
2903
|
+
children: [
|
|
2904
|
+
allowReorder && /* @__PURE__ */ jsx("span", { className: "classic-layer-drag-handle text-muted-foreground", children: /* @__PURE__ */ jsxs(
|
|
2905
|
+
"svg",
|
|
2906
|
+
{
|
|
2907
|
+
width: "12",
|
|
2908
|
+
height: "12",
|
|
2909
|
+
viewBox: "0 0 24 24",
|
|
2910
|
+
fill: "none",
|
|
2911
|
+
stroke: "currentColor",
|
|
2912
|
+
strokeWidth: "2",
|
|
2913
|
+
children: [
|
|
2914
|
+
/* @__PURE__ */ jsx("circle", { cx: "9", cy: "6", r: "1", fill: "currentColor" }),
|
|
2915
|
+
/* @__PURE__ */ jsx("circle", { cx: "15", cy: "6", r: "1", fill: "currentColor" }),
|
|
2916
|
+
/* @__PURE__ */ jsx("circle", { cx: "9", cy: "12", r: "1", fill: "currentColor" }),
|
|
2917
|
+
/* @__PURE__ */ jsx("circle", { cx: "15", cy: "12", r: "1", fill: "currentColor" }),
|
|
2918
|
+
/* @__PURE__ */ jsx("circle", { cx: "9", cy: "18", r: "1", fill: "currentColor" }),
|
|
2919
|
+
/* @__PURE__ */ jsx("circle", { cx: "15", cy: "18", r: "1", fill: "currentColor" })
|
|
2920
|
+
]
|
|
2921
|
+
}
|
|
2922
|
+
) }),
|
|
2923
|
+
/* @__PURE__ */ jsx(
|
|
2924
|
+
Switch,
|
|
2925
|
+
{
|
|
2926
|
+
size: "sm",
|
|
2927
|
+
checked: state.visible,
|
|
2928
|
+
onCheckedChange: () => handleToggleLayer(layer.id),
|
|
2929
|
+
"aria-label": `Toggle ${layer.name}`
|
|
2930
|
+
}
|
|
2931
|
+
),
|
|
2932
|
+
/* @__PURE__ */ jsxs("div", { className: "flex-1 min-w-0", children: [
|
|
2933
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
|
|
2934
|
+
/* @__PURE__ */ jsx("span", { className: "text-sm text-foreground truncate", children: layer.name }),
|
|
2935
|
+
state.loading && /* @__PURE__ */ jsx(
|
|
2936
|
+
"svg",
|
|
2937
|
+
{
|
|
2938
|
+
className: "classic-layer-loading w-3 h-3 text-muted-foreground",
|
|
2939
|
+
viewBox: "0 0 24 24",
|
|
2940
|
+
fill: "none",
|
|
2941
|
+
stroke: "currentColor",
|
|
2942
|
+
strokeWidth: "2",
|
|
2943
|
+
children: /* @__PURE__ */ jsx("path", { d: "M12 2v4m0 12v4M4.93 4.93l2.83 2.83m8.48 8.48l2.83 2.83M2 12h4m12 0h4M4.93 19.07l2.83-2.83m8.48-8.48l2.83-2.83" })
|
|
2944
|
+
}
|
|
2945
|
+
)
|
|
2946
|
+
] }),
|
|
2947
|
+
state.error && /* @__PURE__ */ jsx("span", { className: "classic-layer-error", children: state.error })
|
|
2948
|
+
] }),
|
|
2949
|
+
showOpacity && state.visible && /* @__PURE__ */ jsx(
|
|
2950
|
+
"button",
|
|
2951
|
+
{
|
|
2952
|
+
type: "button",
|
|
2953
|
+
className: "text-muted-foreground hover:text-foreground p-1",
|
|
2954
|
+
onClick: () => setExpandedOpacity(expandedOpacity === layer.id ? null : layer.id),
|
|
2955
|
+
"aria-label": "Adjust opacity",
|
|
2956
|
+
children: /* @__PURE__ */ jsxs(
|
|
2957
|
+
"svg",
|
|
2958
|
+
{
|
|
2959
|
+
width: "14",
|
|
2960
|
+
height: "14",
|
|
2961
|
+
viewBox: "0 0 24 24",
|
|
2962
|
+
fill: "none",
|
|
2963
|
+
stroke: "currentColor",
|
|
2964
|
+
strokeWidth: "2",
|
|
2965
|
+
children: [
|
|
2966
|
+
/* @__PURE__ */ jsx("circle", { cx: "12", cy: "12", r: "10" }),
|
|
2967
|
+
/* @__PURE__ */ jsx("path", { d: "M12 2a10 10 0 0 1 0 20", fill: "currentColor", opacity: "0.3" })
|
|
2968
|
+
]
|
|
2969
|
+
}
|
|
2970
|
+
)
|
|
2971
|
+
}
|
|
2972
|
+
)
|
|
2973
|
+
]
|
|
2974
|
+
},
|
|
2975
|
+
layer.id
|
|
2976
|
+
);
|
|
2977
|
+
};
|
|
2978
|
+
const renderOpacitySlider = (layerId) => {
|
|
2979
|
+
if (expandedOpacity !== layerId) return null;
|
|
2980
|
+
const state = layerStates.get(layerId);
|
|
2981
|
+
if (!state) return null;
|
|
2982
|
+
return /* @__PURE__ */ jsx("div", { className: "px-3 pb-2", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
2983
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground w-12", children: "Opacity" }),
|
|
2984
|
+
/* @__PURE__ */ jsx(
|
|
2985
|
+
"input",
|
|
2986
|
+
{
|
|
2987
|
+
type: "range",
|
|
2988
|
+
min: "0",
|
|
2989
|
+
max: "100",
|
|
2990
|
+
value: state.opacity * 100,
|
|
2991
|
+
onChange: (e) => handleOpacityChange(layerId, Number(e.target.value) / 100),
|
|
2992
|
+
className: "classic-layer-opacity-slider flex-1"
|
|
2993
|
+
}
|
|
2994
|
+
),
|
|
2995
|
+
/* @__PURE__ */ jsxs("span", { className: "text-xs text-muted-foreground w-8 text-right", children: [
|
|
2996
|
+
Math.round(state.opacity * 100),
|
|
2997
|
+
"%"
|
|
2998
|
+
] })
|
|
2999
|
+
] }) });
|
|
3000
|
+
};
|
|
3001
|
+
const visibleLayerStates = getLayerStatesArray(layerStates).filter((s) => s.visible);
|
|
3002
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
3003
|
+
visibleLayerStates.map((state) => {
|
|
3004
|
+
const layer = layers.find((l) => l.id === state.id);
|
|
3005
|
+
return layer ? renderLayer(layer, state) : null;
|
|
3006
|
+
}),
|
|
3007
|
+
/* @__PURE__ */ jsxs(
|
|
3008
|
+
"div",
|
|
3009
|
+
{
|
|
3010
|
+
ref: containerRef,
|
|
3011
|
+
className: cn("absolute z-10", computedPositionClasses, className),
|
|
3012
|
+
style: verticalOffsetStyle,
|
|
3013
|
+
children: [
|
|
3014
|
+
isOpen && /* @__PURE__ */ jsxs(
|
|
3015
|
+
"div",
|
|
3016
|
+
{
|
|
3017
|
+
className: cn(
|
|
3018
|
+
"absolute classic-layer-panel-enter",
|
|
3019
|
+
"bg-card rounded-lg shadow-lg border border-black dark:border-gray-400",
|
|
3020
|
+
"w-64",
|
|
3021
|
+
isTop ? "top-full mt-1" : "bottom-full mb-1",
|
|
3022
|
+
position.includes("right") ? "right-0" : "left-0"
|
|
3023
|
+
),
|
|
3024
|
+
children: [
|
|
3025
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between p-3 border-b border-border", children: [
|
|
3026
|
+
/* @__PURE__ */ jsx("span", { className: "text-sm font-medium text-foreground", children: "Layers" }),
|
|
3027
|
+
collapsible && /* @__PURE__ */ jsx(
|
|
3028
|
+
"button",
|
|
3029
|
+
{
|
|
3030
|
+
type: "button",
|
|
3031
|
+
className: "text-muted-foreground hover:text-foreground",
|
|
3032
|
+
onClick: () => setIsOpen(false),
|
|
3033
|
+
"aria-label": "Close layer manager",
|
|
3034
|
+
children: /* @__PURE__ */ jsx(
|
|
3035
|
+
"svg",
|
|
3036
|
+
{
|
|
3037
|
+
width: "16",
|
|
3038
|
+
height: "16",
|
|
3039
|
+
viewBox: "0 0 24 24",
|
|
3040
|
+
fill: "none",
|
|
3041
|
+
stroke: "currentColor",
|
|
3042
|
+
strokeWidth: "2",
|
|
3043
|
+
children: /* @__PURE__ */ jsx("path", { d: "M18 6L6 18M6 6l12 12" })
|
|
3044
|
+
}
|
|
3045
|
+
)
|
|
3046
|
+
}
|
|
3047
|
+
)
|
|
3048
|
+
] }),
|
|
3049
|
+
showSearch && /* @__PURE__ */ jsx("div", { className: "p-2 border-b border-border", children: /* @__PURE__ */ jsx(
|
|
3050
|
+
"input",
|
|
3051
|
+
{
|
|
3052
|
+
type: "text",
|
|
3053
|
+
placeholder: "Search layers...",
|
|
3054
|
+
value: searchQuery,
|
|
3055
|
+
onChange: (e) => setSearchQuery(e.target.value),
|
|
3056
|
+
className: "classic-layer-search"
|
|
3057
|
+
}
|
|
3058
|
+
) }),
|
|
3059
|
+
showCategories && categories.length > 1 && /* @__PURE__ */ jsx("div", { className: "p-2 border-b border-border", children: /* @__PURE__ */ jsxs("div", { className: "classic-layer-tabs", children: [
|
|
3060
|
+
/* @__PURE__ */ jsx(
|
|
3061
|
+
"button",
|
|
3062
|
+
{
|
|
3063
|
+
type: "button",
|
|
3064
|
+
className: "classic-layer-tab",
|
|
3065
|
+
"data-active": activeCategory === "all",
|
|
3066
|
+
onClick: () => setActiveCategory("all"),
|
|
3067
|
+
children: "All"
|
|
3068
|
+
}
|
|
3069
|
+
),
|
|
3070
|
+
categories.map((cat) => /* @__PURE__ */ jsx(
|
|
3071
|
+
"button",
|
|
3072
|
+
{
|
|
3073
|
+
type: "button",
|
|
3074
|
+
className: "classic-layer-tab",
|
|
3075
|
+
"data-active": activeCategory === cat,
|
|
3076
|
+
onClick: () => setActiveCategory(cat),
|
|
3077
|
+
children: CATEGORY_META[cat].label
|
|
3078
|
+
},
|
|
3079
|
+
cat
|
|
3080
|
+
))
|
|
3081
|
+
] }) }),
|
|
3082
|
+
/* @__PURE__ */ jsxs("div", { className: "max-h-64 overflow-y-auto", children: [
|
|
3083
|
+
showCategories && layerGroups && activeCategory === "all" ? (
|
|
3084
|
+
// Grouped by category
|
|
3085
|
+
categories.map((cat) => {
|
|
3086
|
+
const catLayers = layerGroups[cat];
|
|
3087
|
+
if (catLayers.length === 0) return null;
|
|
3088
|
+
return /* @__PURE__ */ jsxs("div", { children: [
|
|
3089
|
+
/* @__PURE__ */ jsx("div", { className: "px-3 py-2 text-xs font-medium text-muted-foreground uppercase tracking-wider", children: CATEGORY_META[cat].label }),
|
|
3090
|
+
catLayers.map((layer) => /* @__PURE__ */ jsxs(React25.Fragment, { children: [
|
|
3091
|
+
renderLayerItem(layer),
|
|
3092
|
+
renderOpacitySlider(layer.id)
|
|
3093
|
+
] }, layer.id))
|
|
3094
|
+
] }, cat);
|
|
3095
|
+
})
|
|
3096
|
+
) : (
|
|
3097
|
+
// Flat list
|
|
3098
|
+
filteredLayers.map((layer) => /* @__PURE__ */ jsxs(React25.Fragment, { children: [
|
|
3099
|
+
renderLayerItem(layer),
|
|
3100
|
+
renderOpacitySlider(layer.id)
|
|
3101
|
+
] }, layer.id))
|
|
3102
|
+
),
|
|
3103
|
+
filteredLayers.length === 0 && /* @__PURE__ */ jsx("div", { className: "p-4 text-center text-sm text-muted-foreground", children: "No layers found" })
|
|
3104
|
+
] })
|
|
3105
|
+
]
|
|
3106
|
+
}
|
|
3107
|
+
),
|
|
3108
|
+
/* @__PURE__ */ jsx(
|
|
3109
|
+
"button",
|
|
3110
|
+
{
|
|
3111
|
+
type: "button",
|
|
3112
|
+
className: cn(
|
|
3113
|
+
"w-[40px] h-[40px] flex items-center justify-center",
|
|
3114
|
+
"bg-card rounded shadow-lg border border-black dark:border-gray-400",
|
|
3115
|
+
"hover:bg-muted transition-colors cursor-pointer",
|
|
3116
|
+
"text-foreground"
|
|
3117
|
+
),
|
|
3118
|
+
onClick: () => setIsOpen(!isOpen),
|
|
3119
|
+
"aria-label": "Toggle layer manager",
|
|
3120
|
+
"aria-expanded": isOpen,
|
|
3121
|
+
"aria-haspopup": "true",
|
|
3122
|
+
children: /* @__PURE__ */ jsxs(
|
|
3123
|
+
"svg",
|
|
3124
|
+
{
|
|
3125
|
+
width: "20",
|
|
3126
|
+
height: "20",
|
|
3127
|
+
viewBox: "0 0 24 24",
|
|
3128
|
+
fill: "none",
|
|
3129
|
+
stroke: "currentColor",
|
|
3130
|
+
strokeWidth: "2",
|
|
3131
|
+
strokeLinecap: "round",
|
|
3132
|
+
strokeLinejoin: "round",
|
|
3133
|
+
children: [
|
|
3134
|
+
/* @__PURE__ */ jsx("path", { d: "M12.89 1.45l8 4A2 2 0 0 1 22 7.24v9.53a2 2 0 0 1-1.11 1.79l-8 4a2 2 0 0 1-1.78 0l-8-4a2 2 0 0 1-1.11-1.8V7.24a2 2 0 0 1 1.11-1.79l8-4a2 2 0 0 1 1.78 0z" }),
|
|
3135
|
+
/* @__PURE__ */ jsx("polyline", { points: "2.32 6.16 12 11 21.68 6.16" }),
|
|
3136
|
+
/* @__PURE__ */ jsx("line", { x1: "12", y1: "22.76", x2: "12", y2: "11" })
|
|
3137
|
+
]
|
|
3138
|
+
}
|
|
3139
|
+
)
|
|
3140
|
+
}
|
|
3141
|
+
)
|
|
3142
|
+
]
|
|
3143
|
+
}
|
|
3144
|
+
)
|
|
3145
|
+
] });
|
|
3146
|
+
};
|
|
3147
|
+
LayerManager.displayName = "LayerManager";
|
|
2559
3148
|
var DeckOverlay = ({
|
|
2560
3149
|
layers = [],
|
|
2561
3150
|
onHover,
|
|
@@ -2566,9 +3155,9 @@ var DeckOverlay = ({
|
|
|
2566
3155
|
deckProps = {}
|
|
2567
3156
|
}) => {
|
|
2568
3157
|
const { map, loaded } = useMap();
|
|
2569
|
-
const overlayRef =
|
|
2570
|
-
const MapboxOverlayRef =
|
|
2571
|
-
|
|
3158
|
+
const overlayRef = React25.useRef(null);
|
|
3159
|
+
const MapboxOverlayRef = React25.useRef(null);
|
|
3160
|
+
React25.useEffect(() => {
|
|
2572
3161
|
if (!map || !loaded) return;
|
|
2573
3162
|
let cancelled = false;
|
|
2574
3163
|
const initOverlay = async () => {
|
|
@@ -2608,12 +3197,12 @@ var DeckOverlay = ({
|
|
|
2608
3197
|
}
|
|
2609
3198
|
};
|
|
2610
3199
|
}, [map, loaded, interleaved]);
|
|
2611
|
-
|
|
3200
|
+
React25.useEffect(() => {
|
|
2612
3201
|
if (overlayRef.current && "setProps" in overlayRef.current) {
|
|
2613
3202
|
overlayRef.current.setProps({ layers });
|
|
2614
3203
|
}
|
|
2615
3204
|
}, [layers]);
|
|
2616
|
-
|
|
3205
|
+
React25.useEffect(() => {
|
|
2617
3206
|
if (overlayRef.current && "setProps" in overlayRef.current) {
|
|
2618
3207
|
overlayRef.current.setProps({
|
|
2619
3208
|
onHover,
|
|
@@ -2621,7 +3210,7 @@ var DeckOverlay = ({
|
|
|
2621
3210
|
});
|
|
2622
3211
|
}
|
|
2623
3212
|
}, [onHover, onClick]);
|
|
2624
|
-
|
|
3213
|
+
React25.useEffect(() => {
|
|
2625
3214
|
if (overlayRef.current && effects && "setProps" in overlayRef.current) {
|
|
2626
3215
|
overlayRef.current.setProps({ effects });
|
|
2627
3216
|
}
|
|
@@ -2630,4 +3219,4 @@ var DeckOverlay = ({
|
|
|
2630
3219
|
};
|
|
2631
3220
|
DeckOverlay.displayName = "DeckOverlay";
|
|
2632
3221
|
|
|
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 };
|
|
3222
|
+
export { BasemapSwitcher, CircleLayer, CoordinateDisplay, DeckOverlay, FillExtrusionLayer, FillLayer, HeatmapLayer, LayerManager, Legend, LegendGroup, LineLayer, Map2 as Map, MapContainer, MapContext, MapEmpty, MapError, MapSkeleton, Marker, Popup, PopupCard, PopupContent, PopupFooter, PopupHeader, Source, SymbolLayer, cn, useLayer, useMap, useMapInstance, useMapTheme, useReducedMotion };
|