diff --git a/src/ui/marker.js b/src/ui/marker.js index 10bf52fd9e1..795f20fe36c 100644 --- a/src/ui/marker.js +++ b/src/ui/marker.js @@ -92,7 +92,8 @@ export default class Marker extends Evented { '_onUp', '_addDragHandler', '_onMapClick', - '_onKeyPress' + '_onKeyPress', + '_clearOcclusionTimer' ], this); this._anchor = options && options.anchor || 'center'; @@ -248,6 +249,7 @@ export default class Marker extends Evented { map.getCanvasContainer().appendChild(this._element); map.on('move', this._update); map.on('moveend', this._update); + map.on('remove', this._clearOcclusionTimer); this.setDraggable(this._draggable); this._update(); @@ -277,8 +279,10 @@ export default class Marker extends Evented { this._map.off('touchend', this._onUp); this._map.off('mousemove', this._onMove); this._map.off('touchmove', this._onMove); + this._map.off('remove', this._clearOcclusionTimer); delete this._map; } + this._clearOcclusionTimer(); DOM.remove(this._element); if (this._popup) this._popup.remove(); return this; @@ -446,6 +450,13 @@ export default class Marker extends Evented { } } + _clearOcclusionTimer() { + if (this._occlusionTimer) { + clearTimeout(this._occlusionTimer); + this._occlusionTimer = null; + } + } + _onOcclusionTimer() { const tr = this._map.transform; const pos = this._pos ? this._pos.sub(this._transformedOffset()) : null;