Open modal for internal links (WIP)
This commit is contained in:
parent
262540e735
commit
13550078cb
@ -151,12 +151,13 @@ Utils.buildBibliography = async function(recordUri, recordId) {
|
|||||||
* to Stimulus links
|
* to Stimulus links
|
||||||
*/
|
*/
|
||||||
Utils.parseMarkers = function(text) {
|
Utils.parseMarkers = function(text) {
|
||||||
const regex = /(?<marker>\[marker coords=\"(?<coords>[\d\s\.]+)\"\](?<content>[\w\s\.;:\-]+)\[\/marker\])/mig;
|
const regex = /(?<marker>\[marker coords=\"(?<coords>[\d\s\.]+)\"\ ?(group=\"(?<group>\w+)\")?](?<content>[\w\s\.;:\-]+)\[\/marker\])/mig;
|
||||||
let matches = [...text.matchAll(regex)];
|
let matches = [...text.matchAll(regex)];
|
||||||
|
|
||||||
if (matches.length) {
|
if (matches.length) {
|
||||||
matches.forEach(match => {
|
matches.forEach(match => {
|
||||||
const replacement = `<a data-action="marker#go modal#close" data-controller="marker" data-marker-coords-value="${match.groups.coords}">
|
const replacement = `<a data-action="marker#go modal#close tabs#reset marker#goAndOpen" data-controller="marker"
|
||||||
|
data-marker-coords-value="${match.groups.coords}" data-marker-group-value="${match.groups.group}">
|
||||||
${match.groups.content}</a>`;
|
${match.groups.content}</a>`;
|
||||||
text = text.replace(match.groups.marker, replacement.trim());
|
text = text.replace(match.groups.marker, replacement.trim());
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import { Controller } from "@hotwired/stimulus";
|
import { Controller } from "@hotwired/stimulus";
|
||||||
import { GisState, getMarkerByCoords } from "../state.js";
|
import { GisState, getMarkerByCoords } from "../state.js";
|
||||||
|
import UI from "../ui.js";
|
||||||
|
|
||||||
export default class extends Controller {
|
export default class extends Controller {
|
||||||
static values = {
|
static values = {
|
||||||
@ -8,6 +9,11 @@ export default class extends Controller {
|
|||||||
'id': String,
|
'id': String,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
uiModals = {
|
||||||
|
sites: '#site-data',
|
||||||
|
notConserved: '#not-conserved-data',
|
||||||
|
};
|
||||||
|
|
||||||
END_ZOOM = 19;
|
END_ZOOM = 19;
|
||||||
// Animation breaks automatic tooltip opening...
|
// Animation breaks automatic tooltip opening...
|
||||||
mapAnimate = {
|
mapAnimate = {
|
||||||
@ -16,9 +22,6 @@ export default class extends Controller {
|
|||||||
easeLinearity: 0.25
|
easeLinearity: 0.25
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {Event} event
|
|
||||||
*/
|
|
||||||
go() {
|
go() {
|
||||||
let map = GisState.map;
|
let map = GisState.map;
|
||||||
const coords = this.coordsValue.split(' ');
|
const coords = this.coordsValue.split(' ');
|
||||||
@ -31,8 +34,31 @@ export default class extends Controller {
|
|||||||
|
|
||||||
let marker = this.getMarker(map, coords);
|
let marker = this.getMarker(map, coords);
|
||||||
// DEBUG for sites
|
// DEBUG for sites
|
||||||
if (this.groupValue) marker = getMarkerByCoords(coords, this.groupValue);
|
//if (this.groupValue) marker = getMarkerByCoords(coords, this.groupValue);
|
||||||
marker?.openTooltip();
|
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
|
* @param {L.Map} map
|
||||||
|
|||||||
@ -200,6 +200,7 @@ GIS.sites = async function () {
|
|||||||
// Populate app state for reuse and avoid window.Sites etc.
|
// Populate app state for reuse and avoid window.Sites etc.
|
||||||
// Municipality (Capri, Anacapri) added for reuse in dynamic menu
|
// Municipality (Capri, Anacapri) added for reuse in dynamic menu
|
||||||
marker.options.municipality = record.municipality;
|
marker.options.municipality = record.municipality;
|
||||||
|
marker.options.data = record;
|
||||||
const markerIndex = `${record.coordinates[0]} ${record.coordinates[1]}`;
|
const markerIndex = `${record.coordinates[0]} ${record.coordinates[1]}`;
|
||||||
GisState.markers.sites[markerIndex] = marker;
|
GisState.markers.sites[markerIndex] = marker;
|
||||||
}
|
}
|
||||||
@ -230,6 +231,7 @@ GIS.notConserved = async function () {
|
|||||||
// Populate app state for reuse and avoid window.Sites etc.
|
// Populate app state for reuse and avoid window.Sites etc.
|
||||||
const markerLabel = `${record.coordinates[0]} ${record.coordinates[1]}`;
|
const markerLabel = `${record.coordinates[0]} ${record.coordinates[1]}`;
|
||||||
marker.options.municipality = record.municipality;
|
marker.options.municipality = record.municipality;
|
||||||
|
marker.options.data = record;
|
||||||
GisState.markers.notConserved[markerLabel] = marker;
|
GisState.markers.notConserved[markerLabel] = marker;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,6 +264,7 @@ GIS.findings = async function () {
|
|||||||
findings.addLayer(marker);
|
findings.addLayer(marker);
|
||||||
const markerLabel = `${record.coordinates[0]} ${record.coordinates[1]}`;
|
const markerLabel = `${record.coordinates[0]} ${record.coordinates[1]}`;
|
||||||
marker.options.municipality = record.municipality;
|
marker.options.municipality = record.municipality;
|
||||||
|
marker.options.data = record;
|
||||||
GisState.markers.findings[markerLabel] = marker;
|
GisState.markers.findings[markerLabel] = marker;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -293,6 +296,7 @@ GIS.prehistoric = async function () {
|
|||||||
|
|
||||||
const markerLabel = `${record.coordinates[0]} ${record.coordinates[1]}`;
|
const markerLabel = `${record.coordinates[0]} ${record.coordinates[1]}`;
|
||||||
marker.options.municipality = record.municipality;
|
marker.options.municipality = record.municipality;
|
||||||
|
marker.options.data = record;
|
||||||
GisState.markers.prehistoric[markerLabel] = marker;
|
GisState.markers.prehistoric[markerLabel] = marker;
|
||||||
|
|
||||||
prehistoric.addLayer(marker);
|
prehistoric.addLayer(marker);
|
||||||
@ -323,6 +327,7 @@ GIS.underwater = async function () {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const markerLabel = `${record.coordinates[0]} ${record.coordinates[1]}`;
|
const markerLabel = `${record.coordinates[0]} ${record.coordinates[1]}`;
|
||||||
|
marker.options.data = record;
|
||||||
GisState.markers.underwater[markerLabel] = marker;
|
GisState.markers.underwater[markerLabel] = marker;
|
||||||
|
|
||||||
underwater.addLayer(marker);
|
underwater.addLayer(marker);
|
||||||
@ -355,6 +360,7 @@ GIS.reuse = async function () {
|
|||||||
const markerLabel = `${record.coordinates[0]} ${record.coordinates[1]}`;
|
const markerLabel = `${record.coordinates[0]} ${record.coordinates[1]}`;
|
||||||
marker.options.municipality = record.municipality;
|
marker.options.municipality = record.municipality;
|
||||||
marker.options.label = record.label;
|
marker.options.label = record.label;
|
||||||
|
marker.options.data = record;
|
||||||
GisState.markers.reuse[markerLabel] = marker;
|
GisState.markers.reuse[markerLabel] = marker;
|
||||||
|
|
||||||
reuse.addLayer(marker);
|
reuse.addLayer(marker);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user