Skip to content

Commit

Permalink
add whenready for map-extent
Browse files Browse the repository at this point in the history
  • Loading branch information
AliyanH committed Aug 9, 2023
1 parent 7b8ed92 commit e699b30
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/map-extent.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,38 @@ export class MapExtent extends HTMLElement {
this.parentNode.nodeName.toUpperCase() === 'LAYER-'
? this.parentNode
: this.parentNode.host;
this._layer = parentLayer._layer;
parentLayer
.whenReady()
.then(() => {
this._layer = parentLayer._layer;
})
.catch(() => {
throw new Error('Map never became ready');
});
}
disconnectedCallback() {}
whenReady() {
return new Promise((resolve, reject) => {
let interval, failureTimer;
if (this._layer) {
resolve();
} else {
let extentElement = this;
interval = setInterval(testForExtent, 300, extentElement);
failureTimer = setTimeout(extentNotDefined, 10000);
}
function testForExtent(extentElement) {
if (extentElement._layer) {
clearInterval(interval);
clearTimeout(failureTimer);
resolve();
}
}
function extentNotDefined() {
clearInterval(interval);
clearTimeout(failureTimer);
reject('Timeout reached waiting for extent to be ready');
}
});
}
}

0 comments on commit e699b30

Please sign in to comment.