Doc
React-mapbox-glReact wrapper for mapbox-gl-js. Expose a bunch of component meant to be simple to use for React. It is important to understand the difference between the components Map
, Layer
, GeoJsonLayer
, Source
, Feature
(proxy between React and Mapbox API) and the components Marker
, Popup
, Cluster
, ZoomControl
, ScaleControl
, RotationControl
which are real React components.
Include the following elements:
- ReactMapboxGl
- Layer
- Source
- Feature
- Layer type properties
symbol
display a mapbox symbol. - Layer type properties
line
display a lineString. - Layer type properties
fill
display a polygon. - Layer type properties
circle
display a mapbox circle.
- Layer type properties
- GeoJSONLayer
- ZoomControl
- ScaleControl
- RotationControl
- Marker (Projected component)
- Popup (Projected component)
- Cluster
This repository include the Typescript type definition files
How to start
npm install react-mapbox-gl mapbox-gl --save
Example:
// ES6import ReactMapboxGl Layer Feature from "react-mapbox-gl"; // ES5var ReactMapboxGl = ;var Layer = ReactMapboxGlLayer;var Feature = ReactMapboxGlFeature; const Map = ; <Map ="mapbox://styles/mapbox/streets-v9" => <Layer ="symbol" ="marker" => <Feature =/> </Layer></Map>
Why is zoom an array
The zoom property is an array on purpose. With a float as a value we can't tell whether the zoom has changed when checking for value equality 7 === 7 // true
.
We changed it to an array so that between 2 render it check for a reference equality [7] === [7] // false
,
this way we can reliably update the zoom value without having to keep the viewport in the state of the Map component.
Version 2.0 Documentation
Version 1.12 documentation
Contributions
- Ideally before posting an issue you can try to reproduce the bug you encounter using this boilerplate