Skip to content

Commit eb1d50f

Browse files
committed
commit chnages new worldMapControl.tsx
1 parent 42887cf commit eb1d50f

25 files changed

+2732
-56
lines changed
981 KB
Loading

docs/documentation/docs/controls/WorldMap.md

Lines changed: 419 additions & 0 deletions
Large diffs are not rendered by default.

package-lock.json

Lines changed: 532 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,16 @@
7676
"he": "^1.2.0",
7777
"jotai": "^2.4.2",
7878
"lodash": "4.17.21",
79+
"maplibre-gl": "^5.6.1",
7980
"markdown-it": "^14.1.0",
8081
"monaco-editor": "^0.29.1",
8182
"nano-css": "^5.3.4",
83+
"pmtiles": "^4.3.0",
8284
"react": "17.0.1",
8385
"react-accessible-accordion": "^5.0.0",
8486
"react-dom": "17.0.1",
8587
"react-dropzone": "^14.2.3",
88+
"react-map-gl": "^8.0.4",
8689
"react-mentions": "^4.3.0",
8790
"react-quill": "2.0.0",
8891
"regexify-string": "^1.0.16",
@@ -103,6 +106,7 @@
103106
"@types/he": "^1.1.2",
104107
"@types/jest": "25.2.3",
105108
"@types/lodash": "4.14.202",
109+
"@types/maplibre-gl": "^1.13.2",
106110
"@types/quill": "^1.3.10",
107111
"@types/react": "17.0.45",
108112
"@types/react-dom": "17.0.17",

src/WorldMap.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './controls/worldMap/index';

src/controls/worldMap/IData.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
/**
3+
* Data structure for map ___location items.
4+
* Represents a ___location point with metadata for display on the world map.
5+
*/
6+
export interface IData {
7+
/**
8+
* Unique identifier for the ___location.
9+
* @example "nyc-001" or "___location-1"
10+
*/
11+
id: string;
12+
13+
/**
14+
* Display name of the ___location.
15+
* Used for search functionality and marker tooltips.
16+
* @example "New York City" or "Eiffel Tower"
17+
*/
18+
name: string;
19+
20+
/**
21+
* URL to an image representing this ___location.
22+
* Used for marker display or in tooltips.
23+
* @example "https://example.com/nyc-skyline.jpg"
24+
*/
25+
imageUrl: string;
26+
27+
/**
28+
* URL link associated with this ___location.
29+
* Can be used for navigation when marker is clicked.
30+
* @example "https://example.com/locations/new-york" or "/details/nyc"
31+
*/
32+
link: string;
33+
34+
/**
35+
* Geographic coordinates as [longitude, latitude] tuple.
36+
* Used to position the marker on the map.
37+
* @example [-74.006, 40.7128] // New York City coordinates
38+
*/
39+
coordinates: [number, number];
40+
}
Lines changed: 241 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
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+
}

src/controls/worldMap/IMarker.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { IData } from "./IData";
2+
import React from "react";
3+
4+
export interface IMarker {
5+
markerClassName?: string;
6+
markerStyle?: React.CSSProperties;
7+
renderToolTip?: (c: IData) => React.ReactNode;
8+
tooltipClassName?: string;
9+
tooltipStyle?: React.CSSProperties;
10+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { IData } from './IData';
2+
import { IMarker } from './IMarker';
3+
4+
export interface IMarkerProps extends IMarker {
5+
data: IData;
6+
onClick?: (data: IData) => void;
7+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Theme } from "@fluentui/react-components";
2+
3+
export interface IWorldMapProps {
4+
description: string;
5+
isDarkTheme: boolean;
6+
hasTeamsContext: boolean;
7+
title: string;
8+
theme?: Theme
9+
styles?: React.CSSProperties;
10+
className?: string;
11+
mapStyleUrl?: string;
12+
fitPadding?: number;
13+
}

0 commit comments

Comments
 (0)