@classic-homes/maps-react 0.2.3 → 0.2.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 +435 -369
- package/dist/index.d.cts +3 -13
- package/dist/index.d.ts +3 -13
- package/dist/index.js +430 -364
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as React26 from 'react';
|
|
2
2
|
import { useState, useEffect, useCallback } from 'react';
|
|
3
3
|
import { clsx } from 'clsx';
|
|
4
4
|
import { twMerge } from 'tailwind-merge';
|
|
@@ -7,7 +7,7 @@ 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,
|
|
10
|
+
import { createPositioningCoordinator, generateMapDescription, applyMarkerProtection, applyMarkerChildProtection, removeMarkerProtection, darkBasicStyle, lightBasicStyle, darkTheme, lightTheme, THEME_DARK, THEME_LIGHT, calculateBounds, EDGE_MARGIN, formatCoordinates, getAvailableBasemaps, FREE_BASEMAPS, resolveBasemapThumbnail, createInitialLayerStates, getLayerCategories, searchLayers, groupLayersByCategory, toggleLayerVisibility, setLayerOpacity, getLayerStatesArray, reorderLayers, CATEGORY_META, resolveBasemapStyle, STACK_GAP, getLayerStyleForTheme, resolveLayerSourceUrl } from '@classic-homes/maps-core';
|
|
11
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';
|
|
@@ -19,7 +19,7 @@ import { Switch } from '@classic-homes/theme-react';
|
|
|
19
19
|
function cn(...inputs) {
|
|
20
20
|
return twMerge(clsx(inputs));
|
|
21
21
|
}
|
|
22
|
-
var MapSkeleton =
|
|
22
|
+
var MapSkeleton = React26.forwardRef(
|
|
23
23
|
({ height = 400, className, ...props }, ref) => {
|
|
24
24
|
const heightStyle = typeof height === "number" ? `${height}px` : height;
|
|
25
25
|
return /* @__PURE__ */ jsxs(
|
|
@@ -73,7 +73,7 @@ var MapSkeleton = React25.forwardRef(
|
|
|
73
73
|
}
|
|
74
74
|
);
|
|
75
75
|
MapSkeleton.displayName = "MapSkeleton";
|
|
76
|
-
var MapError =
|
|
76
|
+
var MapError = React26.forwardRef(
|
|
77
77
|
({ message = "Failed to load map", height = 400, onRetry, className, ...props }, ref) => {
|
|
78
78
|
const heightStyle = typeof height === "number" ? `${height}px` : height;
|
|
79
79
|
return /* @__PURE__ */ jsx(
|
|
@@ -129,7 +129,7 @@ var MapError = React25.forwardRef(
|
|
|
129
129
|
}
|
|
130
130
|
);
|
|
131
131
|
MapError.displayName = "MapError";
|
|
132
|
-
var MapEmpty =
|
|
132
|
+
var MapEmpty = React26.forwardRef(
|
|
133
133
|
({ message = "No map data to display", height = 400, className, ...props }, ref) => {
|
|
134
134
|
const heightStyle = typeof height === "number" ? `${height}px` : height;
|
|
135
135
|
return /* @__PURE__ */ jsx(
|
|
@@ -172,7 +172,7 @@ var MapEmpty = React25.forwardRef(
|
|
|
172
172
|
}
|
|
173
173
|
);
|
|
174
174
|
MapEmpty.displayName = "MapEmpty";
|
|
175
|
-
var MapContainer =
|
|
175
|
+
var MapContainer = React26.forwardRef(
|
|
176
176
|
({
|
|
177
177
|
title,
|
|
178
178
|
description,
|
|
@@ -277,9 +277,9 @@ function useReducedMotion() {
|
|
|
277
277
|
}, []);
|
|
278
278
|
return prefersReducedMotion2;
|
|
279
279
|
}
|
|
280
|
-
var MapContext =
|
|
280
|
+
var MapContext = React26.createContext(null);
|
|
281
281
|
function useMap() {
|
|
282
|
-
const context =
|
|
282
|
+
const context = React26.useContext(MapContext);
|
|
283
283
|
if (!context) {
|
|
284
284
|
throw new Error("useMap must be used within a Map component");
|
|
285
285
|
}
|
|
@@ -289,7 +289,7 @@ function useMapInstance() {
|
|
|
289
289
|
const { map, loaded } = useMap();
|
|
290
290
|
return loaded ? map : null;
|
|
291
291
|
}
|
|
292
|
-
var Map2 =
|
|
292
|
+
var Map2 = React26.forwardRef(
|
|
293
293
|
({
|
|
294
294
|
// Base props
|
|
295
295
|
title,
|
|
@@ -343,108 +343,56 @@ var Map2 = React25.forwardRef(
|
|
|
343
343
|
onZoom,
|
|
344
344
|
onError
|
|
345
345
|
}, ref) => {
|
|
346
|
-
const containerRef =
|
|
347
|
-
const mapRef =
|
|
348
|
-
const [mapLoaded, setMapLoaded] =
|
|
349
|
-
const [mapError, setMapError] =
|
|
350
|
-
const [styleVersion, setStyleVersion] =
|
|
351
|
-
const activeStyleOverrideRef =
|
|
346
|
+
const containerRef = React26.useRef(null);
|
|
347
|
+
const mapRef = React26.useRef(null);
|
|
348
|
+
const [mapLoaded, setMapLoaded] = React26.useState(false);
|
|
349
|
+
const [mapError, setMapError] = React26.useState(null);
|
|
350
|
+
const [styleVersion, setStyleVersion] = React26.useState(0);
|
|
351
|
+
const activeStyleOverrideRef = React26.useRef(
|
|
352
352
|
null
|
|
353
353
|
);
|
|
354
|
-
const
|
|
354
|
+
const positioningCoordinatorRef = React26.useRef(null);
|
|
355
|
+
if (!positioningCoordinatorRef.current) {
|
|
356
|
+
positioningCoordinatorRef.current = createPositioningCoordinator();
|
|
357
|
+
}
|
|
358
|
+
const positioningCoordinator = positioningCoordinatorRef.current;
|
|
359
|
+
const setMapStyle = React26.useCallback((style) => {
|
|
355
360
|
activeStyleOverrideRef.current = style;
|
|
356
361
|
mapRef.current?.setStyle(style);
|
|
357
362
|
}, []);
|
|
358
|
-
const customControlRegistryRef = React25.useRef({
|
|
359
|
-
"top-left": [],
|
|
360
|
-
"top-right": [],
|
|
361
|
-
"bottom-left": [],
|
|
362
|
-
"bottom-right": []
|
|
363
|
-
});
|
|
364
|
-
const [, forceUpdate] = React25.useReducer((x) => x + 1, 0);
|
|
365
363
|
const prefersReducedMotion2 = useReducedMotion();
|
|
366
364
|
const { style: themeStyle } = useMapTheme(themePref);
|
|
367
|
-
const onLoadRef =
|
|
365
|
+
const onLoadRef = React26.useRef(onLoad);
|
|
368
366
|
onLoadRef.current = onLoad;
|
|
369
|
-
const onErrorRef =
|
|
367
|
+
const onErrorRef = React26.useRef(onError);
|
|
370
368
|
onErrorRef.current = onError;
|
|
371
369
|
const mapStyle = customStyle || themeStyle;
|
|
372
|
-
const controlOffsets = React25.useMemo(() => {
|
|
373
|
-
const offsets = {
|
|
374
|
-
"top-left": 0,
|
|
375
|
-
"top-right": 0,
|
|
376
|
-
"bottom-left": 0,
|
|
377
|
-
"bottom-right": 0
|
|
378
|
-
};
|
|
379
|
-
if (navigationControl) {
|
|
380
|
-
offsets[navigationControlPosition] += 100;
|
|
381
|
-
}
|
|
382
|
-
if (scaleControl) {
|
|
383
|
-
offsets[scaleControlPosition] += 28;
|
|
384
|
-
}
|
|
385
|
-
if (fullscreenControl) {
|
|
386
|
-
offsets[fullscreenControlPosition] += 38;
|
|
387
|
-
}
|
|
388
|
-
if (geolocateControl) {
|
|
389
|
-
offsets[geolocateControlPosition] += 38;
|
|
390
|
-
}
|
|
391
|
-
if (attributionControl) {
|
|
392
|
-
offsets["bottom-right"] += 32;
|
|
393
|
-
}
|
|
394
|
-
return offsets;
|
|
395
|
-
}, [
|
|
396
|
-
navigationControl,
|
|
397
|
-
navigationControlPosition,
|
|
398
|
-
scaleControl,
|
|
399
|
-
scaleControlPosition,
|
|
400
|
-
fullscreenControl,
|
|
401
|
-
fullscreenControlPosition,
|
|
402
|
-
geolocateControl,
|
|
403
|
-
geolocateControlPosition,
|
|
404
|
-
attributionControl
|
|
405
|
-
]);
|
|
406
|
-
const registerControl = React25.useCallback(
|
|
407
|
-
(id, position, height2) => {
|
|
408
|
-
const registry = customControlRegistryRef.current;
|
|
409
|
-
const positionControls = registry[position] || [];
|
|
410
|
-
const existingIndex = positionControls.findIndex((c) => c.id === id);
|
|
411
|
-
if (existingIndex >= 0) {
|
|
412
|
-
positionControls[existingIndex].height = height2;
|
|
413
|
-
} else {
|
|
414
|
-
positionControls.push({ id, height: height2 });
|
|
415
|
-
forceUpdate();
|
|
416
|
-
}
|
|
417
|
-
registry[position] = positionControls;
|
|
418
|
-
let offset = 0;
|
|
419
|
-
for (const control of positionControls) {
|
|
420
|
-
if (control.id === id) break;
|
|
421
|
-
offset += control.height + 8;
|
|
422
|
-
}
|
|
423
|
-
return offset;
|
|
424
|
-
},
|
|
425
|
-
[]
|
|
426
|
-
);
|
|
427
|
-
const unregisterControl = React25.useCallback((id, position) => {
|
|
428
|
-
const registry = customControlRegistryRef.current;
|
|
429
|
-
const positionControls = registry[position] || [];
|
|
430
|
-
registry[position] = positionControls.filter((c) => c.id !== id);
|
|
431
|
-
forceUpdate();
|
|
432
|
-
}, []);
|
|
433
|
-
const getCustomControlOffset = React25.useCallback((id, position) => {
|
|
434
|
-
const registry = customControlRegistryRef.current;
|
|
435
|
-
const positionControls = registry[position] || [];
|
|
436
|
-
let offset = 0;
|
|
437
|
-
for (const control of positionControls) {
|
|
438
|
-
if (control.id === id) break;
|
|
439
|
-
offset += control.height + 8;
|
|
440
|
-
}
|
|
441
|
-
return offset;
|
|
442
|
-
}, []);
|
|
443
370
|
const accessibleDescription = description || generateMapDescription(title, {
|
|
444
371
|
center,
|
|
445
372
|
zoom
|
|
446
373
|
});
|
|
447
|
-
|
|
374
|
+
React26.useEffect(() => {
|
|
375
|
+
if (!containerRef.current || !positioningCoordinator) return;
|
|
376
|
+
const updateDimensions = () => {
|
|
377
|
+
if (!containerRef.current) return;
|
|
378
|
+
positioningCoordinator.setMapDimensions({
|
|
379
|
+
width: containerRef.current.offsetWidth,
|
|
380
|
+
height: containerRef.current.offsetHeight
|
|
381
|
+
});
|
|
382
|
+
};
|
|
383
|
+
updateDimensions();
|
|
384
|
+
const resizeObserver = new ResizeObserver(updateDimensions);
|
|
385
|
+
resizeObserver.observe(containerRef.current);
|
|
386
|
+
return () => {
|
|
387
|
+
resizeObserver.disconnect();
|
|
388
|
+
};
|
|
389
|
+
}, [positioningCoordinator]);
|
|
390
|
+
React26.useEffect(() => {
|
|
391
|
+
return () => {
|
|
392
|
+
positioningCoordinator.destroy();
|
|
393
|
+
};
|
|
394
|
+
}, [positioningCoordinator]);
|
|
395
|
+
React26.useEffect(() => {
|
|
448
396
|
if (!containerRef.current || mapRef.current) return;
|
|
449
397
|
try {
|
|
450
398
|
const map = new maplibregl.Map({
|
|
@@ -479,12 +427,45 @@ var Map2 = React25.forwardRef(
|
|
|
479
427
|
}),
|
|
480
428
|
navigationControlPosition
|
|
481
429
|
);
|
|
430
|
+
positioningCoordinator.register({
|
|
431
|
+
id: "maplibre-navigation-control",
|
|
432
|
+
type: "navigation",
|
|
433
|
+
isBuiltIn: true,
|
|
434
|
+
dimensions: { width: 29, height: 91 },
|
|
435
|
+
position: {
|
|
436
|
+
primary: navigationControlPosition
|
|
437
|
+
},
|
|
438
|
+
priority: "critical",
|
|
439
|
+
zLayer: "base"
|
|
440
|
+
});
|
|
482
441
|
}
|
|
483
442
|
if (scaleControl) {
|
|
484
443
|
map.addControl(new maplibregl.ScaleControl({ unit: "metric" }), scaleControlPosition);
|
|
444
|
+
positioningCoordinator.register({
|
|
445
|
+
id: "maplibre-scale-control",
|
|
446
|
+
type: "scale",
|
|
447
|
+
isBuiltIn: true,
|
|
448
|
+
dimensions: { width: 100, height: 20 },
|
|
449
|
+
position: {
|
|
450
|
+
primary: scaleControlPosition
|
|
451
|
+
},
|
|
452
|
+
priority: "critical",
|
|
453
|
+
zLayer: "base"
|
|
454
|
+
});
|
|
485
455
|
}
|
|
486
456
|
if (fullscreenControl) {
|
|
487
457
|
map.addControl(new maplibregl.FullscreenControl(), fullscreenControlPosition);
|
|
458
|
+
positioningCoordinator.register({
|
|
459
|
+
id: "maplibre-fullscreen-control",
|
|
460
|
+
type: "custom",
|
|
461
|
+
isBuiltIn: true,
|
|
462
|
+
dimensions: { width: 29, height: 29 },
|
|
463
|
+
position: {
|
|
464
|
+
primary: fullscreenControlPosition
|
|
465
|
+
},
|
|
466
|
+
priority: "critical",
|
|
467
|
+
zLayer: "base"
|
|
468
|
+
});
|
|
488
469
|
}
|
|
489
470
|
if (geolocateControl) {
|
|
490
471
|
map.addControl(
|
|
@@ -494,6 +475,17 @@ var Map2 = React25.forwardRef(
|
|
|
494
475
|
}),
|
|
495
476
|
geolocateControlPosition
|
|
496
477
|
);
|
|
478
|
+
positioningCoordinator.register({
|
|
479
|
+
id: "maplibre-geolocate-control",
|
|
480
|
+
type: "custom",
|
|
481
|
+
isBuiltIn: true,
|
|
482
|
+
dimensions: { width: 29, height: 29 },
|
|
483
|
+
position: {
|
|
484
|
+
primary: geolocateControlPosition
|
|
485
|
+
},
|
|
486
|
+
priority: "critical",
|
|
487
|
+
zLayer: "base"
|
|
488
|
+
});
|
|
497
489
|
}
|
|
498
490
|
map.on("load", () => {
|
|
499
491
|
setMapLoaded(true);
|
|
@@ -524,8 +516,8 @@ var Map2 = React25.forwardRef(
|
|
|
524
516
|
onErrorRef.current?.({ type: "error", message: errorMessage, error: err });
|
|
525
517
|
}
|
|
526
518
|
}, []);
|
|
527
|
-
const styleInitialized =
|
|
528
|
-
|
|
519
|
+
const styleInitialized = React26.useRef(false);
|
|
520
|
+
React26.useEffect(() => {
|
|
529
521
|
if (!mapRef.current || !mapLoaded) return;
|
|
530
522
|
if (!styleInitialized.current) {
|
|
531
523
|
styleInitialized.current = true;
|
|
@@ -534,12 +526,12 @@ var Map2 = React25.forwardRef(
|
|
|
534
526
|
if (activeStyleOverrideRef.current) return;
|
|
535
527
|
mapRef.current.setStyle(mapStyle);
|
|
536
528
|
}, [mapStyle, mapLoaded]);
|
|
537
|
-
|
|
529
|
+
React26.useEffect(() => {
|
|
538
530
|
if (customStyle) {
|
|
539
531
|
activeStyleOverrideRef.current = null;
|
|
540
532
|
}
|
|
541
533
|
}, [customStyle]);
|
|
542
|
-
|
|
534
|
+
React26.useEffect(() => {
|
|
543
535
|
const map = mapRef.current;
|
|
544
536
|
if (!map || !mapLoaded) return;
|
|
545
537
|
const createEventParams = (e) => ({
|
|
@@ -656,12 +648,9 @@ var Map2 = React25.forwardRef(
|
|
|
656
648
|
value: {
|
|
657
649
|
map: mapRef.current,
|
|
658
650
|
loaded: mapLoaded,
|
|
659
|
-
controlOffsets,
|
|
660
|
-
registerControl,
|
|
661
|
-
unregisterControl,
|
|
662
|
-
getCustomControlOffset,
|
|
663
651
|
styleVersion,
|
|
664
|
-
setMapStyle
|
|
652
|
+
setMapStyle,
|
|
653
|
+
positioningCoordinator
|
|
665
654
|
},
|
|
666
655
|
children: [
|
|
667
656
|
/* @__PURE__ */ jsx("div", { ref: containerRef, className: "absolute inset-0" }),
|
|
@@ -694,9 +683,9 @@ var Source = ({
|
|
|
694
683
|
children
|
|
695
684
|
}) => {
|
|
696
685
|
const { map, loaded, styleVersion } = useMap();
|
|
697
|
-
const sourceAdded =
|
|
698
|
-
const initialFitDone =
|
|
699
|
-
const fitBoundsParamsRef =
|
|
686
|
+
const sourceAdded = React26.useRef(false);
|
|
687
|
+
const initialFitDone = React26.useRef(false);
|
|
688
|
+
const fitBoundsParamsRef = React26.useRef({
|
|
700
689
|
shouldFitBounds,
|
|
701
690
|
data,
|
|
702
691
|
fitBoundsPadding,
|
|
@@ -712,7 +701,7 @@ var Source = ({
|
|
|
712
701
|
fitBoundsAnimate,
|
|
713
702
|
type
|
|
714
703
|
};
|
|
715
|
-
const performFitBounds =
|
|
704
|
+
const performFitBounds = React26.useCallback(
|
|
716
705
|
(cancelledRef) => {
|
|
717
706
|
const params = fitBoundsParamsRef.current;
|
|
718
707
|
if (cancelledRef.current || !params.shouldFitBounds || initialFitDone.current) return;
|
|
@@ -756,7 +745,7 @@ var Source = ({
|
|
|
756
745
|
},
|
|
757
746
|
[map]
|
|
758
747
|
);
|
|
759
|
-
|
|
748
|
+
React26.useEffect(() => {
|
|
760
749
|
if (!map || !loaded || sourceAdded.current) return;
|
|
761
750
|
if (map.getSource(id)) {
|
|
762
751
|
sourceAdded.current = true;
|
|
@@ -906,7 +895,7 @@ var Source = ({
|
|
|
906
895
|
styleVersion
|
|
907
896
|
// re-add source after basemap style changes
|
|
908
897
|
]);
|
|
909
|
-
|
|
898
|
+
React26.useEffect(() => {
|
|
910
899
|
if (!map || !loaded || !sourceAdded.current || type !== "geojson") return;
|
|
911
900
|
const source = map.getSource(id);
|
|
912
901
|
if (!source) return;
|
|
@@ -938,7 +927,7 @@ var Source = ({
|
|
|
938
927
|
return /* @__PURE__ */ jsx(Fragment, { children });
|
|
939
928
|
};
|
|
940
929
|
Source.displayName = "Source";
|
|
941
|
-
var Marker =
|
|
930
|
+
var Marker = React26.forwardRef(
|
|
942
931
|
({
|
|
943
932
|
id,
|
|
944
933
|
coordinates,
|
|
@@ -954,27 +943,27 @@ var Marker = React25.forwardRef(
|
|
|
954
943
|
children
|
|
955
944
|
}, ref) => {
|
|
956
945
|
const { map, loaded } = useMap();
|
|
957
|
-
const markerRef =
|
|
958
|
-
const elementRef =
|
|
959
|
-
const originalLngLatRef =
|
|
960
|
-
const clickHandlerRef =
|
|
961
|
-
const [mounted, setMounted] =
|
|
962
|
-
const onClickRef =
|
|
946
|
+
const markerRef = React26.useRef(null);
|
|
947
|
+
const elementRef = React26.useRef(null);
|
|
948
|
+
const originalLngLatRef = React26.useRef();
|
|
949
|
+
const clickHandlerRef = React26.useRef(null);
|
|
950
|
+
const [mounted, setMounted] = React26.useState(false);
|
|
951
|
+
const onClickRef = React26.useRef(onClick);
|
|
963
952
|
onClickRef.current = onClick;
|
|
964
|
-
const onDragRef =
|
|
953
|
+
const onDragRef = React26.useRef(onDrag);
|
|
965
954
|
onDragRef.current = onDrag;
|
|
966
|
-
const onDragEndRef =
|
|
955
|
+
const onDragEndRef = React26.useRef(onDragEnd);
|
|
967
956
|
onDragEndRef.current = onDragEnd;
|
|
968
|
-
|
|
957
|
+
React26.useEffect(() => {
|
|
969
958
|
setMounted(true);
|
|
970
959
|
return () => setMounted(false);
|
|
971
960
|
}, []);
|
|
972
|
-
|
|
961
|
+
React26.useEffect(() => {
|
|
973
962
|
if (children && !elementRef.current) {
|
|
974
963
|
elementRef.current = document.createElement("div");
|
|
975
964
|
}
|
|
976
965
|
}, [children]);
|
|
977
|
-
|
|
966
|
+
React26.useEffect(() => {
|
|
978
967
|
if (!map || !loaded || !mounted) return;
|
|
979
968
|
if (markerRef.current) return;
|
|
980
969
|
const markerOptions = {
|
|
@@ -1058,17 +1047,17 @@ var Marker = React25.forwardRef(
|
|
|
1058
1047
|
}
|
|
1059
1048
|
};
|
|
1060
1049
|
}, [map, loaded, mounted]);
|
|
1061
|
-
|
|
1050
|
+
React26.useEffect(() => {
|
|
1062
1051
|
if (markerRef.current) {
|
|
1063
1052
|
markerRef.current.setLngLat(coordinates);
|
|
1064
1053
|
}
|
|
1065
1054
|
}, [coordinates]);
|
|
1066
|
-
|
|
1055
|
+
React26.useEffect(() => {
|
|
1067
1056
|
if (markerRef.current) {
|
|
1068
1057
|
markerRef.current.setDraggable(draggable);
|
|
1069
1058
|
}
|
|
1070
1059
|
}, [draggable]);
|
|
1071
|
-
|
|
1060
|
+
React26.useEffect(() => {
|
|
1072
1061
|
if (markerRef.current && rotation !== void 0) {
|
|
1073
1062
|
markerRef.current.setRotation(rotation);
|
|
1074
1063
|
}
|
|
@@ -1114,7 +1103,7 @@ function panToFitPopup(map, popup, padding) {
|
|
|
1114
1103
|
});
|
|
1115
1104
|
}
|
|
1116
1105
|
}
|
|
1117
|
-
var Popup =
|
|
1106
|
+
var Popup = React26.forwardRef(
|
|
1118
1107
|
({
|
|
1119
1108
|
coordinates,
|
|
1120
1109
|
closeButton = true,
|
|
@@ -1132,25 +1121,25 @@ var Popup = React25.forwardRef(
|
|
|
1132
1121
|
children
|
|
1133
1122
|
}, ref) => {
|
|
1134
1123
|
const { map, loaded } = useMap();
|
|
1135
|
-
const popupRef =
|
|
1136
|
-
const onOpenRef =
|
|
1124
|
+
const popupRef = React26.useRef(null);
|
|
1125
|
+
const onOpenRef = React26.useRef(onOpen);
|
|
1137
1126
|
onOpenRef.current = onOpen;
|
|
1138
|
-
const onCloseRef =
|
|
1127
|
+
const onCloseRef = React26.useRef(onClose);
|
|
1139
1128
|
onCloseRef.current = onClose;
|
|
1140
|
-
const coordinatesRef =
|
|
1129
|
+
const coordinatesRef = React26.useRef(coordinates);
|
|
1141
1130
|
coordinatesRef.current = coordinates;
|
|
1142
|
-
const containerRef =
|
|
1131
|
+
const containerRef = React26.useRef(null);
|
|
1143
1132
|
if (!containerRef.current && typeof document !== "undefined") {
|
|
1144
1133
|
containerRef.current = document.createElement("div");
|
|
1145
1134
|
containerRef.current.className = "maplibregl-popup-content-wrapper";
|
|
1146
1135
|
}
|
|
1147
|
-
const [contentReady, setContentReady] =
|
|
1148
|
-
const contentCallbackRef =
|
|
1136
|
+
const [contentReady, setContentReady] = React26.useState(false);
|
|
1137
|
+
const contentCallbackRef = React26.useCallback((node) => {
|
|
1149
1138
|
if (node && containerRef.current) {
|
|
1150
1139
|
setContentReady(true);
|
|
1151
1140
|
}
|
|
1152
1141
|
}, []);
|
|
1153
|
-
|
|
1142
|
+
React26.useEffect(() => {
|
|
1154
1143
|
if (!map || !loaded || !containerRef.current) return;
|
|
1155
1144
|
const popup = new maplibregl.Popup({
|
|
1156
1145
|
closeButton,
|
|
@@ -1190,7 +1179,7 @@ var Popup = React25.forwardRef(
|
|
|
1190
1179
|
maxWidth,
|
|
1191
1180
|
focusAfterOpen
|
|
1192
1181
|
]);
|
|
1193
|
-
|
|
1182
|
+
React26.useEffect(() => {
|
|
1194
1183
|
if (!popupRef.current || !ref) return;
|
|
1195
1184
|
if (typeof ref === "function") {
|
|
1196
1185
|
ref(popupRef.current);
|
|
@@ -1198,12 +1187,12 @@ var Popup = React25.forwardRef(
|
|
|
1198
1187
|
ref.current = popupRef.current;
|
|
1199
1188
|
}
|
|
1200
1189
|
}, [ref]);
|
|
1201
|
-
|
|
1190
|
+
React26.useEffect(() => {
|
|
1202
1191
|
if (popupRef.current) {
|
|
1203
1192
|
popupRef.current.setLngLat(coordinates);
|
|
1204
1193
|
}
|
|
1205
1194
|
}, [coordinates]);
|
|
1206
|
-
|
|
1195
|
+
React26.useEffect(() => {
|
|
1207
1196
|
if (!map || !popupRef.current || !contentReady) return;
|
|
1208
1197
|
let rafHandle;
|
|
1209
1198
|
if (open) {
|
|
@@ -1232,7 +1221,7 @@ var Popup = React25.forwardRef(
|
|
|
1232
1221
|
}
|
|
1233
1222
|
);
|
|
1234
1223
|
Popup.displayName = "Popup";
|
|
1235
|
-
var PopupCard =
|
|
1224
|
+
var PopupCard = React26.forwardRef(
|
|
1236
1225
|
({ className, children, ...props }, ref) => {
|
|
1237
1226
|
return /* @__PURE__ */ jsx("div", { ref, className: cn("bg-popover text-popover-foreground", className), ...props, children });
|
|
1238
1227
|
}
|
|
@@ -1252,7 +1241,7 @@ var badgeVariants = cva("text-xs px-1.5 py-0.5 rounded font-medium flex-shrink-0
|
|
|
1252
1241
|
badgeVariant: "secondary"
|
|
1253
1242
|
}
|
|
1254
1243
|
});
|
|
1255
|
-
var PopupHeader =
|
|
1244
|
+
var PopupHeader = React26.forwardRef(
|
|
1256
1245
|
({ className, title, badge, badgeVariant, ...props }, ref) => {
|
|
1257
1246
|
return /* @__PURE__ */ jsxs(
|
|
1258
1247
|
"div",
|
|
@@ -1272,13 +1261,13 @@ var PopupHeader = React25.forwardRef(
|
|
|
1272
1261
|
}
|
|
1273
1262
|
);
|
|
1274
1263
|
PopupHeader.displayName = "PopupHeader";
|
|
1275
|
-
var PopupContent =
|
|
1264
|
+
var PopupContent = React26.forwardRef(
|
|
1276
1265
|
({ className, children, ...props }, ref) => {
|
|
1277
1266
|
return /* @__PURE__ */ jsx("div", { ref, className: cn("px-4 py-3 text-sm", className), ...props, children });
|
|
1278
1267
|
}
|
|
1279
1268
|
);
|
|
1280
1269
|
PopupContent.displayName = "PopupContent";
|
|
1281
|
-
var PopupFooter =
|
|
1270
|
+
var PopupFooter = React26.forwardRef(
|
|
1282
1271
|
({ className, children, ...props }, ref) => {
|
|
1283
1272
|
return /* @__PURE__ */ jsx(
|
|
1284
1273
|
"div",
|
|
@@ -1313,14 +1302,14 @@ function useLayer({
|
|
|
1313
1302
|
hoverThrottleMs = 0
|
|
1314
1303
|
}) {
|
|
1315
1304
|
const { map, loaded, styleVersion } = useMap();
|
|
1316
|
-
const [layerAdded, setLayerAdded] =
|
|
1317
|
-
const hoveredFeatureId =
|
|
1318
|
-
const lastHoverCallTime =
|
|
1319
|
-
const lastMousePosition =
|
|
1320
|
-
|
|
1305
|
+
const [layerAdded, setLayerAdded] = React26.useState(false);
|
|
1306
|
+
const hoveredFeatureId = React26.useRef(null);
|
|
1307
|
+
const lastHoverCallTime = React26.useRef(0);
|
|
1308
|
+
const lastMousePosition = React26.useRef(null);
|
|
1309
|
+
React26.useEffect(() => {
|
|
1321
1310
|
hoveredFeatureId.current = null;
|
|
1322
1311
|
}, [styleVersion]);
|
|
1323
|
-
|
|
1312
|
+
React26.useEffect(() => {
|
|
1324
1313
|
if (!map || !loaded) return;
|
|
1325
1314
|
if (!map.getSource(source)) {
|
|
1326
1315
|
let timeoutId = null;
|
|
@@ -1391,24 +1380,24 @@ function useLayer({
|
|
|
1391
1380
|
}
|
|
1392
1381
|
};
|
|
1393
1382
|
}, [map, loaded, id, source, sourceLayer, type, beforeId, styleVersion]);
|
|
1394
|
-
|
|
1383
|
+
React26.useEffect(() => {
|
|
1395
1384
|
if (!map || !layerAdded) return;
|
|
1396
1385
|
if (!map.getLayer(id)) return;
|
|
1397
1386
|
map.setLayoutProperty(id, "visibility", visible ? "visible" : "none");
|
|
1398
1387
|
}, [map, id, visible, layerAdded]);
|
|
1399
|
-
|
|
1388
|
+
React26.useEffect(() => {
|
|
1400
1389
|
if (!map || !layerAdded) return;
|
|
1401
1390
|
if (!map.getLayer(id)) return;
|
|
1402
1391
|
Object.entries(paint).forEach(([key, value]) => {
|
|
1403
1392
|
map.setPaintProperty(id, key, value);
|
|
1404
1393
|
});
|
|
1405
1394
|
}, [map, id, paint, layerAdded]);
|
|
1406
|
-
|
|
1395
|
+
React26.useEffect(() => {
|
|
1407
1396
|
if (!map || !layerAdded || !filter) return;
|
|
1408
1397
|
if (!map.getLayer(id)) return;
|
|
1409
1398
|
map.setFilter(id, filter);
|
|
1410
1399
|
}, [map, id, filter, layerAdded]);
|
|
1411
|
-
|
|
1400
|
+
React26.useEffect(() => {
|
|
1412
1401
|
if (!map || !layerAdded) return;
|
|
1413
1402
|
const createFeatureParams = (e) => {
|
|
1414
1403
|
const feature = e.features?.[0];
|
|
@@ -1544,7 +1533,7 @@ var FillLayer = ({
|
|
|
1544
1533
|
fillTranslate,
|
|
1545
1534
|
fillAntialias
|
|
1546
1535
|
}) => {
|
|
1547
|
-
const paint =
|
|
1536
|
+
const paint = React26.useMemo(() => {
|
|
1548
1537
|
const p = {};
|
|
1549
1538
|
if (fillColor !== void 0) p["fill-color"] = fillColor;
|
|
1550
1539
|
if (fillOpacity !== void 0) p["fill-opacity"] = fillOpacity;
|
|
@@ -1565,7 +1554,7 @@ var FillLayer = ({
|
|
|
1565
1554
|
fillAntialias,
|
|
1566
1555
|
opacity
|
|
1567
1556
|
]);
|
|
1568
|
-
const layout =
|
|
1557
|
+
const layout = React26.useMemo(() => ({}), []);
|
|
1569
1558
|
useLayer({
|
|
1570
1559
|
id,
|
|
1571
1560
|
source,
|
|
@@ -1609,7 +1598,7 @@ var LineLayer = ({
|
|
|
1609
1598
|
lineOffset,
|
|
1610
1599
|
lineGradient
|
|
1611
1600
|
}) => {
|
|
1612
|
-
const paint =
|
|
1601
|
+
const paint = React26.useMemo(() => {
|
|
1613
1602
|
const p = {};
|
|
1614
1603
|
if (lineColor !== void 0) p["line-color"] = lineColor;
|
|
1615
1604
|
if (lineWidth !== void 0) p["line-width"] = lineWidth;
|
|
@@ -1634,7 +1623,7 @@ var LineLayer = ({
|
|
|
1634
1623
|
lineGradient,
|
|
1635
1624
|
opacity
|
|
1636
1625
|
]);
|
|
1637
|
-
const layout =
|
|
1626
|
+
const layout = React26.useMemo(() => {
|
|
1638
1627
|
const l = {};
|
|
1639
1628
|
if (lineCap !== void 0) l["line-cap"] = lineCap;
|
|
1640
1629
|
if (lineJoin !== void 0) l["line-join"] = lineJoin;
|
|
@@ -1683,7 +1672,7 @@ var CircleLayer = ({
|
|
|
1683
1672
|
circlePitchScale,
|
|
1684
1673
|
circleTranslate
|
|
1685
1674
|
}) => {
|
|
1686
|
-
const paint =
|
|
1675
|
+
const paint = React26.useMemo(() => {
|
|
1687
1676
|
const p = {};
|
|
1688
1677
|
if (circleRadius !== void 0) p["circle-radius"] = circleRadius;
|
|
1689
1678
|
if (circleColor !== void 0) p["circle-color"] = circleColor;
|
|
@@ -1712,7 +1701,7 @@ var CircleLayer = ({
|
|
|
1712
1701
|
circleTranslate,
|
|
1713
1702
|
opacity
|
|
1714
1703
|
]);
|
|
1715
|
-
const layout =
|
|
1704
|
+
const layout = React26.useMemo(() => ({}), []);
|
|
1716
1705
|
useLayer({
|
|
1717
1706
|
id,
|
|
1718
1707
|
source,
|
|
@@ -1772,7 +1761,7 @@ var SymbolLayer = ({
|
|
|
1772
1761
|
symbolSpacing,
|
|
1773
1762
|
symbolSortKey
|
|
1774
1763
|
}) => {
|
|
1775
|
-
const paint =
|
|
1764
|
+
const paint = React26.useMemo(() => {
|
|
1776
1765
|
const p = {};
|
|
1777
1766
|
if (iconOpacity !== void 0) p["icon-opacity"] = iconOpacity;
|
|
1778
1767
|
if (iconColor !== void 0) p["icon-color"] = iconColor;
|
|
@@ -1793,7 +1782,7 @@ var SymbolLayer = ({
|
|
|
1793
1782
|
textHaloColor,
|
|
1794
1783
|
textHaloWidth
|
|
1795
1784
|
]);
|
|
1796
|
-
const layout =
|
|
1785
|
+
const layout = React26.useMemo(() => {
|
|
1797
1786
|
const l = {};
|
|
1798
1787
|
if (iconImage !== void 0) l["icon-image"] = iconImage;
|
|
1799
1788
|
if (iconSize !== void 0) l["icon-size"] = iconSize;
|
|
@@ -1874,7 +1863,7 @@ var FillExtrusionLayer = ({
|
|
|
1874
1863
|
fillExtrusionTranslate,
|
|
1875
1864
|
fillExtrusionVerticalGradient
|
|
1876
1865
|
}) => {
|
|
1877
|
-
const paint =
|
|
1866
|
+
const paint = React26.useMemo(() => {
|
|
1878
1867
|
const p = {};
|
|
1879
1868
|
if (fillExtrusionHeight !== void 0) p["fill-extrusion-height"] = fillExtrusionHeight;
|
|
1880
1869
|
if (fillExtrusionBase !== void 0) p["fill-extrusion-base"] = fillExtrusionBase;
|
|
@@ -1900,7 +1889,7 @@ var FillExtrusionLayer = ({
|
|
|
1900
1889
|
fillExtrusionVerticalGradient,
|
|
1901
1890
|
opacity
|
|
1902
1891
|
]);
|
|
1903
|
-
const layout =
|
|
1892
|
+
const layout = React26.useMemo(() => ({}), []);
|
|
1904
1893
|
useLayer({
|
|
1905
1894
|
id,
|
|
1906
1895
|
source,
|
|
@@ -1939,7 +1928,7 @@ var HeatmapLayer = ({
|
|
|
1939
1928
|
heatmapRadius,
|
|
1940
1929
|
heatmapOpacity
|
|
1941
1930
|
}) => {
|
|
1942
|
-
const paint =
|
|
1931
|
+
const paint = React26.useMemo(() => {
|
|
1943
1932
|
const p = {};
|
|
1944
1933
|
if (heatmapIntensity !== void 0) p["heatmap-intensity"] = heatmapIntensity;
|
|
1945
1934
|
if (heatmapWeight !== void 0) p["heatmap-weight"] = heatmapWeight;
|
|
@@ -1951,7 +1940,7 @@ var HeatmapLayer = ({
|
|
|
1951
1940
|
}
|
|
1952
1941
|
return p;
|
|
1953
1942
|
}, [heatmapIntensity, heatmapWeight, heatmapColor, heatmapRadius, heatmapOpacity, opacity]);
|
|
1954
|
-
const layout =
|
|
1943
|
+
const layout = React26.useMemo(() => ({}), []);
|
|
1955
1944
|
useLayer({
|
|
1956
1945
|
id,
|
|
1957
1946
|
source,
|
|
@@ -1971,6 +1960,127 @@ var HeatmapLayer = ({
|
|
|
1971
1960
|
return null;
|
|
1972
1961
|
};
|
|
1973
1962
|
HeatmapLayer.displayName = "HeatmapLayer";
|
|
1963
|
+
function useControlPosition(ref, options) {
|
|
1964
|
+
const {
|
|
1965
|
+
id,
|
|
1966
|
+
type,
|
|
1967
|
+
position,
|
|
1968
|
+
fallbacks,
|
|
1969
|
+
priority = "normal",
|
|
1970
|
+
zLayer = "interactive",
|
|
1971
|
+
hasExpandedState = false,
|
|
1972
|
+
isBuiltIn = false
|
|
1973
|
+
} = options;
|
|
1974
|
+
const { positioningCoordinator } = useMap();
|
|
1975
|
+
const [offset, setOffset] = React26.useState(null);
|
|
1976
|
+
React26.useEffect(() => {
|
|
1977
|
+
if (!ref.current || !positioningCoordinator) return;
|
|
1978
|
+
const element = ref.current;
|
|
1979
|
+
const initialOffset = positioningCoordinator.register({
|
|
1980
|
+
id,
|
|
1981
|
+
type,
|
|
1982
|
+
isBuiltIn,
|
|
1983
|
+
dimensions: {
|
|
1984
|
+
width: element.offsetWidth || 200,
|
|
1985
|
+
height: element.offsetHeight || 100
|
|
1986
|
+
},
|
|
1987
|
+
position: {
|
|
1988
|
+
primary: position,
|
|
1989
|
+
fallbacks
|
|
1990
|
+
},
|
|
1991
|
+
priority,
|
|
1992
|
+
zLayer,
|
|
1993
|
+
hasExpandedState,
|
|
1994
|
+
isExpanded: false
|
|
1995
|
+
});
|
|
1996
|
+
setOffset(initialOffset);
|
|
1997
|
+
const unsubscribe = positioningCoordinator.subscribe((event) => {
|
|
1998
|
+
const newOffset = event.offsets.get(id);
|
|
1999
|
+
if (newOffset) {
|
|
2000
|
+
setOffset(newOffset);
|
|
2001
|
+
}
|
|
2002
|
+
});
|
|
2003
|
+
const resizeObserver = new ResizeObserver(() => {
|
|
2004
|
+
if (!element) return;
|
|
2005
|
+
positioningCoordinator.update(id, {
|
|
2006
|
+
dimensions: {
|
|
2007
|
+
width: element.offsetWidth,
|
|
2008
|
+
height: element.offsetHeight
|
|
2009
|
+
}
|
|
2010
|
+
});
|
|
2011
|
+
});
|
|
2012
|
+
resizeObserver.observe(element);
|
|
2013
|
+
return () => {
|
|
2014
|
+
resizeObserver.disconnect();
|
|
2015
|
+
unsubscribe();
|
|
2016
|
+
positioningCoordinator.unregister(id);
|
|
2017
|
+
};
|
|
2018
|
+
}, [
|
|
2019
|
+
id,
|
|
2020
|
+
type,
|
|
2021
|
+
position,
|
|
2022
|
+
fallbacks,
|
|
2023
|
+
priority,
|
|
2024
|
+
zLayer,
|
|
2025
|
+
hasExpandedState,
|
|
2026
|
+
isBuiltIn,
|
|
2027
|
+
positioningCoordinator,
|
|
2028
|
+
ref
|
|
2029
|
+
]);
|
|
2030
|
+
React26.useEffect(() => {
|
|
2031
|
+
if (!positioningCoordinator) return;
|
|
2032
|
+
positioningCoordinator.update(id, {
|
|
2033
|
+
position: {
|
|
2034
|
+
primary: position,
|
|
2035
|
+
fallbacks
|
|
2036
|
+
},
|
|
2037
|
+
priority,
|
|
2038
|
+
zLayer
|
|
2039
|
+
});
|
|
2040
|
+
}, [id, position, fallbacks, priority, zLayer, positioningCoordinator]);
|
|
2041
|
+
const setExpanded = React26.useCallback(
|
|
2042
|
+
(isExpanded) => {
|
|
2043
|
+
if (positioningCoordinator) {
|
|
2044
|
+
positioningCoordinator.setExpanded(id, isExpanded);
|
|
2045
|
+
}
|
|
2046
|
+
},
|
|
2047
|
+
[id, positioningCoordinator]
|
|
2048
|
+
);
|
|
2049
|
+
const style = React26.useMemo(() => {
|
|
2050
|
+
if (!offset) {
|
|
2051
|
+
return {
|
|
2052
|
+
position: "absolute",
|
|
2053
|
+
visibility: "hidden"
|
|
2054
|
+
};
|
|
2055
|
+
}
|
|
2056
|
+
const resolvedPosition = offset.position;
|
|
2057
|
+
const isLeftPosition = resolvedPosition.includes("left") || resolvedPosition.includes("center");
|
|
2058
|
+
const isCenterHorizontal = resolvedPosition.includes("center");
|
|
2059
|
+
const baseStyle = {
|
|
2060
|
+
position: "absolute",
|
|
2061
|
+
zIndex: offset.zIndex
|
|
2062
|
+
};
|
|
2063
|
+
if (isCenterHorizontal) {
|
|
2064
|
+
baseStyle.left = offset.x;
|
|
2065
|
+
} else if (isLeftPosition) {
|
|
2066
|
+
baseStyle.left = offset.x;
|
|
2067
|
+
} else {
|
|
2068
|
+
baseStyle.right = offset.x;
|
|
2069
|
+
}
|
|
2070
|
+
if (resolvedPosition.startsWith("bottom")) {
|
|
2071
|
+
baseStyle.bottom = offset.y;
|
|
2072
|
+
} else {
|
|
2073
|
+
baseStyle.top = offset.y;
|
|
2074
|
+
}
|
|
2075
|
+
return baseStyle;
|
|
2076
|
+
}, [offset]);
|
|
2077
|
+
return {
|
|
2078
|
+
offset,
|
|
2079
|
+
setExpanded,
|
|
2080
|
+
style,
|
|
2081
|
+
visible: offset?.visible ?? false
|
|
2082
|
+
};
|
|
2083
|
+
}
|
|
1974
2084
|
var legendIdCounter = 0;
|
|
1975
2085
|
var Legend = ({
|
|
1976
2086
|
title,
|
|
@@ -1985,30 +2095,17 @@ var Legend = ({
|
|
|
1985
2095
|
class: className,
|
|
1986
2096
|
onItemClick
|
|
1987
2097
|
}) => {
|
|
1988
|
-
const
|
|
1989
|
-
const
|
|
1990
|
-
const
|
|
1991
|
-
const
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
setCustomControlOffset(offset);
|
|
2000
|
-
};
|
|
2001
|
-
updatePosition();
|
|
2002
|
-
const observer = new ResizeObserver(updatePosition);
|
|
2003
|
-
observer.observe(legendRef.current);
|
|
2004
|
-
return () => {
|
|
2005
|
-
observer.disconnect();
|
|
2006
|
-
unregisterControl?.(legendIdRef.current, position);
|
|
2007
|
-
};
|
|
2008
|
-
}, [position, registerControl, unregisterControl]);
|
|
2009
|
-
const verticalOffsetStyle = React25.useMemo(() => {
|
|
2010
|
-
return computeVerticalOffsetStyle(position, customControlOffset);
|
|
2011
|
-
}, [customControlOffset, position]);
|
|
2098
|
+
const [isCollapsed, setIsCollapsed] = React26.useState(initialCollapsed);
|
|
2099
|
+
const legendRef = React26.useRef(null);
|
|
2100
|
+
const legendIdRef = React26.useRef(`legend-${++legendIdCounter}`);
|
|
2101
|
+
const { style, visible } = useControlPosition(legendRef, {
|
|
2102
|
+
id: legendIdRef.current,
|
|
2103
|
+
type: "legend",
|
|
2104
|
+
position,
|
|
2105
|
+
priority: "normal",
|
|
2106
|
+
zLayer: "interactive",
|
|
2107
|
+
hasExpandedState: collapsible
|
|
2108
|
+
});
|
|
2012
2109
|
const handleItemClick = (item, index) => {
|
|
2013
2110
|
if (onItemClick) {
|
|
2014
2111
|
onItemClick(item, index);
|
|
@@ -2019,26 +2116,22 @@ var Legend = ({
|
|
|
2019
2116
|
setIsCollapsed(!isCollapsed);
|
|
2020
2117
|
}
|
|
2021
2118
|
};
|
|
2022
|
-
const gradientStyle =
|
|
2119
|
+
const gradientStyle = React26.useMemo(() => {
|
|
2023
2120
|
if (type !== "gradient" || gradient.length === 0) return "";
|
|
2024
2121
|
const stops = gradient.map((stop) => `${stop.color} ${stop.position * 100}%`).join(", ");
|
|
2025
2122
|
return `linear-gradient(to right, ${stops})`;
|
|
2026
2123
|
}, [type, gradient]);
|
|
2027
|
-
const hasControlsAtPosition = (controlOffsets?.[position] ?? 0) > 0;
|
|
2028
|
-
const computedPositionClasses = React25.useMemo(() => {
|
|
2029
|
-
return computePositionClasses(position, hasControlsAtPosition);
|
|
2030
|
-
}, [position, hasControlsAtPosition]);
|
|
2031
2124
|
return /* @__PURE__ */ jsxs(
|
|
2032
2125
|
"div",
|
|
2033
2126
|
{
|
|
2034
2127
|
ref: legendRef,
|
|
2035
2128
|
className: cn(
|
|
2036
|
-
"absolute
|
|
2129
|
+
"absolute bg-card rounded-lg shadow-lg border border-black dark:border-gray-400",
|
|
2037
2130
|
"text-sm min-w-[140px] max-w-[280px]",
|
|
2038
|
-
|
|
2131
|
+
!visible && "invisible",
|
|
2039
2132
|
className
|
|
2040
2133
|
),
|
|
2041
|
-
style
|
|
2134
|
+
style,
|
|
2042
2135
|
children: [
|
|
2043
2136
|
(title || collapsible) && /* @__PURE__ */ jsxs(
|
|
2044
2137
|
"button",
|
|
@@ -2046,7 +2139,8 @@ var Legend = ({
|
|
|
2046
2139
|
type: "button",
|
|
2047
2140
|
className: cn(
|
|
2048
2141
|
"w-full flex items-center justify-between px-3 py-2 font-medium text-card-foreground",
|
|
2049
|
-
collapsible && "cursor-pointer hover:bg-muted
|
|
2142
|
+
collapsible && "cursor-pointer hover:bg-muted",
|
|
2143
|
+
collapsible && (isCollapsed ? "rounded-lg" : "rounded-t-lg"),
|
|
2050
2144
|
!collapsible && "cursor-default"
|
|
2051
2145
|
),
|
|
2052
2146
|
onClick: toggleCollapse,
|
|
@@ -2123,45 +2217,31 @@ var LegendGroup = ({
|
|
|
2123
2217
|
allowCollapseAll = false,
|
|
2124
2218
|
class: className
|
|
2125
2219
|
}) => {
|
|
2126
|
-
const
|
|
2127
|
-
const
|
|
2128
|
-
const groupIdRef = React25.useRef(`legend-group-${++legendGroupIdCounter}`);
|
|
2129
|
-
const [customControlOffset, setCustomControlOffset] = React25.useState(0);
|
|
2220
|
+
const containerRef = React26.useRef(null);
|
|
2221
|
+
const groupIdRef = React26.useRef(`legend-group-${++legendGroupIdCounter}`);
|
|
2130
2222
|
const getInitialExpanded = () => {
|
|
2131
2223
|
if (controlledExpanded !== void 0) return controlledExpanded;
|
|
2132
2224
|
if (defaultExpanded) return defaultExpanded;
|
|
2133
2225
|
return legends[0]?.id || null;
|
|
2134
2226
|
};
|
|
2135
|
-
const [internalExpanded, setInternalExpanded] =
|
|
2227
|
+
const [internalExpanded, setInternalExpanded] = React26.useState(getInitialExpanded);
|
|
2136
2228
|
const expandedId = controlledExpanded !== void 0 ? controlledExpanded : internalExpanded;
|
|
2229
|
+
const { style, visible, setExpanded } = useControlPosition(containerRef, {
|
|
2230
|
+
id: groupIdRef.current,
|
|
2231
|
+
type: "legend-group",
|
|
2232
|
+
position,
|
|
2233
|
+
priority: "normal",
|
|
2234
|
+
zLayer: "interactive",
|
|
2235
|
+
hasExpandedState: true
|
|
2236
|
+
});
|
|
2137
2237
|
const handleToggle = (id) => {
|
|
2138
2238
|
const newExpanded = expandedId === id ? allowCollapseAll ? null : id : id;
|
|
2139
2239
|
if (controlledExpanded === void 0) {
|
|
2140
2240
|
setInternalExpanded(newExpanded);
|
|
2141
2241
|
}
|
|
2242
|
+
setExpanded(newExpanded !== null);
|
|
2142
2243
|
onExpandedChange?.(newExpanded);
|
|
2143
2244
|
};
|
|
2144
|
-
React25.useEffect(() => {
|
|
2145
|
-
if (!containerRef.current || !registerControl) return;
|
|
2146
|
-
const timeoutId = setTimeout(() => {
|
|
2147
|
-
if (containerRef.current) {
|
|
2148
|
-
const height = containerRef.current.offsetHeight;
|
|
2149
|
-
const offset = registerControl(groupIdRef.current, position, height);
|
|
2150
|
-
setCustomControlOffset(offset);
|
|
2151
|
-
}
|
|
2152
|
-
}, 50);
|
|
2153
|
-
return () => {
|
|
2154
|
-
clearTimeout(timeoutId);
|
|
2155
|
-
unregisterControl?.(groupIdRef.current, position);
|
|
2156
|
-
};
|
|
2157
|
-
}, [position, expandedId, registerControl, unregisterControl]);
|
|
2158
|
-
const verticalOffsetStyle = React25.useMemo(() => {
|
|
2159
|
-
return computeVerticalOffsetStyle(position, customControlOffset);
|
|
2160
|
-
}, [customControlOffset, position]);
|
|
2161
|
-
const hasControlsAtPosition = (controlOffsets?.[position] ?? 0) > 0;
|
|
2162
|
-
const computedPositionClasses = React25.useMemo(() => {
|
|
2163
|
-
return computePositionClasses(position, hasControlsAtPosition);
|
|
2164
|
-
}, [position, hasControlsAtPosition]);
|
|
2165
2245
|
const getGradientStyle = (legend) => {
|
|
2166
2246
|
if (legend.type !== "gradient" || !legend.gradient?.length) return "";
|
|
2167
2247
|
const stops = legend.gradient.map((stop) => `${stop.color} ${stop.position * 100}%`).join(", ");
|
|
@@ -2175,12 +2255,12 @@ var LegendGroup = ({
|
|
|
2175
2255
|
{
|
|
2176
2256
|
ref: containerRef,
|
|
2177
2257
|
className: cn(
|
|
2178
|
-
"absolute
|
|
2258
|
+
"absolute bg-card rounded-lg shadow-lg border border-black dark:border-gray-400",
|
|
2179
2259
|
"text-sm min-w-[160px] max-w-[280px]",
|
|
2180
|
-
|
|
2260
|
+
!visible && "invisible",
|
|
2181
2261
|
className
|
|
2182
2262
|
),
|
|
2183
|
-
style
|
|
2263
|
+
style,
|
|
2184
2264
|
children: legends.map((legend, legendIndex) => {
|
|
2185
2265
|
const isExpanded = expandedId === legend.id;
|
|
2186
2266
|
const isFirst = legendIndex === 0;
|
|
@@ -2281,6 +2361,7 @@ var LegendGroup = ({
|
|
|
2281
2361
|
};
|
|
2282
2362
|
LegendGroup.displayName = "LegendGroup";
|
|
2283
2363
|
var coordDisplayIdCounter = 0;
|
|
2364
|
+
var NAV_CONTROL_WIDTH = 29;
|
|
2284
2365
|
var CoordinateDisplay = ({
|
|
2285
2366
|
position = "bottom-right",
|
|
2286
2367
|
format = "decimal",
|
|
@@ -2289,33 +2370,40 @@ var CoordinateDisplay = ({
|
|
|
2289
2370
|
showBearing = false,
|
|
2290
2371
|
class: className
|
|
2291
2372
|
}) => {
|
|
2292
|
-
const { map, loaded
|
|
2293
|
-
const [cursorLngLat, setCursorLngLat] =
|
|
2294
|
-
const [currentZoom, setCurrentZoom] =
|
|
2295
|
-
const [currentBearing, setCurrentBearing] =
|
|
2296
|
-
const
|
|
2297
|
-
const
|
|
2298
|
-
const
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2373
|
+
const { map, loaded } = useMap();
|
|
2374
|
+
const [cursorLngLat, setCursorLngLat] = React26.useState(null);
|
|
2375
|
+
const [currentZoom, setCurrentZoom] = React26.useState(0);
|
|
2376
|
+
const [currentBearing, setCurrentBearing] = React26.useState(0);
|
|
2377
|
+
const controlRef = React26.useRef(null);
|
|
2378
|
+
const controlIdRef = React26.useRef(`coord-display-${++coordDisplayIdCounter}`);
|
|
2379
|
+
const { style, visible } = useControlPosition(controlRef, {
|
|
2380
|
+
id: controlIdRef.current,
|
|
2381
|
+
type: "coordinate-display",
|
|
2382
|
+
position,
|
|
2383
|
+
priority: "critical",
|
|
2384
|
+
zLayer: "base"
|
|
2385
|
+
});
|
|
2386
|
+
const adjustedStyle = React26.useMemo(() => {
|
|
2387
|
+
if (!style) return style;
|
|
2388
|
+
if (position === "top-right") {
|
|
2389
|
+
const rightOffset = NAV_CONTROL_WIDTH + STACK_GAP + EDGE_MARGIN;
|
|
2390
|
+
return {
|
|
2391
|
+
...style,
|
|
2392
|
+
top: EDGE_MARGIN,
|
|
2393
|
+
right: rightOffset
|
|
2394
|
+
};
|
|
2395
|
+
}
|
|
2396
|
+
if (position === "bottom-right") {
|
|
2397
|
+
const ATTRIBUTION_HEIGHT = 32;
|
|
2398
|
+
const bottomOffset = EDGE_MARGIN + ATTRIBUTION_HEIGHT;
|
|
2399
|
+
return {
|
|
2400
|
+
...style,
|
|
2401
|
+
bottom: bottomOffset
|
|
2402
|
+
};
|
|
2403
|
+
}
|
|
2404
|
+
return style;
|
|
2405
|
+
}, [position, style]);
|
|
2406
|
+
const formatCoord = React26.useCallback(
|
|
2319
2407
|
(lngLat) => {
|
|
2320
2408
|
return formatCoordinates(lngLat, precision, format);
|
|
2321
2409
|
},
|
|
@@ -2328,11 +2416,7 @@ var CoordinateDisplay = ({
|
|
|
2328
2416
|
const normalized = (bearing % 360 + 360) % 360;
|
|
2329
2417
|
return `${normalized.toFixed(0)}\xB0`;
|
|
2330
2418
|
};
|
|
2331
|
-
|
|
2332
|
-
const computedPositionClasses = React25.useMemo(() => {
|
|
2333
|
-
return computePositionClasses(position, hasControlsAtPosition);
|
|
2334
|
-
}, [position, hasControlsAtPosition]);
|
|
2335
|
-
React25.useEffect(() => {
|
|
2419
|
+
React26.useEffect(() => {
|
|
2336
2420
|
if (!map || !loaded) return;
|
|
2337
2421
|
setCurrentZoom(map.getZoom());
|
|
2338
2422
|
setCurrentBearing(map.getBearing());
|
|
@@ -2359,14 +2443,14 @@ var CoordinateDisplay = ({
|
|
|
2359
2443
|
{
|
|
2360
2444
|
ref: controlRef,
|
|
2361
2445
|
className: cn(
|
|
2362
|
-
"absolute
|
|
2446
|
+
"absolute bg-card rounded px-2 py-1",
|
|
2363
2447
|
"text-xs font-mono text-muted-foreground",
|
|
2364
2448
|
"border border-black dark:border-gray-400 shadow-sm",
|
|
2365
2449
|
"flex items-center gap-3",
|
|
2366
|
-
|
|
2450
|
+
!visible && "invisible",
|
|
2367
2451
|
className
|
|
2368
2452
|
),
|
|
2369
|
-
style:
|
|
2453
|
+
style: adjustedStyle,
|
|
2370
2454
|
children: [
|
|
2371
2455
|
cursorLngLat ? /* @__PURE__ */ jsx("span", { title: "Cursor coordinates", children: formatCoord(cursorLngLat) }) : /* @__PURE__ */ jsx("span", { className: "text-muted-foreground/60", children: "Move cursor over map" }),
|
|
2372
2456
|
showZoom && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
@@ -2398,17 +2482,16 @@ var BasemapSwitcher = ({
|
|
|
2398
2482
|
position = "bottom-right",
|
|
2399
2483
|
class: className
|
|
2400
2484
|
}) => {
|
|
2401
|
-
const {
|
|
2402
|
-
const [isOpen, setIsOpen] =
|
|
2403
|
-
const [internalActiveId, setInternalActiveId] =
|
|
2485
|
+
const { setMapStyle } = useMap();
|
|
2486
|
+
const [isOpen, setIsOpen] = React26.useState(false);
|
|
2487
|
+
const [internalActiveId, setInternalActiveId] = React26.useState(
|
|
2404
2488
|
defaultBasemapId
|
|
2405
2489
|
);
|
|
2406
|
-
const
|
|
2407
|
-
const
|
|
2408
|
-
const
|
|
2409
|
-
const switcherIdRef = React25.useRef(`basemap-switcher-${++switcherIdCounter}`);
|
|
2490
|
+
const containerRef = React26.useRef(null);
|
|
2491
|
+
const panelRef = React26.useRef(null);
|
|
2492
|
+
const switcherIdRef = React26.useRef(`basemap-switcher-${++switcherIdCounter}`);
|
|
2410
2493
|
const sourceBasemaps = basemaps ?? FREE_BASEMAPS;
|
|
2411
|
-
const availableBasemaps =
|
|
2494
|
+
const availableBasemaps = React26.useMemo(() => {
|
|
2412
2495
|
const available = getAvailableBasemaps(sourceBasemaps, apiKeys);
|
|
2413
2496
|
if (extraBasemaps?.length) {
|
|
2414
2497
|
return [...available, ...getAvailableBasemaps(extraBasemaps, apiKeys)];
|
|
@@ -2416,66 +2499,59 @@ var BasemapSwitcher = ({
|
|
|
2416
2499
|
return available;
|
|
2417
2500
|
}, [sourceBasemaps, extraBasemaps, apiKeys]);
|
|
2418
2501
|
const currentActiveId = activeBasemapId ?? internalActiveId ?? availableBasemaps[0]?.id;
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
const observer = new ResizeObserver(updatePosition);
|
|
2429
|
-
observer.observe(containerRef.current);
|
|
2430
|
-
return () => {
|
|
2431
|
-
observer.disconnect();
|
|
2432
|
-
unregisterControl?.(switcherIdRef.current, position);
|
|
2433
|
-
};
|
|
2434
|
-
}, [position, registerControl, unregisterControl]);
|
|
2435
|
-
React25.useEffect(() => {
|
|
2502
|
+
const { style, visible, setExpanded } = useControlPosition(containerRef, {
|
|
2503
|
+
id: switcherIdRef.current,
|
|
2504
|
+
type: "basemap-switcher",
|
|
2505
|
+
position,
|
|
2506
|
+
priority: "normal",
|
|
2507
|
+
zLayer: "interactive",
|
|
2508
|
+
hasExpandedState: true
|
|
2509
|
+
});
|
|
2510
|
+
React26.useEffect(() => {
|
|
2436
2511
|
if (!isOpen) return;
|
|
2437
2512
|
const handleMouseDown = (e) => {
|
|
2438
2513
|
if (containerRef.current && !containerRef.current.contains(e.target)) {
|
|
2439
2514
|
setIsOpen(false);
|
|
2515
|
+
setExpanded(false);
|
|
2440
2516
|
}
|
|
2441
2517
|
};
|
|
2442
2518
|
document.addEventListener("mousedown", handleMouseDown);
|
|
2443
2519
|
return () => document.removeEventListener("mousedown", handleMouseDown);
|
|
2444
|
-
}, [isOpen]);
|
|
2445
|
-
|
|
2520
|
+
}, [isOpen, setExpanded]);
|
|
2521
|
+
React26.useEffect(() => {
|
|
2446
2522
|
if (!isOpen) return;
|
|
2447
2523
|
const handleKeyDown = (e) => {
|
|
2448
2524
|
if (e.key === "Escape") {
|
|
2449
2525
|
setIsOpen(false);
|
|
2526
|
+
setExpanded(false);
|
|
2450
2527
|
}
|
|
2451
2528
|
};
|
|
2452
2529
|
document.addEventListener("keydown", handleKeyDown);
|
|
2453
2530
|
return () => document.removeEventListener("keydown", handleKeyDown);
|
|
2454
|
-
}, [isOpen]);
|
|
2531
|
+
}, [isOpen, setExpanded]);
|
|
2455
2532
|
const handleSelect = (basemap) => {
|
|
2456
|
-
const
|
|
2457
|
-
if (!
|
|
2533
|
+
const resolvedStyle = resolveBasemapStyle(basemap, apiKeys);
|
|
2534
|
+
if (!resolvedStyle) return;
|
|
2458
2535
|
if (!activeBasemapId) {
|
|
2459
2536
|
setInternalActiveId(basemap.id);
|
|
2460
2537
|
}
|
|
2461
|
-
setMapStyle?.(
|
|
2538
|
+
setMapStyle?.(resolvedStyle);
|
|
2462
2539
|
onBasemapChange?.(basemap);
|
|
2463
2540
|
setIsOpen(false);
|
|
2541
|
+
setExpanded(false);
|
|
2542
|
+
};
|
|
2543
|
+
const handleToggle = () => {
|
|
2544
|
+
const newState = !isOpen;
|
|
2545
|
+
setIsOpen(newState);
|
|
2546
|
+
setExpanded(newState);
|
|
2464
2547
|
};
|
|
2465
|
-
const verticalOffsetStyle = React25.useMemo(() => {
|
|
2466
|
-
return computeVerticalOffsetStyle(position, customControlOffset);
|
|
2467
|
-
}, [customControlOffset, position]);
|
|
2468
|
-
const hasControlsAtPosition = (controlOffsets?.[position] ?? 0) > 0;
|
|
2469
|
-
const computedPositionClasses = React25.useMemo(() => {
|
|
2470
|
-
return computePositionClasses(position, hasControlsAtPosition);
|
|
2471
|
-
}, [position, hasControlsAtPosition]);
|
|
2472
2548
|
const isTop = position.startsWith("top");
|
|
2473
2549
|
return /* @__PURE__ */ jsxs(
|
|
2474
2550
|
"div",
|
|
2475
2551
|
{
|
|
2476
2552
|
ref: containerRef,
|
|
2477
|
-
className: cn("absolute
|
|
2478
|
-
style
|
|
2553
|
+
className: cn("absolute", !visible && "invisible", className),
|
|
2554
|
+
style,
|
|
2479
2555
|
children: [
|
|
2480
2556
|
isOpen && /* @__PURE__ */ jsx(
|
|
2481
2557
|
"div",
|
|
@@ -2550,7 +2626,7 @@ var BasemapSwitcher = ({
|
|
|
2550
2626
|
"hover:bg-muted transition-colors cursor-pointer",
|
|
2551
2627
|
"text-foreground"
|
|
2552
2628
|
),
|
|
2553
|
-
onClick:
|
|
2629
|
+
onClick: handleToggle,
|
|
2554
2630
|
"aria-label": "Switch basemap",
|
|
2555
2631
|
"aria-expanded": isOpen,
|
|
2556
2632
|
"aria-haspopup": "true",
|
|
@@ -2593,22 +2669,28 @@ var LayerManager = ({
|
|
|
2593
2669
|
onLayerChange,
|
|
2594
2670
|
class: className
|
|
2595
2671
|
}) => {
|
|
2596
|
-
const { controlOffsets, registerControl, unregisterControl } = useMap();
|
|
2597
2672
|
const { isDark } = useMapTheme();
|
|
2598
|
-
const [isOpen, setIsOpen] =
|
|
2599
|
-
const [layerStates, setLayerStates] =
|
|
2673
|
+
const [isOpen, setIsOpen] = React26.useState(false);
|
|
2674
|
+
const [layerStates, setLayerStates] = React26.useState(
|
|
2600
2675
|
() => createInitialLayerStates(layers, initialActiveLayers)
|
|
2601
2676
|
);
|
|
2602
|
-
const [searchQuery, setSearchQuery] =
|
|
2603
|
-
const [activeCategory, setActiveCategory] =
|
|
2604
|
-
const [
|
|
2605
|
-
const [
|
|
2606
|
-
const [
|
|
2607
|
-
const
|
|
2608
|
-
const
|
|
2609
|
-
const
|
|
2610
|
-
const
|
|
2611
|
-
|
|
2677
|
+
const [searchQuery, setSearchQuery] = React26.useState("");
|
|
2678
|
+
const [activeCategory, setActiveCategory] = React26.useState("all");
|
|
2679
|
+
const [expandedOpacity, setExpandedOpacity] = React26.useState(null);
|
|
2680
|
+
const [draggedId, setDraggedId] = React26.useState(null);
|
|
2681
|
+
const [dragOver, setDragOver] = React26.useState(null);
|
|
2682
|
+
const containerRef = React26.useRef(null);
|
|
2683
|
+
const managerIdRef = React26.useRef(`layer-manager-${++managerIdCounter}`);
|
|
2684
|
+
const lastLayerIdsRef = React26.useRef(new Set(layers.map((l) => l.id)));
|
|
2685
|
+
const { style, visible, setExpanded } = useControlPosition(containerRef, {
|
|
2686
|
+
id: managerIdRef.current,
|
|
2687
|
+
type: "layer-manager",
|
|
2688
|
+
position,
|
|
2689
|
+
priority: "high",
|
|
2690
|
+
zLayer: "interactive",
|
|
2691
|
+
hasExpandedState: true
|
|
2692
|
+
});
|
|
2693
|
+
React26.useEffect(() => {
|
|
2612
2694
|
const currentLayerIds = new Set(layers.map((l) => l.id));
|
|
2613
2695
|
const hasNewLayers = layers.some((l) => !lastLayerIdsRef.current.has(l.id));
|
|
2614
2696
|
const hasRemovedLayers = Array.from(lastLayerIdsRef.current).some(
|
|
@@ -2639,8 +2721,8 @@ var LayerManager = ({
|
|
|
2639
2721
|
lastLayerIdsRef.current = currentLayerIds;
|
|
2640
2722
|
}
|
|
2641
2723
|
}, [layers, initialActiveLayers]);
|
|
2642
|
-
const categories =
|
|
2643
|
-
const filteredLayers =
|
|
2724
|
+
const categories = React26.useMemo(() => getLayerCategories(layers), [layers]);
|
|
2725
|
+
const filteredLayers = React26.useMemo(() => {
|
|
2644
2726
|
let result = layers;
|
|
2645
2727
|
if (searchQuery) {
|
|
2646
2728
|
result = searchLayers(result, searchQuery);
|
|
@@ -2654,47 +2736,33 @@ var LayerManager = ({
|
|
|
2654
2736
|
return orderA - orderB;
|
|
2655
2737
|
});
|
|
2656
2738
|
}, [layers, searchQuery, activeCategory, layerStates]);
|
|
2657
|
-
const layerGroups =
|
|
2739
|
+
const layerGroups = React26.useMemo(
|
|
2658
2740
|
() => showCategories ? groupLayersByCategory(filteredLayers) : null,
|
|
2659
2741
|
[filteredLayers, showCategories]
|
|
2660
2742
|
);
|
|
2661
|
-
|
|
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(() => {
|
|
2743
|
+
React26.useEffect(() => {
|
|
2678
2744
|
if (!isOpen) return;
|
|
2679
2745
|
const handleMouseDown = (e) => {
|
|
2680
2746
|
if (containerRef.current && !containerRef.current.contains(e.target)) {
|
|
2681
2747
|
setIsOpen(false);
|
|
2748
|
+
setExpanded(false);
|
|
2682
2749
|
}
|
|
2683
2750
|
};
|
|
2684
2751
|
document.addEventListener("mousedown", handleMouseDown);
|
|
2685
2752
|
return () => document.removeEventListener("mousedown", handleMouseDown);
|
|
2686
|
-
}, [isOpen]);
|
|
2687
|
-
|
|
2753
|
+
}, [isOpen, setExpanded]);
|
|
2754
|
+
React26.useEffect(() => {
|
|
2688
2755
|
if (!isOpen) return;
|
|
2689
2756
|
const handleKeyDown = (e) => {
|
|
2690
2757
|
if (e.key === "Escape") {
|
|
2691
2758
|
setIsOpen(false);
|
|
2759
|
+
setExpanded(false);
|
|
2692
2760
|
}
|
|
2693
2761
|
};
|
|
2694
2762
|
document.addEventListener("keydown", handleKeyDown);
|
|
2695
2763
|
return () => document.removeEventListener("keydown", handleKeyDown);
|
|
2696
|
-
}, [isOpen]);
|
|
2697
|
-
const handleToggleLayer =
|
|
2764
|
+
}, [isOpen, setExpanded]);
|
|
2765
|
+
const handleToggleLayer = React26.useCallback(
|
|
2698
2766
|
(layerId) => {
|
|
2699
2767
|
setLayerStates((prev) => {
|
|
2700
2768
|
const newStates = toggleLayerVisibility(prev, layerId);
|
|
@@ -2707,7 +2775,7 @@ var LayerManager = ({
|
|
|
2707
2775
|
},
|
|
2708
2776
|
[onLayerChange]
|
|
2709
2777
|
);
|
|
2710
|
-
const handleOpacityChange =
|
|
2778
|
+
const handleOpacityChange = React26.useCallback(
|
|
2711
2779
|
(layerId, opacity) => {
|
|
2712
2780
|
setLayerStates((prev) => {
|
|
2713
2781
|
const newStates = setLayerOpacity(prev, layerId, opacity);
|
|
@@ -2720,12 +2788,12 @@ var LayerManager = ({
|
|
|
2720
2788
|
},
|
|
2721
2789
|
[onLayerChange]
|
|
2722
2790
|
);
|
|
2723
|
-
const handleDragStart =
|
|
2791
|
+
const handleDragStart = React26.useCallback((e, layerId) => {
|
|
2724
2792
|
setDraggedId(layerId);
|
|
2725
2793
|
e.dataTransfer.effectAllowed = "move";
|
|
2726
2794
|
e.dataTransfer.setData("text/plain", layerId);
|
|
2727
2795
|
}, []);
|
|
2728
|
-
const handleDragOver =
|
|
2796
|
+
const handleDragOver = React26.useCallback(
|
|
2729
2797
|
(e, layerId) => {
|
|
2730
2798
|
e.preventDefault();
|
|
2731
2799
|
e.dataTransfer.dropEffect = "move";
|
|
@@ -2745,14 +2813,14 @@ var LayerManager = ({
|
|
|
2745
2813
|
},
|
|
2746
2814
|
[draggedId, dragOver]
|
|
2747
2815
|
);
|
|
2748
|
-
const handleDragLeave =
|
|
2816
|
+
const handleDragLeave = React26.useCallback(() => {
|
|
2749
2817
|
setDragOver(null);
|
|
2750
2818
|
}, []);
|
|
2751
|
-
const handleDragEnd =
|
|
2819
|
+
const handleDragEnd = React26.useCallback(() => {
|
|
2752
2820
|
setDraggedId(null);
|
|
2753
2821
|
setDragOver(null);
|
|
2754
2822
|
}, []);
|
|
2755
|
-
const handleDrop =
|
|
2823
|
+
const handleDrop = React26.useCallback(
|
|
2756
2824
|
(e, targetLayerId) => {
|
|
2757
2825
|
e.preventDefault();
|
|
2758
2826
|
const sourceLayerId = e.dataTransfer.getData("text/plain");
|
|
@@ -2782,13 +2850,6 @@ var LayerManager = ({
|
|
|
2782
2850
|
},
|
|
2783
2851
|
[layerStates, onLayerChange, dragOver]
|
|
2784
2852
|
);
|
|
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
2853
|
const isTop = position.startsWith("top");
|
|
2793
2854
|
const renderLayer = (layer, state) => {
|
|
2794
2855
|
if (!state.visible) return null;
|
|
@@ -2999,6 +3060,11 @@ var LayerManager = ({
|
|
|
2999
3060
|
] }) });
|
|
3000
3061
|
};
|
|
3001
3062
|
const visibleLayerStates = getLayerStatesArray(layerStates).filter((s) => s.visible);
|
|
3063
|
+
const handleToggle = () => {
|
|
3064
|
+
const newState = !isOpen;
|
|
3065
|
+
setIsOpen(newState);
|
|
3066
|
+
setExpanded(newState);
|
|
3067
|
+
};
|
|
3002
3068
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
3003
3069
|
visibleLayerStates.map((state) => {
|
|
3004
3070
|
const layer = layers.find((l) => l.id === state.id);
|
|
@@ -3008,8 +3074,8 @@ var LayerManager = ({
|
|
|
3008
3074
|
"div",
|
|
3009
3075
|
{
|
|
3010
3076
|
ref: containerRef,
|
|
3011
|
-
className: cn("absolute
|
|
3012
|
-
style
|
|
3077
|
+
className: cn("absolute", !visible && "invisible", className),
|
|
3078
|
+
style,
|
|
3013
3079
|
children: [
|
|
3014
3080
|
isOpen && /* @__PURE__ */ jsxs(
|
|
3015
3081
|
"div",
|
|
@@ -3087,7 +3153,7 @@ var LayerManager = ({
|
|
|
3087
3153
|
if (catLayers.length === 0) return null;
|
|
3088
3154
|
return /* @__PURE__ */ jsxs("div", { children: [
|
|
3089
3155
|
/* @__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(
|
|
3156
|
+
catLayers.map((layer) => /* @__PURE__ */ jsxs(React26.Fragment, { children: [
|
|
3091
3157
|
renderLayerItem(layer),
|
|
3092
3158
|
renderOpacitySlider(layer.id)
|
|
3093
3159
|
] }, layer.id))
|
|
@@ -3095,7 +3161,7 @@ var LayerManager = ({
|
|
|
3095
3161
|
})
|
|
3096
3162
|
) : (
|
|
3097
3163
|
// Flat list
|
|
3098
|
-
filteredLayers.map((layer) => /* @__PURE__ */ jsxs(
|
|
3164
|
+
filteredLayers.map((layer) => /* @__PURE__ */ jsxs(React26.Fragment, { children: [
|
|
3099
3165
|
renderLayerItem(layer),
|
|
3100
3166
|
renderOpacitySlider(layer.id)
|
|
3101
3167
|
] }, layer.id))
|
|
@@ -3115,7 +3181,7 @@ var LayerManager = ({
|
|
|
3115
3181
|
"hover:bg-muted transition-colors cursor-pointer",
|
|
3116
3182
|
"text-foreground"
|
|
3117
3183
|
),
|
|
3118
|
-
onClick:
|
|
3184
|
+
onClick: handleToggle,
|
|
3119
3185
|
"aria-label": "Toggle layer manager",
|
|
3120
3186
|
"aria-expanded": isOpen,
|
|
3121
3187
|
"aria-haspopup": "true",
|
|
@@ -3155,9 +3221,9 @@ var DeckOverlay = ({
|
|
|
3155
3221
|
deckProps = {}
|
|
3156
3222
|
}) => {
|
|
3157
3223
|
const { map, loaded } = useMap();
|
|
3158
|
-
const overlayRef =
|
|
3159
|
-
const MapboxOverlayRef =
|
|
3160
|
-
|
|
3224
|
+
const overlayRef = React26.useRef(null);
|
|
3225
|
+
const MapboxOverlayRef = React26.useRef(null);
|
|
3226
|
+
React26.useEffect(() => {
|
|
3161
3227
|
if (!map || !loaded) return;
|
|
3162
3228
|
let cancelled = false;
|
|
3163
3229
|
const initOverlay = async () => {
|
|
@@ -3197,12 +3263,12 @@ var DeckOverlay = ({
|
|
|
3197
3263
|
}
|
|
3198
3264
|
};
|
|
3199
3265
|
}, [map, loaded, interleaved]);
|
|
3200
|
-
|
|
3266
|
+
React26.useEffect(() => {
|
|
3201
3267
|
if (overlayRef.current && "setProps" in overlayRef.current) {
|
|
3202
3268
|
overlayRef.current.setProps({ layers });
|
|
3203
3269
|
}
|
|
3204
3270
|
}, [layers]);
|
|
3205
|
-
|
|
3271
|
+
React26.useEffect(() => {
|
|
3206
3272
|
if (overlayRef.current && "setProps" in overlayRef.current) {
|
|
3207
3273
|
overlayRef.current.setProps({
|
|
3208
3274
|
onHover,
|
|
@@ -3210,7 +3276,7 @@ var DeckOverlay = ({
|
|
|
3210
3276
|
});
|
|
3211
3277
|
}
|
|
3212
3278
|
}, [onHover, onClick]);
|
|
3213
|
-
|
|
3279
|
+
React26.useEffect(() => {
|
|
3214
3280
|
if (overlayRef.current && effects && "setProps" in overlayRef.current) {
|
|
3215
3281
|
overlayRef.current.setProps({ effects });
|
|
3216
3282
|
}
|