Skip to content

Commit

Permalink
fix(kepler-integration): remove mapboxMap.remove (#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
igorDykhta authored Jan 14, 2022
1 parent 85df350 commit 07618b3
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,16 @@ export class ExportVideoPanelPreview extends Component {

if (this.mapRef.current) {
const map = this.mapRef.current.getMap();
map.remove();

// remove all rendering related handlers to prevent rendering after unmount
const listeners = [...map._listeners.render];
listeners.forEach(listener => {
map.off('render', listener);
});

this.state.mapboxLayerIds?.forEach(id => {
map.removeLayer(id);
});
}
}

Expand Down Expand Up @@ -132,16 +141,22 @@ export class ExportVideoPanelPreview extends Component {
const keplerLayers = this.createLayers();
const beforeId = this.props.mapboxLayerBeforeId;

const mapboxLayerIds = [];

// If there aren't any layers, combine map and deck with a fake layer.
if (!keplerLayers.length) {
map.addLayer(new MapboxLayer({id: '%%blank-layer', deck}));
mapboxLayerIds.push('%%blank-layer');
}

for (let i = 0; i < keplerLayers.length; i++) {
// Adds DeckGL layers to Mapbox so Mapbox can be the bottom layer. Removing this clips DeckGL layers
map.addLayer(new MapboxLayer({id: keplerLayers[i].id, deck}), beforeId);
mapboxLayerIds.push(keplerLayers[i].id);
}

this.setState({mapboxLayerIds});

map.on('render', this._onAfterRender);
}

Expand Down

0 comments on commit 07618b3

Please sign in to comment.