Reorder execution of init.

Set "on" binding before awaiting cache reset.
Set "wfslayers" to a empty map
immediately on reset.
This commit is contained in:
Noenandre
2023-07-23 14:16:19 +02:00
parent 4d44eedb3d
commit f3bf7dbf4d

View File

@@ -307,16 +307,13 @@ function searchLimited(limit, projection, rtree) {
export default {
init: async function () {
this.event = utilRebind(this, dispatch, 'on');
if (!_vegbilderCache) {
await this.reset();
}
this.event = utilRebind(this, dispatch, 'on');
},
reset: async function () {
const availableLayers = await fetchAvailableLayers();
if (_vegbilderCache) {
for (const layer of _vegbilderCache.wfslayers.values()) {
for (const controller of layer.inflight.values()) {
@@ -325,7 +322,16 @@ export default {
}
}
const wfslayers = availableLayers.reduce((wfslayers, layerInfo) => {
_vegbilderCache = {
wfslayers: new Map(),
rtree: new RBush(),
image2sequence_map: new Map()
};
const availableLayers = await fetchAvailableLayers();
const {wfslayers} = _vegbilderCache;
for (const layerInfo of availableLayers) {
const cache = {
layerInfo,
loaded: new Map(),
@@ -334,17 +340,9 @@ export default {
sequences: []
};
wfslayers.set(layerInfo.name, cache);
return wfslayers;
}, new Map());
_vegbilderCache = {
wfslayers,
rtree: new RBush(),
image2sequence_map: new Map()
};
}
},
images: function (projection) {
const limit = 5;
return searchLimited(limit, projection, _vegbilderCache.rtree);