diff --git a/webgis/js/controllers/search_controller.js b/webgis/js/controllers/search_controller.js index 6eb58fb..1296136 100644 --- a/webgis/js/controllers/search_controller.js +++ b/webgis/js/controllers/search_controller.js @@ -38,8 +38,8 @@ export default class extends Controller { const results = await response.json(); this.containerTarget.classList.remove('is-hidden'); - this.#injectResults(results); - if (results.length) { + if (results.count) { + this.#injectResults(results); // Reset zoom level after successful search map.setZoom(INIT_ZOOM); this.#filterMap(results); @@ -48,7 +48,7 @@ export default class extends Controller { // Should technique always be shown after a search? for (const key of Object.keys(techsMarkers)) { - for (const record of results) { + for (const record of results.sites) { // Adjust for non-site records!! if (techsMarkers[key].options.site === record.label && techsMarkers[key].options.label === body.technique) @@ -80,7 +80,9 @@ export default class extends Controller { const output = this.resultsTarget; output.innerHTML = ''; - if (results.length === 0) { + console.debug(results); + + if (results.count === 0) { output.innerHTML = html`
Nessun risultato trovato per i parametri di ricerca @@ -88,12 +90,24 @@ export default class extends Controller { `; } - const sites = GisState.markers.sites; + delete results.count; - for (const result of results) { - let coordinates = '' - for (let key of Object.keys(sites)) { - if (sites[key].options.data.label === result.label) { + for (const group of Object.keys(results)) { + if (results[group].length) this.#populateResults(group, results[group], output); + } + } + /** + * + * @param {string} group + * @param {Array