From 13550078cb0df2e6d058ea4268e4742dd2c060d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20P?= Date: Wed, 29 Oct 2025 18:23:34 +0100 Subject: [PATCH] Open modal for internal links (WIP) --- webgis/js/components/utils.js | 5 ++-- webgis/js/controllers/marker_controller.js | 34 +++++++++++++++++++--- webgis/js/gis.js | 6 ++++ 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/webgis/js/components/utils.js b/webgis/js/components/utils.js index 27cd5dc..6ec9d60 100644 --- a/webgis/js/components/utils.js +++ b/webgis/js/components/utils.js @@ -151,12 +151,13 @@ Utils.buildBibliography = async function(recordUri, recordId) { * to Stimulus links */ Utils.parseMarkers = function(text) { - const regex = /(?\[marker coords=\"(?[\d\s\.]+)\"\](?[\w\s\.;:\-]+)\[\/marker\])/mig; + const regex = /(?\[marker coords=\"(?[\d\s\.]+)\"\ ?(group=\"(?\w+)\")?](?[\w\s\.;:\-]+)\[\/marker\])/mig; let matches = [...text.matchAll(regex)]; if (matches.length) { matches.forEach(match => { - const replacement = ` + const replacement = ` ${match.groups.content}`; text = text.replace(match.groups.marker, replacement.trim()); }); diff --git a/webgis/js/controllers/marker_controller.js b/webgis/js/controllers/marker_controller.js index 76b548f..061b12c 100644 --- a/webgis/js/controllers/marker_controller.js +++ b/webgis/js/controllers/marker_controller.js @@ -1,5 +1,6 @@ import { Controller } from "@hotwired/stimulus"; import { GisState, getMarkerByCoords } from "../state.js"; +import UI from "../ui.js"; export default class extends Controller { static values = { @@ -7,6 +8,11 @@ export default class extends Controller { 'group': String, 'id': String, }; + + uiModals = { + sites: '#site-data', + notConserved: '#not-conserved-data', + }; END_ZOOM = 19; // Animation breaks automatic tooltip opening... @@ -16,9 +22,6 @@ export default class extends Controller { easeLinearity: 0.25 }; - /** - * @param {Event} event - */ go() { let map = GisState.map; const coords = this.coordsValue.split(' '); @@ -31,8 +34,31 @@ export default class extends Controller { let marker = this.getMarker(map, coords); // DEBUG for sites - if (this.groupValue) marker = getMarkerByCoords(coords, this.groupValue); + //if (this.groupValue) marker = getMarkerByCoords(coords, this.groupValue); marker?.openTooltip(); + + return marker; + } + /** + * Go to a marker location on the map + * and open its modal + */ + goAndOpen() { + const marker = this.go(); + const selector = this.uiModals[this.groupValue]; + const data = marker.options.data; + + switch(this.groupValue) { + case 'sites': + UI.openSiteModal(data, selector); + break; + case 'notConserved': + UI.openNotConserModal(data, selector); + break; + default: + console.log('Cannot open modal...'); + break; + } } /** * @param {L.Map} map diff --git a/webgis/js/gis.js b/webgis/js/gis.js index 6320a0e..8a8a0d8 100644 --- a/webgis/js/gis.js +++ b/webgis/js/gis.js @@ -200,6 +200,7 @@ GIS.sites = async function () { // Populate app state for reuse and avoid window.Sites etc. // Municipality (Capri, Anacapri) added for reuse in dynamic menu marker.options.municipality = record.municipality; + marker.options.data = record; const markerIndex = `${record.coordinates[0]} ${record.coordinates[1]}`; GisState.markers.sites[markerIndex] = marker; } @@ -230,6 +231,7 @@ GIS.notConserved = async function () { // Populate app state for reuse and avoid window.Sites etc. const markerLabel = `${record.coordinates[0]} ${record.coordinates[1]}`; marker.options.municipality = record.municipality; + marker.options.data = record; GisState.markers.notConserved[markerLabel] = marker; } @@ -262,6 +264,7 @@ GIS.findings = async function () { findings.addLayer(marker); const markerLabel = `${record.coordinates[0]} ${record.coordinates[1]}`; marker.options.municipality = record.municipality; + marker.options.data = record; GisState.markers.findings[markerLabel] = marker; } @@ -293,6 +296,7 @@ GIS.prehistoric = async function () { const markerLabel = `${record.coordinates[0]} ${record.coordinates[1]}`; marker.options.municipality = record.municipality; + marker.options.data = record; GisState.markers.prehistoric[markerLabel] = marker; prehistoric.addLayer(marker); @@ -323,6 +327,7 @@ GIS.underwater = async function () { ); const markerLabel = `${record.coordinates[0]} ${record.coordinates[1]}`; + marker.options.data = record; GisState.markers.underwater[markerLabel] = marker; underwater.addLayer(marker); @@ -355,6 +360,7 @@ GIS.reuse = async function () { const markerLabel = `${record.coordinates[0]} ${record.coordinates[1]}`; marker.options.municipality = record.municipality; marker.options.label = record.label; + marker.options.data = record; GisState.markers.reuse[markerLabel] = marker; reuse.addLayer(marker);