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
*/
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) {