Search adjustments + building techs

This commit is contained in:
2026-05-24 16:21:33 +02:00
parent 487995366e
commit cb39695e6c
8 changed files with 83 additions and 5 deletions

View File

@@ -186,4 +186,9 @@ a:visited {
.marker-cluster-small span { .marker-cluster-small span {
color: #fff; color: #fff;
}
/* Apply Bulma's is-danger color based on state */
input:invalid {
border-color: #ff6685;
} }

View File

@@ -90,7 +90,7 @@
<div class="field"> <div class="field">
<label class="label">Testo libero</label> <label class="label">Testo libero</label>
<div class="control is-full-width"> <div class="control is-full-width">
<input class="input" type="text" name="text" placeholder="Inserire parole chiave" /> <input class="input" type="text" minlength="3" name="text" placeholder="Inserire parole chiave" />
</div> </div>
</div> </div>
<div class="field"> <div class="field">

View File

@@ -20,6 +20,14 @@ export default class extends Controller {
event.preventDefault(); event.preventDefault();
const data = new FormData(event.target); const data = new FormData(event.target);
const body = {}; const body = {};
const map = GisState.map;
const techs = GisState.layers.buildingTechs;
const techsMarkers = GisState.markers.buildingTechs;
// Reset search for building techs...
for (const key of Object.keys(techsMarkers)) {
map.removeLayer(techsMarkers[key]);
}
for (const entry of data.entries()) { for (const entry of data.entries()) {
body[entry[0]] = entry[1]; body[entry[0]] = entry[1];
@@ -28,9 +36,18 @@ export default class extends Controller {
const response = await fetch(`${GisState.apiUrl}/search?` + new URLSearchParams(body)); const response = await fetch(`${GisState.apiUrl}/search?` + new URLSearchParams(body));
const results = await response.json(); const results = await response.json();
console.warn(body);
this.containerTarget.classList.remove('is-hidden'); this.containerTarget.classList.remove('is-hidden');
this.#injectResults(results); this.#injectResults(results);
if (results.length) this.#filterMap(results); if (results.length) {
this.#filterMap(results);
// Should technique always be shown after a search?
for (const key of Object.keys(techsMarkers)) {
if (techsMarkers[key].options.label === body.technique)
map.addLayer(techsMarkers[key]);
}
}
} }
clearSearch() { clearSearch() {

View File

@@ -74,6 +74,7 @@ GIS.initMap = async function (mapId, zoomLevel = this.INIT_ZOOM) {
await this.addLayerGroups(map); await this.addLayerGroups(map);
await this.fetchCartographyLayers(); await this.fetchCartographyLayers();
const buildingTechs = await this.buildingTechs();
const reprojectedWMSLayer = GIS.reprojectWMS(); const reprojectedWMSLayer = GIS.reprojectWMS();
const wmsLayer = new reprojectedWMSLayer( const wmsLayer = new reprojectedWMSLayer(
@@ -94,6 +95,7 @@ GIS.initMap = async function (mapId, zoomLevel = this.INIT_ZOOM) {
'Fabbricati' : buildings, 'Fabbricati' : buildings,
'Vincoli archeologici' : layerVincoli, 'Vincoli archeologici' : layerVincoli,
'Vincoli archeologici indiretti' : layerPaesistici, 'Vincoli archeologici indiretti' : layerPaesistici,
'Tecniche murarie' : buildingTechs,
}; };
L.control.layers(baseMap, cartography).addTo(map); L.control.layers(baseMap, cartography).addTo(map);
@@ -114,6 +116,35 @@ GIS.fetchCartographyLayers = async function () {
GisState.cartography.historic.push({id, label}); GisState.cartography.historic.push({id, label});
} }
} }
/**
* Create building techs layer
* @returns {L.Layer}
*/
GIS.buildingTechs = async function () {
let techsData = await fetch(`${API_URL}/building_techs`)
.then(data => data.json());
let techs = new L.LayerGroup();
for (let record of techsData) {
const marker = L.marker(
record.coordinates,
{icon: Icons.techs, label: record.technique}
)
.bindTooltip(record.technique)
.bindPopup(UI.createBuildingTechTable(record));
techs.addLayer(marker);
const markerLabel = `${record.coordinates[0]} ${record.coordinates[1]}`;
marker.options.data = record;
marker.options.site = record.site.label;
GisState.markers.buildingTechs[markerLabel] = marker;
}
GisState.layers.buildingTechs = techs;
return techs;
}
/** /**
* Load georeferenced image overlays layer group * Load georeferenced image overlays layer group
* @param {Number} imageId - The API id of the georeferenced image * @param {Number} imageId - The API id of the georeferenced image

View File

@@ -59,4 +59,6 @@ Icons.reuse = L.icon(
Icons.camera = L.divIcon({className: 'fa fa-camera'}); Icons.camera = L.divIcon({className: 'fa fa-camera'});
Icons.techs = L.divIcon({className: 'fa fa-circle has-text-primary-25'});
export default Icons; export default Icons;

View File

@@ -1,5 +1,6 @@
import GIS from './gis.js'; import GIS from './gis.js';
import UI from './ui.js'; import UI from './ui.js';
import { GisState } from './state.js';
import { Application } from '@hotwired/stimulus'; import { Application } from '@hotwired/stimulus';
import MenuController from './controllers/menu_controller.js'; import MenuController from './controllers/menu_controller.js';
import ModalController from './controllers/modal_controller.js'; import ModalController from './controllers/modal_controller.js';
@@ -15,13 +16,13 @@ document.addEventListener('DOMContentLoaded', async () => {
let progress = document.querySelector('progress'); let progress = document.querySelector('progress');
const map = await GIS.initMap('map'); const map = await GIS.initMap('map');
progress.classList.add('is-hidden');
map._container.setAttribute('aria-busy', false);
// Trigger Stimulus buildMenu method... // Trigger Stimulus buildMenu method...
const menuEvent = new Event('menu-ready'); const menuEvent = new Event('menu-ready');
document.dispatchEvent(menuEvent); document.dispatchEvent(menuEvent);
progress.classList.add('is-hidden');
map._container.setAttribute('aria-busy', false);
GIS.toggleSpherical(map); GIS.toggleSpherical(map);

View File

@@ -28,6 +28,7 @@ export const GisState = {
prehistoric: {}, prehistoric: {},
underwater: {}, underwater: {},
reuse: {}, reuse: {},
buildingTechs: {},
}, },
layers: { layers: {
sites: {}, sites: {},
@@ -36,6 +37,7 @@ export const GisState = {
prehistoric: {}, prehistoric: {},
underwater: {}, underwater: {},
reuse: {}, reuse: {},
buildingTechs: {},
}, },
bibliography: null, bibliography: null,
apiUrl : null, apiUrl : null,

View File

@@ -12,6 +12,8 @@ import { Underwater } from './components/Underwater.js';
import { GisState } from "./state.js"; import { GisState } from "./state.js";
import { Reuse } from './components/Reuse.js'; import { Reuse } from './components/Reuse.js';
const html = String.raw;
/** /**
* @namespace UI * @namespace UI
*/ */
@@ -270,5 +272,23 @@ UI.imageGallery = function (galleryId, items, video = false) {
}); });
} }
} }
/**
* @param {Object} record
* @returns {string}
*/
UI.createBuildingTechTable = function(record) {
return html`
<table class="table is-striped is-size-6 m-2">
<tbody>
<tr><th>Tecnica</th><td>${record.technique}</td></tr>
<tr><th>Descrizione</th><td>${record.description}</td></tr>
<tr><th>Funzione</th><td>${record.function}</td></tr>
<tr><th>Materiale</th><td>${record.material}</td></tr>
<tr><th>Sito</th><td>${record.site.label}</td></tr>
<tr><th>Comune</th><td>${record.municipality}</td></tr>
</tbody>
</table>
;`
}
export default UI; export default UI;