@classic-homes/maps-react 0.2.5 → 0.2.6
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 +65 -8
- package/dist/index.d.cts +126 -3
- package/dist/index.d.ts +126 -3
- package/dist/index.js +49 -11
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -281,7 +281,8 @@ function useMapTheme(preference = "auto") {
|
|
|
281
281
|
return {
|
|
282
282
|
themeName: isDark ? mapsCore.THEME_DARK : mapsCore.THEME_LIGHT,
|
|
283
283
|
theme: isDark ? mapsCore.darkTheme : mapsCore.lightTheme,
|
|
284
|
-
style
|
|
284
|
+
// Use the default MapTiler basemap style (works well for both light and dark modes)
|
|
285
|
+
style: mapsCore.DEFAULT_BASEMAP.style,
|
|
285
286
|
isDark
|
|
286
287
|
};
|
|
287
288
|
}
|
|
@@ -707,8 +708,8 @@ var Source = ({
|
|
|
707
708
|
children
|
|
708
709
|
}) => {
|
|
709
710
|
const { map, loaded, styleVersion } = useMap();
|
|
710
|
-
const sourceAdded = React26__namespace.useRef(false);
|
|
711
711
|
const initialFitDone = React26__namespace.useRef(false);
|
|
712
|
+
const lastStyleVersionRef = React26__namespace.useRef(styleVersion);
|
|
712
713
|
const fitBoundsParamsRef = React26__namespace.useRef({
|
|
713
714
|
shouldFitBounds,
|
|
714
715
|
data,
|
|
@@ -770,9 +771,12 @@ var Source = ({
|
|
|
770
771
|
[map]
|
|
771
772
|
);
|
|
772
773
|
React26__namespace.useEffect(() => {
|
|
773
|
-
if (!map || !loaded
|
|
774
|
+
if (!map || !loaded) return;
|
|
775
|
+
if (styleVersion !== lastStyleVersionRef.current) {
|
|
776
|
+
lastStyleVersionRef.current = styleVersion;
|
|
777
|
+
initialFitDone.current = false;
|
|
778
|
+
}
|
|
774
779
|
if (map.getSource(id)) {
|
|
775
|
-
sourceAdded.current = true;
|
|
776
780
|
return;
|
|
777
781
|
}
|
|
778
782
|
try {
|
|
@@ -859,7 +863,6 @@ var Source = ({
|
|
|
859
863
|
};
|
|
860
864
|
map.once("idle", handleIdle);
|
|
861
865
|
map.addSource(id, sourceConfig);
|
|
862
|
-
sourceAdded.current = true;
|
|
863
866
|
const source = map.getSource(id);
|
|
864
867
|
if (source && map.isSourceLoaded(id)) {
|
|
865
868
|
map.off("sourcedata", handleSourceData);
|
|
@@ -877,7 +880,7 @@ var Source = ({
|
|
|
877
880
|
};
|
|
878
881
|
return () => {
|
|
879
882
|
cleanupListeners();
|
|
880
|
-
if (map
|
|
883
|
+
if (map) {
|
|
881
884
|
try {
|
|
882
885
|
const style = map.getStyle();
|
|
883
886
|
if (style?.layers) {
|
|
@@ -894,7 +897,6 @@ var Source = ({
|
|
|
894
897
|
}
|
|
895
898
|
} catch {
|
|
896
899
|
}
|
|
897
|
-
sourceAdded.current = false;
|
|
898
900
|
}
|
|
899
901
|
};
|
|
900
902
|
} catch (err) {
|
|
@@ -920,7 +922,7 @@ var Source = ({
|
|
|
920
922
|
// re-add source after basemap style changes
|
|
921
923
|
]);
|
|
922
924
|
React26__namespace.useEffect(() => {
|
|
923
|
-
if (!map || !loaded ||
|
|
925
|
+
if (!map || !loaded || type !== "geojson") return;
|
|
924
926
|
const source = map.getSource(id);
|
|
925
927
|
if (!source) return;
|
|
926
928
|
let cancelled = false;
|
|
@@ -3235,6 +3237,42 @@ var LayerManager = ({
|
|
|
3235
3237
|
] });
|
|
3236
3238
|
};
|
|
3237
3239
|
LayerManager.displayName = "LayerManager";
|
|
3240
|
+
var customControlIdCounter = 0;
|
|
3241
|
+
var CustomControl = ({
|
|
3242
|
+
position = "top-right",
|
|
3243
|
+
fallbacks,
|
|
3244
|
+
priority = "normal",
|
|
3245
|
+
zLayer = "interactive",
|
|
3246
|
+
id,
|
|
3247
|
+
hasExpandedState = false,
|
|
3248
|
+
className,
|
|
3249
|
+
style: userStyle,
|
|
3250
|
+
children
|
|
3251
|
+
}) => {
|
|
3252
|
+
const controlRef = React26__namespace.useRef(null);
|
|
3253
|
+
const controlIdRef = React26__namespace.useRef(id ?? `custom-control-${++customControlIdCounter}`);
|
|
3254
|
+
const { style, visible, setExpanded } = useControlPosition(controlRef, {
|
|
3255
|
+
id: controlIdRef.current,
|
|
3256
|
+
type: "custom",
|
|
3257
|
+
position,
|
|
3258
|
+
fallbacks,
|
|
3259
|
+
priority,
|
|
3260
|
+
zLayer,
|
|
3261
|
+
hasExpandedState
|
|
3262
|
+
});
|
|
3263
|
+
const mergedStyle = React26__namespace.useMemo(() => ({ ...style, ...userStyle }), [style, userStyle]);
|
|
3264
|
+
const contextValue = React26__namespace.useMemo(() => ({ setExpanded }), [setExpanded]);
|
|
3265
|
+
return /* @__PURE__ */ jsxRuntime.jsx(CustomControlContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsxRuntime.jsx("div", { ref: controlRef, className: cn(!visible && "invisible", className), style: mergedStyle, children }) });
|
|
3266
|
+
};
|
|
3267
|
+
CustomControl.displayName = "CustomControl";
|
|
3268
|
+
var CustomControlContext = React26__namespace.createContext(null);
|
|
3269
|
+
function useCustomControl() {
|
|
3270
|
+
const context = React26__namespace.useContext(CustomControlContext);
|
|
3271
|
+
if (!context) {
|
|
3272
|
+
throw new Error("useCustomControl must be used within a CustomControl");
|
|
3273
|
+
}
|
|
3274
|
+
return context;
|
|
3275
|
+
}
|
|
3238
3276
|
var DeckOverlay = ({
|
|
3239
3277
|
layers = [],
|
|
3240
3278
|
onHover,
|
|
@@ -3329,6 +3367,10 @@ Object.defineProperty(exports, "CITY_LIMITS", {
|
|
|
3329
3367
|
enumerable: true,
|
|
3330
3368
|
get: function () { return mapsCore.CITY_LIMITS; }
|
|
3331
3369
|
});
|
|
3370
|
+
Object.defineProperty(exports, "DEFAULT_BASEMAP", {
|
|
3371
|
+
enumerable: true,
|
|
3372
|
+
get: function () { return mapsCore.DEFAULT_BASEMAP; }
|
|
3373
|
+
});
|
|
3332
3374
|
Object.defineProperty(exports, "FLOOD_ZONES", {
|
|
3333
3375
|
enumerable: true,
|
|
3334
3376
|
get: function () { return mapsCore.FLOOD_ZONES; }
|
|
@@ -3345,6 +3387,14 @@ Object.defineProperty(exports, "PARKS", {
|
|
|
3345
3387
|
enumerable: true,
|
|
3346
3388
|
get: function () { return mapsCore.PARKS; }
|
|
3347
3389
|
});
|
|
3390
|
+
Object.defineProperty(exports, "PRIMARY_BASEMAPS", {
|
|
3391
|
+
enumerable: true,
|
|
3392
|
+
get: function () { return mapsCore.PRIMARY_BASEMAPS; }
|
|
3393
|
+
});
|
|
3394
|
+
Object.defineProperty(exports, "SATELLITE_BASEMAP", {
|
|
3395
|
+
enumerable: true,
|
|
3396
|
+
get: function () { return mapsCore.SATELLITE_BASEMAP; }
|
|
3397
|
+
});
|
|
3348
3398
|
Object.defineProperty(exports, "SCHOOL_DISTRICTS", {
|
|
3349
3399
|
enumerable: true,
|
|
3350
3400
|
get: function () { return mapsCore.SCHOOL_DISTRICTS; }
|
|
@@ -3361,6 +3411,10 @@ Object.defineProperty(exports, "THEME_LIGHT", {
|
|
|
3361
3411
|
enumerable: true,
|
|
3362
3412
|
get: function () { return mapsCore.THEME_LIGHT; }
|
|
3363
3413
|
});
|
|
3414
|
+
Object.defineProperty(exports, "TOPO_BASEMAP", {
|
|
3415
|
+
enumerable: true,
|
|
3416
|
+
get: function () { return mapsCore.TOPO_BASEMAP; }
|
|
3417
|
+
});
|
|
3364
3418
|
Object.defineProperty(exports, "TRAILS", {
|
|
3365
3419
|
enumerable: true,
|
|
3366
3420
|
get: function () { return mapsCore.TRAILS; }
|
|
@@ -3536,6 +3590,7 @@ Object.defineProperty(exports, "validateGeoJSON", {
|
|
|
3536
3590
|
exports.BasemapSwitcher = BasemapSwitcher;
|
|
3537
3591
|
exports.CircleLayer = CircleLayer;
|
|
3538
3592
|
exports.CoordinateDisplay = CoordinateDisplay;
|
|
3593
|
+
exports.CustomControl = CustomControl;
|
|
3539
3594
|
exports.DeckOverlay = DeckOverlay;
|
|
3540
3595
|
exports.FillExtrusionLayer = FillExtrusionLayer;
|
|
3541
3596
|
exports.FillLayer = FillLayer;
|
|
@@ -3559,6 +3614,8 @@ exports.PopupHeader = PopupHeader;
|
|
|
3559
3614
|
exports.Source = Source;
|
|
3560
3615
|
exports.SymbolLayer = SymbolLayer;
|
|
3561
3616
|
exports.cn = cn;
|
|
3617
|
+
exports.useControlPosition = useControlPosition;
|
|
3618
|
+
exports.useCustomControl = useCustomControl;
|
|
3562
3619
|
exports.useLayer = useLayer;
|
|
3563
3620
|
exports.useMap = useMap;
|
|
3564
3621
|
exports.useMapInstance = useMapInstance;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { MapProps, PositioningCoordinator, SourceProps, MarkerProps, PopupProps, BaseLayerProps, FeatureClickEventParams, FeatureHoverEventParams, FillLayerProps, LineLayerProps, CircleLayerProps, SymbolLayerProps, FillExtrusionLayerProps, HeatmapLayerProps, LegendProps, LegendGroupProps, CoordinateDisplayProps, BasemapSwitcherProps, LayerManagerProps, MapTheme, MapStyleSpec } from '@classic-homes/maps-core';
|
|
3
|
-
export { BIKE_LANES, BUILTIN_BASEMAPS, BUILTIN_OVERLAY_LAYERS, BaseMapProps, BasemapApiKeys, BasemapCategory, BasemapDefinition, BasemapProvider, BasemapSwitcherProps, BoundsArray, CATEGORY_META, CITY_LIMITS, CircleLayerProps, ClusterExpandOptions, ClusterFeatureProperties, CoordinateDisplayProps, FLOOD_ZONES, FREE_BASEMAPS, FeatureClickEventParams, FeatureHoverEventParams, FillExtrusionLayerProps, FillLayerProps, GeoJSONFeature, GeoJSONFeatureCollection, GradientStop, HeatmapLayerProps, LayerManagerProps, LegendConfig, LegendGroupProps, LegendItem, LegendProps, LineLayerProps, LngLat, LoadGeoJSONOptions, LoadGeoJSONResult, MapBounds, MapClickEventParams, MapHoverEventParams, MapMoveEventParams, MapProps, MapViewport, MarkerClickEventParams, MarkerData, MarkerDragEventParams, MarkerProps, OSM_STANDARD, OverlayApiKeys, OverlayLayerCategory, OverlayLayerDefinition, OverlayLayerState, PARKS, PopupProps, SCHOOL_DISTRICTS, SPORTS_FACILITIES, SourceProps, SymbolLayerProps, THEME_DARK, THEME_LIGHT, TRAILS, TRANSIT_ROUTES, ValidationResult, 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';
|
|
2
|
+
import { MapProps, PositioningCoordinator, SourceProps, MarkerProps, PopupProps, BaseLayerProps, FeatureClickEventParams, FeatureHoverEventParams, FillLayerProps, LineLayerProps, CircleLayerProps, SymbolLayerProps, FillExtrusionLayerProps, HeatmapLayerProps, LegendProps, LegendGroupProps, CoordinateDisplayProps, BasemapSwitcherProps, LayerManagerProps, ExtendedControlPosition, ControlPriority, ZIndexLayer, MapTheme, MapStyleSpec, ControlType, ControlOffset } from '@classic-homes/maps-core';
|
|
3
|
+
export { BIKE_LANES, BUILTIN_BASEMAPS, BUILTIN_OVERLAY_LAYERS, BaseMapProps, BasemapApiKeys, BasemapCategory, BasemapDefinition, BasemapProvider, BasemapSwitcherProps, BoundsArray, CATEGORY_META, CITY_LIMITS, CircleLayerProps, ClusterExpandOptions, ClusterFeatureProperties, ControlOffset, ControlPriority, ControlType, CoordinateDisplayProps, DEFAULT_BASEMAP, ExtendedControlPosition, FLOOD_ZONES, FREE_BASEMAPS, FeatureClickEventParams, FeatureHoverEventParams, FillExtrusionLayerProps, FillLayerProps, GeoJSONFeature, GeoJSONFeatureCollection, GradientStop, HeatmapLayerProps, LayerManagerProps, LegendConfig, LegendGroupProps, LegendItem, LegendProps, LineLayerProps, LngLat, LoadGeoJSONOptions, LoadGeoJSONResult, MapBounds, MapClickEventParams, MapHoverEventParams, MapMoveEventParams, MapProps, MapViewport, MarkerClickEventParams, MarkerData, MarkerDragEventParams, MarkerProps, OSM_STANDARD, OverlayApiKeys, OverlayLayerCategory, OverlayLayerDefinition, OverlayLayerState, PARKS, PRIMARY_BASEMAPS, PopupProps, SATELLITE_BASEMAP, SCHOOL_DISTRICTS, SPORTS_FACILITIES, SourceProps, SymbolLayerProps, THEME_DARK, THEME_LIGHT, TOPO_BASEMAP, TRAILS, TRANSIT_ROUTES, ValidationResult, WATERSHEDS, ZIndexLayer, 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';
|
|
4
4
|
import maplibregl, { Map as Map$1, StyleSpecification } from 'maplibre-gl';
|
|
5
5
|
import * as class_variance_authority_types from 'class-variance-authority/types';
|
|
6
6
|
import { VariantProps } from 'class-variance-authority';
|
|
@@ -340,6 +340,66 @@ interface LayerManagerComponentProps extends LayerManagerProps {
|
|
|
340
340
|
*/
|
|
341
341
|
declare const LayerManager: React.FC<LayerManagerComponentProps>;
|
|
342
342
|
|
|
343
|
+
interface CustomControlProps {
|
|
344
|
+
/** Position on the map (default: 'top-right') */
|
|
345
|
+
position?: ExtendedControlPosition;
|
|
346
|
+
/** Fallback positions if primary is occupied */
|
|
347
|
+
fallbacks?: ExtendedControlPosition[];
|
|
348
|
+
/** Priority for collision resolution (default: 'normal') */
|
|
349
|
+
priority?: ControlPriority;
|
|
350
|
+
/** Z-index layer (default: 'interactive') */
|
|
351
|
+
zLayer?: ZIndexLayer;
|
|
352
|
+
/** Optional unique ID (auto-generated if not provided) */
|
|
353
|
+
id?: string;
|
|
354
|
+
/** Whether the control has an expandable state */
|
|
355
|
+
hasExpandedState?: boolean;
|
|
356
|
+
/** Additional CSS class names */
|
|
357
|
+
className?: string;
|
|
358
|
+
/** Inline styles (merged with positioning styles) */
|
|
359
|
+
style?: React.CSSProperties;
|
|
360
|
+
/** Child content */
|
|
361
|
+
children: React.ReactNode;
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* CustomControl component for positioning arbitrary content on the map
|
|
365
|
+
*
|
|
366
|
+
* This component integrates with the map's positioning coordinator for
|
|
367
|
+
* collision avoidance and proper stacking with other controls.
|
|
368
|
+
*
|
|
369
|
+
* @example
|
|
370
|
+
* ```tsx
|
|
371
|
+
* <Map>
|
|
372
|
+
* <CustomControl position="top-right">
|
|
373
|
+
* <div className="bg-white p-2 rounded shadow">
|
|
374
|
+
* Custom widget content
|
|
375
|
+
* </div>
|
|
376
|
+
* </CustomControl>
|
|
377
|
+
* </Map>
|
|
378
|
+
* ```
|
|
379
|
+
*/
|
|
380
|
+
declare const CustomControl: React.FC<CustomControlProps>;
|
|
381
|
+
/**
|
|
382
|
+
* Context for accessing CustomControl methods from children
|
|
383
|
+
*/
|
|
384
|
+
interface CustomControlContextValue {
|
|
385
|
+
/** Update the expanded state of the control */
|
|
386
|
+
setExpanded: (isExpanded: boolean) => void;
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Hook to access the CustomControl context from child components
|
|
390
|
+
*
|
|
391
|
+
* @example
|
|
392
|
+
* ```tsx
|
|
393
|
+
* const MyExpandableContent = () => {
|
|
394
|
+
* const { setExpanded } = useCustomControl();
|
|
395
|
+
* return (
|
|
396
|
+
* <button onClick={() => setExpanded(true)}>Expand</button>
|
|
397
|
+
* );
|
|
398
|
+
* };
|
|
399
|
+
* ```
|
|
400
|
+
*/
|
|
401
|
+
declare function useCustomControl(): CustomControlContextValue;
|
|
402
|
+
|
|
343
403
|
/**
|
|
344
404
|
* Props for the DeckOverlay component
|
|
345
405
|
*/
|
|
@@ -423,9 +483,72 @@ declare function useMapTheme(preference?: 'light' | 'dark' | 'auto'): {
|
|
|
423
483
|
*/
|
|
424
484
|
declare function useReducedMotion(): boolean;
|
|
425
485
|
|
|
486
|
+
/**
|
|
487
|
+
* Options for useControlPosition hook
|
|
488
|
+
*/
|
|
489
|
+
interface UseControlPositionOptions {
|
|
490
|
+
/** Unique identifier for the control instance */
|
|
491
|
+
id: string;
|
|
492
|
+
/** Type of control */
|
|
493
|
+
type: ControlType;
|
|
494
|
+
/** Primary position for the control */
|
|
495
|
+
position: ExtendedControlPosition;
|
|
496
|
+
/** Fallback positions to try if primary is occupied */
|
|
497
|
+
fallbacks?: ExtendedControlPosition[];
|
|
498
|
+
/** Priority level for collision resolution (default: 'normal') */
|
|
499
|
+
priority?: ControlPriority;
|
|
500
|
+
/** Z-index layer (default: 'interactive') */
|
|
501
|
+
zLayer?: ZIndexLayer;
|
|
502
|
+
/** Whether the control has an expanded state */
|
|
503
|
+
hasExpandedState?: boolean;
|
|
504
|
+
/** Whether the control is a built-in MapLibre control */
|
|
505
|
+
isBuiltIn?: boolean;
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* Return value from useControlPosition hook
|
|
509
|
+
*/
|
|
510
|
+
interface UseControlPositionResult {
|
|
511
|
+
/** Current computed offset and position */
|
|
512
|
+
offset: ControlOffset | null;
|
|
513
|
+
/** Update the expanded state */
|
|
514
|
+
setExpanded: (isExpanded: boolean) => void;
|
|
515
|
+
/** Style object to apply to the control */
|
|
516
|
+
style: React.CSSProperties;
|
|
517
|
+
/** Whether the control should be visible */
|
|
518
|
+
visible: boolean;
|
|
519
|
+
}
|
|
520
|
+
/**
|
|
521
|
+
* Hook for registering a control with the positioning coordinator
|
|
522
|
+
*
|
|
523
|
+
* Handles auto-registration on mount, dimension updates via ResizeObserver,
|
|
524
|
+
* and cleanup on unmount.
|
|
525
|
+
*
|
|
526
|
+
* @param ref - Ref to the control element
|
|
527
|
+
* @param options - Control registration options
|
|
528
|
+
* @returns Position offset, visibility, and style to apply
|
|
529
|
+
*
|
|
530
|
+
* @example
|
|
531
|
+
* ```tsx
|
|
532
|
+
* const legendRef = useRef<HTMLDivElement>(null);
|
|
533
|
+
* const { style, visible, setExpanded } = useControlPosition(legendRef, {
|
|
534
|
+
* id: 'legend-1',
|
|
535
|
+
* type: 'legend',
|
|
536
|
+
* position: 'bottom-left',
|
|
537
|
+
* priority: 'normal',
|
|
538
|
+
* });
|
|
539
|
+
*
|
|
540
|
+
* return (
|
|
541
|
+
* <div ref={legendRef} style={style} hidden={!visible}>
|
|
542
|
+
* ...
|
|
543
|
+
* </div>
|
|
544
|
+
* );
|
|
545
|
+
* ```
|
|
546
|
+
*/
|
|
547
|
+
declare function useControlPosition(ref: React.RefObject<HTMLElement | null>, options: UseControlPositionOptions): UseControlPositionResult;
|
|
548
|
+
|
|
426
549
|
/**
|
|
427
550
|
* Merge class names with Tailwind CSS conflict resolution
|
|
428
551
|
*/
|
|
429
552
|
declare function cn(...inputs: ClassValue[]): string;
|
|
430
553
|
|
|
431
|
-
export { BasemapSwitcher, type BasemapSwitcherComponentProps, CircleLayer, type CircleLayerComponentProps, CoordinateDisplay, type CoordinateDisplayComponentProps, DeckOverlay, type DeckOverlayProps, FillExtrusionLayer, type FillExtrusionLayerComponentProps, FillLayer, type FillLayerComponentProps, HeatmapLayer, type HeatmapLayerComponentProps, LayerManager, type LayerManagerComponentProps, Legend, type LegendComponentProps, LegendGroup, type LegendGroupComponentProps, LineLayer, type LineLayerComponentProps, Map, type MapComponentProps, MapContainer, type MapContainerProps, MapContext, type MapContextValue, MapEmpty, type MapEmptyProps, MapError, type MapErrorProps, MapSkeleton, type MapSkeletonProps, Marker, type MarkerComponentProps, Popup, PopupCard, type PopupCardProps, type PopupComponentProps, PopupContent, type PopupContentProps, PopupFooter, type PopupFooterProps, PopupHeader, type PopupHeaderProps, type ReactFeatureClickEventParams, type ReactFeatureHoverEventParams, Source, type SourceComponentProps, SymbolLayer, type SymbolLayerComponentProps, type UseLayerOptions, cn, useLayer, useMap, useMapInstance, useMapTheme, useReducedMotion };
|
|
554
|
+
export { BasemapSwitcher, type BasemapSwitcherComponentProps, CircleLayer, type CircleLayerComponentProps, CoordinateDisplay, type CoordinateDisplayComponentProps, CustomControl, type CustomControlContextValue, type CustomControlProps, DeckOverlay, type DeckOverlayProps, FillExtrusionLayer, type FillExtrusionLayerComponentProps, FillLayer, type FillLayerComponentProps, HeatmapLayer, type HeatmapLayerComponentProps, LayerManager, type LayerManagerComponentProps, Legend, type LegendComponentProps, LegendGroup, type LegendGroupComponentProps, LineLayer, type LineLayerComponentProps, Map, type MapComponentProps, MapContainer, type MapContainerProps, MapContext, type MapContextValue, MapEmpty, type MapEmptyProps, MapError, type MapErrorProps, MapSkeleton, type MapSkeletonProps, Marker, type MarkerComponentProps, Popup, PopupCard, type PopupCardProps, type PopupComponentProps, PopupContent, type PopupContentProps, PopupFooter, type PopupFooterProps, PopupHeader, type PopupHeaderProps, type ReactFeatureClickEventParams, type ReactFeatureHoverEventParams, Source, type SourceComponentProps, SymbolLayer, type SymbolLayerComponentProps, type UseControlPositionOptions, type UseControlPositionResult, type UseLayerOptions, cn, useControlPosition, useCustomControl, useLayer, useMap, useMapInstance, useMapTheme, useReducedMotion };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { MapProps, PositioningCoordinator, SourceProps, MarkerProps, PopupProps, BaseLayerProps, FeatureClickEventParams, FeatureHoverEventParams, FillLayerProps, LineLayerProps, CircleLayerProps, SymbolLayerProps, FillExtrusionLayerProps, HeatmapLayerProps, LegendProps, LegendGroupProps, CoordinateDisplayProps, BasemapSwitcherProps, LayerManagerProps, MapTheme, MapStyleSpec } from '@classic-homes/maps-core';
|
|
3
|
-
export { BIKE_LANES, BUILTIN_BASEMAPS, BUILTIN_OVERLAY_LAYERS, BaseMapProps, BasemapApiKeys, BasemapCategory, BasemapDefinition, BasemapProvider, BasemapSwitcherProps, BoundsArray, CATEGORY_META, CITY_LIMITS, CircleLayerProps, ClusterExpandOptions, ClusterFeatureProperties, CoordinateDisplayProps, FLOOD_ZONES, FREE_BASEMAPS, FeatureClickEventParams, FeatureHoverEventParams, FillExtrusionLayerProps, FillLayerProps, GeoJSONFeature, GeoJSONFeatureCollection, GradientStop, HeatmapLayerProps, LayerManagerProps, LegendConfig, LegendGroupProps, LegendItem, LegendProps, LineLayerProps, LngLat, LoadGeoJSONOptions, LoadGeoJSONResult, MapBounds, MapClickEventParams, MapHoverEventParams, MapMoveEventParams, MapProps, MapViewport, MarkerClickEventParams, MarkerData, MarkerDragEventParams, MarkerProps, OSM_STANDARD, OverlayApiKeys, OverlayLayerCategory, OverlayLayerDefinition, OverlayLayerState, PARKS, PopupProps, SCHOOL_DISTRICTS, SPORTS_FACILITIES, SourceProps, SymbolLayerProps, THEME_DARK, THEME_LIGHT, TRAILS, TRANSIT_ROUTES, ValidationResult, 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';
|
|
2
|
+
import { MapProps, PositioningCoordinator, SourceProps, MarkerProps, PopupProps, BaseLayerProps, FeatureClickEventParams, FeatureHoverEventParams, FillLayerProps, LineLayerProps, CircleLayerProps, SymbolLayerProps, FillExtrusionLayerProps, HeatmapLayerProps, LegendProps, LegendGroupProps, CoordinateDisplayProps, BasemapSwitcherProps, LayerManagerProps, ExtendedControlPosition, ControlPriority, ZIndexLayer, MapTheme, MapStyleSpec, ControlType, ControlOffset } from '@classic-homes/maps-core';
|
|
3
|
+
export { BIKE_LANES, BUILTIN_BASEMAPS, BUILTIN_OVERLAY_LAYERS, BaseMapProps, BasemapApiKeys, BasemapCategory, BasemapDefinition, BasemapProvider, BasemapSwitcherProps, BoundsArray, CATEGORY_META, CITY_LIMITS, CircleLayerProps, ClusterExpandOptions, ClusterFeatureProperties, ControlOffset, ControlPriority, ControlType, CoordinateDisplayProps, DEFAULT_BASEMAP, ExtendedControlPosition, FLOOD_ZONES, FREE_BASEMAPS, FeatureClickEventParams, FeatureHoverEventParams, FillExtrusionLayerProps, FillLayerProps, GeoJSONFeature, GeoJSONFeatureCollection, GradientStop, HeatmapLayerProps, LayerManagerProps, LegendConfig, LegendGroupProps, LegendItem, LegendProps, LineLayerProps, LngLat, LoadGeoJSONOptions, LoadGeoJSONResult, MapBounds, MapClickEventParams, MapHoverEventParams, MapMoveEventParams, MapProps, MapViewport, MarkerClickEventParams, MarkerData, MarkerDragEventParams, MarkerProps, OSM_STANDARD, OverlayApiKeys, OverlayLayerCategory, OverlayLayerDefinition, OverlayLayerState, PARKS, PRIMARY_BASEMAPS, PopupProps, SATELLITE_BASEMAP, SCHOOL_DISTRICTS, SPORTS_FACILITIES, SourceProps, SymbolLayerProps, THEME_DARK, THEME_LIGHT, TOPO_BASEMAP, TRAILS, TRANSIT_ROUTES, ValidationResult, WATERSHEDS, ZIndexLayer, 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';
|
|
4
4
|
import maplibregl, { Map as Map$1, StyleSpecification } from 'maplibre-gl';
|
|
5
5
|
import * as class_variance_authority_types from 'class-variance-authority/types';
|
|
6
6
|
import { VariantProps } from 'class-variance-authority';
|
|
@@ -340,6 +340,66 @@ interface LayerManagerComponentProps extends LayerManagerProps {
|
|
|
340
340
|
*/
|
|
341
341
|
declare const LayerManager: React.FC<LayerManagerComponentProps>;
|
|
342
342
|
|
|
343
|
+
interface CustomControlProps {
|
|
344
|
+
/** Position on the map (default: 'top-right') */
|
|
345
|
+
position?: ExtendedControlPosition;
|
|
346
|
+
/** Fallback positions if primary is occupied */
|
|
347
|
+
fallbacks?: ExtendedControlPosition[];
|
|
348
|
+
/** Priority for collision resolution (default: 'normal') */
|
|
349
|
+
priority?: ControlPriority;
|
|
350
|
+
/** Z-index layer (default: 'interactive') */
|
|
351
|
+
zLayer?: ZIndexLayer;
|
|
352
|
+
/** Optional unique ID (auto-generated if not provided) */
|
|
353
|
+
id?: string;
|
|
354
|
+
/** Whether the control has an expandable state */
|
|
355
|
+
hasExpandedState?: boolean;
|
|
356
|
+
/** Additional CSS class names */
|
|
357
|
+
className?: string;
|
|
358
|
+
/** Inline styles (merged with positioning styles) */
|
|
359
|
+
style?: React.CSSProperties;
|
|
360
|
+
/** Child content */
|
|
361
|
+
children: React.ReactNode;
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* CustomControl component for positioning arbitrary content on the map
|
|
365
|
+
*
|
|
366
|
+
* This component integrates with the map's positioning coordinator for
|
|
367
|
+
* collision avoidance and proper stacking with other controls.
|
|
368
|
+
*
|
|
369
|
+
* @example
|
|
370
|
+
* ```tsx
|
|
371
|
+
* <Map>
|
|
372
|
+
* <CustomControl position="top-right">
|
|
373
|
+
* <div className="bg-white p-2 rounded shadow">
|
|
374
|
+
* Custom widget content
|
|
375
|
+
* </div>
|
|
376
|
+
* </CustomControl>
|
|
377
|
+
* </Map>
|
|
378
|
+
* ```
|
|
379
|
+
*/
|
|
380
|
+
declare const CustomControl: React.FC<CustomControlProps>;
|
|
381
|
+
/**
|
|
382
|
+
* Context for accessing CustomControl methods from children
|
|
383
|
+
*/
|
|
384
|
+
interface CustomControlContextValue {
|
|
385
|
+
/** Update the expanded state of the control */
|
|
386
|
+
setExpanded: (isExpanded: boolean) => void;
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Hook to access the CustomControl context from child components
|
|
390
|
+
*
|
|
391
|
+
* @example
|
|
392
|
+
* ```tsx
|
|
393
|
+
* const MyExpandableContent = () => {
|
|
394
|
+
* const { setExpanded } = useCustomControl();
|
|
395
|
+
* return (
|
|
396
|
+
* <button onClick={() => setExpanded(true)}>Expand</button>
|
|
397
|
+
* );
|
|
398
|
+
* };
|
|
399
|
+
* ```
|
|
400
|
+
*/
|
|
401
|
+
declare function useCustomControl(): CustomControlContextValue;
|
|
402
|
+
|
|
343
403
|
/**
|
|
344
404
|
* Props for the DeckOverlay component
|
|
345
405
|
*/
|
|
@@ -423,9 +483,72 @@ declare function useMapTheme(preference?: 'light' | 'dark' | 'auto'): {
|
|
|
423
483
|
*/
|
|
424
484
|
declare function useReducedMotion(): boolean;
|
|
425
485
|
|
|
486
|
+
/**
|
|
487
|
+
* Options for useControlPosition hook
|
|
488
|
+
*/
|
|
489
|
+
interface UseControlPositionOptions {
|
|
490
|
+
/** Unique identifier for the control instance */
|
|
491
|
+
id: string;
|
|
492
|
+
/** Type of control */
|
|
493
|
+
type: ControlType;
|
|
494
|
+
/** Primary position for the control */
|
|
495
|
+
position: ExtendedControlPosition;
|
|
496
|
+
/** Fallback positions to try if primary is occupied */
|
|
497
|
+
fallbacks?: ExtendedControlPosition[];
|
|
498
|
+
/** Priority level for collision resolution (default: 'normal') */
|
|
499
|
+
priority?: ControlPriority;
|
|
500
|
+
/** Z-index layer (default: 'interactive') */
|
|
501
|
+
zLayer?: ZIndexLayer;
|
|
502
|
+
/** Whether the control has an expanded state */
|
|
503
|
+
hasExpandedState?: boolean;
|
|
504
|
+
/** Whether the control is a built-in MapLibre control */
|
|
505
|
+
isBuiltIn?: boolean;
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* Return value from useControlPosition hook
|
|
509
|
+
*/
|
|
510
|
+
interface UseControlPositionResult {
|
|
511
|
+
/** Current computed offset and position */
|
|
512
|
+
offset: ControlOffset | null;
|
|
513
|
+
/** Update the expanded state */
|
|
514
|
+
setExpanded: (isExpanded: boolean) => void;
|
|
515
|
+
/** Style object to apply to the control */
|
|
516
|
+
style: React.CSSProperties;
|
|
517
|
+
/** Whether the control should be visible */
|
|
518
|
+
visible: boolean;
|
|
519
|
+
}
|
|
520
|
+
/**
|
|
521
|
+
* Hook for registering a control with the positioning coordinator
|
|
522
|
+
*
|
|
523
|
+
* Handles auto-registration on mount, dimension updates via ResizeObserver,
|
|
524
|
+
* and cleanup on unmount.
|
|
525
|
+
*
|
|
526
|
+
* @param ref - Ref to the control element
|
|
527
|
+
* @param options - Control registration options
|
|
528
|
+
* @returns Position offset, visibility, and style to apply
|
|
529
|
+
*
|
|
530
|
+
* @example
|
|
531
|
+
* ```tsx
|
|
532
|
+
* const legendRef = useRef<HTMLDivElement>(null);
|
|
533
|
+
* const { style, visible, setExpanded } = useControlPosition(legendRef, {
|
|
534
|
+
* id: 'legend-1',
|
|
535
|
+
* type: 'legend',
|
|
536
|
+
* position: 'bottom-left',
|
|
537
|
+
* priority: 'normal',
|
|
538
|
+
* });
|
|
539
|
+
*
|
|
540
|
+
* return (
|
|
541
|
+
* <div ref={legendRef} style={style} hidden={!visible}>
|
|
542
|
+
* ...
|
|
543
|
+
* </div>
|
|
544
|
+
* );
|
|
545
|
+
* ```
|
|
546
|
+
*/
|
|
547
|
+
declare function useControlPosition(ref: React.RefObject<HTMLElement | null>, options: UseControlPositionOptions): UseControlPositionResult;
|
|
548
|
+
|
|
426
549
|
/**
|
|
427
550
|
* Merge class names with Tailwind CSS conflict resolution
|
|
428
551
|
*/
|
|
429
552
|
declare function cn(...inputs: ClassValue[]): string;
|
|
430
553
|
|
|
431
|
-
export { BasemapSwitcher, type BasemapSwitcherComponentProps, CircleLayer, type CircleLayerComponentProps, CoordinateDisplay, type CoordinateDisplayComponentProps, DeckOverlay, type DeckOverlayProps, FillExtrusionLayer, type FillExtrusionLayerComponentProps, FillLayer, type FillLayerComponentProps, HeatmapLayer, type HeatmapLayerComponentProps, LayerManager, type LayerManagerComponentProps, Legend, type LegendComponentProps, LegendGroup, type LegendGroupComponentProps, LineLayer, type LineLayerComponentProps, Map, type MapComponentProps, MapContainer, type MapContainerProps, MapContext, type MapContextValue, MapEmpty, type MapEmptyProps, MapError, type MapErrorProps, MapSkeleton, type MapSkeletonProps, Marker, type MarkerComponentProps, Popup, PopupCard, type PopupCardProps, type PopupComponentProps, PopupContent, type PopupContentProps, PopupFooter, type PopupFooterProps, PopupHeader, type PopupHeaderProps, type ReactFeatureClickEventParams, type ReactFeatureHoverEventParams, Source, type SourceComponentProps, SymbolLayer, type SymbolLayerComponentProps, type UseLayerOptions, cn, useLayer, useMap, useMapInstance, useMapTheme, useReducedMotion };
|
|
554
|
+
export { BasemapSwitcher, type BasemapSwitcherComponentProps, CircleLayer, type CircleLayerComponentProps, CoordinateDisplay, type CoordinateDisplayComponentProps, CustomControl, type CustomControlContextValue, type CustomControlProps, DeckOverlay, type DeckOverlayProps, FillExtrusionLayer, type FillExtrusionLayerComponentProps, FillLayer, type FillLayerComponentProps, HeatmapLayer, type HeatmapLayerComponentProps, LayerManager, type LayerManagerComponentProps, Legend, type LegendComponentProps, LegendGroup, type LegendGroupComponentProps, LineLayer, type LineLayerComponentProps, Map, type MapComponentProps, MapContainer, type MapContainerProps, MapContext, type MapContextValue, MapEmpty, type MapEmptyProps, MapError, type MapErrorProps, MapSkeleton, type MapSkeletonProps, Marker, type MarkerComponentProps, Popup, PopupCard, type PopupCardProps, type PopupComponentProps, PopupContent, type PopupContentProps, PopupFooter, type PopupFooterProps, PopupHeader, type PopupHeaderProps, type ReactFeatureClickEventParams, type ReactFeatureHoverEventParams, Source, type SourceComponentProps, SymbolLayer, type SymbolLayerComponentProps, type UseControlPositionOptions, type UseControlPositionResult, type UseLayerOptions, cn, useControlPosition, useCustomControl, useLayer, useMap, useMapInstance, useMapTheme, useReducedMotion };
|
package/dist/index.js
CHANGED
|
@@ -7,8 +7,8 @@ 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 { createPositioningCoordinator, generateMapDescription, applyMarkerProtection, applyMarkerChildProtection, removeMarkerProtection,
|
|
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';
|
|
10
|
+
import { createPositioningCoordinator, generateMapDescription, applyMarkerProtection, applyMarkerChildProtection, removeMarkerProtection, DEFAULT_BASEMAP, 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
|
+
export { BIKE_LANES, BUILTIN_BASEMAPS, BUILTIN_OVERLAY_LAYERS, CATEGORY_META, CITY_LIMITS, DEFAULT_BASEMAP, FLOOD_ZONES, FREE_BASEMAPS, OSM_STANDARD, PARKS, PRIMARY_BASEMAPS, SATELLITE_BASEMAP, SCHOOL_DISTRICTS, SPORTS_FACILITIES, THEME_DARK, THEME_LIGHT, TOPO_BASEMAP, 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';
|
|
@@ -257,7 +257,8 @@ function useMapTheme(preference = "auto") {
|
|
|
257
257
|
return {
|
|
258
258
|
themeName: isDark ? THEME_DARK : THEME_LIGHT,
|
|
259
259
|
theme: isDark ? darkTheme : lightTheme,
|
|
260
|
-
style
|
|
260
|
+
// Use the default MapTiler basemap style (works well for both light and dark modes)
|
|
261
|
+
style: DEFAULT_BASEMAP.style,
|
|
261
262
|
isDark
|
|
262
263
|
};
|
|
263
264
|
}
|
|
@@ -683,8 +684,8 @@ var Source = ({
|
|
|
683
684
|
children
|
|
684
685
|
}) => {
|
|
685
686
|
const { map, loaded, styleVersion } = useMap();
|
|
686
|
-
const sourceAdded = React26.useRef(false);
|
|
687
687
|
const initialFitDone = React26.useRef(false);
|
|
688
|
+
const lastStyleVersionRef = React26.useRef(styleVersion);
|
|
688
689
|
const fitBoundsParamsRef = React26.useRef({
|
|
689
690
|
shouldFitBounds,
|
|
690
691
|
data,
|
|
@@ -746,9 +747,12 @@ var Source = ({
|
|
|
746
747
|
[map]
|
|
747
748
|
);
|
|
748
749
|
React26.useEffect(() => {
|
|
749
|
-
if (!map || !loaded
|
|
750
|
+
if (!map || !loaded) return;
|
|
751
|
+
if (styleVersion !== lastStyleVersionRef.current) {
|
|
752
|
+
lastStyleVersionRef.current = styleVersion;
|
|
753
|
+
initialFitDone.current = false;
|
|
754
|
+
}
|
|
750
755
|
if (map.getSource(id)) {
|
|
751
|
-
sourceAdded.current = true;
|
|
752
756
|
return;
|
|
753
757
|
}
|
|
754
758
|
try {
|
|
@@ -835,7 +839,6 @@ var Source = ({
|
|
|
835
839
|
};
|
|
836
840
|
map.once("idle", handleIdle);
|
|
837
841
|
map.addSource(id, sourceConfig);
|
|
838
|
-
sourceAdded.current = true;
|
|
839
842
|
const source = map.getSource(id);
|
|
840
843
|
if (source && map.isSourceLoaded(id)) {
|
|
841
844
|
map.off("sourcedata", handleSourceData);
|
|
@@ -853,7 +856,7 @@ var Source = ({
|
|
|
853
856
|
};
|
|
854
857
|
return () => {
|
|
855
858
|
cleanupListeners();
|
|
856
|
-
if (map
|
|
859
|
+
if (map) {
|
|
857
860
|
try {
|
|
858
861
|
const style = map.getStyle();
|
|
859
862
|
if (style?.layers) {
|
|
@@ -870,7 +873,6 @@ var Source = ({
|
|
|
870
873
|
}
|
|
871
874
|
} catch {
|
|
872
875
|
}
|
|
873
|
-
sourceAdded.current = false;
|
|
874
876
|
}
|
|
875
877
|
};
|
|
876
878
|
} catch (err) {
|
|
@@ -896,7 +898,7 @@ var Source = ({
|
|
|
896
898
|
// re-add source after basemap style changes
|
|
897
899
|
]);
|
|
898
900
|
React26.useEffect(() => {
|
|
899
|
-
if (!map || !loaded ||
|
|
901
|
+
if (!map || !loaded || type !== "geojson") return;
|
|
900
902
|
const source = map.getSource(id);
|
|
901
903
|
if (!source) return;
|
|
902
904
|
let cancelled = false;
|
|
@@ -3211,6 +3213,42 @@ var LayerManager = ({
|
|
|
3211
3213
|
] });
|
|
3212
3214
|
};
|
|
3213
3215
|
LayerManager.displayName = "LayerManager";
|
|
3216
|
+
var customControlIdCounter = 0;
|
|
3217
|
+
var CustomControl = ({
|
|
3218
|
+
position = "top-right",
|
|
3219
|
+
fallbacks,
|
|
3220
|
+
priority = "normal",
|
|
3221
|
+
zLayer = "interactive",
|
|
3222
|
+
id,
|
|
3223
|
+
hasExpandedState = false,
|
|
3224
|
+
className,
|
|
3225
|
+
style: userStyle,
|
|
3226
|
+
children
|
|
3227
|
+
}) => {
|
|
3228
|
+
const controlRef = React26.useRef(null);
|
|
3229
|
+
const controlIdRef = React26.useRef(id ?? `custom-control-${++customControlIdCounter}`);
|
|
3230
|
+
const { style, visible, setExpanded } = useControlPosition(controlRef, {
|
|
3231
|
+
id: controlIdRef.current,
|
|
3232
|
+
type: "custom",
|
|
3233
|
+
position,
|
|
3234
|
+
fallbacks,
|
|
3235
|
+
priority,
|
|
3236
|
+
zLayer,
|
|
3237
|
+
hasExpandedState
|
|
3238
|
+
});
|
|
3239
|
+
const mergedStyle = React26.useMemo(() => ({ ...style, ...userStyle }), [style, userStyle]);
|
|
3240
|
+
const contextValue = React26.useMemo(() => ({ setExpanded }), [setExpanded]);
|
|
3241
|
+
return /* @__PURE__ */ jsx(CustomControlContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx("div", { ref: controlRef, className: cn(!visible && "invisible", className), style: mergedStyle, children }) });
|
|
3242
|
+
};
|
|
3243
|
+
CustomControl.displayName = "CustomControl";
|
|
3244
|
+
var CustomControlContext = React26.createContext(null);
|
|
3245
|
+
function useCustomControl() {
|
|
3246
|
+
const context = React26.useContext(CustomControlContext);
|
|
3247
|
+
if (!context) {
|
|
3248
|
+
throw new Error("useCustomControl must be used within a CustomControl");
|
|
3249
|
+
}
|
|
3250
|
+
return context;
|
|
3251
|
+
}
|
|
3214
3252
|
var DeckOverlay = ({
|
|
3215
3253
|
layers = [],
|
|
3216
3254
|
onHover,
|
|
@@ -3285,4 +3323,4 @@ var DeckOverlay = ({
|
|
|
3285
3323
|
};
|
|
3286
3324
|
DeckOverlay.displayName = "DeckOverlay";
|
|
3287
3325
|
|
|
3288
|
-
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 };
|
|
3326
|
+
export { BasemapSwitcher, CircleLayer, CoordinateDisplay, CustomControl, 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, useControlPosition, useCustomControl, useLayer, useMap, useMapInstance, useMapTheme, useReducedMotion };
|