@classic-homes/maps-react 0.2.5 → 0.2.7
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 +69 -10
- package/dist/index.d.cts +127 -4
- package/dist/index.d.ts +127 -4
- package/dist/index.js +53 -13
- 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
|
}
|
|
@@ -439,8 +440,10 @@ var Map2 = React26__namespace.forwardRef(
|
|
|
439
440
|
attributionControl: attributionControl ? { customAttribution } : false
|
|
440
441
|
});
|
|
441
442
|
mapRef.current = map;
|
|
442
|
-
map.on("
|
|
443
|
-
|
|
443
|
+
map.on("data", (e) => {
|
|
444
|
+
if (e.dataType === "style") {
|
|
445
|
+
setStyleVersion((v) => v + 1);
|
|
446
|
+
}
|
|
444
447
|
});
|
|
445
448
|
if (navigationControl) {
|
|
446
449
|
map.addControl(
|
|
@@ -707,8 +710,8 @@ var Source = ({
|
|
|
707
710
|
children
|
|
708
711
|
}) => {
|
|
709
712
|
const { map, loaded, styleVersion } = useMap();
|
|
710
|
-
const sourceAdded = React26__namespace.useRef(false);
|
|
711
713
|
const initialFitDone = React26__namespace.useRef(false);
|
|
714
|
+
const lastStyleVersionRef = React26__namespace.useRef(styleVersion);
|
|
712
715
|
const fitBoundsParamsRef = React26__namespace.useRef({
|
|
713
716
|
shouldFitBounds,
|
|
714
717
|
data,
|
|
@@ -770,9 +773,12 @@ var Source = ({
|
|
|
770
773
|
[map]
|
|
771
774
|
);
|
|
772
775
|
React26__namespace.useEffect(() => {
|
|
773
|
-
if (!map || !loaded
|
|
776
|
+
if (!map || !loaded) return;
|
|
777
|
+
if (styleVersion !== lastStyleVersionRef.current) {
|
|
778
|
+
lastStyleVersionRef.current = styleVersion;
|
|
779
|
+
initialFitDone.current = false;
|
|
780
|
+
}
|
|
774
781
|
if (map.getSource(id)) {
|
|
775
|
-
sourceAdded.current = true;
|
|
776
782
|
return;
|
|
777
783
|
}
|
|
778
784
|
try {
|
|
@@ -859,7 +865,6 @@ var Source = ({
|
|
|
859
865
|
};
|
|
860
866
|
map.once("idle", handleIdle);
|
|
861
867
|
map.addSource(id, sourceConfig);
|
|
862
|
-
sourceAdded.current = true;
|
|
863
868
|
const source = map.getSource(id);
|
|
864
869
|
if (source && map.isSourceLoaded(id)) {
|
|
865
870
|
map.off("sourcedata", handleSourceData);
|
|
@@ -877,7 +882,7 @@ var Source = ({
|
|
|
877
882
|
};
|
|
878
883
|
return () => {
|
|
879
884
|
cleanupListeners();
|
|
880
|
-
if (map
|
|
885
|
+
if (map) {
|
|
881
886
|
try {
|
|
882
887
|
const style = map.getStyle();
|
|
883
888
|
if (style?.layers) {
|
|
@@ -894,7 +899,6 @@ var Source = ({
|
|
|
894
899
|
}
|
|
895
900
|
} catch {
|
|
896
901
|
}
|
|
897
|
-
sourceAdded.current = false;
|
|
898
902
|
}
|
|
899
903
|
};
|
|
900
904
|
} catch (err) {
|
|
@@ -920,7 +924,7 @@ var Source = ({
|
|
|
920
924
|
// re-add source after basemap style changes
|
|
921
925
|
]);
|
|
922
926
|
React26__namespace.useEffect(() => {
|
|
923
|
-
if (!map || !loaded ||
|
|
927
|
+
if (!map || !loaded || type !== "geojson") return;
|
|
924
928
|
const source = map.getSource(id);
|
|
925
929
|
if (!source) return;
|
|
926
930
|
let cancelled = false;
|
|
@@ -3235,6 +3239,42 @@ var LayerManager = ({
|
|
|
3235
3239
|
] });
|
|
3236
3240
|
};
|
|
3237
3241
|
LayerManager.displayName = "LayerManager";
|
|
3242
|
+
var customControlIdCounter = 0;
|
|
3243
|
+
var CustomControl = ({
|
|
3244
|
+
position = "top-right",
|
|
3245
|
+
fallbacks,
|
|
3246
|
+
priority = "normal",
|
|
3247
|
+
zLayer = "interactive",
|
|
3248
|
+
id,
|
|
3249
|
+
hasExpandedState = false,
|
|
3250
|
+
className,
|
|
3251
|
+
style: userStyle,
|
|
3252
|
+
children
|
|
3253
|
+
}) => {
|
|
3254
|
+
const controlRef = React26__namespace.useRef(null);
|
|
3255
|
+
const controlIdRef = React26__namespace.useRef(id ?? `custom-control-${++customControlIdCounter}`);
|
|
3256
|
+
const { style, visible, setExpanded } = useControlPosition(controlRef, {
|
|
3257
|
+
id: controlIdRef.current,
|
|
3258
|
+
type: "custom",
|
|
3259
|
+
position,
|
|
3260
|
+
fallbacks,
|
|
3261
|
+
priority,
|
|
3262
|
+
zLayer,
|
|
3263
|
+
hasExpandedState
|
|
3264
|
+
});
|
|
3265
|
+
const mergedStyle = React26__namespace.useMemo(() => ({ ...style, ...userStyle }), [style, userStyle]);
|
|
3266
|
+
const contextValue = React26__namespace.useMemo(() => ({ setExpanded }), [setExpanded]);
|
|
3267
|
+
return /* @__PURE__ */ jsxRuntime.jsx(CustomControlContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsxRuntime.jsx("div", { ref: controlRef, className: cn(!visible && "invisible", className), style: mergedStyle, children }) });
|
|
3268
|
+
};
|
|
3269
|
+
CustomControl.displayName = "CustomControl";
|
|
3270
|
+
var CustomControlContext = React26__namespace.createContext(null);
|
|
3271
|
+
function useCustomControl() {
|
|
3272
|
+
const context = React26__namespace.useContext(CustomControlContext);
|
|
3273
|
+
if (!context) {
|
|
3274
|
+
throw new Error("useCustomControl must be used within a CustomControl");
|
|
3275
|
+
}
|
|
3276
|
+
return context;
|
|
3277
|
+
}
|
|
3238
3278
|
var DeckOverlay = ({
|
|
3239
3279
|
layers = [],
|
|
3240
3280
|
onHover,
|
|
@@ -3329,6 +3369,10 @@ Object.defineProperty(exports, "CITY_LIMITS", {
|
|
|
3329
3369
|
enumerable: true,
|
|
3330
3370
|
get: function () { return mapsCore.CITY_LIMITS; }
|
|
3331
3371
|
});
|
|
3372
|
+
Object.defineProperty(exports, "DEFAULT_BASEMAP", {
|
|
3373
|
+
enumerable: true,
|
|
3374
|
+
get: function () { return mapsCore.DEFAULT_BASEMAP; }
|
|
3375
|
+
});
|
|
3332
3376
|
Object.defineProperty(exports, "FLOOD_ZONES", {
|
|
3333
3377
|
enumerable: true,
|
|
3334
3378
|
get: function () { return mapsCore.FLOOD_ZONES; }
|
|
@@ -3345,6 +3389,14 @@ Object.defineProperty(exports, "PARKS", {
|
|
|
3345
3389
|
enumerable: true,
|
|
3346
3390
|
get: function () { return mapsCore.PARKS; }
|
|
3347
3391
|
});
|
|
3392
|
+
Object.defineProperty(exports, "PRIMARY_BASEMAPS", {
|
|
3393
|
+
enumerable: true,
|
|
3394
|
+
get: function () { return mapsCore.PRIMARY_BASEMAPS; }
|
|
3395
|
+
});
|
|
3396
|
+
Object.defineProperty(exports, "SATELLITE_BASEMAP", {
|
|
3397
|
+
enumerable: true,
|
|
3398
|
+
get: function () { return mapsCore.SATELLITE_BASEMAP; }
|
|
3399
|
+
});
|
|
3348
3400
|
Object.defineProperty(exports, "SCHOOL_DISTRICTS", {
|
|
3349
3401
|
enumerable: true,
|
|
3350
3402
|
get: function () { return mapsCore.SCHOOL_DISTRICTS; }
|
|
@@ -3361,6 +3413,10 @@ Object.defineProperty(exports, "THEME_LIGHT", {
|
|
|
3361
3413
|
enumerable: true,
|
|
3362
3414
|
get: function () { return mapsCore.THEME_LIGHT; }
|
|
3363
3415
|
});
|
|
3416
|
+
Object.defineProperty(exports, "TOPO_BASEMAP", {
|
|
3417
|
+
enumerable: true,
|
|
3418
|
+
get: function () { return mapsCore.TOPO_BASEMAP; }
|
|
3419
|
+
});
|
|
3364
3420
|
Object.defineProperty(exports, "TRAILS", {
|
|
3365
3421
|
enumerable: true,
|
|
3366
3422
|
get: function () { return mapsCore.TRAILS; }
|
|
@@ -3536,6 +3592,7 @@ Object.defineProperty(exports, "validateGeoJSON", {
|
|
|
3536
3592
|
exports.BasemapSwitcher = BasemapSwitcher;
|
|
3537
3593
|
exports.CircleLayer = CircleLayer;
|
|
3538
3594
|
exports.CoordinateDisplay = CoordinateDisplay;
|
|
3595
|
+
exports.CustomControl = CustomControl;
|
|
3539
3596
|
exports.DeckOverlay = DeckOverlay;
|
|
3540
3597
|
exports.FillExtrusionLayer = FillExtrusionLayer;
|
|
3541
3598
|
exports.FillLayer = FillLayer;
|
|
@@ -3559,6 +3616,8 @@ exports.PopupHeader = PopupHeader;
|
|
|
3559
3616
|
exports.Source = Source;
|
|
3560
3617
|
exports.SymbolLayer = SymbolLayer;
|
|
3561
3618
|
exports.cn = cn;
|
|
3619
|
+
exports.useControlPosition = useControlPosition;
|
|
3620
|
+
exports.useCustomControl = useCustomControl;
|
|
3562
3621
|
exports.useLayer = useLayer;
|
|
3563
3622
|
exports.useMap = useMap;
|
|
3564
3623
|
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';
|
|
@@ -108,7 +108,7 @@ interface MapContextValue {
|
|
|
108
108
|
map: Map$1 | null;
|
|
109
109
|
/** Whether the map has loaded */
|
|
110
110
|
loaded: boolean;
|
|
111
|
-
/** Counter incremented on each style
|
|
111
|
+
/** Counter incremented on each style change (via data event), used to re-initialize sources/layers */
|
|
112
112
|
styleVersion: number;
|
|
113
113
|
/** Set the map style programmatically (e.g. basemap switching) */
|
|
114
114
|
setMapStyle?: (style: string | StyleSpecification) => void;
|
|
@@ -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';
|
|
@@ -108,7 +108,7 @@ interface MapContextValue {
|
|
|
108
108
|
map: Map$1 | null;
|
|
109
109
|
/** Whether the map has loaded */
|
|
110
110
|
loaded: boolean;
|
|
111
|
-
/** Counter incremented on each style
|
|
111
|
+
/** Counter incremented on each style change (via data event), used to re-initialize sources/layers */
|
|
112
112
|
styleVersion: number;
|
|
113
113
|
/** Set the map style programmatically (e.g. basemap switching) */
|
|
114
114
|
setMapStyle?: (style: string | StyleSpecification) => void;
|
|
@@ -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
|
}
|
|
@@ -415,8 +416,10 @@ var Map2 = React26.forwardRef(
|
|
|
415
416
|
attributionControl: attributionControl ? { customAttribution } : false
|
|
416
417
|
});
|
|
417
418
|
mapRef.current = map;
|
|
418
|
-
map.on("
|
|
419
|
-
|
|
419
|
+
map.on("data", (e) => {
|
|
420
|
+
if (e.dataType === "style") {
|
|
421
|
+
setStyleVersion((v) => v + 1);
|
|
422
|
+
}
|
|
420
423
|
});
|
|
421
424
|
if (navigationControl) {
|
|
422
425
|
map.addControl(
|
|
@@ -683,8 +686,8 @@ var Source = ({
|
|
|
683
686
|
children
|
|
684
687
|
}) => {
|
|
685
688
|
const { map, loaded, styleVersion } = useMap();
|
|
686
|
-
const sourceAdded = React26.useRef(false);
|
|
687
689
|
const initialFitDone = React26.useRef(false);
|
|
690
|
+
const lastStyleVersionRef = React26.useRef(styleVersion);
|
|
688
691
|
const fitBoundsParamsRef = React26.useRef({
|
|
689
692
|
shouldFitBounds,
|
|
690
693
|
data,
|
|
@@ -746,9 +749,12 @@ var Source = ({
|
|
|
746
749
|
[map]
|
|
747
750
|
);
|
|
748
751
|
React26.useEffect(() => {
|
|
749
|
-
if (!map || !loaded
|
|
752
|
+
if (!map || !loaded) return;
|
|
753
|
+
if (styleVersion !== lastStyleVersionRef.current) {
|
|
754
|
+
lastStyleVersionRef.current = styleVersion;
|
|
755
|
+
initialFitDone.current = false;
|
|
756
|
+
}
|
|
750
757
|
if (map.getSource(id)) {
|
|
751
|
-
sourceAdded.current = true;
|
|
752
758
|
return;
|
|
753
759
|
}
|
|
754
760
|
try {
|
|
@@ -835,7 +841,6 @@ var Source = ({
|
|
|
835
841
|
};
|
|
836
842
|
map.once("idle", handleIdle);
|
|
837
843
|
map.addSource(id, sourceConfig);
|
|
838
|
-
sourceAdded.current = true;
|
|
839
844
|
const source = map.getSource(id);
|
|
840
845
|
if (source && map.isSourceLoaded(id)) {
|
|
841
846
|
map.off("sourcedata", handleSourceData);
|
|
@@ -853,7 +858,7 @@ var Source = ({
|
|
|
853
858
|
};
|
|
854
859
|
return () => {
|
|
855
860
|
cleanupListeners();
|
|
856
|
-
if (map
|
|
861
|
+
if (map) {
|
|
857
862
|
try {
|
|
858
863
|
const style = map.getStyle();
|
|
859
864
|
if (style?.layers) {
|
|
@@ -870,7 +875,6 @@ var Source = ({
|
|
|
870
875
|
}
|
|
871
876
|
} catch {
|
|
872
877
|
}
|
|
873
|
-
sourceAdded.current = false;
|
|
874
878
|
}
|
|
875
879
|
};
|
|
876
880
|
} catch (err) {
|
|
@@ -896,7 +900,7 @@ var Source = ({
|
|
|
896
900
|
// re-add source after basemap style changes
|
|
897
901
|
]);
|
|
898
902
|
React26.useEffect(() => {
|
|
899
|
-
if (!map || !loaded ||
|
|
903
|
+
if (!map || !loaded || type !== "geojson") return;
|
|
900
904
|
const source = map.getSource(id);
|
|
901
905
|
if (!source) return;
|
|
902
906
|
let cancelled = false;
|
|
@@ -3211,6 +3215,42 @@ var LayerManager = ({
|
|
|
3211
3215
|
] });
|
|
3212
3216
|
};
|
|
3213
3217
|
LayerManager.displayName = "LayerManager";
|
|
3218
|
+
var customControlIdCounter = 0;
|
|
3219
|
+
var CustomControl = ({
|
|
3220
|
+
position = "top-right",
|
|
3221
|
+
fallbacks,
|
|
3222
|
+
priority = "normal",
|
|
3223
|
+
zLayer = "interactive",
|
|
3224
|
+
id,
|
|
3225
|
+
hasExpandedState = false,
|
|
3226
|
+
className,
|
|
3227
|
+
style: userStyle,
|
|
3228
|
+
children
|
|
3229
|
+
}) => {
|
|
3230
|
+
const controlRef = React26.useRef(null);
|
|
3231
|
+
const controlIdRef = React26.useRef(id ?? `custom-control-${++customControlIdCounter}`);
|
|
3232
|
+
const { style, visible, setExpanded } = useControlPosition(controlRef, {
|
|
3233
|
+
id: controlIdRef.current,
|
|
3234
|
+
type: "custom",
|
|
3235
|
+
position,
|
|
3236
|
+
fallbacks,
|
|
3237
|
+
priority,
|
|
3238
|
+
zLayer,
|
|
3239
|
+
hasExpandedState
|
|
3240
|
+
});
|
|
3241
|
+
const mergedStyle = React26.useMemo(() => ({ ...style, ...userStyle }), [style, userStyle]);
|
|
3242
|
+
const contextValue = React26.useMemo(() => ({ setExpanded }), [setExpanded]);
|
|
3243
|
+
return /* @__PURE__ */ jsx(CustomControlContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx("div", { ref: controlRef, className: cn(!visible && "invisible", className), style: mergedStyle, children }) });
|
|
3244
|
+
};
|
|
3245
|
+
CustomControl.displayName = "CustomControl";
|
|
3246
|
+
var CustomControlContext = React26.createContext(null);
|
|
3247
|
+
function useCustomControl() {
|
|
3248
|
+
const context = React26.useContext(CustomControlContext);
|
|
3249
|
+
if (!context) {
|
|
3250
|
+
throw new Error("useCustomControl must be used within a CustomControl");
|
|
3251
|
+
}
|
|
3252
|
+
return context;
|
|
3253
|
+
}
|
|
3214
3254
|
var DeckOverlay = ({
|
|
3215
3255
|
layers = [],
|
|
3216
3256
|
onHover,
|
|
@@ -3285,4 +3325,4 @@ var DeckOverlay = ({
|
|
|
3285
3325
|
};
|
|
3286
3326
|
DeckOverlay.displayName = "DeckOverlay";
|
|
3287
3327
|
|
|
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 };
|
|
3328
|
+
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 };
|