modifs pas finies de la carte interactive + clean des scss
This commit is contained in:
@@ -16,7 +16,7 @@ use Drupal\Core\Render\Markup;
|
||||
* )
|
||||
*/
|
||||
class SitesMap extends BlockBase {
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -25,67 +25,33 @@ class SitesMap extends BlockBase {
|
||||
|
||||
$allSites = \Drupal::entityTypeManager()->getStorage('node')
|
||||
->loadByProperties(['type' => 'projet', 'status' => 1]);
|
||||
|
||||
|
||||
$sites_paths = "";
|
||||
|
||||
$vp_w = 600;
|
||||
$vp_h = 600;
|
||||
|
||||
// Coordonnées géographiques des coins de la carte (France)
|
||||
$latTop = 52.0; // Nord-Ouest (coin supérieur gauche)
|
||||
$lonLeft = -6.0;
|
||||
$latBottom = 40.0; // Sud-Est (coin inférieur droit)
|
||||
$lonRight = 11.0;
|
||||
|
||||
|
||||
foreach($allSites as $index => $site){
|
||||
$title = $site->get('title')->getString();
|
||||
$subtitle = $site->get('field_sous_titre')->getString();
|
||||
$place = $site->get('field_localisation_textuel')->getString();
|
||||
|
||||
$link_options = ['absolute' => FALSE, 'attributes' => ['class' => 'site-link']];
|
||||
$site_link_object = Link::createFromRoute("voir le site", 'entity.node.canonical', ['node' => $site->id()], $link_options);
|
||||
$link = $site_link_object->toString()->getGeneratedLink();
|
||||
// $link = $site_link_object->toString()->getGeneratedLink();
|
||||
$href = $site_link_object->getUrl()->toString();
|
||||
|
||||
$datacontent = htmlspecialchars("<strong>$title</strong><br>$subtitle<br>$link");
|
||||
// $datacontent = htmlspecialchars("<strong>$title</strong><br>$subtitle<br>$link");
|
||||
|
||||
$geofield = $site->get('field_carte')->get(0);
|
||||
$lon = $geofield->lon;
|
||||
$lat = $geofield->lat;
|
||||
$geofieldData = "$lon,$lat"; // Utiliser une chaîne pour stocker la position
|
||||
|
||||
$x = round(($lon - $lonLeft) / ($lonRight - $lonLeft) * $vp_w);
|
||||
$y = round(($latTop - $lat) / ($latTop - $latBottom) * $vp_h);
|
||||
|
||||
$r = 10;
|
||||
$m = -$r+4;
|
||||
$l = $r*2-7;
|
||||
$sites_paths .= <<<SVGSITEPATH
|
||||
<g
|
||||
id="projet-$index"
|
||||
data-geofield="$geofieldData"
|
||||
transform="translate($x,$y)"
|
||||
style="cursor: pointer;" <!-- Change le curseur pour indiquer l'interaction -->
|
||||
>
|
||||
<rect width="10" height="10" transform="translate($x,$y)" fill="none" onclick="handleCircleClick('$datacontent')"></rect> <!-- Zone d'interaction invisible -->
|
||||
|
||||
<circle
|
||||
class="site-link"
|
||||
data-content="$datacontent"
|
||||
cx="0" cy="0" r="$r"
|
||||
style="fill-opacity:1;fill-rule:nonzero;" />
|
||||
<path
|
||||
id="path84"
|
||||
d="m 0,$m v $l"
|
||||
style="pointer-events: none;fill:none;stroke:#ffffff;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1" />
|
||||
<path
|
||||
id="path85"
|
||||
d="m $m,0 h $l"
|
||||
style="pointer-events: none;fill:none;stroke:#ffffff;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1" />
|
||||
|
||||
</g>
|
||||
SVGSITEPATH;
|
||||
$svg_template_path = DRUPAL_ROOT . '/modules/custom/erable_mod/assets/svg/feuille.svg';
|
||||
$svg_template= file_get_contents($svg_template_path);
|
||||
$sites_paths .= str_replace(
|
||||
['$index', '$lon', '$lat', '$href', '$title', '$place'],
|
||||
[$index, $lon, $lat, $href, $title, $place],
|
||||
$svg_template
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
$return = [
|
||||
'#cache' => [
|
||||
@@ -94,8 +60,6 @@ class SitesMap extends BlockBase {
|
||||
'svg_mapsites' => [
|
||||
'#theme' => 'svg_mapsites',
|
||||
'#sites' => $sites_paths,
|
||||
'#vpw' => $vp_w,
|
||||
'#vph' => $vp_h,
|
||||
'#attached' => [
|
||||
'library' => [
|
||||
'erable_mod/sites_map_block',
|
||||
@@ -112,4 +76,4 @@ class SitesMap extends BlockBase {
|
||||
public function getCacheMaxAge() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user