react-bing-map 1.0.7 → 1.0.8
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/README.md +284 -121
- package/lib/cjs/index.cjs +520 -0
- package/lib/cjs/index.cjs.map +1 -0
- package/lib/esm/components/MapView/BingMaps.d.ts +3 -0
- package/lib/esm/components/RouteSelectionWithGPS.d.ts +22 -0
- package/lib/esm/components/index.d.ts +3 -0
- package/lib/esm/hooks/useBingMaps.d.ts +5 -0
- package/lib/esm/index.d.ts +1 -0
- package/lib/esm/index.js +517 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/stories/BingMaps.stories.d.ts +8 -0
- package/lib/esm/type/component.type.d.ts +63 -0
- package/package.json +51 -29
package/README.md
CHANGED
|
@@ -1,176 +1,339 @@
|
|
|
1
|
-
|
|
1
|
+
# React Bing Map
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A React + TypeScript wrapper for Bing Maps with pushpins, infoboxes, route navigation, device GPS support, route distance, route duration, and a ready-to-use route selection panel.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Features
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
- Render Bing Maps in React applications.
|
|
8
|
+
- Add multiple pushpins with custom icons and infobox content.
|
|
9
|
+
- Draw routes between a `source` and `destination`.
|
|
10
|
+
- Use the browser/device current location as the route source.
|
|
11
|
+
- Receive route distance and duration with `onRouteCalculated`.
|
|
12
|
+
- Use `RouteSelectionWithGPS` for a built-in route form and map layout.
|
|
13
|
+
- Position the route drawer on the `left`, `right`, `top`, or `bottom`.
|
|
14
|
+
- Supports React `16`, `17`, `18`, and `19`.
|
|
8
15
|
|
|
9
|
-
|
|
10
|
-
yarn add react-bing-map
|
|
16
|
+
## Prerequisites
|
|
11
17
|
|
|
12
|
-
|
|
18
|
+
You need a Bing Maps API key from the [Bing Maps Dev Center](https://www.bingmapsportal.com).
|
|
13
19
|
|
|
14
|
-
|
|
15
|
-
```
|
|
20
|
+
GPS/current-location features require a secure browser context:
|
|
16
21
|
|
|
17
|
-
|
|
22
|
+
- `localhost` during development
|
|
23
|
+
- `https://` in production
|
|
18
24
|
|
|
19
|
-
|
|
25
|
+
The browser user must also allow location permission.
|
|
20
26
|
|
|
21
|
-
|
|
27
|
+
## Installation
|
|
22
28
|
|
|
23
|
-
```
|
|
24
|
-
|
|
29
|
+
```sh
|
|
30
|
+
npm install react-bing-map
|
|
25
31
|
```
|
|
26
32
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
```js
|
|
30
|
-
<BingMaps
|
|
31
|
-
mapType="grayscale"
|
|
32
|
-
bingKey="key"
|
|
33
|
-
centerLocation={[28.6448, 77.216721]}
|
|
34
|
-
language="en-IN"
|
|
35
|
-
zoom={0}
|
|
36
|
-
pushPins={[]}
|
|
37
|
-
mapPosition={ north: 49.234, south: 24.175, east: -65.573, west: -125.778 }
|
|
38
|
-
infoBoxStyle={ maxWidth: 490, maxHeight: 600 }
|
|
39
|
-
pushPinIcon=""
|
|
40
|
-
showScalebar={true}
|
|
41
|
-
showCopyright={true}
|
|
42
|
-
showLogo={true}
|
|
43
|
-
disableZooming={false}
|
|
44
|
-
showBreadcrumb={true}
|
|
45
|
-
showLocateMeButton={true}
|
|
46
|
-
showZoomButtons={true}
|
|
47
|
-
showMapTypeSelector={true}
|
|
48
|
-
|
|
49
|
-
/>
|
|
33
|
+
```sh
|
|
34
|
+
yarn add react-bing-map
|
|
50
35
|
```
|
|
51
36
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
#### 1. mapType
|
|
37
|
+
## Basic Usage
|
|
55
38
|
|
|
56
|
-
|
|
39
|
+
```tsx
|
|
40
|
+
import { BingMaps } from "react-bing-map";
|
|
57
41
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
42
|
+
export const App = () => {
|
|
43
|
+
return (
|
|
44
|
+
<div style={{ width: "100%", height: "500px", position: "relative" }}>
|
|
45
|
+
<BingMaps
|
|
46
|
+
bingKey="YOUR_BING_MAPS_KEY"
|
|
47
|
+
mapType="grayscale"
|
|
48
|
+
centerLocation={[28.6448, 77.216721]}
|
|
49
|
+
zoom={6}
|
|
50
|
+
/>
|
|
51
|
+
</div>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
70
54
|
```
|
|
71
55
|
|
|
72
|
-
|
|
56
|
+
The parent container should have a height and `position: "relative"` because the map fills its parent.
|
|
73
57
|
|
|
74
|
-
|
|
58
|
+
## Pushpins and Infoboxes
|
|
75
59
|
|
|
76
|
-
|
|
60
|
+
```tsx
|
|
61
|
+
import { BingMaps } from "react-bing-map";
|
|
77
62
|
|
|
78
|
-
|
|
63
|
+
const pushPins = [
|
|
64
|
+
{
|
|
65
|
+
icon: "",
|
|
66
|
+
location: {
|
|
67
|
+
latitude: 28.6448,
|
|
68
|
+
longitude: 77.216721,
|
|
69
|
+
},
|
|
70
|
+
content: {
|
|
71
|
+
title: "Delhi",
|
|
72
|
+
description: "Simple text or HTML content",
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
];
|
|
79
76
|
|
|
80
|
-
|
|
81
|
-
|
|
77
|
+
export const MapWithPins = () => {
|
|
78
|
+
return (
|
|
79
|
+
<div style={{ width: "100%", height: "500px", position: "relative" }}>
|
|
80
|
+
<BingMaps
|
|
81
|
+
bingKey="YOUR_BING_MAPS_KEY"
|
|
82
|
+
mapType="road"
|
|
83
|
+
centerLocation={[28.6448, 77.216721]}
|
|
84
|
+
zoom={8}
|
|
85
|
+
pushPins={pushPins}
|
|
86
|
+
pushPinIcon=""
|
|
87
|
+
infoBoxStyle={{ maxWidth: 490, maxHeight: 600 }}
|
|
88
|
+
/>
|
|
89
|
+
</div>
|
|
90
|
+
);
|
|
91
|
+
}
|
|
82
92
|
```
|
|
83
93
|
|
|
84
|
-
|
|
94
|
+
## Route Navigation
|
|
85
95
|
|
|
86
|
-
|
|
96
|
+
Use `source`, `destination`, and `showRoute` to draw a route between two coordinates.
|
|
87
97
|
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
```
|
|
98
|
+
```tsx
|
|
99
|
+
import { BingMaps } from "react-bing-map";
|
|
91
100
|
|
|
92
|
-
|
|
101
|
+
const source = { latitude: 13.0827, longitude: 80.2707 }; // Chennai
|
|
102
|
+
const destination = { latitude: 12.9716, longitude: 77.5946 }; // Bangalore
|
|
103
|
+
|
|
104
|
+
export function RouteMap() {
|
|
105
|
+
return (
|
|
106
|
+
<div style={{ width: "100%", height: "500px", position: "relative" }}>
|
|
107
|
+
<BingMaps
|
|
108
|
+
bingKey="YOUR_BING_MAPS_KEY"
|
|
109
|
+
mapType="road"
|
|
110
|
+
source={source}
|
|
111
|
+
destination={destination}
|
|
112
|
+
showRoute={true}
|
|
113
|
+
routeMode="driving"
|
|
114
|
+
zoom={6}
|
|
115
|
+
onRouteCalculated={(routeInfo) => {
|
|
116
|
+
console.log("Distance:", routeInfo.distance, routeInfo.distanceUnit);
|
|
117
|
+
console.log("Duration in seconds:", routeInfo.duration);
|
|
118
|
+
}}
|
|
119
|
+
/>
|
|
120
|
+
</div>
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
```
|
|
93
124
|
|
|
94
|
-
|
|
125
|
+
Route modes:
|
|
95
126
|
|
|
96
|
-
```
|
|
97
|
-
|
|
127
|
+
```ts
|
|
128
|
+
type TRouteMode = "driving" | "walking" | "transit";
|
|
98
129
|
```
|
|
99
130
|
|
|
100
|
-
|
|
131
|
+
## Use Current Location as Source
|
|
101
132
|
|
|
102
|
-
|
|
133
|
+
Set `useGPS={true}` with a `destination`. The component gets the browser/device location and uses it as the route source.
|
|
103
134
|
|
|
104
|
-
```
|
|
105
|
-
{
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
135
|
+
```tsx
|
|
136
|
+
import { BingMaps } from "react-bing-map";
|
|
137
|
+
|
|
138
|
+
const destination = { latitude: 12.9716, longitude: 77.5946 }; // Bangalore
|
|
139
|
+
|
|
140
|
+
export function CurrentLocationRoute() {
|
|
141
|
+
return (
|
|
142
|
+
<div style={{ width: "100%", height: "500px", position: "relative" }}>
|
|
143
|
+
<BingMaps
|
|
144
|
+
bingKey="YOUR_BING_MAPS_KEY"
|
|
145
|
+
mapType="road"
|
|
146
|
+
destination={destination}
|
|
147
|
+
showRoute={true}
|
|
148
|
+
useGPS={true}
|
|
149
|
+
routeMode="driving"
|
|
150
|
+
onGPSLocationFound={(location) => {
|
|
151
|
+
console.log("Device location:", location);
|
|
152
|
+
}}
|
|
153
|
+
onGPSError={(error) => {
|
|
154
|
+
console.error(error);
|
|
155
|
+
}}
|
|
156
|
+
onRouteCalculated={(routeInfo) => {
|
|
157
|
+
console.log(`${routeInfo.distance.toFixed(2)} km`);
|
|
158
|
+
}}
|
|
159
|
+
/>
|
|
160
|
+
</div>
|
|
161
|
+
);
|
|
115
162
|
}
|
|
116
163
|
```
|
|
117
164
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
This icon used to show the category based pushpin we can use it or else set empty sting and use the `pushPinIon`key for global icon.
|
|
121
|
-
|
|
122
|
-
The content of the description should be like the inner HTML content below
|
|
165
|
+
If GPS is unavailable or permission is denied, `onGPSError` is called. If `source` is also provided, the component can fall back to routing from `source` to `destination`.
|
|
123
166
|
|
|
124
|
-
|
|
167
|
+
## Route Selection Component
|
|
125
168
|
|
|
126
|
-
|
|
169
|
+
`RouteSelectionWithGPS` is a ready-made map + route form component. It includes source selection, destination selection, a `Current Location` source option, GPS checkbox, route mode selector, route summary, distance, duration, and drawer positioning.
|
|
127
170
|
|
|
128
|
-
```
|
|
171
|
+
```tsx
|
|
172
|
+
import { RouteSelectionWithGPS } from "react-bing-map";
|
|
129
173
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
`
|
|
142
|
-
}
|
|
174
|
+
export function RoutePlanner() {
|
|
175
|
+
return (
|
|
176
|
+
<RouteSelectionWithGPS
|
|
177
|
+
bingKey="YOUR_BING_MAPS_KEY"
|
|
178
|
+
drawerPosition="right"
|
|
179
|
+
mapType="grayscale"
|
|
180
|
+
zoom={5}
|
|
181
|
+
/>
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
```
|
|
143
185
|
|
|
186
|
+
### Custom Locations
|
|
187
|
+
|
|
188
|
+
```tsx
|
|
189
|
+
import { RouteSelectionWithGPS } from "react-bing-map";
|
|
190
|
+
|
|
191
|
+
const locations = {
|
|
192
|
+
chennai: { latitude: 13.0827, longitude: 80.2707 },
|
|
193
|
+
bangalore: { latitude: 12.9716, longitude: 77.5946 },
|
|
194
|
+
hyderabad: { latitude: 17.385, longitude: 78.4867 },
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
export function CustomRoutePlanner() {
|
|
198
|
+
return (
|
|
199
|
+
<RouteSelectionWithGPS
|
|
200
|
+
bingKey="YOUR_BING_MAPS_KEY"
|
|
201
|
+
locations={locations}
|
|
202
|
+
initialSourceKey="chennai"
|
|
203
|
+
initialDestinationKey="bangalore"
|
|
204
|
+
drawerPosition="bottom"
|
|
205
|
+
mapType="road"
|
|
206
|
+
/>
|
|
207
|
+
);
|
|
208
|
+
}
|
|
144
209
|
```
|
|
145
210
|
|
|
146
|
-
|
|
211
|
+
### Drawer Positions
|
|
147
212
|
|
|
148
|
-
```
|
|
149
|
-
"
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
213
|
+
```tsx
|
|
214
|
+
<RouteSelectionWithGPS drawerPosition="left" />
|
|
215
|
+
<RouteSelectionWithGPS drawerPosition="right" />
|
|
216
|
+
<RouteSelectionWithGPS drawerPosition="top" />
|
|
217
|
+
<RouteSelectionWithGPS drawerPosition="bottom" />
|
|
153
218
|
```
|
|
154
219
|
|
|
155
|
-
|
|
220
|
+
## `BingMaps` Props
|
|
221
|
+
|
|
222
|
+
| Prop | Type | Default | Description |
|
|
223
|
+
| --- | --- | --- | --- |
|
|
224
|
+
| `bingKey` | `string` | `""` | Bing Maps API key. Required for map and route features. |
|
|
225
|
+
| `mapType` | `string` | `"grayscale"` | Bing Maps map type. |
|
|
226
|
+
| `centerLocation` | `[number, number]` | `[0, 0]` | Initial map center as `[latitude, longitude]`. |
|
|
227
|
+
| `language` | `string` | `"en-IN"` | Bing Maps script language. |
|
|
228
|
+
| `zoom` | `number` | `0` | Initial map zoom level. |
|
|
229
|
+
| `pushPins` | `TPushPin[]` | `[]` | List of pushpins to render. |
|
|
230
|
+
| `pushPinIcon` | `string` | `""` | Global pushpin icon used when an item has no icon. |
|
|
231
|
+
| `mapPosition` | `TMapPosition` | US bounds | Initial map bounds. |
|
|
232
|
+
| `infoBoxStyle` | `TInfoBoxStyle` | `{ maxWidth: 600, maxHeight: 450 }` | Infobox sizing options. |
|
|
233
|
+
| `showScalebar` | `boolean` | `true` | Show or hide scale bar. |
|
|
234
|
+
| `showCopyright` | `boolean` | `true` | Show or hide copyright text. |
|
|
235
|
+
| `showLogo` | `boolean` | `true` | Show or hide Bing logo. |
|
|
236
|
+
| `disableZooming` | `boolean` | `false` | Disable user zoom interaction. |
|
|
237
|
+
| `showBreadcrumb` | `boolean` | `true` | Show or hide breadcrumb control. |
|
|
238
|
+
| `showLocateMeButton` | `boolean` | `true` | Show or hide locate me button. |
|
|
239
|
+
| `showZoomButtons` | `boolean` | `true` | Show or hide zoom buttons. |
|
|
240
|
+
| `showMapTypeSelector` | `boolean` | `true` | Show or hide map type selector. |
|
|
241
|
+
| `source` | `TLocation` | `undefined` | Route source coordinate. |
|
|
242
|
+
| `destination` | `TLocation` | `undefined` | Route destination coordinate. |
|
|
243
|
+
| `showRoute` | `boolean` | `false` | Draw route when `source`/GPS and `destination` are available. |
|
|
244
|
+
| `routeMode` | `"driving" \| "walking" \| "transit"` | `"driving"` | Route travel mode. |
|
|
245
|
+
| `useGPS` | `boolean` | `false` | Use browser/device current location as route source. |
|
|
246
|
+
| `onGPSLocationFound` | `(location: TLocation) => void` | `undefined` | Called when GPS location is found. |
|
|
247
|
+
| `onGPSError` | `(error: string) => void` | `undefined` | Called when GPS or route calculation fails. |
|
|
248
|
+
| `onRouteCalculated` | `(routeInfo: TRouteInfo) => void` | `undefined` | Called with route distance and duration. |
|
|
249
|
+
|
|
250
|
+
## `RouteSelectionWithGPS` Props
|
|
251
|
+
|
|
252
|
+
| Prop | Type | Default | Description |
|
|
253
|
+
| --- | --- | --- | --- |
|
|
254
|
+
| `bingKey` | `string` | `""` | Bing Maps API key. |
|
|
255
|
+
| `drawerPosition` | `"left" \| "right" \| "top" \| "bottom"` | `"right"` | Position of the route configuration panel. |
|
|
256
|
+
| `locations` | `Record<string, TLocation>` | Built-in India city list | Source/destination options shown in the form. |
|
|
257
|
+
| `initialSourceKey` | `string` | `"delhi"` | Initial source key from `locations`. |
|
|
258
|
+
| `initialDestinationKey` | `string` | `"mumbai"` | Initial destination key from `locations`. |
|
|
259
|
+
| `mapType` | `string` | `"grayscale"` | Map type passed to `BingMaps`. |
|
|
260
|
+
| `language` | `string` | `"en-IN"` | Map language passed to `BingMaps`. |
|
|
261
|
+
| `zoom` | `number` | `5` | Initial map zoom. |
|
|
262
|
+
| `disableZooming` | `boolean` | `false` | Disable map zooming. |
|
|
263
|
+
| `showScalebar` | `boolean` | `true` | Show scale bar. |
|
|
264
|
+
| `showCopyright` | `boolean` | `true` | Show copyright text. |
|
|
265
|
+
| `showLogo` | `boolean` | `true` | Show Bing logo. |
|
|
266
|
+
| `showBreadcrumb` | `boolean` | `true` | Show breadcrumb control. |
|
|
267
|
+
| `showLocateMeButton` | `boolean` | `true` | Show locate me button. |
|
|
268
|
+
| `showZoomButtons` | `boolean` | `true` | Show zoom buttons. |
|
|
269
|
+
| `showMapTypeSelector` | `boolean` | `true` | Show map type selector. |
|
|
270
|
+
|
|
271
|
+
## Types
|
|
272
|
+
|
|
273
|
+
```ts
|
|
274
|
+
type TLocation = {
|
|
275
|
+
latitude: number;
|
|
276
|
+
longitude: number;
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
type TMapPosition = {
|
|
280
|
+
north: number;
|
|
281
|
+
south: number;
|
|
282
|
+
east: number;
|
|
283
|
+
west: number;
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
type TPushPin = {
|
|
287
|
+
icon: string | any;
|
|
288
|
+
location: TLocation;
|
|
289
|
+
content: {
|
|
290
|
+
title: string;
|
|
291
|
+
description: HTMLElement | string;
|
|
292
|
+
};
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
type TRouteInfo = {
|
|
296
|
+
source: TLocation;
|
|
297
|
+
destination: TLocation;
|
|
298
|
+
distance: number;
|
|
299
|
+
distanceUnit: "kilometers";
|
|
300
|
+
duration?: number;
|
|
301
|
+
isFallback?: boolean;
|
|
302
|
+
};
|
|
303
|
+
```
|
|
156
304
|
|
|
157
|
-
|
|
305
|
+
## Map Type Options
|
|
158
306
|
|
|
159
|
-
```
|
|
160
|
-
|
|
307
|
+
```ts
|
|
308
|
+
[
|
|
309
|
+
"aerial",
|
|
310
|
+
"canvasDark",
|
|
311
|
+
"canvasLight",
|
|
312
|
+
"birdseye",
|
|
313
|
+
"grayscale",
|
|
314
|
+
"mercator",
|
|
315
|
+
"ordnanceSurvey",
|
|
316
|
+
"road",
|
|
317
|
+
"streetside",
|
|
318
|
+
]
|
|
161
319
|
```
|
|
162
320
|
|
|
163
|
-
|
|
321
|
+
## Development
|
|
164
322
|
|
|
165
|
-
|
|
323
|
+
```sh
|
|
324
|
+
npm install
|
|
325
|
+
npm run storybook
|
|
326
|
+
npm run build
|
|
327
|
+
```
|
|
166
328
|
|
|
167
|
-
|
|
329
|
+
## Troubleshooting
|
|
168
330
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
331
|
+
- Make sure `bingKey` is valid and created for a web application.
|
|
332
|
+
- Routes require reachable source and destination coordinates.
|
|
333
|
+
- GPS requires `localhost` or HTTPS and browser location permission.
|
|
334
|
+
- The map fills its parent; always give the parent container a height.
|
|
335
|
+
- If route calculation fails, `onRouteCalculated` may return `isFallback: true` with straight-line distance.
|
|
173
336
|
|
|
174
|
-
|
|
337
|
+
## License
|
|
175
338
|
|
|
176
|
-
|
|
339
|
+
MIT
|