|
| 1 | +import { IData } from "./IData"; |
| 2 | +import React from "react"; |
| 3 | +import { Theme } from "@fluentui/react-components"; |
| 4 | + |
| 5 | +/** Props for the world map component. */ |
| 6 | +export interface IMaplibreWorldMapProps { |
| 7 | + /** |
| 8 | + * Array of ___location data to display on the map. Each item must include coordinates as [longitude, latitude]. |
| 9 | + * @example |
| 10 | + * ```tsx |
| 11 | + * const data = [ |
| 12 | + * { id: '1', name: 'New York', coordinates: [-74.006, 40.7128], imageUrl: '...', link: '...' } |
| 13 | + * ]; |
| 14 | + * ``` |
| 15 | + */ |
| 16 | + data: IData[]; |
| 17 | + |
| 18 | + /** |
| 19 | + * Callback function triggered when a marker is clicked. |
| 20 | + * @param c - The data item associated with the clicked marker |
| 21 | + * @example |
| 22 | + * ```tsx |
| 23 | + * onClick={(___location) => console.log('Clicked:', ___location.name)} |
| 24 | + * ``` |
| 25 | + */ |
| 26 | + onClick?: (c: IData) => void; |
| 27 | + |
| 28 | + /** |
| 29 | + * Custom map style URL. If provided with mapKey, the key will be automatically appended. |
| 30 | + * If provided without mapKey, the URL will be used as-is. |
| 31 | + * @example |
| 32 | + * ```tsx |
| 33 | + * mapStyleUrl="https://api.maptiler.com/maps/satellite/style.json" |
| 34 | + * ``` |
| 35 | + */ |
| 36 | + mapStyleUrl?: string; |
| 37 | + |
| 38 | + /** |
| 39 | + * MapTiler API key for accessing premium map styles. |
| 40 | + * If provided alone, uses MapTiler streets style by default. |
| 41 | + * If not provided, falls back to free demo map. |
| 42 | + * @example |
| 43 | + * ```tsx |
| 44 | + * mapKey="your-maptiler-api-key-here" |
| 45 | + * ``` |
| 46 | + */ |
| 47 | + mapKey?: string; |
| 48 | + |
| 49 | + /** |
| 50 | + * Custom CSS styles for the map container. |
| 51 | + * @example |
| 52 | + * ```tsx |
| 53 | + * style={{ width: '100%', height: '500px', border: '1px solid #ccc' }} |
| 54 | + * ``` |
| 55 | + */ |
| 56 | + style?: React.CSSProperties; |
| 57 | + |
| 58 | + /** |
| 59 | + * Padding (in pixels) around the map when fitting bounds to show all markers. |
| 60 | + * @default 20 |
| 61 | + * @example |
| 62 | + * ```tsx |
| 63 | + * fitPadding={50} // Adds 50px padding around markers when auto-fitting |
| 64 | + * ``` |
| 65 | + */ |
| 66 | + fitPadding?: number; |
| 67 | + |
| 68 | + /** |
| 69 | + * Title displayed above the map. Can be a string or React element. |
| 70 | + * @default 'World Map' |
| 71 | + * @example |
| 72 | + * ```tsx |
| 73 | + * title="My Custom Map" |
| 74 | + * // or |
| 75 | + * title={<h2>Interactive Location Map</h2>} |
| 76 | + * ``` |
| 77 | + */ |
| 78 | + title?: string | React.ReactNode; |
| 79 | + |
| 80 | + /** |
| 81 | + * Description text displayed below the title (not currently implemented in UI). |
| 82 | + * @example |
| 83 | + * ```tsx |
| 84 | + * description="Click on markers to view ___location details" |
| 85 | + * ``` |
| 86 | + */ |
| 87 | + description?: string | React.ReactNode; |
| 88 | + |
| 89 | + /** |
| 90 | + * CSS class name applied to the root container. |
| 91 | + * @example |
| 92 | + * ```tsx |
| 93 | + * className="my-custom-map-class" |
| 94 | + * ``` |
| 95 | + */ |
| 96 | + className?: string; |
| 97 | + |
| 98 | + /** |
| 99 | + * Configuration options for map markers appearance and behavior. |
| 100 | + */ |
| 101 | + marker?: { |
| 102 | + /** |
| 103 | + * CSS class name applied to marker elements. |
| 104 | + * @example "custom-marker-style" |
| 105 | + */ |
| 106 | + markerClassName?: string; |
| 107 | + |
| 108 | + /** |
| 109 | + * Custom CSS styles applied to marker elements. |
| 110 | + * @example {{ backgroundColor: 'red', borderRadius: '50%' }} |
| 111 | + */ |
| 112 | + markerStyle?: React.CSSProperties; |
| 113 | + |
| 114 | + /** |
| 115 | + * Size of marker images in pixels. |
| 116 | + * @default 40 |
| 117 | + * @example 60 |
| 118 | + */ |
| 119 | + imageSize?: number; |
| 120 | + |
| 121 | + /** |
| 122 | + * Custom function to render tooltip content for markers. |
| 123 | + * @param c - The data item for the marker |
| 124 | + * @returns React element to display in tooltip |
| 125 | + * @example |
| 126 | + * ```tsx |
| 127 | + * renderToolTip={(item) => <div><strong>{item.name}</strong><br/>{item.description}</div>} |
| 128 | + * ``` |
| 129 | + */ |
| 130 | + renderToolTip?: (c: IData) => React.ReactNode; |
| 131 | + |
| 132 | + /** |
| 133 | + * CSS class name applied to tooltip elements. |
| 134 | + * @example "custom-tooltip-style" |
| 135 | + */ |
| 136 | + tooltipClassName?: string; |
| 137 | + |
| 138 | + /** |
| 139 | + * Custom CSS styles applied to tooltip elements. |
| 140 | + * @example {{ backgroundColor: 'black', color: 'white', padding: '8px' }} |
| 141 | + */ |
| 142 | + tooltipStyle?: React.CSSProperties; |
| 143 | + } |
| 144 | + |
| 145 | + /** |
| 146 | + * Configuration options for the search functionality. |
| 147 | + */ |
| 148 | + search?: { |
| 149 | + /** |
| 150 | + * Enable or disable the search feature. |
| 151 | + * @default true |
| 152 | + * @example |
| 153 | + * ```tsx |
| 154 | + * search={{ enabled: false }} // Disables search |
| 155 | + * ``` |
| 156 | + */ |
| 157 | + enabled?: boolean; |
| 158 | + |
| 159 | + /** |
| 160 | + * Placeholder text displayed in the search input. |
| 161 | + * @default "Search locations..." |
| 162 | + * @example |
| 163 | + * ```tsx |
| 164 | + * search={{ placeholder: "Find a city or landmark..." }} |
| 165 | + * ``` |
| 166 | + */ |
| 167 | + placeholder?: string; |
| 168 | + |
| 169 | + /** |
| 170 | + * Callback function triggered when search term changes or results are filtered. |
| 171 | + * @param searchTerm - The current search term |
| 172 | + * @param filteredData - Array of data items matching the search |
| 173 | + * @example |
| 174 | + * ```tsx |
| 175 | + * onSearchChange={(term, results) => { |
| 176 | + * console.log(`Search: "${term}" found ${results.length} results`); |
| 177 | + * }} |
| 178 | + * ``` |
| 179 | + */ |
| 180 | + onSearchChange?: (searchTerm: string, filteredData: IData[]) => void; |
| 181 | + |
| 182 | + /** |
| 183 | + * Field to search on or a custom function to extract the search term from data items. |
| 184 | + * @default "name" |
| 185 | + * @example |
| 186 | + * ```tsx |
| 187 | + * // Search by specific field |
| 188 | + * searchField: "id" |
| 189 | + * |
| 190 | + * // Custom search function |
| 191 | + * searchField: (item) => `${item.name} ${item.description}` |
| 192 | + * ``` |
| 193 | + */ |
| 194 | + searchField?: keyof IData | ((item: IData) => string); |
| 195 | + |
| 196 | + /** |
| 197 | + * Zoom level to use when focusing on search results. |
| 198 | + * @default 8 |
| 199 | + * @example |
| 200 | + * ```tsx |
| 201 | + * search={{ zoomLevel: 12 }} // Closer zoom for search results |
| 202 | + * ``` |
| 203 | + */ |
| 204 | + zoomLevel?: number; |
| 205 | + |
| 206 | + /** |
| 207 | + * Position of the search overlay on the map. |
| 208 | + * @default { top: '10px', left: '10px' } |
| 209 | + * @example |
| 210 | + * ```tsx |
| 211 | + * // Top-right position |
| 212 | + * search={{ position: { top: '10px', right: '10px' } }} |
| 213 | + * |
| 214 | + * // Bottom-left position |
| 215 | + * search={{ position: { bottom: '20px', left: '20px' } }} |
| 216 | + * ``` |
| 217 | + */ |
| 218 | + position?: { |
| 219 | + /** Distance from the top edge of the map */ |
| 220 | + top?: string; |
| 221 | + /** Distance from the left edge of the map */ |
| 222 | + left?: string; |
| 223 | + /** Distance from the right edge of the map */ |
| 224 | + right?: string; |
| 225 | + /** Distance from the bottom edge of the map */ |
| 226 | + bottom?: string; |
| 227 | + }; |
| 228 | + } |
| 229 | + |
| 230 | + /** |
| 231 | + * Fluent UI theme object for consistent styling. |
| 232 | + * @example |
| 233 | + * ```tsx |
| 234 | + * import { useTheme } from '@fluentui/react-components'; |
| 235 | + * |
| 236 | + * const theme = useTheme(); |
| 237 | + * <MaplibreWorldMap theme={theme} /> |
| 238 | + * ``` |
| 239 | + */ |
| 240 | + theme?: Theme |
| 241 | +} |
0 commit comments