我正在使用 React-MAP-GL,并且在尝试更新对象时出现问题Style is not done loading 。mapStyle
import React from 'react';
import ReactMapGL from 'react-map-gl';
import {defaultMapStyle, dataLayer} from './map-style.js';
import {fromJS} from 'immutable';
import geoJson from './cali.json';
export default class Map extends React.Component {
constructor(props) {
super(props);
this.state = {
mapStyle: defaultMapStyle,
data: null,
viewport: {
width: 600,
height: 800,
latitude: 36.7783,
longitude: -119.4179,
zoom: 5,
},
};
}
componentDidMount() {
window.addEventListener('resize', this._resize);
this._loadData(geoJson);
}
_loadData = data => {
const mapStyle = defaultMapStyle
.setIn(['sources', 'incomeByState'], fromJS({type: 'geojson', data}))
.set('layers', defaultMapStyle.get('layers').push(dataLayer));
this.setState({data, mapStyle});
};
render() {
return (
<div>
<ReactMapGL
{...this.state.viewport}
mapStyle={this.state.mapStyle}
onViewportChange={viewport => {
this.setState({viewport});
}}
mapboxApiAccessToken=""
/>
</div>
);
}
}