@tracktor/map 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/MarkerMap/MarkerMap.d.ts +55 -0
- package/dist/components/MarkerMap/useMarkerMap.d.ts +12 -0
- package/dist/types/Markers.d.ts +41 -0
- package/dist/utils/addPopup.d.ts +32 -4
- package/dist/utils/coordinateConverter.d.ts +11 -2
- package/dist/utils/handleMapClick.d.ts +15 -4
- package/dist/utils/loadMarkers.d.ts +35 -9
- package/dist/utils/mapOptions.d.ts +31 -6
- package/package.json +1 -1
|
@@ -1,3 +1,58 @@
|
|
|
1
1
|
import { MarkerMapProps } from '../../types/MarkerMap.tsx';
|
|
2
|
+
/**
|
|
3
|
+
* MarkerMap is a reusable React component that displays an interactive Mapbox map
|
|
4
|
+
* with customizable markers and behavior.
|
|
5
|
+
*
|
|
6
|
+
* It supports features like:
|
|
7
|
+
* - Auto-fitting bounds to markers
|
|
8
|
+
* - Custom marker icons and tooltips
|
|
9
|
+
* - Light/dark theming
|
|
10
|
+
* - Fly animations and zooming
|
|
11
|
+
* - Popup display (on click or hover)
|
|
12
|
+
* - Custom styling for the map container
|
|
13
|
+
* - Manual or automatic control of map centering and zoom
|
|
14
|
+
*
|
|
15
|
+
* @param {object} props - Props used to configure the map rendering.
|
|
16
|
+
* @param {boolean} [props.fitBounds] - If true, automatically adjusts the viewport to fit all markers.
|
|
17
|
+
* @param {number} [props.fitBoundsPadding] - Padding in pixels when fitting bounds to markers.
|
|
18
|
+
* @param {LngLatLike | number[]} [props.center] - Initial center of the map [lng, lat].
|
|
19
|
+
* @param {string} [props.mapStyle] - Mapbox style URL or identifier (e.g. "mapbox://styles/mapbox/streets-v11").
|
|
20
|
+
* @param {number} [props.zoom] - Initial zoom level of the map.
|
|
21
|
+
* @param {number} [props.zoomFlyFrom] - Zoom level to use before initiating a flyTo animation.
|
|
22
|
+
* @param {string} [props.popupMaxWidth] - Maximum width of popups (e.g., "200px").
|
|
23
|
+
* @param {number | string} [props.width="100%"] - Width of the map container.
|
|
24
|
+
* @param {number | string} [props.height=300] - Height of the map container.
|
|
25
|
+
* @param {boolean} [props.loading] - Optional flag indicating if the map is in loading state.
|
|
26
|
+
* @param {string} [props.markerImageURL] - URL of a custom image used for default marker icons.
|
|
27
|
+
* @param {SxProps} [props.containerStyle] - Style object (MUI `sx`) to customize the map container.
|
|
28
|
+
* @param {boolean} [props.disableFlyTo] - If true, disables flyTo animation when focusing on a marker.
|
|
29
|
+
* @param {number} [props.flyToDuration] - Duration of fly animation in milliseconds.
|
|
30
|
+
* @param {number} [props.fitBoundDuration] - Duration of fitBounds animation in milliseconds.
|
|
31
|
+
* @param {boolean} [props.square] - If true, forces the map container to be a square.
|
|
32
|
+
* @param {number | string} [props.openPopup] - ID of the marker whose popup should be open by default.
|
|
33
|
+
* @param {boolean} [props.openPopupOnHover] - If true, opens the popup on marker hover instead of click.
|
|
34
|
+
* @param {MarkerProps[]} [props.markers] - Array of marker objects to render on the map.
|
|
35
|
+
* @param {(lng: number, lat: number) => void} [props.onMapClick] - Callback triggered when the map is clicked.
|
|
36
|
+
* @param {"light" | "dark" | ThemeOptions} [props.theme] - Optional theme override for map rendering.
|
|
37
|
+
*
|
|
38
|
+
* @returns {JSX.Element} The rendered map component with optional markers and behavior.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```tsx
|
|
42
|
+
* <MarkerMap
|
|
43
|
+
* center={[2.3488, 48.8534]}
|
|
44
|
+
* zoom={13}
|
|
45
|
+
* fitBounds
|
|
46
|
+
* markers={[
|
|
47
|
+
* { id: 1, lat: 48.8534, lng: 2.3488, name: "Marker 1" },
|
|
48
|
+
* { id: 2, lat: 48.8566, lng: 2.3522, name: "Marker 2" },
|
|
49
|
+
* ]}
|
|
50
|
+
* openPopupOnHover
|
|
51
|
+
* popupMaxWidth="250px"
|
|
52
|
+
* mapStyle="mapbox://styles/mapbox/light-v10"
|
|
53
|
+
* theme="light"
|
|
54
|
+
* />
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
2
57
|
declare const MarkerMap: ({ containerStyle, square, theme, height, width, ...props }: MarkerMapProps) => import("react/jsx-runtime").JSX.Element;
|
|
3
58
|
export default MarkerMap;
|
|
@@ -2,6 +2,18 @@ import { Map } from 'mapbox-gl';
|
|
|
2
2
|
import { MarkerMapProps } from '../../types/MarkerMap.tsx';
|
|
3
3
|
export declare const DEFAULT_CENTER_LNG = 2.333;
|
|
4
4
|
export declare const DEFAULT_CENTER_LAT = 46.8677;
|
|
5
|
+
/**
|
|
6
|
+
* Custom React hook to integrate and manage a Mapbox map instance with dynamic markers,
|
|
7
|
+
* popups, zooming, centering, and click handling.
|
|
8
|
+
*
|
|
9
|
+
* This hook:
|
|
10
|
+
* - Initializes a Mapbox map inside a container
|
|
11
|
+
* - Loads and displays markers on the map
|
|
12
|
+
* - Adds popups to specific markers when requested
|
|
13
|
+
* - Adjusts the map center or fits bounds based on markers
|
|
14
|
+
* - Handles map click events with a provided callback
|
|
15
|
+
* - Supports customizable flyTo behavior, zoom levels, and map style
|
|
16
|
+
*/
|
|
5
17
|
declare const useMarkerMap: ({ markers, loading, center, flyToDuration, fitBoundDuration, fitBounds, disableFlyTo, fitBoundsPadding, mapStyle, zoom, zoomFlyFrom, openPopup, onMapClick, }: MarkerMapProps) => {
|
|
6
18
|
loading: boolean | undefined;
|
|
7
19
|
map: import('react').RefObject<Map | null>;
|
package/dist/types/Markers.d.ts
CHANGED
|
@@ -1,15 +1,56 @@
|
|
|
1
1
|
import { default as React, ReactNode } from 'react';
|
|
2
2
|
export interface MarkerProps {
|
|
3
|
+
/**
|
|
4
|
+
* Optional unique identifier for the marker.
|
|
5
|
+
*/
|
|
3
6
|
id?: number | string;
|
|
7
|
+
/**
|
|
8
|
+
* Longitude coordinate of the marker.
|
|
9
|
+
* Should be a number; using 'unknown' allows flexibility but requires validation.
|
|
10
|
+
*/
|
|
4
11
|
lng: number | unknown;
|
|
12
|
+
/**
|
|
13
|
+
* Latitude coordinate of the marker.
|
|
14
|
+
* Should be a number; using 'unknown' allows flexibility but requires validation.
|
|
15
|
+
*/
|
|
5
16
|
lat: number | unknown;
|
|
17
|
+
/**
|
|
18
|
+
* Optional tooltip element displayed when hovering or clicking on the marker.
|
|
19
|
+
* Can be a React component or any ReactNode.
|
|
20
|
+
*/
|
|
6
21
|
Tooltip?: ReactNode;
|
|
22
|
+
/**
|
|
23
|
+
* URL or name of the icon image to display for the marker.
|
|
24
|
+
* Only used if no IconComponent is provided.
|
|
25
|
+
*/
|
|
7
26
|
iconImage?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Optional size (scale) of the marker icon.
|
|
29
|
+
*/
|
|
8
30
|
size?: number;
|
|
31
|
+
/**
|
|
32
|
+
* Z-index to control layering of the marker relative to others.
|
|
33
|
+
*/
|
|
9
34
|
zIndex?: number;
|
|
35
|
+
/**
|
|
36
|
+
* Function to call when the marker is clicked.
|
|
37
|
+
*/
|
|
10
38
|
onClick?: () => void;
|
|
39
|
+
/**
|
|
40
|
+
* Optional type/category of the marker (e.g., 'restaurant', 'user', etc.).
|
|
41
|
+
*/
|
|
11
42
|
type?: string;
|
|
43
|
+
/**
|
|
44
|
+
* Optional display name for the marker.
|
|
45
|
+
*/
|
|
12
46
|
name?: string;
|
|
47
|
+
/**
|
|
48
|
+
* Optional custom React component to use as the marker icon.
|
|
49
|
+
* Overrides iconImage if provided.
|
|
50
|
+
*/
|
|
13
51
|
IconComponent?: React.ComponentType<any>;
|
|
52
|
+
/**
|
|
53
|
+
* Optional props to pass to the IconComponent.
|
|
54
|
+
*/
|
|
14
55
|
iconProps?: Record<string, any>;
|
|
15
56
|
}
|
package/dist/utils/addPopup.d.ts
CHANGED
|
@@ -6,10 +6,38 @@ interface AddPopupProps {
|
|
|
6
6
|
map: MutableRefObject<Map | null>;
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
9
|
+
* Adds a React-based popup to a Mapbox map
|
|
10
|
+
*
|
|
11
|
+
* This function creates and displays a popup on a Mapbox map with custom content rendered
|
|
12
|
+
* using React. The popup includes a styled close button and properly handles React component
|
|
13
|
+
* lifecycle to prevent memory leaks.
|
|
14
|
+
*
|
|
15
|
+
* @param {Object} options - The configuration options
|
|
16
|
+
* @param {MutableRefObject<Map | null>} options.map - Reference to the Mapbox map instance
|
|
17
|
+
* @param {ReactNode} [options.tooltip] - React node to render inside the popup
|
|
18
|
+
* @param {[number, number]} [options.coordinates] - [longitude, latitude] where the popup should appear
|
|
19
|
+
* @returns {void}
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* // Basic usage
|
|
23
|
+
* addPopup({
|
|
24
|
+
* map: mapRef,
|
|
25
|
+
* coordinates: [-73.985, 40.748],
|
|
26
|
+
* tooltip: <div>Empire State Building</div>
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* // With complex React content
|
|
31
|
+
* addPopup({
|
|
32
|
+
* map: mapRef,
|
|
33
|
+
* coordinates: marker.position,
|
|
34
|
+
* tooltip: (
|
|
35
|
+
* <InfoWindow title={marker.title}>
|
|
36
|
+
* <p>{marker.description}</p>
|
|
37
|
+
* <button onClick={handleAction}>More Info</button>
|
|
38
|
+
* </InfoWindow>
|
|
39
|
+
* )
|
|
40
|
+
* });
|
|
13
41
|
*/
|
|
14
42
|
declare const addPopup: ({ map, tooltip, coordinates }: AddPopupProps) => void;
|
|
15
43
|
export default addPopup;
|
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
import { LngLatLike } from 'mapbox-gl';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* Converts coordinates to a format compatible with Mapbox's LngLatLike type
|
|
4
|
+
*
|
|
5
|
+
* This utility function ensures coordinates are properly formatted for Mapbox operations.
|
|
6
|
+
* It handles different input formats and converts them to the expected LngLatLike format,
|
|
7
|
+
* which requires longitude and latitude values in the form [lng, lat].
|
|
8
|
+
*
|
|
9
|
+
* @param {LngLatLike | number[] | undefined} center - Coordinates to convert, which can be:
|
|
10
|
+
* - LngLatLike object (already in Mapbox format)
|
|
11
|
+
* - number array in [longitude, latitude] format
|
|
12
|
+
* - undefined (no coordinates provided)
|
|
13
|
+
* @returns {LngLatLike | undefined} - Properly formatted coordinates or undefined if invalid
|
|
5
14
|
*/
|
|
6
15
|
declare const coordinateConverter: (center: LngLatLike | number[] | undefined) => LngLatLike | undefined;
|
|
7
16
|
export default coordinateConverter;
|
|
@@ -7,9 +7,20 @@ export interface HandleMapClickProps {
|
|
|
7
7
|
event: MapMouseEvent;
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
10
|
+
* Handles map click events to display popups on clicked markers
|
|
11
|
+
*
|
|
12
|
+
* This function:
|
|
13
|
+
* 1. Identifies if a marker was clicked within the map
|
|
14
|
+
* 2. Extracts the coordinates and properties of the clicked marker
|
|
15
|
+
* 3. Finds the corresponding marker in the provided markers array
|
|
16
|
+
* 4. Displays a popup at the marker's location with its tooltip content
|
|
17
|
+
*
|
|
18
|
+
* The function only processes clicks on layers whose IDs start with "marker-".
|
|
19
|
+
*
|
|
20
|
+
* @param {Object} options - The click handler configuration
|
|
21
|
+
* @param {MutableRefObject<Map | null>} options.map - Reference to the Mapbox map instance
|
|
22
|
+
* @param {MarkerProps[]} options.markers - Array of marker objects with tooltips and properties
|
|
23
|
+
* @param {MapMouseEvent} options.event - The Mapbox mouse event triggered by clicking
|
|
24
|
+
* @returns {void}
|
|
14
25
|
*/
|
|
15
26
|
export declare const handleMapClick: ({ map, markers, event }: HandleMapClickProps) => void;
|
|
@@ -13,10 +13,28 @@ interface LoadMarkersProps {
|
|
|
13
13
|
markers: MarkerProps[];
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
16
|
+
* Generates visual styles for map markers based on theme palette and marker type
|
|
17
|
+
*
|
|
18
|
+
* Creates consistent styling for different marker types with:
|
|
19
|
+
* - Dynamic color theming (light/dark mode support)
|
|
20
|
+
* - Type-specific visual differentiation
|
|
21
|
+
* - Responsive sizing
|
|
22
|
+
*
|
|
23
|
+
* @param {Object} params - Configuration parameters
|
|
24
|
+
* @param {Palette} params.palette - Design system color palette
|
|
25
|
+
* @param {string} [params.type] - Optional marker type identifier (e.g. "dropOff")
|
|
26
|
+
*
|
|
27
|
+
* @returns {Object} Mapbox GL paint properties object containing:
|
|
28
|
+
* - circle-color: Center fill color
|
|
29
|
+
* - circle-radius: Size of marker
|
|
30
|
+
* - circle-stroke-color: Border color
|
|
31
|
+
* - circle-stroke-width: Border thickness
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* const markerStyle = generateMarkers({
|
|
35
|
+
* palette: theme.palette,
|
|
36
|
+
* type: "dropOff"
|
|
37
|
+
* });
|
|
20
38
|
*/
|
|
21
39
|
export declare const generateMarkers: ({ palette, type }: GenerateMarkersProps) => {
|
|
22
40
|
"circle-color": string;
|
|
@@ -25,11 +43,19 @@ export declare const generateMarkers: ({ palette, type }: GenerateMarkersProps)
|
|
|
25
43
|
"circle-stroke-width": number;
|
|
26
44
|
};
|
|
27
45
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
46
|
+
* Main entry point for loading markers onto a Mapbox GL map
|
|
47
|
+
*
|
|
48
|
+
* Orchestrates:
|
|
49
|
+
* - Data conversion to GeoJSON
|
|
50
|
+
* - Marker type classification
|
|
51
|
+
* - Parallel loading of different marker types
|
|
52
|
+
* - Loading state management
|
|
53
|
+
*
|
|
54
|
+
* @param {Object} params - Configuration parameters
|
|
55
|
+
* @param {MutableRefObject<Map|null>} params.map - React ref to Mapbox GL instance
|
|
56
|
+
* @param {function} params.setLoadingMapBox - Loading state callback
|
|
57
|
+
* @param {Palette} params.palette - Design system color palette
|
|
58
|
+
* @param {MarkerProps[]} params.markers - Array of marker definitions
|
|
33
59
|
*/
|
|
34
60
|
export declare const loadMarkers: ({ map, setLoadingMapBox, palette, markers }: LoadMarkersProps) => void;
|
|
35
61
|
export {};
|
|
@@ -9,12 +9,37 @@ interface MapOptionsProps {
|
|
|
9
9
|
zoomFlyFrom?: number;
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
12
|
+
* Generates configuration options for initializing a Mapbox map
|
|
13
|
+
*
|
|
14
|
+
* This utility function creates a standardized configuration object for Mapbox GL JS
|
|
15
|
+
* by processing various input parameters. It handles:
|
|
16
|
+
* - Center point calculation (with fallback to marker positions or default)
|
|
17
|
+
* - Container element reference validation
|
|
18
|
+
* - Style application
|
|
19
|
+
* - Initial zoom level
|
|
20
|
+
*
|
|
21
|
+
* @param {Object} params - Configuration parameters
|
|
22
|
+
* @param {string} params.mapStyle - Mapbox style URL or specification
|
|
23
|
+
* @param {React.RefObject} [params.mapContainer] - Reference to the DOM container element
|
|
24
|
+
* @param {number} [params.zoomFlyFrom] - Initial zoom level for fly-to animation
|
|
25
|
+
* @param {MarkerProps[]} [params.markers] - Array of marker definitions
|
|
26
|
+
* @param {LngLatLike|number[]} [params.center] - Optional center coordinates (either as LngLat object or [lng, lat] array)
|
|
27
|
+
*
|
|
28
|
+
* @returns {Object} Mapbox-compatible configuration object with:
|
|
29
|
+
* - center: Calculated center coordinates
|
|
30
|
+
* - container: Validated container reference
|
|
31
|
+
* - cooperativeGestures: Enabled by default
|
|
32
|
+
* - failIfMajorPerformanceCaveat: Disabled by default
|
|
33
|
+
* - style: The provided map style
|
|
34
|
+
* - zoom: Initial zoom level
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* const options = mapOptions({
|
|
38
|
+
* mapStyle: 'mapbox://styles/mapbox/streets-v11',
|
|
39
|
+
* mapContainer: mapRef,
|
|
40
|
+
* markers: [{ lat: 48.8584, lng: 2.2945 }],
|
|
41
|
+
* zoomFlyFrom: 12
|
|
42
|
+
* });
|
|
18
43
|
*/
|
|
19
44
|
declare const mapOptions: ({ mapStyle, mapContainer, zoomFlyFrom, markers, center }: MapOptionsProps) => {
|
|
20
45
|
center: {
|