mirror of
https://github.com/visgl/react-map-gl.git
synced 2025-12-08 20:16:02 +00:00
1.5 KiB
1.5 KiB
Get Started
Installation
Using react-map-gl requires node >= v4 and react >= 15.4.
npm install --save react-map-gl
Using with Browserify, Webpack, and other JavaScript Bundlers
-
browserify- react-map-gl is extensively tested withbrowserifyand works without configuration. -
webpack 2- Most of the provided react-map-gl examples use webpack 2. For a minimal example, look at the exhibit-webpack folder, demonstrating a working demo usingwebpack 2. -
create-react-app- At this point configuration-free builds are not possible with webpack due to the way the mapbox-gl-js module is published. You will need to eject your app and add an alias to your webpack config. The following tutorial might be helpful.
There's many other ready-to-run examples you can take a look at if you need more inspiration.
Example Code
import {Component} from 'react';
import ReactMapGL from 'react-map-gl';
class Map extends Component {
render() {
return (
<ReactMapGL
width={400}
height={400}
latitude={37.7577}
longitude={-122.4376}
zoom={8}
onViewportChange={(viewport) => {
const {width, height, latitude, longitude, zoom} = viewport;
// Optionally call `setState` and use the state to update the map.
}}
/>
);
}
}