From bb9192072ea44c825b8fef8a45ec7e4be50d0acc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Sandvik?= Date: Tue, 9 Mar 2021 18:05:50 +0100 Subject: [PATCH] fix: only set feature hover state if layer is still on map --- src/layers/Layer.js | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/layers/Layer.js b/src/layers/Layer.js index 96bf03f4..85b9b1e0 100644 --- a/src/layers/Layer.js +++ b/src/layers/Layer.js @@ -247,16 +247,20 @@ class Layer extends Evented { // Highlight a layer feature highlight(id) { - const feature = id ? this.getFeature(id) : null - - this.getMap().setHoverState( - feature - ? { - id: feature.id, - source: this.getId(), - } - : null - ) + const map = this.getMap() + + if (map) { + const feature = id ? this.getFeature(id) : null + + map.setHoverState( + feature + ? { + id: feature.id, + source: this.getId(), + } + : null + ) + } } // Override if needed in subclass