aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem@fripost.org>2025-05-25 13:19:25 +0200
committerGuilhem Moulin <guilhem@fripost.org>2025-05-25 13:19:25 +0200
commit53130612f24ef0670ae6414595826512aa2c7a1f (patch)
tree023abe3aa26d2d966d16fb47073bd22f4c974230
parent0a53333d5e8a0ec64c2ec132a7d606346c9a1093 (diff)
Batch requests to CGI.
Cf. 527fdfd1e46d66007758861dd0decf9c03043d0a in tools.
-rw-r--r--main.js47
1 files changed, 26 insertions, 21 deletions
diff --git a/main.js b/main.js
index 0931823..9eb4517 100644
--- a/main.js
+++ b/main.js
@@ -3704,33 +3704,42 @@ const vectorLayers = (function() {
btnExpand.title = btnExpandTitle;
btnExpand.setAttribute('aria-label', btnExpand.title);
+ const fetch_body = []
map.forEachFeatureAtPixel(event.pixel, function(feature, layer) {
const layerGroup = layer.get('layerGroup');
const layerName = feature.getProperties().layer;
const def = layers[layerGroup + '_' + layerName];
- if (def === undefined || def.popover === undefined) {
+ if (def !== undefined && def.popover !== undefined) {
/* skip layers which didn't opt-in for popover */
- return;
- }
-
- if (features.length === 0) {
- document.body.classList.add('progress');
+ if (!fetch_body.length) {
+ document.body.classList.add('progress');
+ }
+ fetch_body.push({
+ layer_group: layerGroup,
+ layer: layerName,
+ fid: feature.getId(),
+ });
+ if (fetch_body.length >= 100) {
+ return true; /* enough matches already, stop detection here */
+ }
}
+ }, {
+ hitTolerance: 5,
+ checkWrapped: false,
+ layerFilter: (l) => l !== null && l.get('layerGroup') !== undefined,
+ });
- // TODO batch requests and use
- // https://github.com/uhop/stream-json/wiki/StreamArray
+ if (fetch_body.length > 0) {
+ // TODO use https://github.com/uhop/stream-json/wiki/StreamArray
+ // to process each item immediately
fetch('/q', {
method: 'POST',
- body: JSON.stringify({
- mvt: layerGroup,
- layer: layerName,
- fid: feature.getId()
- }),
+ body: JSON.stringify(fetch_body),
headers: {
'Content-Type': 'application/json; charset=UTF-8'
}
}).then((resp) => resp.json())
- .then((data) => {
+ .then((data) => data.forEach(function(data) {
document.body.classList.remove('progress');
const properties = data.properties || {};
const feature0 = new GeoJSON().readFeature(data);
@@ -3742,6 +3751,7 @@ const vectorLayers = (function() {
const tbody = document.createElement('tbody');
table.appendChild(tbody);
+ const def = layers[properties.layer_group + '_' + properties.layer];
def.popover.forEach(function([desc, key, opts]) {
let v = properties[key];
if (opts === undefined) {
@@ -3846,16 +3856,11 @@ const vectorLayers = (function() {
else if (popover.tip.classList.contains('popover-detached')) {
refreshPopover();
}
- })
+ }))
.catch(function() {
document.body.classList.remove('progress');
});
-
- }, {
- hitTolerance: 5,
- checkWrapped: false,
- layerFilter: (l) => l.get('layerGroup') !== undefined,
- });
+ }
if (features.length === 0 && popover !== null && popover.tip !== null) {
/* dispose pre-detached popover */