From 2208d3621d51897ffc956a0b74e5453c2fd4d32f Mon Sep 17 00:00:00 2001 From: Bartek Fabiszewski Date: Fri, 15 May 2020 20:49:55 +0200 Subject: [PATCH] Fix using api which is not ready --- js/src/mapviewmodel.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/js/src/mapviewmodel.js b/js/src/mapviewmodel.js index eff39e4..36a5757 100644 --- a/js/src/mapviewmodel.js +++ b/js/src/mapviewmodel.js @@ -81,17 +81,22 @@ export default class MapViewModel extends ViewModel { * @param {string} apiName API name */ loadMapAPI(apiName) { - if (this.api) { + let mapApi = this.api; + this.api = null; + if (mapApi) { try { - this.savedBounds = this.api.getBounds(); + this.savedBounds = mapApi.getBounds(); } catch (e) { this.savedBounds = null; } - this.api.cleanup(); + mapApi.cleanup(); } - this.api = this.getApi(apiName); - this.api.init() - .then(() => this.onReady()) + mapApi = this.getApi(apiName); + mapApi.init() + .then(() => { + this.api = mapApi; + this.onReady(); + }) .catch((e) => { let txt = $._('apifailure', apiName); if (e && e.message) {