diff --git a/lib/HeatmapLayer.js b/lib/HeatmapLayer.js index fac909d..49af6a5 100644 --- a/lib/HeatmapLayer.js +++ b/lib/HeatmapLayer.js @@ -306,6 +306,12 @@ exports.default = (0, _reactLeaflet.withLeaflet)((_temp = _class = function (_Ma }; HeatmapLayer.prototype.redraw = function redraw() { + // It's possible that the map has unmounted while we've waited for an animation frame, so we + // need to check that it still exists before proceeding with the redraw. + if (!this.props.leaflet.map._mapPane) { + return; + } + var r = this._heatmap._r; var size = this.props.leaflet.map.getSize(); diff --git a/package.json b/package.json index 6735b02..66d9c67 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-leaflet-heatmap-layer", - "version": "2.0.0", + "version": "2.0.1", "description": "A custom layer for heatmaps in react-leaflet", "main": "lib/HeatmapLayer.js", "scripts": { diff --git a/src/HeatmapLayer.js b/src/HeatmapLayer.js index 7534929..2eec3f6 100644 --- a/src/HeatmapLayer.js +++ b/src/HeatmapLayer.js @@ -294,6 +294,12 @@ export default withLeaflet(class HeatmapLayer extends MapLayer { } redraw(): void { + // It's possible that the map has unmounted while we've waited for an animation frame, so we + // need to check that it still exists before proceeding with the redraw. + if (!this.props.leaflet.map._mapPane) { + return; + } + const r = this._heatmap._r; const size = this.props.leaflet.map.getSize();