mirror of
https://github.com/maputnik/editor.git
synced 2025-12-30 18:10:01 +00:00
Try solve no map changes problem
This commit is contained in:
36
src/map.jsx
36
src/map.jsx
@@ -1,6 +1,6 @@
|
||||
import React from 'react'
|
||||
import ReactMapboxGl, { ZoomControl } from "react-mapbox-gl"
|
||||
|
||||
import MapboxGl from 'mapbox-gl';
|
||||
import diffStyles from 'mapbox-gl-style-spec/lib/diff'
|
||||
import theme from './theme.js'
|
||||
|
||||
export class Map extends React.Component {
|
||||
@@ -8,11 +8,33 @@ export class Map extends React.Component {
|
||||
mapStyle: React.PropTypes.object.isRequired
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
const map = this.state.map
|
||||
if(map) {
|
||||
const changes = diffStyles(this.props.mapStyle, nextProps.mapStyle)
|
||||
changes.forEach(change => {
|
||||
map[change.command].apply(map, change.args);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
shouldComponentUpdate(nextProps, nextState) {
|
||||
return nextProps.mapStyle !== this.props.mapStyle
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
MapboxGl.accessToken = "pk.eyJ1IjoibW9yZ2Vua2FmZmVlIiwiYSI6IjIzcmN0NlkifQ.0LRTNgCc-envt9d5MzR75w";
|
||||
const map = new MapboxGl.Map({
|
||||
container: this.container,
|
||||
style: this.props.mapStyle,
|
||||
});
|
||||
|
||||
map.on("style.load", (...args) => {
|
||||
this.setState({ map });
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
return <ReactMapboxGl
|
||||
style={this.props.mapStyle}
|
||||
accessToken="pk.eyJ1IjoibW9yZ2Vua2FmZmVlIiwiYSI6IjIzcmN0NlkifQ.0LRTNgCc-envt9d5MzR75w">
|
||||
<ZoomControl/>
|
||||
</ReactMapboxGl>
|
||||
return <div ref={x => this.container = x}></div>
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user