mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2024-12-28 16:01:15 +01:00
Fix bug with empty map
This commit is contained in:
parent
b088af1586
commit
7da97ddd6e
1 changed files with 9 additions and 5 deletions
14
src/gl.jsx
14
src/gl.jsx
|
@ -7,6 +7,10 @@ import Immutable from 'immutable'
|
||||||
import validateColor from 'mapbox-gl-style-spec/lib/validate/validate_color'
|
import validateColor from 'mapbox-gl-style-spec/lib/validate/validate_color'
|
||||||
|
|
||||||
export class MapboxGlMap extends Map {
|
export class MapboxGlMap extends Map {
|
||||||
|
constructor(props) {
|
||||||
|
super(props)
|
||||||
|
this.state = { map: null }
|
||||||
|
}
|
||||||
componentWillReceiveProps(nextProps) {
|
componentWillReceiveProps(nextProps) {
|
||||||
const tokenChanged = nextProps.accessToken !== MapboxGl.accessToken
|
const tokenChanged = nextProps.accessToken !== MapboxGl.accessToken
|
||||||
|
|
||||||
|
@ -15,13 +19,13 @@ export class MapboxGlMap extends Map {
|
||||||
// TODO: might already be handled in diff algorithm?
|
// TODO: might already be handled in diff algorithm?
|
||||||
const mapIdChanged = this.props.mapStyle.get('id') !== nextProps.mapStyle.get('id')
|
const mapIdChanged = this.props.mapStyle.get('id') !== nextProps.mapStyle.get('id')
|
||||||
|
|
||||||
if(mapIdChanged || tokenChanged) {
|
|
||||||
this.state.map.setStyle(style.toJSON(nextProps.mapStyle))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: If there is no map yet we need to apply the changes later?
|
// TODO: If there is no map yet we need to apply the changes later?
|
||||||
if(this.state.map) {
|
if(this.state.map) {
|
||||||
|
if(mapIdChanged || tokenChanged) {
|
||||||
|
this.state.map.setStyle(style.toJSON(nextProps.mapStyle))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
style.diffStyles(this.props.mapStyle, nextProps.mapStyle).forEach(change => {
|
style.diffStyles(this.props.mapStyle, nextProps.mapStyle).forEach(change => {
|
||||||
|
|
||||||
//TODO: Invalid outline color can cause map to freeze?
|
//TODO: Invalid outline color can cause map to freeze?
|
||||||
|
|
Loading…
Reference in a new issue