mirror of
https://github.com/visgl/react-map-gl.git
synced 2026-01-18 15:54:22 +00:00
48 lines
1.0 KiB
JavaScript
48 lines
1.0 KiB
JavaScript
import React, {Component} from 'react';
|
|
import {render} from 'react-dom';
|
|
import MapGL from 'react-map-gl';
|
|
import ControlPanel from './control-panel';
|
|
|
|
const MAPBOX_TOKEN = ''; // Set your mapbox token here
|
|
|
|
export default class App extends Component {
|
|
state = {
|
|
mapStyle: '',
|
|
viewport: {
|
|
latitude: 37.805,
|
|
longitude: -122.447,
|
|
zoom: 15.5,
|
|
bearing: 0,
|
|
pitch: 0
|
|
}
|
|
};
|
|
|
|
_onViewportChange = viewport => this.setState({viewport});
|
|
|
|
_onStyleChange = mapStyle => this.setState({mapStyle});
|
|
|
|
render() {
|
|
const {viewport, mapStyle} = this.state;
|
|
|
|
return (
|
|
<MapGL
|
|
{...viewport}
|
|
width="100%"
|
|
height="100%"
|
|
mapStyle={mapStyle}
|
|
onViewportChange={this._onViewportChange}
|
|
mapboxApiAccessToken={MAPBOX_TOKEN}
|
|
>
|
|
<ControlPanel
|
|
containerComponent={this.props.containerComponent}
|
|
onChange={this._onStyleChange}
|
|
/>
|
|
</MapGL>
|
|
);
|
|
}
|
|
}
|
|
|
|
export function renderToDom(container) {
|
|
render(<App />, container);
|
|
}
|