Skip to content

Commit

Permalink
reorganize get-started examples (#971)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pessimistress committed Jan 2, 2020
1 parent c293324 commit 439e7ec
Show file tree
Hide file tree
Showing 30 changed files with 132 additions and 111 deletions.
11 changes: 7 additions & 4 deletions docs/get-started/get-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

## Installation

Using `react-map-gl` requires `node >= v4` and `react >= 15.4`.
Using `react-map-gl` requires `node >= v4` and `react >= 16.3`.

```sh
npm install --save react-map-gl
Expand All @@ -27,12 +27,14 @@ function Map() {
return (
<ReactMapGL
{...viewport}
onViewportChange={viewport => setViewport(viewport)}
onViewportChange={setViewport}
/>
);
}
```

See full project setup in [get-started examples](https://github.com/uber/react-map-gl/tree/master/examples/get-started)

## Styling

The current mapbox-gl release requires its stylesheet be included at all times. The marker, popup and navigation components in react-map-gl also need the stylesheet to work properly.
Expand All @@ -43,10 +45,11 @@ You may add the stylesheet to the head of your page:
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v<YOUR_MAPBOX_VERSION>/mapbox-gl.css' rel='stylesheet' />
```

Find out your mapbox version by running yarn list mapbox-gl or npm ls mapbox-gl.
Find out your mapbox version by running `yarn list mapbox-gl` or `npm ls mapbox-gl`.

Or embed it in your app by using - [browserify-css](https://www.npmjs.com/package/browserify-css)
with Browserify or - [css-loader](https://webpack.github.io/docs/stylesheets.html) with Webpack:

```js
// app.js
import 'mapbox-gl/dist/mapbox-gl.css';
Expand All @@ -62,4 +65,4 @@ import 'mapbox-gl/dist/mapbox-gl.css';

* `create-react-app-typescript` - react-map-gl is compatible with [create-react-app-typescript](https://github.com/wmonk/create-react-app-typescript). You can see an example [here](https://github.com/zackhsi/react-map-gl-typescript).

There's many other ready-to-run [examples](https://github.com/uber/react-map-gl/tree/5.0-release/examples) you can take a look at if you need more inspiration.
There's many other ready-to-run [examples](https://github.com/uber/react-map-gl/tree/master/examples) you can take a look at if you need more inspiration.
2 changes: 1 addition & 1 deletion examples/additional-overlays/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"immutable": "^3.8.1",
"react": "^16.3.0",
"react-dom": "^16.3.0",
"react-map-gl": "^5.1.0-alpha"
"react-map-gl": "^5.1.0"
},
"devDependencies": {
"@babel/core": "^7.0.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/controls/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"dependencies": {
"react": "^16.3.0",
"react-dom": "^16.3.0",
"react-map-gl": "^5.1.0-alpha"
"react-map-gl": "^5.1.0"
},
"devDependencies": {
"@babel/core": "^7.0.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/custom-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"dependencies": {
"react": "^16.3.0",
"react-dom": "^16.3.0",
"react-map-gl": "^5.1.0-alpha"
"react-map-gl": "^5.1.0"
},
"devDependencies": {
"@babel/core": "^7.0.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/custom-cursor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"dependencies": {
"react": "^16.3.0",
"react-dom": "^16.3.0",
"react-map-gl": "^5.1.0-alpha"
"react-map-gl": "^5.1.0"
},
"devDependencies": {
"@babel/core": "^7.0.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/deckgl-overlay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"probe.gl": "2.0.0-beta.1",
"react": "^16.3.0",
"react-dom": "^16.3.0",
"react-map-gl": "^5.1.0-alpha"
"react-map-gl": "^5.1.0"
},
"devDependencies": {
"@babel/core": "^7.0.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/draggable-markers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"dependencies": {
"react": "^16.3.0",
"react-dom": "^16.3.0",
"react-map-gl": "^5.1.0-alpha"
"react-map-gl": "^5.1.0"
},
"devDependencies": {
"@babel/core": "^7.0.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/draw-polygon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"@turf/area": "^6.0.1",
"react": "^16.3.0",
"react-dom": "^16.3.0",
"react-map-gl": "^5.1.0-alpha",
"react-map-gl": "^5.1.0",
"react-map-gl-draw": "^0.15.0",
"styled-components": "^4.3.2"
},
Expand Down
10 changes: 0 additions & 10 deletions examples/exhibit-browserify/README.md

This file was deleted.

40 changes: 0 additions & 40 deletions examples/exhibit-browserify/app.js

This file was deleted.

26 changes: 0 additions & 26 deletions examples/exhibit-browserify/package.json

This file was deleted.

2 changes: 1 addition & 1 deletion examples/filter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"dependencies": {
"react": "^16.3.0",
"react-dom": "^16.3.0",
"react-map-gl": "^5.1.0-alpha"
"react-map-gl": "^5.1.0"
},
"devDependencies": {
"@babel/core": "^7.0.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/geojson-animation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"dependencies": {
"react": "^16.3.0",
"react-dom": "^16.3.0",
"react-map-gl": "^5.1.0-alpha"
"react-map-gl": "^5.1.0"
},
"devDependencies": {
"@babel/core": "^7.0.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/geojson/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"d3-scale": "^1.0.6",
"react": "^16.3.0",
"react-dom": "^16.3.0",
"react-map-gl": "^5.1.0-alpha"
"react-map-gl": "^5.1.0"
},
"devDependencies": {
"@babel/core": "^7.0.0",
Expand Down
13 changes: 13 additions & 0 deletions examples/get-started/classic/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<div align="center">
<img src="https://avatars3.githubusercontent.com/u/2105791?v=3&s=200" />
</div>

## react-map-gl example with React Component

The configuration showcased here is a bit less straightforward than its browserify
equivalent due to some incompatibilities with mapbox-gl, but has been kept at a
strict minimum.

You should keep in mind that it is a development configuration, and probably
should be tweaked a bit for production optimization, there is plenty ressources
on the subject and are not in the scope of this example.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class Root extends Component {
super(props);
this.state = {
viewport: {
latitude: 37.785164,
longitude: -122.41669,
latitude: 37.8,
longitude: -122.4,
zoom: 14,
bearing: 0,
pitch: 0
Expand All @@ -20,20 +20,18 @@ class Root extends Component {
}

render() {
const {viewport} = this.state;

return (
<MapGL
{...viewport}
{...this.state.viewport}
width="100vw"
height="100vh"
mapStyle="mapbox://styles/mapbox/dark-v9"
onViewportChange={v => this.setState({viewport: v})}
preventStyleDiffing={false}
onViewportChange={viewport => this.setState({viewport})}
mapboxApiAccessToken={MAPBOX_TOKEN}
/>
);
}
}

document.body.style.margin = 0;
render(<Root />, document.body.appendChild(document.createElement('div')));
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
"start": "webpack-dev-server --progress --hot --open"
},
"dependencies": {
"immutable": "^3.8.1",
"react": "^16.3.0",
"react-dom": "^16.3.0",
"react-map-gl": "^5.1.0-alpha"
"react-map-gl": "^5.1.0"
},
"devDependencies": {
"@babel/core": "^7.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
const resolve = require('path').resolve;
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
mode: 'development',

entry: {
app: resolve('./app.js')
app: './app.js'
},

devtool: 'source-map',
Expand All @@ -16,7 +15,6 @@ module.exports = {
{
// Compile ES2015 using babel
test: /\.js$/,
include: [resolve('.')],
exclude: [/node_modules/],
use: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<img src="https://avatars3.githubusercontent.com/u/2105791?v=3&s=200" />
</div>

## Exhibits: Webpack
## react-map-gl example with React Hooks

The configuration showcased here is a bit less straightforward than its browserify
equivalent due to some incompatibilities with mapbox-gl, but has been kept at a
Expand Down
30 changes: 30 additions & 0 deletions examples/get-started/hooks/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* global document */
import React, {useState} from 'react';
import {render} from 'react-dom';
import MapGL from 'react-map-gl';

const MAPBOX_TOKEN = ''; // Set your mapbox token here

function Root() {
const [viewport, setViewport] = useState({
latitude: 37.8,
longitude: -122.4,
zoom: 14,
bearing: 0,
pitch: 0
});

return (
<MapGL
{...viewport}
width="100vw"
height="100vh"
mapStyle="mapbox://styles/mapbox/dark-v9"
onViewportChange={setViewport}
mapboxApiAccessToken={MAPBOX_TOKEN}
/>
);
}

document.body.style.margin = 0;
render(<Root />, document.body.appendChild(document.createElement('div')));
20 changes: 20 additions & 0 deletions examples/get-started/hooks/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"scripts": {
"start": "webpack-dev-server --progress --hot --open"
},
"dependencies": {
"react": "^16.8.0",
"react-dom": "^16.8.0",
"react-map-gl": "^5.1.0"
},
"devDependencies": {
"@babel/core": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/preset-react": "^7.0.0",
"babel-loader": "^8.0.0",
"html-webpack-plugin": "^3.0.7",
"webpack": "^4.20.0",
"webpack-cli": "^3.1.2",
"webpack-dev-server": "^3.1.0"
}
}
36 changes: 36 additions & 0 deletions examples/get-started/hooks/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
mode: 'development',

entry: {
app: './app.js'
},

devtool: 'source-map',

module: {
rules: [
{
// Compile ES2015 using babel
test: /\.js$/,
exclude: [/node_modules/],
use: [
{
loader: 'babel-loader',
options: {
presets: ['@babel/env', '@babel/react']
}
}
]
}
]
},

// Optional: Enables reading mapbox token from environment variable
plugins: [
new HtmlWebpackPlugin({title: 'react-map-gl Example'}),
new webpack.EnvironmentPlugin(['MapboxAccessToken'])
]
};
Loading

0 comments on commit 439e7ec

Please sign in to comment.