@classic-homes/maps-react 0.1.4 → 0.1.5
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 +812 -144
- package/dist/index.d.cts +10 -3
- package/dist/index.d.ts +10 -3
- package/dist/index.js +723 -140
- 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(
|
|
@@ -125,7 +127,7 @@ var MapError = React6.forwardRef(
|
|
|
125
127
|
}
|
|
126
128
|
);
|
|
127
129
|
MapError.displayName = "MapError";
|
|
128
|
-
var MapEmpty =
|
|
130
|
+
var MapEmpty = React25.forwardRef(
|
|
129
131
|
({ message = "No map data to display", height = 400, className, ...props }, ref) => {
|
|
130
132
|
const heightStyle = typeof height === "number" ? `${height}px` : height;
|
|
131
133
|
return /* @__PURE__ */ jsx(
|
|
@@ -168,7 +170,7 @@ var MapEmpty = React6.forwardRef(
|
|
|
168
170
|
}
|
|
169
171
|
);
|
|
170
172
|
MapEmpty.displayName = "MapEmpty";
|
|
171
|
-
var MapContainer =
|
|
173
|
+
var MapContainer = React25.forwardRef(
|
|
172
174
|
({
|
|
173
175
|
title,
|
|
174
176
|
description,
|
|
@@ -273,9 +275,9 @@ function useReducedMotion() {
|
|
|
273
275
|
}, []);
|
|
274
276
|
return prefersReducedMotion2;
|
|
275
277
|
}
|
|
276
|
-
var MapContext =
|
|
278
|
+
var MapContext = React25.createContext(null);
|
|
277
279
|
function useMap() {
|
|
278
|
-
const context =
|
|
280
|
+
const context = React25.useContext(MapContext);
|
|
279
281
|
if (!context) {
|
|
280
282
|
throw new Error("useMap must be used within a Map component");
|
|
281
283
|
}
|
|
@@ -285,7 +287,7 @@ function useMapInstance() {
|
|
|
285
287
|
const { map, loaded } = useMap();
|
|
286
288
|
return loaded ? map : null;
|
|
287
289
|
}
|
|
288
|
-
var
|
|
290
|
+
var Map2 = React25.forwardRef(
|
|
289
291
|
({
|
|
290
292
|
// Base props
|
|
291
293
|
title,
|
|
@@ -339,33 +341,33 @@ var Map = React6.forwardRef(
|
|
|
339
341
|
onZoom,
|
|
340
342
|
onError
|
|
341
343
|
}, ref) => {
|
|
342
|
-
const containerRef =
|
|
343
|
-
const mapRef =
|
|
344
|
-
const [mapLoaded, setMapLoaded] =
|
|
345
|
-
const [mapError, setMapError] =
|
|
346
|
-
const [styleVersion, setStyleVersion] =
|
|
347
|
-
const activeStyleOverrideRef =
|
|
344
|
+
const containerRef = React25.useRef(null);
|
|
345
|
+
const mapRef = React25.useRef(null);
|
|
346
|
+
const [mapLoaded, setMapLoaded] = React25.useState(false);
|
|
347
|
+
const [mapError, setMapError] = React25.useState(null);
|
|
348
|
+
const [styleVersion, setStyleVersion] = React25.useState(0);
|
|
349
|
+
const activeStyleOverrideRef = React25.useRef(
|
|
348
350
|
null
|
|
349
351
|
);
|
|
350
|
-
const setMapStyle =
|
|
352
|
+
const setMapStyle = React25.useCallback((style) => {
|
|
351
353
|
activeStyleOverrideRef.current = style;
|
|
352
354
|
mapRef.current?.setStyle(style);
|
|
353
355
|
}, []);
|
|
354
|
-
const customControlRegistryRef =
|
|
356
|
+
const customControlRegistryRef = React25.useRef({
|
|
355
357
|
"top-left": [],
|
|
356
358
|
"top-right": [],
|
|
357
359
|
"bottom-left": [],
|
|
358
360
|
"bottom-right": []
|
|
359
361
|
});
|
|
360
|
-
const [, forceUpdate] =
|
|
362
|
+
const [, forceUpdate] = React25.useReducer((x) => x + 1, 0);
|
|
361
363
|
const prefersReducedMotion2 = useReducedMotion();
|
|
362
364
|
const { style: themeStyle } = useMapTheme(themePref);
|
|
363
|
-
const onLoadRef =
|
|
365
|
+
const onLoadRef = React25.useRef(onLoad);
|
|
364
366
|
onLoadRef.current = onLoad;
|
|
365
|
-
const onErrorRef =
|
|
367
|
+
const onErrorRef = React25.useRef(onError);
|
|
366
368
|
onErrorRef.current = onError;
|
|
367
369
|
const mapStyle = customStyle || themeStyle;
|
|
368
|
-
const controlOffsets =
|
|
370
|
+
const controlOffsets = React25.useMemo(() => {
|
|
369
371
|
const offsets = {
|
|
370
372
|
"top-left": 0,
|
|
371
373
|
"top-right": 0,
|
|
@@ -395,7 +397,7 @@ var Map = React6.forwardRef(
|
|
|
395
397
|
geolocateControl,
|
|
396
398
|
geolocateControlPosition
|
|
397
399
|
]);
|
|
398
|
-
const registerControl =
|
|
400
|
+
const registerControl = React25.useCallback(
|
|
399
401
|
(id, position, height2) => {
|
|
400
402
|
const registry = customControlRegistryRef.current;
|
|
401
403
|
const positionControls = registry[position] || [];
|
|
@@ -416,13 +418,13 @@ var Map = React6.forwardRef(
|
|
|
416
418
|
},
|
|
417
419
|
[]
|
|
418
420
|
);
|
|
419
|
-
const unregisterControl =
|
|
421
|
+
const unregisterControl = React25.useCallback((id, position) => {
|
|
420
422
|
const registry = customControlRegistryRef.current;
|
|
421
423
|
const positionControls = registry[position] || [];
|
|
422
424
|
registry[position] = positionControls.filter((c) => c.id !== id);
|
|
423
425
|
forceUpdate();
|
|
424
426
|
}, []);
|
|
425
|
-
const getCustomControlOffset =
|
|
427
|
+
const getCustomControlOffset = React25.useCallback((id, position) => {
|
|
426
428
|
const registry = customControlRegistryRef.current;
|
|
427
429
|
const positionControls = registry[position] || [];
|
|
428
430
|
let offset = 0;
|
|
@@ -436,7 +438,7 @@ var Map = React6.forwardRef(
|
|
|
436
438
|
center,
|
|
437
439
|
zoom
|
|
438
440
|
});
|
|
439
|
-
|
|
441
|
+
React25.useEffect(() => {
|
|
440
442
|
if (!containerRef.current || mapRef.current) return;
|
|
441
443
|
try {
|
|
442
444
|
const map = new maplibregl.Map({
|
|
@@ -516,8 +518,8 @@ var Map = React6.forwardRef(
|
|
|
516
518
|
onErrorRef.current?.({ type: "error", message: errorMessage, error: err });
|
|
517
519
|
}
|
|
518
520
|
}, []);
|
|
519
|
-
const styleInitialized =
|
|
520
|
-
|
|
521
|
+
const styleInitialized = React25.useRef(false);
|
|
522
|
+
React25.useEffect(() => {
|
|
521
523
|
if (!mapRef.current || !mapLoaded) return;
|
|
522
524
|
if (!styleInitialized.current) {
|
|
523
525
|
styleInitialized.current = true;
|
|
@@ -526,12 +528,12 @@ var Map = React6.forwardRef(
|
|
|
526
528
|
if (activeStyleOverrideRef.current) return;
|
|
527
529
|
mapRef.current.setStyle(mapStyle);
|
|
528
530
|
}, [mapStyle, mapLoaded]);
|
|
529
|
-
|
|
531
|
+
React25.useEffect(() => {
|
|
530
532
|
if (customStyle) {
|
|
531
533
|
activeStyleOverrideRef.current = null;
|
|
532
534
|
}
|
|
533
535
|
}, [customStyle]);
|
|
534
|
-
|
|
536
|
+
React25.useEffect(() => {
|
|
535
537
|
const map = mapRef.current;
|
|
536
538
|
if (!map || !mapLoaded) return;
|
|
537
539
|
const createEventParams = (e) => ({
|
|
@@ -665,7 +667,7 @@ var Map = React6.forwardRef(
|
|
|
665
667
|
);
|
|
666
668
|
}
|
|
667
669
|
);
|
|
668
|
-
|
|
670
|
+
Map2.displayName = "Map";
|
|
669
671
|
var Source = ({
|
|
670
672
|
id,
|
|
671
673
|
type,
|
|
@@ -686,9 +688,9 @@ var Source = ({
|
|
|
686
688
|
children
|
|
687
689
|
}) => {
|
|
688
690
|
const { map, loaded, styleVersion } = useMap();
|
|
689
|
-
const sourceAdded =
|
|
690
|
-
const initialFitDone =
|
|
691
|
-
const fitBoundsParamsRef =
|
|
691
|
+
const sourceAdded = React25.useRef(false);
|
|
692
|
+
const initialFitDone = React25.useRef(false);
|
|
693
|
+
const fitBoundsParamsRef = React25.useRef({
|
|
692
694
|
shouldFitBounds,
|
|
693
695
|
data,
|
|
694
696
|
fitBoundsPadding,
|
|
@@ -704,7 +706,7 @@ var Source = ({
|
|
|
704
706
|
fitBoundsAnimate,
|
|
705
707
|
type
|
|
706
708
|
};
|
|
707
|
-
const performFitBounds =
|
|
709
|
+
const performFitBounds = React25.useCallback(
|
|
708
710
|
(cancelledRef) => {
|
|
709
711
|
const params = fitBoundsParamsRef.current;
|
|
710
712
|
if (cancelledRef.current || !params.shouldFitBounds || initialFitDone.current) return;
|
|
@@ -748,7 +750,7 @@ var Source = ({
|
|
|
748
750
|
},
|
|
749
751
|
[map]
|
|
750
752
|
);
|
|
751
|
-
|
|
753
|
+
React25.useEffect(() => {
|
|
752
754
|
if (!map || !loaded || sourceAdded.current) return;
|
|
753
755
|
if (map.getSource(id)) {
|
|
754
756
|
sourceAdded.current = true;
|
|
@@ -898,24 +900,39 @@ var Source = ({
|
|
|
898
900
|
styleVersion
|
|
899
901
|
// re-add source after basemap style changes
|
|
900
902
|
]);
|
|
901
|
-
|
|
903
|
+
React25.useEffect(() => {
|
|
902
904
|
if (!map || !loaded || !sourceAdded.current || type !== "geojson") return;
|
|
903
905
|
const source = map.getSource(id);
|
|
904
906
|
if (!source) return;
|
|
907
|
+
let cancelled = false;
|
|
905
908
|
try {
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
909
|
+
const newData = typeof data === "string" ? data : data && typeof data === "object" ? data : null;
|
|
910
|
+
if (!newData) return;
|
|
911
|
+
const handleSourceData = (e) => {
|
|
912
|
+
if (cancelled) return;
|
|
913
|
+
if (e.sourceId === id && e.isSourceLoaded) {
|
|
914
|
+
map.off("sourcedata", handleSourceData);
|
|
915
|
+
map.triggerRepaint();
|
|
916
|
+
}
|
|
917
|
+
};
|
|
918
|
+
if (cluster) {
|
|
919
|
+
map.on("sourcedata", handleSourceData);
|
|
910
920
|
}
|
|
921
|
+
source.setData(newData);
|
|
922
|
+
return () => {
|
|
923
|
+
cancelled = true;
|
|
924
|
+
if (cluster) {
|
|
925
|
+
map.off("sourcedata", handleSourceData);
|
|
926
|
+
}
|
|
927
|
+
};
|
|
911
928
|
} catch (err) {
|
|
912
929
|
console.error(`[maps-react] Failed to update source "${id}" data:`, err);
|
|
913
930
|
}
|
|
914
|
-
}, [map, loaded, id, type, data]);
|
|
931
|
+
}, [map, loaded, id, type, data, cluster]);
|
|
915
932
|
return /* @__PURE__ */ jsx(Fragment, { children });
|
|
916
933
|
};
|
|
917
934
|
Source.displayName = "Source";
|
|
918
|
-
var Marker =
|
|
935
|
+
var Marker = React25.forwardRef(
|
|
919
936
|
({
|
|
920
937
|
id,
|
|
921
938
|
coordinates,
|
|
@@ -931,27 +948,27 @@ var Marker = React6.forwardRef(
|
|
|
931
948
|
children
|
|
932
949
|
}, ref) => {
|
|
933
950
|
const { map, loaded } = useMap();
|
|
934
|
-
const markerRef =
|
|
935
|
-
const elementRef =
|
|
936
|
-
const originalLngLatRef =
|
|
937
|
-
const clickHandlerRef =
|
|
938
|
-
const [mounted, setMounted] =
|
|
939
|
-
const onClickRef =
|
|
951
|
+
const markerRef = React25.useRef(null);
|
|
952
|
+
const elementRef = React25.useRef(null);
|
|
953
|
+
const originalLngLatRef = React25.useRef();
|
|
954
|
+
const clickHandlerRef = React25.useRef(null);
|
|
955
|
+
const [mounted, setMounted] = React25.useState(false);
|
|
956
|
+
const onClickRef = React25.useRef(onClick);
|
|
940
957
|
onClickRef.current = onClick;
|
|
941
|
-
const onDragRef =
|
|
958
|
+
const onDragRef = React25.useRef(onDrag);
|
|
942
959
|
onDragRef.current = onDrag;
|
|
943
|
-
const onDragEndRef =
|
|
960
|
+
const onDragEndRef = React25.useRef(onDragEnd);
|
|
944
961
|
onDragEndRef.current = onDragEnd;
|
|
945
|
-
|
|
962
|
+
React25.useEffect(() => {
|
|
946
963
|
setMounted(true);
|
|
947
964
|
return () => setMounted(false);
|
|
948
965
|
}, []);
|
|
949
|
-
|
|
966
|
+
React25.useEffect(() => {
|
|
950
967
|
if (children && !elementRef.current) {
|
|
951
968
|
elementRef.current = document.createElement("div");
|
|
952
969
|
}
|
|
953
970
|
}, [children]);
|
|
954
|
-
|
|
971
|
+
React25.useEffect(() => {
|
|
955
972
|
if (!map || !loaded || !mounted) return;
|
|
956
973
|
if (markerRef.current) return;
|
|
957
974
|
const markerOptions = {
|
|
@@ -1035,17 +1052,17 @@ var Marker = React6.forwardRef(
|
|
|
1035
1052
|
}
|
|
1036
1053
|
};
|
|
1037
1054
|
}, [map, loaded, mounted]);
|
|
1038
|
-
|
|
1055
|
+
React25.useEffect(() => {
|
|
1039
1056
|
if (markerRef.current) {
|
|
1040
1057
|
markerRef.current.setLngLat(coordinates);
|
|
1041
1058
|
}
|
|
1042
1059
|
}, [coordinates]);
|
|
1043
|
-
|
|
1060
|
+
React25.useEffect(() => {
|
|
1044
1061
|
if (markerRef.current) {
|
|
1045
1062
|
markerRef.current.setDraggable(draggable);
|
|
1046
1063
|
}
|
|
1047
1064
|
}, [draggable]);
|
|
1048
|
-
|
|
1065
|
+
React25.useEffect(() => {
|
|
1049
1066
|
if (markerRef.current && rotation !== void 0) {
|
|
1050
1067
|
markerRef.current.setRotation(rotation);
|
|
1051
1068
|
}
|
|
@@ -1091,7 +1108,7 @@ function panToFitPopup(map, popup, padding) {
|
|
|
1091
1108
|
});
|
|
1092
1109
|
}
|
|
1093
1110
|
}
|
|
1094
|
-
var Popup =
|
|
1111
|
+
var Popup = React25.forwardRef(
|
|
1095
1112
|
({
|
|
1096
1113
|
coordinates,
|
|
1097
1114
|
closeButton = true,
|
|
@@ -1109,25 +1126,25 @@ var Popup = React6.forwardRef(
|
|
|
1109
1126
|
children
|
|
1110
1127
|
}, ref) => {
|
|
1111
1128
|
const { map, loaded } = useMap();
|
|
1112
|
-
const popupRef =
|
|
1113
|
-
const onOpenRef =
|
|
1129
|
+
const popupRef = React25.useRef(null);
|
|
1130
|
+
const onOpenRef = React25.useRef(onOpen);
|
|
1114
1131
|
onOpenRef.current = onOpen;
|
|
1115
|
-
const onCloseRef =
|
|
1132
|
+
const onCloseRef = React25.useRef(onClose);
|
|
1116
1133
|
onCloseRef.current = onClose;
|
|
1117
|
-
const coordinatesRef =
|
|
1134
|
+
const coordinatesRef = React25.useRef(coordinates);
|
|
1118
1135
|
coordinatesRef.current = coordinates;
|
|
1119
|
-
const containerRef =
|
|
1136
|
+
const containerRef = React25.useRef(null);
|
|
1120
1137
|
if (!containerRef.current && typeof document !== "undefined") {
|
|
1121
1138
|
containerRef.current = document.createElement("div");
|
|
1122
1139
|
containerRef.current.className = "maplibregl-popup-content-wrapper";
|
|
1123
1140
|
}
|
|
1124
|
-
const [contentReady, setContentReady] =
|
|
1125
|
-
const contentCallbackRef =
|
|
1141
|
+
const [contentReady, setContentReady] = React25.useState(false);
|
|
1142
|
+
const contentCallbackRef = React25.useCallback((node) => {
|
|
1126
1143
|
if (node && containerRef.current) {
|
|
1127
1144
|
setContentReady(true);
|
|
1128
1145
|
}
|
|
1129
1146
|
}, []);
|
|
1130
|
-
|
|
1147
|
+
React25.useEffect(() => {
|
|
1131
1148
|
if (!map || !loaded || !containerRef.current) return;
|
|
1132
1149
|
const popup = new maplibregl.Popup({
|
|
1133
1150
|
closeButton,
|
|
@@ -1167,7 +1184,7 @@ var Popup = React6.forwardRef(
|
|
|
1167
1184
|
maxWidth,
|
|
1168
1185
|
focusAfterOpen
|
|
1169
1186
|
]);
|
|
1170
|
-
|
|
1187
|
+
React25.useEffect(() => {
|
|
1171
1188
|
if (!popupRef.current || !ref) return;
|
|
1172
1189
|
if (typeof ref === "function") {
|
|
1173
1190
|
ref(popupRef.current);
|
|
@@ -1175,12 +1192,12 @@ var Popup = React6.forwardRef(
|
|
|
1175
1192
|
ref.current = popupRef.current;
|
|
1176
1193
|
}
|
|
1177
1194
|
}, [ref]);
|
|
1178
|
-
|
|
1195
|
+
React25.useEffect(() => {
|
|
1179
1196
|
if (popupRef.current) {
|
|
1180
1197
|
popupRef.current.setLngLat(coordinates);
|
|
1181
1198
|
}
|
|
1182
1199
|
}, [coordinates]);
|
|
1183
|
-
|
|
1200
|
+
React25.useEffect(() => {
|
|
1184
1201
|
if (!map || !popupRef.current || !contentReady) return;
|
|
1185
1202
|
let rafHandle;
|
|
1186
1203
|
if (open) {
|
|
@@ -1209,7 +1226,7 @@ var Popup = React6.forwardRef(
|
|
|
1209
1226
|
}
|
|
1210
1227
|
);
|
|
1211
1228
|
Popup.displayName = "Popup";
|
|
1212
|
-
var PopupCard =
|
|
1229
|
+
var PopupCard = React25.forwardRef(
|
|
1213
1230
|
({ className, children, ...props }, ref) => {
|
|
1214
1231
|
return /* @__PURE__ */ jsx("div", { ref, className: cn("bg-popover text-popover-foreground", className), ...props, children });
|
|
1215
1232
|
}
|
|
@@ -1229,7 +1246,7 @@ var badgeVariants = cva("text-xs px-1.5 py-0.5 rounded font-medium flex-shrink-0
|
|
|
1229
1246
|
badgeVariant: "secondary"
|
|
1230
1247
|
}
|
|
1231
1248
|
});
|
|
1232
|
-
var PopupHeader =
|
|
1249
|
+
var PopupHeader = React25.forwardRef(
|
|
1233
1250
|
({ className, title, badge, badgeVariant, ...props }, ref) => {
|
|
1234
1251
|
return /* @__PURE__ */ jsxs(
|
|
1235
1252
|
"div",
|
|
@@ -1249,13 +1266,13 @@ var PopupHeader = React6.forwardRef(
|
|
|
1249
1266
|
}
|
|
1250
1267
|
);
|
|
1251
1268
|
PopupHeader.displayName = "PopupHeader";
|
|
1252
|
-
var PopupContent =
|
|
1269
|
+
var PopupContent = React25.forwardRef(
|
|
1253
1270
|
({ className, children, ...props }, ref) => {
|
|
1254
1271
|
return /* @__PURE__ */ jsx("div", { ref, className: cn("px-4 py-3 text-sm", className), ...props, children });
|
|
1255
1272
|
}
|
|
1256
1273
|
);
|
|
1257
1274
|
PopupContent.displayName = "PopupContent";
|
|
1258
|
-
var PopupFooter =
|
|
1275
|
+
var PopupFooter = React25.forwardRef(
|
|
1259
1276
|
({ className, children, ...props }, ref) => {
|
|
1260
1277
|
return /* @__PURE__ */ jsx(
|
|
1261
1278
|
"div",
|
|
@@ -1290,14 +1307,14 @@ function useLayer({
|
|
|
1290
1307
|
hoverThrottleMs = 0
|
|
1291
1308
|
}) {
|
|
1292
1309
|
const { map, loaded, styleVersion } = useMap();
|
|
1293
|
-
const [layerAdded, setLayerAdded] =
|
|
1294
|
-
const hoveredFeatureId =
|
|
1295
|
-
const lastHoverCallTime =
|
|
1296
|
-
const lastMousePosition =
|
|
1297
|
-
|
|
1310
|
+
const [layerAdded, setLayerAdded] = React25.useState(false);
|
|
1311
|
+
const hoveredFeatureId = React25.useRef(null);
|
|
1312
|
+
const lastHoverCallTime = React25.useRef(0);
|
|
1313
|
+
const lastMousePosition = React25.useRef(null);
|
|
1314
|
+
React25.useEffect(() => {
|
|
1298
1315
|
hoveredFeatureId.current = null;
|
|
1299
1316
|
}, [styleVersion]);
|
|
1300
|
-
|
|
1317
|
+
React25.useEffect(() => {
|
|
1301
1318
|
if (!map || !loaded) return;
|
|
1302
1319
|
if (!map.getSource(source)) {
|
|
1303
1320
|
let timeoutId = null;
|
|
@@ -1368,24 +1385,24 @@ function useLayer({
|
|
|
1368
1385
|
}
|
|
1369
1386
|
};
|
|
1370
1387
|
}, [map, loaded, id, source, sourceLayer, type, beforeId, styleVersion]);
|
|
1371
|
-
|
|
1388
|
+
React25.useEffect(() => {
|
|
1372
1389
|
if (!map || !layerAdded) return;
|
|
1373
1390
|
if (!map.getLayer(id)) return;
|
|
1374
1391
|
map.setLayoutProperty(id, "visibility", visible ? "visible" : "none");
|
|
1375
1392
|
}, [map, id, visible, layerAdded]);
|
|
1376
|
-
|
|
1393
|
+
React25.useEffect(() => {
|
|
1377
1394
|
if (!map || !layerAdded) return;
|
|
1378
1395
|
if (!map.getLayer(id)) return;
|
|
1379
1396
|
Object.entries(paint).forEach(([key, value]) => {
|
|
1380
1397
|
map.setPaintProperty(id, key, value);
|
|
1381
1398
|
});
|
|
1382
1399
|
}, [map, id, paint, layerAdded]);
|
|
1383
|
-
|
|
1400
|
+
React25.useEffect(() => {
|
|
1384
1401
|
if (!map || !layerAdded || !filter) return;
|
|
1385
1402
|
if (!map.getLayer(id)) return;
|
|
1386
1403
|
map.setFilter(id, filter);
|
|
1387
1404
|
}, [map, id, filter, layerAdded]);
|
|
1388
|
-
|
|
1405
|
+
React25.useEffect(() => {
|
|
1389
1406
|
if (!map || !layerAdded) return;
|
|
1390
1407
|
const createFeatureParams = (e) => {
|
|
1391
1408
|
const feature = e.features?.[0];
|
|
@@ -1521,7 +1538,7 @@ var FillLayer = ({
|
|
|
1521
1538
|
fillTranslate,
|
|
1522
1539
|
fillAntialias
|
|
1523
1540
|
}) => {
|
|
1524
|
-
const paint =
|
|
1541
|
+
const paint = React25.useMemo(() => {
|
|
1525
1542
|
const p = {};
|
|
1526
1543
|
if (fillColor !== void 0) p["fill-color"] = fillColor;
|
|
1527
1544
|
if (fillOpacity !== void 0) p["fill-opacity"] = fillOpacity;
|
|
@@ -1542,7 +1559,7 @@ var FillLayer = ({
|
|
|
1542
1559
|
fillAntialias,
|
|
1543
1560
|
opacity
|
|
1544
1561
|
]);
|
|
1545
|
-
const layout =
|
|
1562
|
+
const layout = React25.useMemo(() => ({}), []);
|
|
1546
1563
|
useLayer({
|
|
1547
1564
|
id,
|
|
1548
1565
|
source,
|
|
@@ -1586,7 +1603,7 @@ var LineLayer = ({
|
|
|
1586
1603
|
lineOffset,
|
|
1587
1604
|
lineGradient
|
|
1588
1605
|
}) => {
|
|
1589
|
-
const paint =
|
|
1606
|
+
const paint = React25.useMemo(() => {
|
|
1590
1607
|
const p = {};
|
|
1591
1608
|
if (lineColor !== void 0) p["line-color"] = lineColor;
|
|
1592
1609
|
if (lineWidth !== void 0) p["line-width"] = lineWidth;
|
|
@@ -1611,7 +1628,7 @@ var LineLayer = ({
|
|
|
1611
1628
|
lineGradient,
|
|
1612
1629
|
opacity
|
|
1613
1630
|
]);
|
|
1614
|
-
const layout =
|
|
1631
|
+
const layout = React25.useMemo(() => {
|
|
1615
1632
|
const l = {};
|
|
1616
1633
|
if (lineCap !== void 0) l["line-cap"] = lineCap;
|
|
1617
1634
|
if (lineJoin !== void 0) l["line-join"] = lineJoin;
|
|
@@ -1660,7 +1677,7 @@ var CircleLayer = ({
|
|
|
1660
1677
|
circlePitchScale,
|
|
1661
1678
|
circleTranslate
|
|
1662
1679
|
}) => {
|
|
1663
|
-
const paint =
|
|
1680
|
+
const paint = React25.useMemo(() => {
|
|
1664
1681
|
const p = {};
|
|
1665
1682
|
if (circleRadius !== void 0) p["circle-radius"] = circleRadius;
|
|
1666
1683
|
if (circleColor !== void 0) p["circle-color"] = circleColor;
|
|
@@ -1689,7 +1706,7 @@ var CircleLayer = ({
|
|
|
1689
1706
|
circleTranslate,
|
|
1690
1707
|
opacity
|
|
1691
1708
|
]);
|
|
1692
|
-
const layout =
|
|
1709
|
+
const layout = React25.useMemo(() => ({}), []);
|
|
1693
1710
|
useLayer({
|
|
1694
1711
|
id,
|
|
1695
1712
|
source,
|
|
@@ -1749,7 +1766,7 @@ var SymbolLayer = ({
|
|
|
1749
1766
|
symbolSpacing,
|
|
1750
1767
|
symbolSortKey
|
|
1751
1768
|
}) => {
|
|
1752
|
-
const paint =
|
|
1769
|
+
const paint = React25.useMemo(() => {
|
|
1753
1770
|
const p = {};
|
|
1754
1771
|
if (iconOpacity !== void 0) p["icon-opacity"] = iconOpacity;
|
|
1755
1772
|
if (iconColor !== void 0) p["icon-color"] = iconColor;
|
|
@@ -1770,7 +1787,7 @@ var SymbolLayer = ({
|
|
|
1770
1787
|
textHaloColor,
|
|
1771
1788
|
textHaloWidth
|
|
1772
1789
|
]);
|
|
1773
|
-
const layout =
|
|
1790
|
+
const layout = React25.useMemo(() => {
|
|
1774
1791
|
const l = {};
|
|
1775
1792
|
if (iconImage !== void 0) l["icon-image"] = iconImage;
|
|
1776
1793
|
if (iconSize !== void 0) l["icon-size"] = iconSize;
|
|
@@ -1851,7 +1868,7 @@ var FillExtrusionLayer = ({
|
|
|
1851
1868
|
fillExtrusionTranslate,
|
|
1852
1869
|
fillExtrusionVerticalGradient
|
|
1853
1870
|
}) => {
|
|
1854
|
-
const paint =
|
|
1871
|
+
const paint = React25.useMemo(() => {
|
|
1855
1872
|
const p = {};
|
|
1856
1873
|
if (fillExtrusionHeight !== void 0) p["fill-extrusion-height"] = fillExtrusionHeight;
|
|
1857
1874
|
if (fillExtrusionBase !== void 0) p["fill-extrusion-base"] = fillExtrusionBase;
|
|
@@ -1877,7 +1894,7 @@ var FillExtrusionLayer = ({
|
|
|
1877
1894
|
fillExtrusionVerticalGradient,
|
|
1878
1895
|
opacity
|
|
1879
1896
|
]);
|
|
1880
|
-
const layout =
|
|
1897
|
+
const layout = React25.useMemo(() => ({}), []);
|
|
1881
1898
|
useLayer({
|
|
1882
1899
|
id,
|
|
1883
1900
|
source,
|
|
@@ -1916,7 +1933,7 @@ var HeatmapLayer = ({
|
|
|
1916
1933
|
heatmapRadius,
|
|
1917
1934
|
heatmapOpacity
|
|
1918
1935
|
}) => {
|
|
1919
|
-
const paint =
|
|
1936
|
+
const paint = React25.useMemo(() => {
|
|
1920
1937
|
const p = {};
|
|
1921
1938
|
if (heatmapIntensity !== void 0) p["heatmap-intensity"] = heatmapIntensity;
|
|
1922
1939
|
if (heatmapWeight !== void 0) p["heatmap-weight"] = heatmapWeight;
|
|
@@ -1928,7 +1945,7 @@ var HeatmapLayer = ({
|
|
|
1928
1945
|
}
|
|
1929
1946
|
return p;
|
|
1930
1947
|
}, [heatmapIntensity, heatmapWeight, heatmapColor, heatmapRadius, heatmapOpacity, opacity]);
|
|
1931
|
-
const layout =
|
|
1948
|
+
const layout = React25.useMemo(() => ({}), []);
|
|
1932
1949
|
useLayer({
|
|
1933
1950
|
id,
|
|
1934
1951
|
source,
|
|
@@ -1963,11 +1980,11 @@ var Legend = ({
|
|
|
1963
1980
|
onItemClick
|
|
1964
1981
|
}) => {
|
|
1965
1982
|
const { controlOffsets, registerControl, unregisterControl } = useMap();
|
|
1966
|
-
const [isCollapsed, setIsCollapsed] =
|
|
1967
|
-
const [customControlOffset, setCustomControlOffset] =
|
|
1968
|
-
const legendRef =
|
|
1969
|
-
const legendIdRef =
|
|
1970
|
-
|
|
1983
|
+
const [isCollapsed, setIsCollapsed] = React25.useState(initialCollapsed);
|
|
1984
|
+
const [customControlOffset, setCustomControlOffset] = React25.useState(0);
|
|
1985
|
+
const legendRef = React25.useRef(null);
|
|
1986
|
+
const legendIdRef = React25.useRef(`legend-${++legendIdCounter}`);
|
|
1987
|
+
React25.useEffect(() => {
|
|
1971
1988
|
if (!legendRef.current || !registerControl) return;
|
|
1972
1989
|
const updatePosition = () => {
|
|
1973
1990
|
if (!legendRef.current) return;
|
|
@@ -1983,7 +2000,7 @@ var Legend = ({
|
|
|
1983
2000
|
unregisterControl?.(legendIdRef.current, position);
|
|
1984
2001
|
};
|
|
1985
2002
|
}, [position, registerControl, unregisterControl]);
|
|
1986
|
-
const verticalOffsetStyle =
|
|
2003
|
+
const verticalOffsetStyle = React25.useMemo(() => {
|
|
1987
2004
|
return computeVerticalOffsetStyle(position, customControlOffset);
|
|
1988
2005
|
}, [customControlOffset, position]);
|
|
1989
2006
|
const handleItemClick = (item, index) => {
|
|
@@ -1996,13 +2013,13 @@ var Legend = ({
|
|
|
1996
2013
|
setIsCollapsed(!isCollapsed);
|
|
1997
2014
|
}
|
|
1998
2015
|
};
|
|
1999
|
-
const gradientStyle =
|
|
2016
|
+
const gradientStyle = React25.useMemo(() => {
|
|
2000
2017
|
if (type !== "gradient" || gradient.length === 0) return "";
|
|
2001
2018
|
const stops = gradient.map((stop) => `${stop.color} ${stop.position * 100}%`).join(", ");
|
|
2002
2019
|
return `linear-gradient(to right, ${stops})`;
|
|
2003
2020
|
}, [type, gradient]);
|
|
2004
2021
|
const hasControlsAtPosition = (controlOffsets?.[position] ?? 0) > 0;
|
|
2005
|
-
const computedPositionClasses =
|
|
2022
|
+
const computedPositionClasses = React25.useMemo(() => {
|
|
2006
2023
|
return computePositionClasses(position, hasControlsAtPosition);
|
|
2007
2024
|
}, [position, hasControlsAtPosition]);
|
|
2008
2025
|
return /* @__PURE__ */ jsxs(
|
|
@@ -2101,15 +2118,15 @@ var LegendGroup = ({
|
|
|
2101
2118
|
class: className
|
|
2102
2119
|
}) => {
|
|
2103
2120
|
const { controlOffsets, registerControl, unregisterControl } = useMap();
|
|
2104
|
-
const containerRef =
|
|
2105
|
-
const groupIdRef =
|
|
2106
|
-
const [customControlOffset, setCustomControlOffset] =
|
|
2121
|
+
const containerRef = React25.useRef(null);
|
|
2122
|
+
const groupIdRef = React25.useRef(`legend-group-${++legendGroupIdCounter}`);
|
|
2123
|
+
const [customControlOffset, setCustomControlOffset] = React25.useState(0);
|
|
2107
2124
|
const getInitialExpanded = () => {
|
|
2108
2125
|
if (controlledExpanded !== void 0) return controlledExpanded;
|
|
2109
2126
|
if (defaultExpanded) return defaultExpanded;
|
|
2110
2127
|
return legends[0]?.id || null;
|
|
2111
2128
|
};
|
|
2112
|
-
const [internalExpanded, setInternalExpanded] =
|
|
2129
|
+
const [internalExpanded, setInternalExpanded] = React25.useState(getInitialExpanded);
|
|
2113
2130
|
const expandedId = controlledExpanded !== void 0 ? controlledExpanded : internalExpanded;
|
|
2114
2131
|
const handleToggle = (id) => {
|
|
2115
2132
|
const newExpanded = expandedId === id ? allowCollapseAll ? null : id : id;
|
|
@@ -2118,7 +2135,7 @@ var LegendGroup = ({
|
|
|
2118
2135
|
}
|
|
2119
2136
|
onExpandedChange?.(newExpanded);
|
|
2120
2137
|
};
|
|
2121
|
-
|
|
2138
|
+
React25.useEffect(() => {
|
|
2122
2139
|
if (!containerRef.current || !registerControl) return;
|
|
2123
2140
|
const timeoutId = setTimeout(() => {
|
|
2124
2141
|
if (containerRef.current) {
|
|
@@ -2132,11 +2149,11 @@ var LegendGroup = ({
|
|
|
2132
2149
|
unregisterControl?.(groupIdRef.current, position);
|
|
2133
2150
|
};
|
|
2134
2151
|
}, [position, expandedId, registerControl, unregisterControl]);
|
|
2135
|
-
const verticalOffsetStyle =
|
|
2152
|
+
const verticalOffsetStyle = React25.useMemo(() => {
|
|
2136
2153
|
return computeVerticalOffsetStyle(position, customControlOffset);
|
|
2137
2154
|
}, [customControlOffset, position]);
|
|
2138
2155
|
const hasControlsAtPosition = (controlOffsets?.[position] ?? 0) > 0;
|
|
2139
|
-
const computedPositionClasses =
|
|
2156
|
+
const computedPositionClasses = React25.useMemo(() => {
|
|
2140
2157
|
return computePositionClasses(position, hasControlsAtPosition);
|
|
2141
2158
|
}, [position, hasControlsAtPosition]);
|
|
2142
2159
|
const getGradientStyle = (legend) => {
|
|
@@ -2267,13 +2284,13 @@ var CoordinateDisplay = ({
|
|
|
2267
2284
|
class: className
|
|
2268
2285
|
}) => {
|
|
2269
2286
|
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
|
-
|
|
2287
|
+
const [cursorLngLat, setCursorLngLat] = React25.useState(null);
|
|
2288
|
+
const [currentZoom, setCurrentZoom] = React25.useState(0);
|
|
2289
|
+
const [currentBearing, setCurrentBearing] = React25.useState(0);
|
|
2290
|
+
const [customControlOffset, setCustomControlOffset] = React25.useState(0);
|
|
2291
|
+
const controlRef = React25.useRef(null);
|
|
2292
|
+
const controlIdRef = React25.useRef(`coord-display-${++coordDisplayIdCounter}`);
|
|
2293
|
+
React25.useEffect(() => {
|
|
2277
2294
|
if (!controlRef.current || !registerControl) return;
|
|
2278
2295
|
const updatePosition = () => {
|
|
2279
2296
|
if (!controlRef.current) return;
|
|
@@ -2289,10 +2306,10 @@ var CoordinateDisplay = ({
|
|
|
2289
2306
|
unregisterControl?.(controlIdRef.current, position);
|
|
2290
2307
|
};
|
|
2291
2308
|
}, [position, registerControl, unregisterControl]);
|
|
2292
|
-
const verticalOffsetStyle =
|
|
2309
|
+
const verticalOffsetStyle = React25.useMemo(() => {
|
|
2293
2310
|
return computeVerticalOffsetStyle(position, customControlOffset);
|
|
2294
2311
|
}, [customControlOffset, position]);
|
|
2295
|
-
const formatCoord =
|
|
2312
|
+
const formatCoord = React25.useCallback(
|
|
2296
2313
|
(lngLat) => {
|
|
2297
2314
|
return formatCoordinates(lngLat, precision, format);
|
|
2298
2315
|
},
|
|
@@ -2306,10 +2323,10 @@ var CoordinateDisplay = ({
|
|
|
2306
2323
|
return `${normalized.toFixed(0)}\xB0`;
|
|
2307
2324
|
};
|
|
2308
2325
|
const hasControlsAtPosition = (controlOffsets?.[position] ?? 0) > 0;
|
|
2309
|
-
const computedPositionClasses =
|
|
2326
|
+
const computedPositionClasses = React25.useMemo(() => {
|
|
2310
2327
|
return computePositionClasses(position, hasControlsAtPosition);
|
|
2311
2328
|
}, [position, hasControlsAtPosition]);
|
|
2312
|
-
|
|
2329
|
+
React25.useEffect(() => {
|
|
2313
2330
|
if (!map || !loaded) return;
|
|
2314
2331
|
setCurrentZoom(map.getZoom());
|
|
2315
2332
|
setCurrentBearing(map.getBearing());
|
|
@@ -2376,16 +2393,16 @@ var BasemapSwitcher = ({
|
|
|
2376
2393
|
class: className
|
|
2377
2394
|
}) => {
|
|
2378
2395
|
const { controlOffsets, registerControl, unregisterControl, setMapStyle } = useMap();
|
|
2379
|
-
const [isOpen, setIsOpen] =
|
|
2380
|
-
const [internalActiveId, setInternalActiveId] =
|
|
2396
|
+
const [isOpen, setIsOpen] = React25.useState(false);
|
|
2397
|
+
const [internalActiveId, setInternalActiveId] = React25.useState(
|
|
2381
2398
|
defaultBasemapId
|
|
2382
2399
|
);
|
|
2383
|
-
const [customControlOffset, setCustomControlOffset] =
|
|
2384
|
-
const containerRef =
|
|
2385
|
-
const panelRef =
|
|
2386
|
-
const switcherIdRef =
|
|
2400
|
+
const [customControlOffset, setCustomControlOffset] = React25.useState(0);
|
|
2401
|
+
const containerRef = React25.useRef(null);
|
|
2402
|
+
const panelRef = React25.useRef(null);
|
|
2403
|
+
const switcherIdRef = React25.useRef(`basemap-switcher-${++switcherIdCounter}`);
|
|
2387
2404
|
const sourceBasemaps = basemaps ?? FREE_BASEMAPS;
|
|
2388
|
-
const availableBasemaps =
|
|
2405
|
+
const availableBasemaps = React25.useMemo(() => {
|
|
2389
2406
|
const available = getAvailableBasemaps(sourceBasemaps, apiKeys);
|
|
2390
2407
|
if (extraBasemaps?.length) {
|
|
2391
2408
|
return [...available, ...getAvailableBasemaps(extraBasemaps, apiKeys)];
|
|
@@ -2393,7 +2410,7 @@ var BasemapSwitcher = ({
|
|
|
2393
2410
|
return available;
|
|
2394
2411
|
}, [sourceBasemaps, extraBasemaps, apiKeys]);
|
|
2395
2412
|
const currentActiveId = activeBasemapId ?? internalActiveId ?? availableBasemaps[0]?.id;
|
|
2396
|
-
|
|
2413
|
+
React25.useEffect(() => {
|
|
2397
2414
|
if (!containerRef.current || !registerControl) return;
|
|
2398
2415
|
const updatePosition = () => {
|
|
2399
2416
|
if (!containerRef.current) return;
|
|
@@ -2409,7 +2426,7 @@ var BasemapSwitcher = ({
|
|
|
2409
2426
|
unregisterControl?.(switcherIdRef.current, position);
|
|
2410
2427
|
};
|
|
2411
2428
|
}, [position, registerControl, unregisterControl]);
|
|
2412
|
-
|
|
2429
|
+
React25.useEffect(() => {
|
|
2413
2430
|
if (!isOpen) return;
|
|
2414
2431
|
const handleMouseDown = (e) => {
|
|
2415
2432
|
if (containerRef.current && !containerRef.current.contains(e.target)) {
|
|
@@ -2419,7 +2436,7 @@ var BasemapSwitcher = ({
|
|
|
2419
2436
|
document.addEventListener("mousedown", handleMouseDown);
|
|
2420
2437
|
return () => document.removeEventListener("mousedown", handleMouseDown);
|
|
2421
2438
|
}, [isOpen]);
|
|
2422
|
-
|
|
2439
|
+
React25.useEffect(() => {
|
|
2423
2440
|
if (!isOpen) return;
|
|
2424
2441
|
const handleKeyDown = (e) => {
|
|
2425
2442
|
if (e.key === "Escape") {
|
|
@@ -2439,11 +2456,11 @@ var BasemapSwitcher = ({
|
|
|
2439
2456
|
onBasemapChange?.(basemap);
|
|
2440
2457
|
setIsOpen(false);
|
|
2441
2458
|
};
|
|
2442
|
-
const verticalOffsetStyle =
|
|
2459
|
+
const verticalOffsetStyle = React25.useMemo(() => {
|
|
2443
2460
|
return computeVerticalOffsetStyle(position, customControlOffset);
|
|
2444
2461
|
}, [customControlOffset, position]);
|
|
2445
2462
|
const hasControlsAtPosition = (controlOffsets?.[position] ?? 0) > 0;
|
|
2446
|
-
const computedPositionClasses =
|
|
2463
|
+
const computedPositionClasses = React25.useMemo(() => {
|
|
2447
2464
|
return computePositionClasses(position, hasControlsAtPosition);
|
|
2448
2465
|
}, [position, hasControlsAtPosition]);
|
|
2449
2466
|
const isTop = position.startsWith("top");
|
|
@@ -2556,6 +2573,572 @@ var BasemapSwitcher = ({
|
|
|
2556
2573
|
);
|
|
2557
2574
|
};
|
|
2558
2575
|
BasemapSwitcher.displayName = "BasemapSwitcher";
|
|
2576
|
+
var managerIdCounter = 0;
|
|
2577
|
+
var LayerManager = ({
|
|
2578
|
+
layers,
|
|
2579
|
+
apiKeys,
|
|
2580
|
+
initialActiveLayers,
|
|
2581
|
+
position = "top-right",
|
|
2582
|
+
showSearch = false,
|
|
2583
|
+
showCategories = false,
|
|
2584
|
+
allowReorder = false,
|
|
2585
|
+
showOpacity = false,
|
|
2586
|
+
collapsible = true,
|
|
2587
|
+
onLayerChange,
|
|
2588
|
+
class: className
|
|
2589
|
+
}) => {
|
|
2590
|
+
const { controlOffsets, registerControl, unregisterControl } = useMap();
|
|
2591
|
+
const { isDark } = useMapTheme();
|
|
2592
|
+
const [isOpen, setIsOpen] = React25.useState(false);
|
|
2593
|
+
const [layerStates, setLayerStates] = React25.useState(
|
|
2594
|
+
() => createInitialLayerStates(layers, initialActiveLayers)
|
|
2595
|
+
);
|
|
2596
|
+
const [searchQuery, setSearchQuery] = React25.useState("");
|
|
2597
|
+
const [activeCategory, setActiveCategory] = React25.useState("all");
|
|
2598
|
+
const [customControlOffset, setCustomControlOffset] = React25.useState(0);
|
|
2599
|
+
const [expandedOpacity, setExpandedOpacity] = React25.useState(null);
|
|
2600
|
+
const [draggedId, setDraggedId] = React25.useState(null);
|
|
2601
|
+
const [dragOver, setDragOver] = React25.useState(null);
|
|
2602
|
+
const containerRef = React25.useRef(null);
|
|
2603
|
+
const managerIdRef = React25.useRef(`layer-manager-${++managerIdCounter}`);
|
|
2604
|
+
const lastLayerIdsRef = React25.useRef(new Set(layers.map((l) => l.id)));
|
|
2605
|
+
React25.useEffect(() => {
|
|
2606
|
+
const currentLayerIds = new Set(layers.map((l) => l.id));
|
|
2607
|
+
const hasNewLayers = layers.some((l) => !lastLayerIdsRef.current.has(l.id));
|
|
2608
|
+
const hasRemovedLayers = Array.from(lastLayerIdsRef.current).some(
|
|
2609
|
+
(id) => !currentLayerIds.has(id)
|
|
2610
|
+
);
|
|
2611
|
+
if (hasNewLayers || hasRemovedLayers) {
|
|
2612
|
+
setLayerStates((prev) => {
|
|
2613
|
+
const newStates = new Map(prev);
|
|
2614
|
+
for (const layer of layers) {
|
|
2615
|
+
if (!newStates.has(layer.id)) {
|
|
2616
|
+
newStates.set(layer.id, {
|
|
2617
|
+
id: layer.id,
|
|
2618
|
+
visible: initialActiveLayers?.includes(layer.id) ?? false,
|
|
2619
|
+
opacity: 1,
|
|
2620
|
+
loading: false,
|
|
2621
|
+
error: null,
|
|
2622
|
+
order: newStates.size
|
|
2623
|
+
});
|
|
2624
|
+
}
|
|
2625
|
+
}
|
|
2626
|
+
for (const id of lastLayerIdsRef.current) {
|
|
2627
|
+
if (!currentLayerIds.has(id)) {
|
|
2628
|
+
newStates.delete(id);
|
|
2629
|
+
}
|
|
2630
|
+
}
|
|
2631
|
+
return newStates;
|
|
2632
|
+
});
|
|
2633
|
+
lastLayerIdsRef.current = currentLayerIds;
|
|
2634
|
+
}
|
|
2635
|
+
}, [layers, initialActiveLayers]);
|
|
2636
|
+
const categories = React25.useMemo(() => getLayerCategories(layers), [layers]);
|
|
2637
|
+
const filteredLayers = React25.useMemo(() => {
|
|
2638
|
+
let result = layers;
|
|
2639
|
+
if (searchQuery) {
|
|
2640
|
+
result = searchLayers(result, searchQuery);
|
|
2641
|
+
}
|
|
2642
|
+
if (activeCategory !== "all") {
|
|
2643
|
+
result = result.filter((l) => l.category === activeCategory);
|
|
2644
|
+
}
|
|
2645
|
+
return [...result].sort((a, b) => {
|
|
2646
|
+
const orderA = layerStates.get(a.id)?.order ?? 0;
|
|
2647
|
+
const orderB = layerStates.get(b.id)?.order ?? 0;
|
|
2648
|
+
return orderA - orderB;
|
|
2649
|
+
});
|
|
2650
|
+
}, [layers, searchQuery, activeCategory, layerStates]);
|
|
2651
|
+
const layerGroups = React25.useMemo(
|
|
2652
|
+
() => showCategories ? groupLayersByCategory(filteredLayers) : null,
|
|
2653
|
+
[filteredLayers, showCategories]
|
|
2654
|
+
);
|
|
2655
|
+
React25.useEffect(() => {
|
|
2656
|
+
if (!containerRef.current || !registerControl) return;
|
|
2657
|
+
const updatePosition = () => {
|
|
2658
|
+
if (!containerRef.current) return;
|
|
2659
|
+
const height = containerRef.current.offsetHeight;
|
|
2660
|
+
const offset = registerControl(managerIdRef.current, position, height);
|
|
2661
|
+
setCustomControlOffset(offset);
|
|
2662
|
+
};
|
|
2663
|
+
updatePosition();
|
|
2664
|
+
const observer = new ResizeObserver(updatePosition);
|
|
2665
|
+
observer.observe(containerRef.current);
|
|
2666
|
+
return () => {
|
|
2667
|
+
observer.disconnect();
|
|
2668
|
+
unregisterControl?.(managerIdRef.current, position);
|
|
2669
|
+
};
|
|
2670
|
+
}, [position, registerControl, unregisterControl]);
|
|
2671
|
+
React25.useEffect(() => {
|
|
2672
|
+
if (!isOpen) return;
|
|
2673
|
+
const handleMouseDown = (e) => {
|
|
2674
|
+
if (containerRef.current && !containerRef.current.contains(e.target)) {
|
|
2675
|
+
setIsOpen(false);
|
|
2676
|
+
}
|
|
2677
|
+
};
|
|
2678
|
+
document.addEventListener("mousedown", handleMouseDown);
|
|
2679
|
+
return () => document.removeEventListener("mousedown", handleMouseDown);
|
|
2680
|
+
}, [isOpen]);
|
|
2681
|
+
React25.useEffect(() => {
|
|
2682
|
+
if (!isOpen) return;
|
|
2683
|
+
const handleKeyDown = (e) => {
|
|
2684
|
+
if (e.key === "Escape") {
|
|
2685
|
+
setIsOpen(false);
|
|
2686
|
+
}
|
|
2687
|
+
};
|
|
2688
|
+
document.addEventListener("keydown", handleKeyDown);
|
|
2689
|
+
return () => document.removeEventListener("keydown", handleKeyDown);
|
|
2690
|
+
}, [isOpen]);
|
|
2691
|
+
const handleToggleLayer = React25.useCallback(
|
|
2692
|
+
(layerId) => {
|
|
2693
|
+
setLayerStates((prev) => {
|
|
2694
|
+
const newStates = toggleLayerVisibility(prev, layerId);
|
|
2695
|
+
const state = newStates.get(layerId);
|
|
2696
|
+
if (state && onLayerChange) {
|
|
2697
|
+
onLayerChange(layerId, state);
|
|
2698
|
+
}
|
|
2699
|
+
return newStates;
|
|
2700
|
+
});
|
|
2701
|
+
},
|
|
2702
|
+
[onLayerChange]
|
|
2703
|
+
);
|
|
2704
|
+
const handleOpacityChange = React25.useCallback(
|
|
2705
|
+
(layerId, opacity) => {
|
|
2706
|
+
setLayerStates((prev) => {
|
|
2707
|
+
const newStates = setLayerOpacity(prev, layerId, opacity);
|
|
2708
|
+
const state = newStates.get(layerId);
|
|
2709
|
+
if (state && onLayerChange) {
|
|
2710
|
+
onLayerChange(layerId, state);
|
|
2711
|
+
}
|
|
2712
|
+
return newStates;
|
|
2713
|
+
});
|
|
2714
|
+
},
|
|
2715
|
+
[onLayerChange]
|
|
2716
|
+
);
|
|
2717
|
+
const handleDragStart = React25.useCallback((e, layerId) => {
|
|
2718
|
+
setDraggedId(layerId);
|
|
2719
|
+
e.dataTransfer.effectAllowed = "move";
|
|
2720
|
+
e.dataTransfer.setData("text/plain", layerId);
|
|
2721
|
+
}, []);
|
|
2722
|
+
const handleDragOver = React25.useCallback(
|
|
2723
|
+
(e, layerId) => {
|
|
2724
|
+
e.preventDefault();
|
|
2725
|
+
e.dataTransfer.dropEffect = "move";
|
|
2726
|
+
if (layerId !== draggedId) {
|
|
2727
|
+
const rect = e.currentTarget.getBoundingClientRect();
|
|
2728
|
+
const relativeY = (e.clientY - rect.top) / rect.height;
|
|
2729
|
+
let position2;
|
|
2730
|
+
if (relativeY < 0.3) {
|
|
2731
|
+
position2 = "above";
|
|
2732
|
+
} else if (relativeY > 0.7) {
|
|
2733
|
+
position2 = "below";
|
|
2734
|
+
} else {
|
|
2735
|
+
position2 = dragOver?.id === layerId ? dragOver.position : "below";
|
|
2736
|
+
}
|
|
2737
|
+
setDragOver({ id: layerId, position: position2 });
|
|
2738
|
+
}
|
|
2739
|
+
},
|
|
2740
|
+
[draggedId, dragOver]
|
|
2741
|
+
);
|
|
2742
|
+
const handleDragLeave = React25.useCallback(() => {
|
|
2743
|
+
setDragOver(null);
|
|
2744
|
+
}, []);
|
|
2745
|
+
const handleDragEnd = React25.useCallback(() => {
|
|
2746
|
+
setDraggedId(null);
|
|
2747
|
+
setDragOver(null);
|
|
2748
|
+
}, []);
|
|
2749
|
+
const handleDrop = React25.useCallback(
|
|
2750
|
+
(e, targetLayerId) => {
|
|
2751
|
+
e.preventDefault();
|
|
2752
|
+
const sourceLayerId = e.dataTransfer.getData("text/plain");
|
|
2753
|
+
if (sourceLayerId && sourceLayerId !== targetLayerId) {
|
|
2754
|
+
const sortedStates = getLayerStatesArray(layerStates);
|
|
2755
|
+
const sourceIndex = sortedStates.findIndex((s) => s.id === sourceLayerId);
|
|
2756
|
+
let targetIndex = sortedStates.findIndex((s) => s.id === targetLayerId);
|
|
2757
|
+
if (targetIndex !== -1) {
|
|
2758
|
+
if (dragOver?.position === "below") {
|
|
2759
|
+
targetIndex += 1;
|
|
2760
|
+
}
|
|
2761
|
+
if (sourceIndex < targetIndex) {
|
|
2762
|
+
targetIndex -= 1;
|
|
2763
|
+
}
|
|
2764
|
+
setLayerStates((prev) => {
|
|
2765
|
+
const newStates = reorderLayers(prev, sourceLayerId, targetIndex);
|
|
2766
|
+
const state = newStates.get(sourceLayerId);
|
|
2767
|
+
if (state && onLayerChange) {
|
|
2768
|
+
onLayerChange(sourceLayerId, state);
|
|
2769
|
+
}
|
|
2770
|
+
return newStates;
|
|
2771
|
+
});
|
|
2772
|
+
}
|
|
2773
|
+
}
|
|
2774
|
+
setDraggedId(null);
|
|
2775
|
+
setDragOver(null);
|
|
2776
|
+
},
|
|
2777
|
+
[layerStates, onLayerChange, dragOver]
|
|
2778
|
+
);
|
|
2779
|
+
const verticalOffsetStyle = React25.useMemo(() => {
|
|
2780
|
+
return computeVerticalOffsetStyle(position, customControlOffset);
|
|
2781
|
+
}, [customControlOffset, position]);
|
|
2782
|
+
const hasControlsAtPosition = (controlOffsets?.[position] ?? 0) > 0;
|
|
2783
|
+
const computedPositionClasses = React25.useMemo(() => {
|
|
2784
|
+
return computePositionClasses(position, hasControlsAtPosition);
|
|
2785
|
+
}, [position, hasControlsAtPosition]);
|
|
2786
|
+
const isTop = position.startsWith("top");
|
|
2787
|
+
const renderLayer = (layer, state) => {
|
|
2788
|
+
if (!state.visible) return null;
|
|
2789
|
+
const theme = isDark ? "dark" : "light";
|
|
2790
|
+
const paint = getLayerStyleForTheme(layer, theme);
|
|
2791
|
+
const sourceUrl = resolveLayerSourceUrl(layer, apiKeys);
|
|
2792
|
+
const sourceId = `lm-source-${layer.id}`;
|
|
2793
|
+
const sourceData = layer.source.type === "geojson-inline" ? layer.source.data : layer.source.type === "geojson-url" && sourceUrl ? sourceUrl : void 0;
|
|
2794
|
+
if (!sourceData && layer.source.type !== "vector-tiles") {
|
|
2795
|
+
return null;
|
|
2796
|
+
}
|
|
2797
|
+
const layerProps = {
|
|
2798
|
+
id: `lm-layer-${layer.id}`,
|
|
2799
|
+
source: sourceId,
|
|
2800
|
+
sourceLayer: layer.source.sourceLayer,
|
|
2801
|
+
visible: state.visible,
|
|
2802
|
+
opacity: state.opacity,
|
|
2803
|
+
minZoom: layer.style.minZoom,
|
|
2804
|
+
maxZoom: layer.style.maxZoom
|
|
2805
|
+
};
|
|
2806
|
+
let layerComponent = null;
|
|
2807
|
+
const baseOpacity = {
|
|
2808
|
+
fill: paint["fill-opacity"] ?? 1,
|
|
2809
|
+
line: paint["line-opacity"] ?? 1,
|
|
2810
|
+
circle: paint["circle-opacity"] ?? 1,
|
|
2811
|
+
icon: paint["icon-opacity"] ?? 1
|
|
2812
|
+
};
|
|
2813
|
+
switch (layer.style.renderType) {
|
|
2814
|
+
case "fill":
|
|
2815
|
+
layerComponent = /* @__PURE__ */ jsx(
|
|
2816
|
+
FillLayer,
|
|
2817
|
+
{
|
|
2818
|
+
...layerProps,
|
|
2819
|
+
fillColor: paint["fill-color"],
|
|
2820
|
+
fillOpacity: baseOpacity.fill * state.opacity,
|
|
2821
|
+
fillOutlineColor: paint["fill-outline-color"]
|
|
2822
|
+
}
|
|
2823
|
+
);
|
|
2824
|
+
break;
|
|
2825
|
+
case "line":
|
|
2826
|
+
layerComponent = /* @__PURE__ */ jsx(
|
|
2827
|
+
LineLayer,
|
|
2828
|
+
{
|
|
2829
|
+
...layerProps,
|
|
2830
|
+
lineColor: paint["line-color"],
|
|
2831
|
+
lineWidth: paint["line-width"],
|
|
2832
|
+
lineOpacity: baseOpacity.line * state.opacity,
|
|
2833
|
+
lineDasharray: paint["line-dasharray"]
|
|
2834
|
+
}
|
|
2835
|
+
);
|
|
2836
|
+
break;
|
|
2837
|
+
case "circle":
|
|
2838
|
+
layerComponent = /* @__PURE__ */ jsx(
|
|
2839
|
+
CircleLayer,
|
|
2840
|
+
{
|
|
2841
|
+
...layerProps,
|
|
2842
|
+
circleColor: paint["circle-color"],
|
|
2843
|
+
circleRadius: paint["circle-radius"],
|
|
2844
|
+
circleOpacity: baseOpacity.circle * state.opacity,
|
|
2845
|
+
circleStrokeWidth: paint["circle-stroke-width"],
|
|
2846
|
+
circleStrokeColor: paint["circle-stroke-color"]
|
|
2847
|
+
}
|
|
2848
|
+
);
|
|
2849
|
+
break;
|
|
2850
|
+
case "symbol":
|
|
2851
|
+
layerComponent = /* @__PURE__ */ jsx(
|
|
2852
|
+
SymbolLayer,
|
|
2853
|
+
{
|
|
2854
|
+
...layerProps,
|
|
2855
|
+
iconImage: paint["icon-image"],
|
|
2856
|
+
iconSize: paint["icon-size"],
|
|
2857
|
+
iconOpacity: baseOpacity.icon * state.opacity,
|
|
2858
|
+
textField: paint["text-field"],
|
|
2859
|
+
textSize: paint["text-size"],
|
|
2860
|
+
textColor: paint["text-color"]
|
|
2861
|
+
}
|
|
2862
|
+
);
|
|
2863
|
+
break;
|
|
2864
|
+
}
|
|
2865
|
+
return /* @__PURE__ */ jsx(
|
|
2866
|
+
Source,
|
|
2867
|
+
{
|
|
2868
|
+
id: sourceId,
|
|
2869
|
+
type: layer.source.type === "vector-tiles" ? "vector" : "geojson",
|
|
2870
|
+
data: layer.source.type !== "vector-tiles" ? sourceData : void 0,
|
|
2871
|
+
url: layer.source.type === "vector-tiles" ? sourceUrl ?? void 0 : void 0,
|
|
2872
|
+
tiles: layer.source.type === "vector-tiles" ? [sourceUrl ?? ""] : void 0,
|
|
2873
|
+
attribution: layer.source.attribution,
|
|
2874
|
+
children: layerComponent
|
|
2875
|
+
},
|
|
2876
|
+
layer.id
|
|
2877
|
+
);
|
|
2878
|
+
};
|
|
2879
|
+
const renderLayerItem = (layer) => {
|
|
2880
|
+
const state = layerStates.get(layer.id);
|
|
2881
|
+
if (!state) return null;
|
|
2882
|
+
const isDragging = draggedId === layer.id;
|
|
2883
|
+
const isDragOver = dragOver?.id === layer.id;
|
|
2884
|
+
const dragOverPosition = isDragOver ? dragOver.position : void 0;
|
|
2885
|
+
return /* @__PURE__ */ jsxs(
|
|
2886
|
+
"div",
|
|
2887
|
+
{
|
|
2888
|
+
className: "classic-layer-item",
|
|
2889
|
+
draggable: allowReorder,
|
|
2890
|
+
onDragStart: allowReorder ? (e) => handleDragStart(e, layer.id) : void 0,
|
|
2891
|
+
onDragOver: allowReorder ? (e) => handleDragOver(e, layer.id) : void 0,
|
|
2892
|
+
onDragLeave: allowReorder ? handleDragLeave : void 0,
|
|
2893
|
+
onDragEnd: allowReorder ? handleDragEnd : void 0,
|
|
2894
|
+
onDrop: allowReorder ? (e) => handleDrop(e, layer.id) : void 0,
|
|
2895
|
+
"data-dragging": isDragging || void 0,
|
|
2896
|
+
"data-drag-over": dragOverPosition,
|
|
2897
|
+
children: [
|
|
2898
|
+
allowReorder && /* @__PURE__ */ jsx("span", { className: "classic-layer-drag-handle text-muted-foreground", children: /* @__PURE__ */ jsxs(
|
|
2899
|
+
"svg",
|
|
2900
|
+
{
|
|
2901
|
+
width: "12",
|
|
2902
|
+
height: "12",
|
|
2903
|
+
viewBox: "0 0 24 24",
|
|
2904
|
+
fill: "none",
|
|
2905
|
+
stroke: "currentColor",
|
|
2906
|
+
strokeWidth: "2",
|
|
2907
|
+
children: [
|
|
2908
|
+
/* @__PURE__ */ jsx("circle", { cx: "9", cy: "6", r: "1", fill: "currentColor" }),
|
|
2909
|
+
/* @__PURE__ */ jsx("circle", { cx: "15", cy: "6", r: "1", fill: "currentColor" }),
|
|
2910
|
+
/* @__PURE__ */ jsx("circle", { cx: "9", cy: "12", r: "1", fill: "currentColor" }),
|
|
2911
|
+
/* @__PURE__ */ jsx("circle", { cx: "15", cy: "12", r: "1", fill: "currentColor" }),
|
|
2912
|
+
/* @__PURE__ */ jsx("circle", { cx: "9", cy: "18", r: "1", fill: "currentColor" }),
|
|
2913
|
+
/* @__PURE__ */ jsx("circle", { cx: "15", cy: "18", r: "1", fill: "currentColor" })
|
|
2914
|
+
]
|
|
2915
|
+
}
|
|
2916
|
+
) }),
|
|
2917
|
+
/* @__PURE__ */ jsx(
|
|
2918
|
+
Switch,
|
|
2919
|
+
{
|
|
2920
|
+
size: "sm",
|
|
2921
|
+
checked: state.visible,
|
|
2922
|
+
onCheckedChange: () => handleToggleLayer(layer.id),
|
|
2923
|
+
"aria-label": `Toggle ${layer.name}`
|
|
2924
|
+
}
|
|
2925
|
+
),
|
|
2926
|
+
/* @__PURE__ */ jsxs("div", { className: "flex-1 min-w-0", children: [
|
|
2927
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
|
|
2928
|
+
/* @__PURE__ */ jsx("span", { className: "text-sm text-foreground truncate", children: layer.name }),
|
|
2929
|
+
state.loading && /* @__PURE__ */ jsx(
|
|
2930
|
+
"svg",
|
|
2931
|
+
{
|
|
2932
|
+
className: "classic-layer-loading w-3 h-3 text-muted-foreground",
|
|
2933
|
+
viewBox: "0 0 24 24",
|
|
2934
|
+
fill: "none",
|
|
2935
|
+
stroke: "currentColor",
|
|
2936
|
+
strokeWidth: "2",
|
|
2937
|
+
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" })
|
|
2938
|
+
}
|
|
2939
|
+
)
|
|
2940
|
+
] }),
|
|
2941
|
+
state.error && /* @__PURE__ */ jsx("span", { className: "classic-layer-error", children: state.error })
|
|
2942
|
+
] }),
|
|
2943
|
+
showOpacity && state.visible && /* @__PURE__ */ jsx(
|
|
2944
|
+
"button",
|
|
2945
|
+
{
|
|
2946
|
+
type: "button",
|
|
2947
|
+
className: "text-muted-foreground hover:text-foreground p-1",
|
|
2948
|
+
onClick: () => setExpandedOpacity(expandedOpacity === layer.id ? null : layer.id),
|
|
2949
|
+
"aria-label": "Adjust opacity",
|
|
2950
|
+
children: /* @__PURE__ */ jsxs(
|
|
2951
|
+
"svg",
|
|
2952
|
+
{
|
|
2953
|
+
width: "14",
|
|
2954
|
+
height: "14",
|
|
2955
|
+
viewBox: "0 0 24 24",
|
|
2956
|
+
fill: "none",
|
|
2957
|
+
stroke: "currentColor",
|
|
2958
|
+
strokeWidth: "2",
|
|
2959
|
+
children: [
|
|
2960
|
+
/* @__PURE__ */ jsx("circle", { cx: "12", cy: "12", r: "10" }),
|
|
2961
|
+
/* @__PURE__ */ jsx("path", { d: "M12 2a10 10 0 0 1 0 20", fill: "currentColor", opacity: "0.3" })
|
|
2962
|
+
]
|
|
2963
|
+
}
|
|
2964
|
+
)
|
|
2965
|
+
}
|
|
2966
|
+
)
|
|
2967
|
+
]
|
|
2968
|
+
},
|
|
2969
|
+
layer.id
|
|
2970
|
+
);
|
|
2971
|
+
};
|
|
2972
|
+
const renderOpacitySlider = (layerId) => {
|
|
2973
|
+
if (expandedOpacity !== layerId) return null;
|
|
2974
|
+
const state = layerStates.get(layerId);
|
|
2975
|
+
if (!state) return null;
|
|
2976
|
+
return /* @__PURE__ */ jsx("div", { className: "px-3 pb-2", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
2977
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground w-12", children: "Opacity" }),
|
|
2978
|
+
/* @__PURE__ */ jsx(
|
|
2979
|
+
"input",
|
|
2980
|
+
{
|
|
2981
|
+
type: "range",
|
|
2982
|
+
min: "0",
|
|
2983
|
+
max: "100",
|
|
2984
|
+
value: state.opacity * 100,
|
|
2985
|
+
onChange: (e) => handleOpacityChange(layerId, Number(e.target.value) / 100),
|
|
2986
|
+
className: "classic-layer-opacity-slider flex-1"
|
|
2987
|
+
}
|
|
2988
|
+
),
|
|
2989
|
+
/* @__PURE__ */ jsxs("span", { className: "text-xs text-muted-foreground w-8 text-right", children: [
|
|
2990
|
+
Math.round(state.opacity * 100),
|
|
2991
|
+
"%"
|
|
2992
|
+
] })
|
|
2993
|
+
] }) });
|
|
2994
|
+
};
|
|
2995
|
+
const visibleLayerStates = getLayerStatesArray(layerStates).filter((s) => s.visible);
|
|
2996
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2997
|
+
visibleLayerStates.map((state) => {
|
|
2998
|
+
const layer = layers.find((l) => l.id === state.id);
|
|
2999
|
+
return layer ? renderLayer(layer, state) : null;
|
|
3000
|
+
}),
|
|
3001
|
+
/* @__PURE__ */ jsxs(
|
|
3002
|
+
"div",
|
|
3003
|
+
{
|
|
3004
|
+
ref: containerRef,
|
|
3005
|
+
className: cn("absolute z-10", computedPositionClasses, className),
|
|
3006
|
+
style: verticalOffsetStyle,
|
|
3007
|
+
children: [
|
|
3008
|
+
isOpen && /* @__PURE__ */ jsxs(
|
|
3009
|
+
"div",
|
|
3010
|
+
{
|
|
3011
|
+
className: cn(
|
|
3012
|
+
"absolute classic-layer-panel-enter",
|
|
3013
|
+
"bg-card rounded-lg shadow-lg border border-black dark:border-gray-400",
|
|
3014
|
+
"w-64",
|
|
3015
|
+
isTop ? "top-full mt-1" : "bottom-full mb-1",
|
|
3016
|
+
position.includes("right") ? "right-0" : "left-0"
|
|
3017
|
+
),
|
|
3018
|
+
children: [
|
|
3019
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between p-3 border-b border-border", children: [
|
|
3020
|
+
/* @__PURE__ */ jsx("span", { className: "text-sm font-medium text-foreground", children: "Layers" }),
|
|
3021
|
+
collapsible && /* @__PURE__ */ jsx(
|
|
3022
|
+
"button",
|
|
3023
|
+
{
|
|
3024
|
+
type: "button",
|
|
3025
|
+
className: "text-muted-foreground hover:text-foreground",
|
|
3026
|
+
onClick: () => setIsOpen(false),
|
|
3027
|
+
"aria-label": "Close layer manager",
|
|
3028
|
+
children: /* @__PURE__ */ jsx(
|
|
3029
|
+
"svg",
|
|
3030
|
+
{
|
|
3031
|
+
width: "16",
|
|
3032
|
+
height: "16",
|
|
3033
|
+
viewBox: "0 0 24 24",
|
|
3034
|
+
fill: "none",
|
|
3035
|
+
stroke: "currentColor",
|
|
3036
|
+
strokeWidth: "2",
|
|
3037
|
+
children: /* @__PURE__ */ jsx("path", { d: "M18 6L6 18M6 6l12 12" })
|
|
3038
|
+
}
|
|
3039
|
+
)
|
|
3040
|
+
}
|
|
3041
|
+
)
|
|
3042
|
+
] }),
|
|
3043
|
+
showSearch && /* @__PURE__ */ jsx("div", { className: "p-2 border-b border-border", children: /* @__PURE__ */ jsx(
|
|
3044
|
+
"input",
|
|
3045
|
+
{
|
|
3046
|
+
type: "text",
|
|
3047
|
+
placeholder: "Search layers...",
|
|
3048
|
+
value: searchQuery,
|
|
3049
|
+
onChange: (e) => setSearchQuery(e.target.value),
|
|
3050
|
+
className: "classic-layer-search"
|
|
3051
|
+
}
|
|
3052
|
+
) }),
|
|
3053
|
+
showCategories && categories.length > 1 && /* @__PURE__ */ jsx("div", { className: "p-2 border-b border-border", children: /* @__PURE__ */ jsxs("div", { className: "classic-layer-tabs", children: [
|
|
3054
|
+
/* @__PURE__ */ jsx(
|
|
3055
|
+
"button",
|
|
3056
|
+
{
|
|
3057
|
+
type: "button",
|
|
3058
|
+
className: "classic-layer-tab",
|
|
3059
|
+
"data-active": activeCategory === "all",
|
|
3060
|
+
onClick: () => setActiveCategory("all"),
|
|
3061
|
+
children: "All"
|
|
3062
|
+
}
|
|
3063
|
+
),
|
|
3064
|
+
categories.map((cat) => /* @__PURE__ */ jsx(
|
|
3065
|
+
"button",
|
|
3066
|
+
{
|
|
3067
|
+
type: "button",
|
|
3068
|
+
className: "classic-layer-tab",
|
|
3069
|
+
"data-active": activeCategory === cat,
|
|
3070
|
+
onClick: () => setActiveCategory(cat),
|
|
3071
|
+
children: CATEGORY_META[cat].label
|
|
3072
|
+
},
|
|
3073
|
+
cat
|
|
3074
|
+
))
|
|
3075
|
+
] }) }),
|
|
3076
|
+
/* @__PURE__ */ jsxs("div", { className: "max-h-64 overflow-y-auto", children: [
|
|
3077
|
+
showCategories && layerGroups && activeCategory === "all" ? (
|
|
3078
|
+
// Grouped by category
|
|
3079
|
+
categories.map((cat) => {
|
|
3080
|
+
const catLayers = layerGroups[cat];
|
|
3081
|
+
if (catLayers.length === 0) return null;
|
|
3082
|
+
return /* @__PURE__ */ jsxs("div", { children: [
|
|
3083
|
+
/* @__PURE__ */ jsx("div", { className: "px-3 py-2 text-xs font-medium text-muted-foreground uppercase tracking-wider", children: CATEGORY_META[cat].label }),
|
|
3084
|
+
catLayers.map((layer) => /* @__PURE__ */ jsxs(React25.Fragment, { children: [
|
|
3085
|
+
renderLayerItem(layer),
|
|
3086
|
+
renderOpacitySlider(layer.id)
|
|
3087
|
+
] }, layer.id))
|
|
3088
|
+
] }, cat);
|
|
3089
|
+
})
|
|
3090
|
+
) : (
|
|
3091
|
+
// Flat list
|
|
3092
|
+
filteredLayers.map((layer) => /* @__PURE__ */ jsxs(React25.Fragment, { children: [
|
|
3093
|
+
renderLayerItem(layer),
|
|
3094
|
+
renderOpacitySlider(layer.id)
|
|
3095
|
+
] }, layer.id))
|
|
3096
|
+
),
|
|
3097
|
+
filteredLayers.length === 0 && /* @__PURE__ */ jsx("div", { className: "p-4 text-center text-sm text-muted-foreground", children: "No layers found" })
|
|
3098
|
+
] })
|
|
3099
|
+
]
|
|
3100
|
+
}
|
|
3101
|
+
),
|
|
3102
|
+
/* @__PURE__ */ jsx(
|
|
3103
|
+
"button",
|
|
3104
|
+
{
|
|
3105
|
+
type: "button",
|
|
3106
|
+
className: cn(
|
|
3107
|
+
"w-[40px] h-[40px] flex items-center justify-center",
|
|
3108
|
+
"bg-card rounded shadow-lg border border-black dark:border-gray-400",
|
|
3109
|
+
"hover:bg-muted transition-colors cursor-pointer",
|
|
3110
|
+
"text-foreground"
|
|
3111
|
+
),
|
|
3112
|
+
onClick: () => setIsOpen(!isOpen),
|
|
3113
|
+
"aria-label": "Toggle layer manager",
|
|
3114
|
+
"aria-expanded": isOpen,
|
|
3115
|
+
"aria-haspopup": "true",
|
|
3116
|
+
children: /* @__PURE__ */ jsxs(
|
|
3117
|
+
"svg",
|
|
3118
|
+
{
|
|
3119
|
+
width: "20",
|
|
3120
|
+
height: "20",
|
|
3121
|
+
viewBox: "0 0 24 24",
|
|
3122
|
+
fill: "none",
|
|
3123
|
+
stroke: "currentColor",
|
|
3124
|
+
strokeWidth: "2",
|
|
3125
|
+
strokeLinecap: "round",
|
|
3126
|
+
strokeLinejoin: "round",
|
|
3127
|
+
children: [
|
|
3128
|
+
/* @__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" }),
|
|
3129
|
+
/* @__PURE__ */ jsx("polyline", { points: "2.32 6.16 12 11 21.68 6.16" }),
|
|
3130
|
+
/* @__PURE__ */ jsx("line", { x1: "12", y1: "22.76", x2: "12", y2: "11" })
|
|
3131
|
+
]
|
|
3132
|
+
}
|
|
3133
|
+
)
|
|
3134
|
+
}
|
|
3135
|
+
)
|
|
3136
|
+
]
|
|
3137
|
+
}
|
|
3138
|
+
)
|
|
3139
|
+
] });
|
|
3140
|
+
};
|
|
3141
|
+
LayerManager.displayName = "LayerManager";
|
|
2559
3142
|
var DeckOverlay = ({
|
|
2560
3143
|
layers = [],
|
|
2561
3144
|
onHover,
|
|
@@ -2566,9 +3149,9 @@ var DeckOverlay = ({
|
|
|
2566
3149
|
deckProps = {}
|
|
2567
3150
|
}) => {
|
|
2568
3151
|
const { map, loaded } = useMap();
|
|
2569
|
-
const overlayRef =
|
|
2570
|
-
const MapboxOverlayRef =
|
|
2571
|
-
|
|
3152
|
+
const overlayRef = React25.useRef(null);
|
|
3153
|
+
const MapboxOverlayRef = React25.useRef(null);
|
|
3154
|
+
React25.useEffect(() => {
|
|
2572
3155
|
if (!map || !loaded) return;
|
|
2573
3156
|
let cancelled = false;
|
|
2574
3157
|
const initOverlay = async () => {
|
|
@@ -2608,12 +3191,12 @@ var DeckOverlay = ({
|
|
|
2608
3191
|
}
|
|
2609
3192
|
};
|
|
2610
3193
|
}, [map, loaded, interleaved]);
|
|
2611
|
-
|
|
3194
|
+
React25.useEffect(() => {
|
|
2612
3195
|
if (overlayRef.current && "setProps" in overlayRef.current) {
|
|
2613
3196
|
overlayRef.current.setProps({ layers });
|
|
2614
3197
|
}
|
|
2615
3198
|
}, [layers]);
|
|
2616
|
-
|
|
3199
|
+
React25.useEffect(() => {
|
|
2617
3200
|
if (overlayRef.current && "setProps" in overlayRef.current) {
|
|
2618
3201
|
overlayRef.current.setProps({
|
|
2619
3202
|
onHover,
|
|
@@ -2621,7 +3204,7 @@ var DeckOverlay = ({
|
|
|
2621
3204
|
});
|
|
2622
3205
|
}
|
|
2623
3206
|
}, [onHover, onClick]);
|
|
2624
|
-
|
|
3207
|
+
React25.useEffect(() => {
|
|
2625
3208
|
if (overlayRef.current && effects && "setProps" in overlayRef.current) {
|
|
2626
3209
|
overlayRef.current.setProps({ effects });
|
|
2627
3210
|
}
|
|
@@ -2630,4 +3213,4 @@ var DeckOverlay = ({
|
|
|
2630
3213
|
};
|
|
2631
3214
|
DeckOverlay.displayName = "DeckOverlay";
|
|
2632
3215
|
|
|
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 };
|
|
3216
|
+
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 };
|