From df3fb6aada9b1025f83d16af933cd14a4f8f7380 Mon Sep 17 00:00:00 2001 From: vincent Date: Wed, 28 Aug 2024 22:59:17 +0200 Subject: [PATCH] quelques ameillorations --- assets/controllers/map_controller.js | 22 +++++++++++----------- src/Service/GeoJsonManager.php | 18 ++++++++++++------ templates/home/index.html.twig | 2 ++ 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/assets/controllers/map_controller.js b/assets/controllers/map_controller.js index 4d53d9b..e50c9eb 100644 --- a/assets/controllers/map_controller.js +++ b/assets/controllers/map_controller.js @@ -37,7 +37,7 @@ export default class extends Controller { var layer = L.featureGroup(); - var layer2 = L.featureGroup(); + var overpassLayer = L.featureGroup(); if (this.overpassResultValue !== '') { geojsons = JSON.parse(this.overpassResultValue); if (geojsons.elements.length > 0) { @@ -47,12 +47,12 @@ export default class extends Controller { color: '#0dcaf0', weight: 6, opacity: 0.8, - }).addTo(layer2).bindPopup(L.popup({ + }).addTo(overpassLayer).bindPopup(L.popup({ overpassElement: element, }).setContent('…')); }); }); - layer2.on('popupopen', function (event) { + overpassLayer.on('popupopen', function (event) { var element = event.popup.options.overpassElement; delete element.members; element['map'] = { @@ -69,11 +69,11 @@ export default class extends Controller { event.popup.setContent(text); }); }); - layer2.addTo(layer); + overpassLayer.addTo(layer); } } - var layer1 = L.featureGroup(); + var taskLayer = L.featureGroup(); geojsons = JSON.parse(this.geojsonValue); if (geojsons.length > 0) { geojsons.forEach(function (geojson) { @@ -90,7 +90,7 @@ export default class extends Controller { } return {color: color}; } - }).bindTooltip(feature0.name).addTo(layer1).on('click', function (event) { + }).bindTooltip(feature0.name).addTo(taskLayer).on('click', function (event) { window.location.href = event.layer.feature.properties.url; }); @@ -98,23 +98,23 @@ export default class extends Controller { icon: icons[feature0.color], title: feature0.name, clickUrl: feature0.url, - }).addTo(layer1).on('click', function (event) { + }).addTo(taskLayer).on('click', function (event) { window.location.href = event.target.options.clickUrl; }); }); - layer1.addTo(layer); + taskLayer.addTo(layer); } layer.addTo(map); if (this.overpassResultValue !== '') { L.control.layers({}, { - 'Overpass': layer2, - 'Tâches': layer1, + 'Overpass': overpassLayer, + 'Tâches': taskLayer, }).addTo(map); } - map.fitBounds(layer1.getBounds()); + map.fitBounds(taskLayer.getBounds()); } } diff --git a/src/Service/GeoJsonManager.php b/src/Service/GeoJsonManager.php index 1a43cef..7448a1b 100644 --- a/src/Service/GeoJsonManager.php +++ b/src/Service/GeoJsonManager.php @@ -29,15 +29,21 @@ class GeoJsonManager return null; } - if (!isset($data['features'][0]['properties'])) { + if (!isset($data['features']) or empty($data['features'])) { return null; } - $data['features'][0]['properties'] = array_merge($data['features'][0]['properties'], [ - 'name' => $task->getName(), - 'url' => $this->router->generate('app_task_show', ['slug' => $task->getSlug()], UrlGeneratorInterface::ABSOLUTE_URL), - 'color' => $this->taskLifecycleStateMachine->getMetadataStore()->getPlaceMetadata($task->getStatus())['color'], - ]); + foreach($data['features'] as $index => $feature) { + if (!isset($feature['properties'])) { + continue; + } + $feature['properties'] = array_merge($feature['properties'], [ + 'name' => $task->getName(), + 'url' => $this->router->generate('app_task_show', ['slug' => $task->getSlug()], UrlGeneratorInterface::ABSOLUTE_URL), + 'color' => $this->taskLifecycleStateMachine->getMetadataStore()->getPlaceMetadata($task->getStatus())['color'], + ]); + $data['features'][$index] = $feature; + } return $data; } diff --git a/templates/home/index.html.twig b/templates/home/index.html.twig index 0ecea3e..f6e36fc 100644 --- a/templates/home/index.html.twig +++ b/templates/home/index.html.twig @@ -4,7 +4,9 @@

{{ long_title }}

+

Gère les tâches, même avec des nœuds (ou pas).

L’idée c’est d’avoir un petit outil collaboratif simple et facile à administrer/utiliser pour mapper des trucs de façon coordonnée à un endroit.

+

Si d’aventure vous souhaitez contacter le développeur, merci d’écrire à v+osm@caboulot.org