You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/api-reference/map.md
+7-11Lines changed: 7 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -53,7 +53,6 @@ function App() {
53
53
</TabItem>
54
54
</Tabs>
55
55
56
-
57
56
## Properties
58
57
59
58
Aside from the props listed below, the `Map` component supports all parameters of the `Map` class constructor ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/map/) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/MapOptions/)). Beware that this is not an exhaustive list of all props. Different base map libraries may offer different options and default values. When in doubt, refer to your base map library's documentation.
@@ -64,6 +63,10 @@ Aside from the props listed below, the `Map` component supports all parameters o
64
63
65
64
Map container id.
66
65
66
+
Required when [`MapProvider`](./map-provider.md)s are used. Used to reference the map with [`useMap`](./use-map.md).
67
+
68
+
Make sure to pick a name that has no conflict with other imports (there are no checks or errors in this case).
@@ -461,13 +463,14 @@ Called when one of the map's sources loads or changes, including if a tile belon
461
463
462
464
### Other options
463
465
464
-
The following props, along with any options of the `Map` class ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/map/) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/MapOptions/)) not listed above, can be specified to construct the underlying `Map` instance.
466
+
The following props, along with any options of the `Map` class ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/map/) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/MapOptions/)) not listed above, can be specified to construct the underlying `Map` instance.
465
467
466
468
Note: props in this section are not reactive. They are only used once when the Map instance is constructed.
467
469
468
470
#### `mapLib`: any {#maplib}
469
471
470
472
Default:
473
+
471
474
-`import('mapbox-gl')` if imported from `react-map-gl`
472
475
-`import('maplibre-gl')` if imported from `react-map-gl/maplibre`
Token used to access the Mapbox data service. See [about map tokens](../get-started/mapbox-tokens.md).
@@ -561,8 +563,6 @@ The number of web workers instantiated on a page with mapbox-gl maps.
561
563
562
564
Provides an interface for loading mapbox-gl's WebWorker bundle from a self-hosted URL. This is useful if your site needs to operate in a strict CSP (Content Security Policy) environment wherein you are not allowed to load JavaScript code from a Blob URL, which is default behavior.
563
565
564
-
565
-
566
566
## Methods
567
567
568
568
Imperative methods are accessible via a [React ref](https://reactjs.org/docs/refs-and-the-dom.html#creating-refs) or the [useMap](./use-map.md) hook.
@@ -592,7 +592,6 @@ function App() {
592
592
</TabItem>
593
593
<TabItemvalue="maplibre"label="Maplibre">
594
594
595
-
596
595
```tsx
597
596
import*asReactfrom'react';
598
597
import {useRef, useCallback} from'react';
@@ -612,7 +611,6 @@ function App() {
612
611
}
613
612
```
614
613
615
-
616
614
</TabItem>
617
615
</Tabs>
618
616
@@ -624,8 +622,6 @@ You can still access the hidden members via `getMap()`:
624
622
625
623
Returns the native `Map` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/map/) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/Map/)) instance associated with this component.
Copy file name to clipboardExpand all lines: docs/api-reference/use-map.md
+7-3Lines changed: 7 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,8 @@
1
1
# useMap
2
2
3
-
The `useMap` hook allows a custom component to reference the [Map](./map.md) that contains it.
3
+
The `useMap` hook allows a component to reference the [Map](./map.md) that contains it.
4
+
5
+
When used with [MapProvider](./map-provider.md), this hook can also reference maps that are rendered outside of the current map component's direct render tree.
4
6
5
7
import Tabs from '@theme/Tabs';
6
8
import TabItem from '@theme/TabItem';
@@ -60,7 +62,7 @@ function NavigateButton() {
60
62
</Tabs>
61
63
62
64
63
-
When used with the [MapProvider](./map-provider.md), this hook can also reference maps that are rendered outside of the current component's direct render tree.
65
+
When used with the [MapProvider](./map-provider.md), this hook can also reference maps that are rendered outside of the current component's direct render tree as long as both trees are part of the current `<MapProvider>`.
64
66
65
67
66
68
<TabsgroupId="map-library">
@@ -70,6 +72,8 @@ When used with the [MapProvider](./map-provider.md), this hook can also referenc
// Note: `useMap` will not work in <Root>, only children of <MapProvider> can use `useMap`
76
+
73
77
return (
74
78
<MapProvider>
75
79
<Mapid="myMapA"... />
@@ -131,7 +135,7 @@ See a full example [here](https://github.com/visgl/react-map-gl/tree/7.0-release
131
135
132
136
The hook returns an object that contains all mounted maps under the closest `MapProvider`. The keys are each map's [id](./map.md#id) and the values are the [MapRef](./types.md#mapref).
133
137
134
-
If the hook is used inside a decendent of a `Map` component, the returned object also contains a `current` field that references the containing map.
138
+
If the hook is used inside a decendent of a `Map` component, the returned object additionally contains a `current` field that references the containing map.
0 commit comments