From cf518ff1a5e0e54a2f63faa144aeaa50888e0bc6 Mon Sep 17 00:00:00 2001 From: ghybs Date: Tue, 31 Oct 2017 19:46:28 +0400 Subject: [PATCH] Fix(Map): stopLocate on map.remove (#5893) so that Geolocation handlers (namely _handleGeolocationResponse and _handleGeolocationError) do not try to access DOM elements which have been cleared by map.remove(). Of course developer should currently call map.stopLocate() manually before map.remove(), but it looks like he/she may forget it. Check for _locationWatchId is not perfect (watch may have been already stopped), but calling stopLocate again does not harm. It prevents trying to access the Geolocation API if locate had never been called, even though doing so should not harm either. --- src/map/Map.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/map/Map.js b/src/map/Map.js index 6cd82fd9..4861695d 100644 --- a/src/map/Map.js +++ b/src/map/Map.js @@ -722,6 +722,10 @@ export var Map = Evented.extend({ this._containerId = undefined; } + if (this._locationWatchId !== undefined) { + this.stopLocate(); + } + this._stop(); DomUtil.remove(this._mapPane);