mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2024-11-10 09:07:47 +01:00
Ensure style updates are applied after inspect
This commit is contained in:
parent
c363c88f23
commit
91604afccb
1 changed files with 11 additions and 10 deletions
|
@ -40,6 +40,7 @@ export default class MapboxGlMap extends React.Component {
|
|||
MapboxGl.accessToken = props.accessToken
|
||||
this.state = {
|
||||
map: null,
|
||||
inspect: null,
|
||||
isPopupOpen: false,
|
||||
popupX: 0,
|
||||
popupY: 0,
|
||||
|
@ -51,15 +52,15 @@ export default class MapboxGlMap extends React.Component {
|
|||
|
||||
if(!this.state.map) return
|
||||
|
||||
if(!this.props.inspectModeEnabled) {
|
||||
if(this.props.inspectModeEnabled !== nextProps.inspectModeEnabled) {
|
||||
this.state.inspect.toggleInspector()
|
||||
}
|
||||
|
||||
if(!nextProps.inspectModeEnabled) {
|
||||
//Mapbox GL now does diffing natively so we don't need to calculate
|
||||
//the necessary operations ourselves!
|
||||
this.state.map.setStyle(nextProps.mapStyle, { diff: true})
|
||||
}
|
||||
|
||||
if(this.props.inspectModeEnabled !== nextProps.inspectModeEnabled) {
|
||||
this.inspect.toggleInspector()
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
|
@ -69,10 +70,10 @@ export default class MapboxGlMap extends React.Component {
|
|||
hash: true,
|
||||
})
|
||||
|
||||
const nav = new MapboxGl.NavigationControl();
|
||||
map.addControl(nav, 'top-right');
|
||||
const nav = new MapboxGl.NavigationControl();
|
||||
map.addControl(nav, 'top-right');
|
||||
|
||||
this.inspect = new MapboxInspect({
|
||||
const inspect = new MapboxInspect({
|
||||
popup: new MapboxGl.Popup({
|
||||
closeButton: false,
|
||||
closeOnClick: false
|
||||
|
@ -86,10 +87,10 @@ export default class MapboxGlMap extends React.Component {
|
|||
}
|
||||
}
|
||||
})
|
||||
map.addControl(this.inspect)
|
||||
map.addControl(inspect)
|
||||
|
||||
map.on("style.load", () => {
|
||||
this.setState({ map });
|
||||
this.setState({ map, inspect });
|
||||
})
|
||||
|
||||
map.on("data", e => {
|
||||
|
|
Loading…
Reference in a new issue