mirror of
https://github.com/visgl/react-map-gl.git
synced 2026-01-25 16:02:50 +00:00
49 lines
1.1 KiB
JavaScript
49 lines
1.1 KiB
JavaScript
import React, {Component} from 'react';
|
|
import {render} from 'react-dom';
|
|
import BartMap from './bart-map';
|
|
|
|
const LIGHT_STYLE = 'mapbox://styles/mapbox/light-v9';
|
|
const DARK_STYLE = 'mapbox://styles/mapbox/dark-v9';
|
|
|
|
export default class App extends Component {
|
|
state = {
|
|
showMap: true,
|
|
mapStyleLight: true
|
|
};
|
|
|
|
_toggleMap() {
|
|
let {showMap, mapStyleLight} = this.state;
|
|
|
|
showMap = !this.state.showMap;
|
|
if (showMap) {
|
|
mapStyleLight = !mapStyleLight;
|
|
}
|
|
|
|
this.setState({
|
|
showMap,
|
|
mapStyleLight
|
|
});
|
|
}
|
|
|
|
render() {
|
|
const {showMap, mapStyleLight} = this.state;
|
|
const mapStyle = mapStyleLight ? LIGHT_STYLE : DARK_STYLE;
|
|
if (showMap) {
|
|
// eslint-disable-next-line no-console, no-undef
|
|
console.warn(mapStyle);
|
|
}
|
|
return (
|
|
<div style={{height: '100%'}}>
|
|
<button style={{position: 'fixed', zIndex: 1}} onClick={this._toggleMap.bind(this)}>
|
|
Toggle Map
|
|
</button>
|
|
{showMap && <BartMap mapStyle={mapStyle} />}
|
|
</div>
|
|
);
|
|
}
|
|
}
|
|
|
|
export function renderToDom(container) {
|
|
render(<App />, container);
|
|
}
|