• Stars
    star
    1,915
  • Rank 24,206 (Top 0.5 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 8 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A React binding of mapbox-gl-js

Logo

React-mapbox-gl | Documentation | Demos

Build Status npm version npm downloads TypeScript

React wrapper for mapbox-gl-js.



London cycle example gif

Components

Proxy components (proxy between React and Mapbox API)

  • ReactMapboxGL
  • Layer & Feature
    • property symbol displays a mapbox symbol.
    • property line displays a lineString.
    • property fill displays a polygon.
    • property circle displays a mapbox circle.
    • property raster displays a mapbox raster tiles.
    • property fill-extrusion displays a layer with extruded buildings.
    • property background displays a mapbox background layer.
    • property heatmap displays a mapbox heatmap layer.
  • Source
  • GeoJSONLayer

DOM components (normal React components)

  • ZoomControl
  • ScaleControl
  • RotationControl
  • Marker (Projected component)
  • Popup (Projected component)
  • Cluster

Getting Started

npm install react-mapbox-gl mapbox-gl --save

Example:

Adding the css in your index.html:

<html>
  <head>
    ...
    <link
      href="https://api.mapbox.com/mapbox-gl-js/v1.10.1/mapbox-gl.css"
      rel="stylesheet"
    />
  </head>
</html>
// ES6
import ReactMapboxGl, { Layer, Feature } from 'react-mapbox-gl';
import 'mapbox-gl/dist/mapbox-gl.css';

// ES5
var ReactMapboxGl = require('react-mapbox-gl');
var Layer = ReactMapboxGl.Layer;
var Feature = ReactMapboxGl.Feature;
require('mapbox-gl/dist/mapbox-gl.css');

const Map = ReactMapboxGl({
  accessToken:
    'pk.eyJ1IjoiZmFicmljOCIsImEiOiJjaWc5aTV1ZzUwMDJwdzJrb2w0dXRmc2d0In0.p6GGlfyV-WksaDV_KdN27A'
});

// in render()
<Map
  style="mapbox://styles/mapbox/streets-v9"
  containerStyle={{
    height: '100vh',
    width: '100vw'
  }}
>
  <Layer type="symbol" id="marker" layout={{ 'icon-image': 'marker-15' }}>
    <Feature coordinates={[-0.481747846041145, 51.3233379650232]} />
  </Layer>
</Map>;

Why are zoom, bearing and pitch Arrays ?

If those properties changed at the mapbox-gl-js level and you don't update the value kept in your state, it will be unsynced with the current viewport. At some point you might want to update the viewport value (zoom, pitch or bearing) with the ones in your state but using value equality is not enough. Taking zoom as example, you will still have the unsynced zoom value therefore we can't tell if you want to update the prop or not. In order to explicitly update the current viewport values you can instead break the references of those props and reliably update the current viewport with the one you have in your state to be synced again.

Current version documentation

Version 3.0 documentation

Version 2.0 documentation

Contributions

Please try to reproduce your problem with the boilerplate before posting an issue.

mapbox-gl-draw compatibility

Try react-mapbox-gl-draw

Looking for an Angular alternative?

Try ngx-mapbox-gl

More Repositories

1

react-leaflet-draw

React component for leaflet-draw on top of react-leaflet
JavaScript
222
star
2

sensmove

Smart insole system which provide to the user the ability to visualize his foot forces simultaneously on his smartphone
Objective-C
56
star
3

gymbox-bot

Simplify the booking of a gymbox class.
JavaScript
23
star
4

react-typescript-starter

Simple starter-kit for react, redux, typescript, aphrodite, webpack
TypeScript
13
star
5

react-mapping

Projection mapping in React
TypeScript
12
star
6

react-mapbox-gl-debug

Simple boilerplate to start an app with react-mapbox-gl
HTML
11
star
7

node-express-ts

Minimalistic node express boilerplate in Typescript
TypeScript
3
star
8

food

Leave to algorithm the choice for your lunch.
Python
3
star
9

ts-pq

Typescript priority queue
TypeScript
3
star
10

numeractive

Full javascript Blog boilerplate
JavaScript
3
star
11

hackcessangels

iOS app to help people with disabilities get help from nearby agents in train stations.
Objective-C
2
star
12

elm-twitter

Twitter feed made with Elm
Elm
2
star
13

sharexp

An app to share expense between a group of users (Experimental project made in Elm)
Elm
2
star
14

express-fixturer

Express middleware to automatically generate and use fixtures
TypeScript
2
star
15

dotfiles

Some of my settings files
Vim Script
2
star
16

reselect-brownbag

Code from a brownbag about reselect
TypeScript
1
star
17

food-discovery

TypeScript
1
star
18

raclette-party

JavaScript
1
star
19

isomorphic-fetch-rx

Small wrapper on top of isomorphic that output an observable
TypeScript
1
star
20

gousto-app

TypeScript
1
star
21

euler-project-typescript

TypeScript
1
star
22

monzo-map

JavaScript
1
star
23

Jira-github-plugin

Lambdas to update Jira according to Github actions
JavaScript
1
star
24

awesome-lifehack-scripts

A curated list of scripts to improve your lifestyle and save you time
1
star