From 0c636f078212783ac88d5a9211c5441a2117d364 Mon Sep 17 00:00:00 2001 From: Kamil Sienkiewicz Date: Wed, 6 Mar 2024 23:57:25 +0100 Subject: [PATCH 1/3] chore: call _remove on fragment styles when destroing Style --- src/style/style.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/style/style.js b/src/style/style.js index 8067c79df50..34e03abc7f1 100644 --- a/src/style/style.js +++ b/src/style/style.js @@ -3037,6 +3037,9 @@ class Style extends Evented { destroy() { this._clearWorkerCaches(); + this.fragments.forEach(fragment=>{ + fragment.style._remove(); + }); if (this.terrainSetForDrapingOnly()) { delete this.terrain; delete this.stylesheet.terrain; From 60cb95ea82c45fb402fee638a7d15e672c5e415a Mon Sep 17 00:00:00 2001 From: Kamil Sienkiewicz Date: Thu, 7 Mar 2024 00:01:11 +0100 Subject: [PATCH 2/3] chore: apply code styling --- src/style/style.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/style/style.js b/src/style/style.js index 34e03abc7f1..631a5d2a2c4 100644 --- a/src/style/style.js +++ b/src/style/style.js @@ -3037,7 +3037,7 @@ class Style extends Evented { destroy() { this._clearWorkerCaches(); - this.fragments.forEach(fragment=>{ + this.fragments.forEach(fragment => { fragment.style._remove(); }); if (this.terrainSetForDrapingOnly()) { From 97b57dfa6288dd491f0a28204c951ed82e98b167 Mon Sep 17 00:00:00 2001 From: Stepan Kuzmin Date: Thu, 14 Mar 2024 16:42:06 +0200 Subject: [PATCH 3/3] Cleanup MapSessionAPI error callback on map.remove --- src/ui/map.js | 5 ++++- src/util/mapbox.js | 9 +++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/ui/map.js b/src/ui/map.js index 827ff84c181..5dedc0bb661 100755 --- a/src/ui/map.js +++ b/src/ui/map.js @@ -5,7 +5,7 @@ import {asyncAll, extend, bindAll, warnOnce, uniqueId, isSafariWithAntialiasingB import browser from '../util/browser.js'; import * as DOM from '../util/dom.js'; import {getImage, getJSON, ResourceType} from '../util/ajax.js'; -import {RequestManager, getMapSessionAPI, postPerformanceEvent, postMapLoadEvent, AUTH_ERR_MSG, storeAuthState, removeAuthState} from '../util/mapbox.js'; +import {RequestManager, mapSessionAPI, getMapSessionAPI, postPerformanceEvent, postMapLoadEvent, AUTH_ERR_MSG, storeAuthState, removeAuthState} from '../util/mapbox.js'; import Style from '../style/style.js'; import EvaluationParameters from '../style/evaluation_parameters.js'; import Painter from '../render/painter.js'; @@ -4012,6 +4012,9 @@ class Map extends Camera { PerformanceUtils.clearMetrics(); removeAuthState(this.painter.context.gl); + + mapSessionAPI.remove(); + this._removed = true; this.fire(new Event('remove')); } diff --git a/src/util/mapbox.js b/src/util/mapbox.js index 8e346017baa..9c1faf8b9eb 100644 --- a/src/util/mapbox.js +++ b/src/util/mapbox.js @@ -576,6 +576,11 @@ export class MapSessionAPI extends TelemetryEvent { } }, customAccessToken); } + + remove() { + // $FlowFixMe[incompatible-type] + this.errorCb = null; + } } export class TurnstileEvent extends TelemetryEvent { @@ -660,9 +665,9 @@ export const performanceEvent_: PerformanceEvent = new PerformanceEvent(); // $FlowFixMe[method-unbinding] export const postPerformanceEvent: (?string, LivePerformanceData) => void = performanceEvent_.postPerformanceEvent.bind(performanceEvent_); -const mapSessionAPI_ = new MapSessionAPI(); +export const mapSessionAPI: MapSessionAPI = new MapSessionAPI(); // $FlowFixMe[method-unbinding] -export const getMapSessionAPI: (number, string, ?string, EventCallback) => void = mapSessionAPI_.getSessionAPI.bind(mapSessionAPI_); +export const getMapSessionAPI: (number, string, ?string, EventCallback) => void = mapSessionAPI.getSessionAPI.bind(mapSessionAPI); const authenticatedMaps = new Set(); export function storeAuthState(gl: WebGL2RenderingContext, state: boolean) {