Skip to content

Commit 38d5fe3

Browse files
committed
[v8] Documentation (#2471)
1 parent cb4cac9 commit 38d5fe3

39 files changed

+2123
-786
lines changed

README.md

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ npm install react-map-gl mapbox-gl
3636
// Using Maplibre
3737
import * as React from 'react';
3838
import Map from 'react-map-gl/maplibre';
39+
import 'maplibre-gl/dist/maplibre-gl.css';
3940

4041
function App() {
4142
return (
@@ -56,11 +57,13 @@ _or_
5657
```js
5758
// Using Mapbox
5859
import * as React from 'react';
59-
import Map from 'react-map-gl';
60+
import Map from 'react-map-gl/mapbox';
61+
import 'mapbox-gl/dist/mapbox-gl.css';
6062

6163
function App() {
6264
return (
6365
<Map
66+
// https://visgl.github.io/react-map-gl/docs/get-started/mapbox-tokens
6467
mapboxAccessToken="<Mapbox access token>"
6568
initialViewState={{
6669
longitude: -100,
@@ -76,18 +79,6 @@ function App() {
7679

7780
Learn more with in our [Getting Started](https://visgl.github.io/react-map-gl/docs/get-started) guide.
7881

79-
### Using Mapbox Tokens
80-
81-
**Starting with v2.0, mapbox-gl requires a Mapbox token for any usage, with or without the Mapbox data service. See [about Mapbox tokens](/docs/get-started/mapbox-tokens.md) for your options.**
82-
83-
To show maps from a service such as Mapbox you will need to register on their website in order to retrieve an access token required by the map component, which will be used to identify you and start serving up map tiles. The service will be free until a certain level of traffic is exceeded.
84-
85-
There are several ways to provide a token to your app, as showcased in some of the example folders:
86-
87-
* Provide a `mapboxAccessToken` prop to the map component
88-
* Set the `MapboxAccessToken` environment variable (or set `REACT_APP_MAPBOX_ACCESS_TOKEN` if you are using Create React App)
89-
* Provide it in the URL, e.g `?access_token=TOKEN`
90-
9182

9283
### Contribute
9384

docs/README.md

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,25 @@
11

22
# Introduction
33

4-
<p align="center">
5-
These docs are for
6-
<a href="https://github.com/visgl/react-map-gl/tree/7.0-release/docs">
7-
<img src="https://img.shields.io/badge/v7.0-brightgreen.svg?style=flat-square" />
8-
</a>
9-
Looking for an old version?
10-
<a href="https://github.com/visgl/react-map-gl/tree/6.1-release/docs">
11-
<img src="https://img.shields.io/badge/v6.1-brightgreen.svg?style=flat-square" />
12-
</a>
13-
<a href="https://github.com/visgl/react-map-gl/tree/5.3-release/docs">
14-
<img src="https://img.shields.io/badge/v5.3-brightgreen.svg?style=flat-square" />
15-
</a>
16-
</p>
4+
> These docs are for v8.0. For v7, see [here](https://github.com/visgl/react-map-gl/tree/7.1-release/docs).
175
186
react-map-gl is a suite of [React](http://facebook.github.io/react/) components for
19-
[mapbox-gl](https://github.com/mapbox/mapbox-gl-js), [maplibre-gl](https://maplibre.org/maplibre-gl-js/docs/) or compatible libraries.
7+
[mapbox-gl](https://www.npmjs.com/package/mapbox-gl), [maplibre-gl](https://www.npmjs.com/package/maplibre-gl) or compatible libraries.
208

219
| Library | Description |
2210
| --- | --- |
23-
| [MapLibre GL JS](https://github.com/MapLibre/maplibre-gl-js) | An open fork of mapbox-gl v1, that can be used without a mapbox token. |
24-
| [Mapbox GL JS v1](https://github.com/mapbox/mapbox-gl-js) | The previous version of mapbox GL JS. This version is free open source and can be used with non-mapbox basemaps without a mapbox token. |
25-
| [Mapbox GL JS v2](https://github.com/mapbox/mapbox-gl-js) | The latest version of Mapbox GL JS. Note that version 2 is not free open source, and a mapbox token is required and billable events are generated even if you do not use mapbox hosted basemaps. |
26-
| Other mapbox-gl forks | It may be possible to use react-map-gl with other mapbox forks, but this is not a supported use case. Minor PRs to enable other forks to be used may be accepted. |
11+
| [MapLibre GL JS](https://maplibre.org/maplibre-gl-js/docs/) | An Open-source TypeScript library for publishing web maps. |
12+
| [Mapbox GL JS](https://www.mapbox.com/mapbox-gljs) | A JavaScript library for interactive, customizable vector maps on the web. |
13+
| [Mapbox GL JS v1](https://github.com/mapbox/mapbox-gl-js/tree/release-v1.13.3) | The last free-open-source version of Mapbox GL JS. This version can be used without a Mapbox token if you do not use Mapbox hosted basemaps. |
14+
| Other compatible forks | It may be possible to use react-map-gl with mapbox-gl/maplibre-gl forks, but this is not a supported use case. Minor PRs to enable other forks to be used may be accepted. |
2715

28-
For basemaps:
29-
- You can load map data from Mapbox's own service.
30-
- You can create and host your own map data using one of the many [open source tools](https://github.com/mapbox/awesome-vector-tiles).
16+
If you need help choosing a base map library that is right for you:
17+
18+
- Decide where to get your vector map data.
19+
+ `mapbox-gl` is designed to work seamlessly with Mapbox's own data service. You will need a billable Mapbox token to use it.
20+
+ There are a number of [map data providers](./get-started/mapbox-tokens.md#display-maps-without-a-mapbox-token) who support `maplibre-gl`, with a variaty of data quality and price options.
21+
+ You can create and host your own map tiles and use them with `maplibre-gl` for (almost) free, if you are comfortable of using [open source tools](./get-started/mapbox-tokens.md#display-maps-without-a-mapbox-token) and setting up a cloud storage account.
22+
- Visit Mapbox and MapLibre websites for examples and documentation. Each library offer unique features that may not exist in another.
3123

3224
New to react-map-gl? [Get Started](./get-started/get-started.md)
3325

@@ -44,10 +36,10 @@ This does not scale when we have many components that need to synchronize with e
4436

4537
Ultimately, in the spirit of the [reactive programming paradigm](https://en.wikipedia.org/wiki/Reactive_programming), data always flows **down**. As long as the map manages its own state, as mapbox-gl is designed to do, we risk the components going out of sync.
4638

47-
react-map-gl creates a fully reactive wrapper for mapbox-gl. The [Map](./api-reference/map.md) component can be fully [controlled](https://reactjs.org/docs/forms.html#controlled-components), that is, the map's camera would never deviate from the props that it's assigned. Read more about this core behavior in [state management](./get-started/state-management.md).
39+
react-map-gl creates a fully reactive wrapper for mapbox-gl/maplibre-gl. The [Map](./api-reference/maplibre/map.md) component can be fully [controlled](https://reactjs.org/docs/forms.html#controlled-components), that is, the map's camera would never deviate from the props that it's assigned. Read more about this core behavior in [state management](./get-started/state-management.md).
4840

4941
## Limitations
5042

5143
In v7.0, react-map-gl was fully rewritten to better align its API with the underlying Mapbox GL JS library. Wherever the reactive usage patterns permits, the wrapper's props and methods are 1:1 mappings to their native API equivelants.
5244

53-
It is possible to call the native methods directly from the `Map` instance obtained via [getMap](./api-reference/map.md#gemap). However, doing so may result in the map's state to deviate from its props. For example, calling `map.setMaxZoom` directly will cause the map's constraint settings to differ from the value of the `maxZoom` prop. Generally speaking, calling a native method is disencouraged if the same thing can be achieved through the React interface. If a third-party plugin does so, then it may lead to some unexpected behaviors.
45+
It is possible to call the native methods directly from the `Map` instance obtained via [getMap](./api-reference/maplibre/map.md#gemap). However, doing so may result in the map's state to deviate from its props. For example, calling `map.setMaxZoom` directly will cause the map's constraint settings to differ from the value of the `maxZoom` prop. Generally speaking, calling a native method is disencouraged if the same thing can be achieved through the React interface. If a third-party plugin does so, then it may lead to some unexpected behaviors.

docs/api-reference/attribution-control.md renamed to docs/api-reference/mapbox/attribution-control.md

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
# AttributionControl
22

3-
React component that wraps the base library's `AttributionControl` class ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/markers/#attributioncontrol) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/AttributionControl/)).
4-
5-
6-
import Tabs from '@theme/Tabs';
7-
import TabItem from '@theme/TabItem';
8-
9-
<Tabs groupId="map-library">
10-
<TabItem value="mapbox" label="Mapbox">
3+
React component that wraps mapbox-gl's [AttributionControl](https://docs.mapbox.com/mapbox-gl-js/api/markers/#attributioncontrol) class.
114

125
```tsx
136
import * as React from 'react';
14-
import Map, {AttributionControl} from 'react-map-gl';
7+
import Map, {AttributionControl} from 'react-map-gl/mapbox';
8+
import 'mapbox-gl/dist/mapbox-gl.css';
159

1610
function App() {
1711
return <Map
@@ -30,37 +24,11 @@ function App() {
3024
}
3125
```
3226

33-
</TabItem>
34-
<TabItem value="maplibre" label="Maplibre">
35-
36-
```tsx
37-
import * as React from 'react';
38-
import Map, {AttributionControl} from 'react-map-gl/maplibre';
39-
40-
function App() {
41-
return <Map
42-
initialViewState={{
43-
longitude: -100,
44-
latitude: 40,
45-
zoom: 3.5
46-
}}
47-
mapStyle="https://api.maptiler.com/maps/streets/style.json?key=get_your_own_key"
48-
// disable the default attribution
49-
attributionControl={false}
50-
>
51-
<AttributionControl customAttribution="Map design by me" />
52-
</Map>;
53-
}
54-
```
55-
56-
</TabItem>
57-
</Tabs>
58-
5927
## Properties
6028

6129
### Reactive Properties
6230

63-
#### `style`: CSSProperties {#style}
31+
#### `style`: CSSProperties {#style}
6432

6533
CSS style override that applies to the control's container.
6634

@@ -75,7 +43,7 @@ Any options supported by the `AttributionControl` class ([Mapbox](https://docs.m
7543

7644
Plus the following:
7745

78-
#### `position`: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' {#position}
46+
#### `position`: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' {#position}
7947

8048
Default: `'bottom-right'`
8149

docs/api-reference/fullscreen-control.md renamed to docs/api-reference/mapbox/fullscreen-control.md

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
# FullscreenControl
22

3-
React component that wraps the base library's `FullscreenControl` class ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/markers/#fullscreencontrol) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/FullscreenControl/)).
4-
5-
6-
import Tabs from '@theme/Tabs';
7-
import TabItem from '@theme/TabItem';
8-
9-
<Tabs groupId="map-library">
10-
<TabItem value="mapbox" label="Mapbox">
3+
React component that wraps mapbox-gl's [FullscreenControl](https://docs.mapbox.com/mapbox-gl-js/api/markers/#fullscreencontrol) class.
114

125
```tsx
136
import * as React from 'react';
14-
import Map, {FullscreenControl} from 'react-map-gl';
7+
import Map, {FullscreenControl} from 'react-map-gl/mapbox';
8+
import 'mapbox-gl/dist/mapbox-gl.css';
159

1610
function App() {
1711
return <Map
@@ -28,29 +22,6 @@ function App() {
2822
}
2923
```
3024

31-
</TabItem>
32-
<TabItem value="maplibre" label="Maplibre">
33-
34-
```tsx
35-
import * as React from 'react';
36-
import Map, {FullscreenControl} from 'react-map-gl/maplibre';
37-
38-
function App() {
39-
return <Map
40-
initialViewState={{
41-
longitude: -100,
42-
latitude: 40,
43-
zoom: 3.5
44-
}}
45-
mapStyle="https://api.maptiler.com/maps/streets/style.json?key=get_your_own_key"
46-
>
47-
<FullscreenControl />
48-
</Map>;
49-
}
50-
```
51-
52-
</TabItem>
53-
</Tabs>
5425

5526
## Properties
5627

docs/api-reference/geolocate-control.md renamed to docs/api-reference/mapbox/geolocate-control.md

Lines changed: 11 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
# GeolocateControl
22

3-
React component that wraps the base library's `GeolocateControl` class ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/markers/#geolocatecontrol) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/GeolocateControl/)).
4-
5-
6-
import Tabs from '@theme/Tabs';
7-
import TabItem from '@theme/TabItem';
8-
9-
<Tabs groupId="map-library">
10-
<TabItem value="mapbox" label="Mapbox">
3+
React component that wraps mapbox-gl's [GeolocateControl](https://docs.mapbox.com/mapbox-gl-js/api/markers/#geolocatecontrol) class.
114

125
```tsx
136
import * as React from 'react';
14-
import Map, {GeolocateControl} from 'react-map-gl';
7+
import Map, {GeolocateControl} from 'react-map-gl/mapbox';
8+
import 'mapbox-gl/dist/mapbox-gl.css';
159

1610
function App() {
1711
return <Map
@@ -28,58 +22,33 @@ function App() {
2822
}
2923
```
3024

31-
</TabItem>
32-
<TabItem value="maplibre" label="Maplibre">
33-
34-
```tsx
35-
import * as React from 'react';
36-
import Map, {GeolocateControl} from 'react-map-gl/maplibre';
37-
38-
function App() {
39-
return <Map
40-
initialViewState={{
41-
longitude: -100,
42-
latitude: 40,
43-
zoom: 3.5
44-
}}
45-
mapStyle="https://api.maptiler.com/maps/streets/style.json?key=get_your_own_key"
46-
>
47-
<GeolocateControl />
48-
</Map>;
49-
}
50-
```
51-
52-
</TabItem>
53-
</Tabs>
54-
55-
5625
## Properties
5726

5827
### Reactive Properties
5928

60-
#### `style`: CSSProperties {#style}
29+
#### `style`: CSSProperties {#style}
6130

6231
CSS style override that applies to the control's container.
6332

6433
### Callbacks
6534

66-
#### `onGeolocate`: (evt: [GeolocateResultEvent](./types.md#geolocateresultevent)) => void {#ongeolocate}
35+
#### `onGeolocate`: (evt: [GeolocateResultEvent](./types.md#geolocateresultevent)) => void {#ongeolocate}
6736

6837
Called on each Geolocation API position update that returned as success.
6938

70-
#### `onError`: (evt: [GeolocateErrorEvent](./types.md#geolocateerrorevent)) => void {#onerror}
39+
#### `onError`: (evt: [GeolocateErrorEvent](./types.md#geolocateerrorevent)) => void {#onerror}
7140

7241
Called on each Geolocation API position update that returned as an error.
7342

74-
#### `onOutOfMaxBounds`: (evt: [GeolocateResultEvent](./types.md#geolocateresultevent)) => void {#onoutofmaxbounds}
43+
#### `onOutOfMaxBounds`: (evt: [GeolocateResultEvent](./types.md#geolocateresultevent)) => void {#onoutofmaxbounds}
7544

7645
Called on each Geolocation API position update that returned as success but user position is out of map `maxBounds`.
7746

78-
#### `onTrackUserLocationStart`: (evt: [GeolocateEvent](./types.md#geolocateevent)) => void {#ontrackuserlocationstart}
47+
#### `onTrackUserLocationStart`: (evt: [GeolocateEvent](./types.md#geolocateevent)) => void {#ontrackuserlocationstart}
7948

8049
Called when the GeolocateControl changes to the active lock state.
8150

82-
#### `onTrackUserLocationEnd`: (evt: [GeolocateEvent](./types.md#geolocateevent)) => void {#ontrackuserlocationend}
51+
#### `onTrackUserLocationEnd`: (evt: [GeolocateEvent](./types.md#geolocateevent)) => void {#ontrackuserlocationend}
8352

8453
Called when the GeolocateControl changes to the background state.
8554

@@ -98,7 +67,7 @@ Any options supported by the `GeolocateControl` class ([Mapbox](https://docs.map
9867

9968
Plus the following:
10069

101-
#### `position`: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' {#position}
70+
#### `position`: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' {#position}
10271

10372
Default: `'bottom-right'`
10473

@@ -110,13 +79,10 @@ Placement of the control relative to the map.
11079
The underlying native `GeolocateControl` instance is accessible via a [React ref](https://reactjs.org/docs/refs-and-the-dom.html#creating-refs) hook.
11180
You may use it to call any imperative methods:
11281

113-
<Tabs groupId="map-library">
114-
<TabItem value="mapbox" label="Mapbox">
115-
11682
```tsx
11783
import * as React from 'react';
11884
import {useRef, useEffect} from 'react';
119-
import Map, {GeolocateControl} from 'react-map-gl';
85+
import Map, {GeolocateControl} from 'react-map-gl/mapbox';
12086
import type mapboxgl from 'mapbox-gl';
12187

12288
function App() {
@@ -133,33 +99,6 @@ function App() {
13399
}
134100
```
135101

136-
</TabItem>
137-
<TabItem value="maplibre" label="Maplibre">
138-
139-
140-
```tsx
141-
import * as React from 'react';
142-
import {useRef, useEffect} from 'react';
143-
import Map, {GeolocateControl} from 'react-map-gl/maplibre';
144-
import type maplibregl from 'maplibre-gl';
145-
146-
function App() {
147-
const geoControlRef = useRef<maplibregl.GeolocateControl>();
148-
149-
useEffect(() => {
150-
// Activate as soon as the control is loaded
151-
geoControlRef.current?.trigger();
152-
}, [geoControlRef.current]);
153-
154-
return <Map>
155-
<GeolocateControl ref={geoControlRef} />
156-
</Map>;
157-
}
158-
```
159-
160-
</TabItem>
161-
</Tabs>
162-
163102

164103
## Source
165104

0 commit comments

Comments
 (0)