Fix map loading indicator

This commit is contained in:
D. Berge
2020-08-11 20:57:29 +02:00
parent 656f5a2c6d
commit d53105ef7a

View File

@@ -137,7 +137,7 @@ export default {
data () {
return {
//map: null,
loading: false,
requestsCount: 0,
layerRefreshConfig: [
{
layer: layers.Preplots,
@@ -167,6 +167,12 @@ export default {
};
},
computed: {
loading () {
return this.requestsCount > 0;
}
},
watch: {
loading (isLoading) {
if (isLoading) {
@@ -179,12 +185,20 @@ export default {
methods: {
queueRequest () {
this.requestsCount++;
},
dequeueRequest () {
(--this.requestsCount < 0) && (this.requestsCount = 0);
},
async fitProjectBounds () {
this.loading = true;
this.queueRequest();
const res = await this.api([`/project/${this.$route.params.project}/gis`]);
const bbox = new L.GeoJSON(res);
map.fitBounds(bbox.getBounds());
this.loading = false;
this.dequeueRequest();
},
async refreshLayers (layerset) {
@@ -201,26 +215,22 @@ export default {
const query = new URLSearchParams({bbox, limit});
let requestsCount = 0;
for (const l of this.layerRefreshConfig.filter(i => !layerset || layerset.includes(i.layer))) {
if (map.hasLayer(l.layer)) {
// Firing all refresh events asynchronously, which is OK provided
// we don't have hundreds of layers to be refreshed.
requestsCount++;
this.queueRequest();
await this.api([l.url(query)]).then( (layer) => {
l.layer.clearLayers();
if ((layer.features && layer.features.length < limit) || ("length" in layer && layer.length < limit)) {
l.layer.addData(layer);
} else {
}
if (--requestsCount == 0) {
this.loading = false;
console.warn("Too much data from", l.url(query));
}
this.dequeueRequest();
})
}
}
this.loading = requestsCount > 0;
},
...mapActions(["api"])