Skip to content

Commit

Permalink
Another attempt to fix the issue
Browse files Browse the repository at this point in the history
  • Loading branch information
HarelM committed Mar 14, 2024
1 parent 3c043fd commit 00962c6
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions src/components/MapMaplibreGl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,6 @@ export default class MapMaplibreGl extends React.Component<MapMaplibreGlProps, M
}
}

updateMapFromProps(props: MapMaplibreGlProps) {
if(!this.state.map) return

//Maplibre GL now does diffing natively so we don't need to calculate
//the necessary operations ourselves!
if (props?.mapStyle) {
if (!props.mapStyle.metadata) {
props.mapStyle.metadata = {};
}
}
this.state.map.setStyle(
this.props.replaceAccessTokens(props.mapStyle),
{diff: true}
)
}

shouldComponentUpdate(nextProps: MapMaplibreGlProps, nextState: MapMaplibreGlState) {
let should = false;
Expand All @@ -119,13 +104,23 @@ export default class MapMaplibreGl extends React.Component<MapMaplibreGlProps, M
componentDidUpdate() {
const map = this.state.map;

this.updateMapFromProps(this.props);
const styleWithTokens = this.props.replaceAccessTokens(this.props.mapStyle);
if (map) {
// Maplibre GL now does diffing natively so we don't need to calculate
// the necessary operations ourselves!
// We also need to update the style for inspect to work properly
map.setStyle(styleWithTokens, {diff: true});
}

if(this.state.inspect && this.props.inspectModeEnabled !== this.state.inspect._showInspectMap) {
this.state.inspect.toggleInspector()
}
if (this.state.inspect && this.props.inspectModeEnabled) {
this.state.inspect!.setOriginalStyle(this.props.replaceAccessTokens(this.props.mapStyle));
this.state.inspect.setOriginalStyle(styleWithTokens);
// In case the sources are the same, there's a need to refresh the style
setTimeout(() => {
this.state.inspect!.render();
}, 500);
}
if (map) {
map.showTileBoundaries = this.props.options?.showTileBoundaries!;
Expand Down

0 comments on commit 00962c6

Please sign in to comment.