From ea811fccb5d82f6d16accfc6cfe55af414980baa Mon Sep 17 00:00:00 2001 From: ouidade Date: Thu, 7 Nov 2024 21:43:28 +0100 Subject: [PATCH] php et js point carte cliquable --- .../custom/q2d_mod/assets/js/carte-interactive-qdd.js | 11 +++++++++++ .../custom/q2d_mod/src/Plugin/Block/SitesMap.php | 6 ++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/web/modules/custom/q2d_mod/assets/js/carte-interactive-qdd.js b/web/modules/custom/q2d_mod/assets/js/carte-interactive-qdd.js index 6795f26..2ecdc8d 100644 --- a/web/modules/custom/q2d_mod/assets/js/carte-interactive-qdd.js +++ b/web/modules/custom/q2d_mod/assets/js/carte-interactive-qdd.js @@ -101,3 +101,14 @@ if (pageIdMatch) { const matchingCircle = document.querySelector(`#site-${pageId} circle`); if (matchingCircle) matchingCircle.setAttribute('fill', 'red'); } + + +// Écouter les événements de clic sur le SVG +svgElement.addEventListener('click', function(event) { + if (event.target.tagName === 'circle' && event.target.classList.contains('site-link')) { + const targetUrl = event.target.getAttribute('data-url'); // Récupérer l'URL de redirection + if (targetUrl) { + window.location.href = targetUrl; // Rediriger vers l'URL cible + } + } +}); diff --git a/web/modules/custom/q2d_mod/src/Plugin/Block/SitesMap.php b/web/modules/custom/q2d_mod/src/Plugin/Block/SitesMap.php index 97bf162..fcd1444 100644 --- a/web/modules/custom/q2d_mod/src/Plugin/Block/SitesMap.php +++ b/web/modules/custom/q2d_mod/src/Plugin/Block/SitesMap.php @@ -42,7 +42,8 @@ class SitesMap extends BlockBase { $title = $site->get('title')->getString(); $subtitle = $site->get('field_sous_titre')->getString(); - $link_options = ['absolute' => FALSE, 'attributes' => ['class' => 'site-link']]; + $link_options = ['absolute' => TRUE, 'attributes' => ['class' => 'site-link']]; // Passer 'absolute' à TRUE + $site_url = $site->toUrl('canonical', $link_options)->toString(); // URL absolue pour le data-url $site_link_object = Link::createFromRoute("voir le site", 'entity.node.canonical', ['node' => $site->id()], $link_options); $link = $site_link_object->toString()->getGeneratedLink(); @@ -70,7 +71,8 @@ class SitesMap extends BlockBase {