Fix using api which is not ready

This commit is contained in:
Bartek Fabiszewski 2020-05-15 20:49:55 +02:00
parent f4ac9edad7
commit 2208d3621d

View File

@ -81,17 +81,22 @@ export default class MapViewModel extends ViewModel {
* @param {string} apiName API name * @param {string} apiName API name
*/ */
loadMapAPI(apiName) { loadMapAPI(apiName) {
if (this.api) { let mapApi = this.api;
this.api = null;
if (mapApi) {
try { try {
this.savedBounds = this.api.getBounds(); this.savedBounds = mapApi.getBounds();
} catch (e) { } catch (e) {
this.savedBounds = null; this.savedBounds = null;
} }
this.api.cleanup(); mapApi.cleanup();
} }
this.api = this.getApi(apiName); mapApi = this.getApi(apiName);
this.api.init() mapApi.init()
.then(() => this.onReady()) .then(() => {
this.api = mapApi;
this.onReady();
})
.catch((e) => { .catch((e) => {
let txt = $._('apifailure', apiName); let txt = $._('apifailure', apiName);
if (e && e.message) { if (e && e.message) {