From 9a1386fd7062647dd0984fee7bd4c7e12d3bd30e Mon Sep 17 00:00:00 2001 From: David Drury Date: Wed, 16 Feb 2022 11:32:45 +0000 Subject: [PATCH] Simplify code --- app/Module/PedigreeMapModule.php | 13 +++++------ .../views/modules/pedigree-map/chart.phtml | 22 +++++++++---------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/app/Module/PedigreeMapModule.php b/app/Module/PedigreeMapModule.php index 9a49270d43f..d26020f147c 100644 --- a/app/Module/PedigreeMapModule.php +++ b/app/Module/PedigreeMapModule.php @@ -242,6 +242,7 @@ private function getMapData(ServerRequestInterface $request): array ]; $sosa_points = []; + $lines = []; foreach ($facts as $sosa => $fact) { $location = new PlaceLocation($fact->place()->gedcomName()); @@ -257,16 +258,12 @@ private function getMapData(ServerRequestInterface $request): array } if ($latitude !== null && $longitude !== null) { - $polyline = null; $sosa_points[$sosa] = [$latitude, $longitude]; $sosa_child = intdiv($sosa, 2); $color = 'var(--wt-pedigree-map-gen-' . $sosa_child % self::GENERATION_COLORS . ')'; if (array_key_exists($sosa_child, $sosa_points)) { - // Would like to use a GeometryCollection to hold LineStrings - // rather than generate polylines but the MarkerCluster library - // doesn't seem to like them - $polyline = [ + $lines[] = [ 'points' => [ $sosa_points[$sosa_child], [$latitude, $longitude], @@ -284,7 +281,6 @@ private function getMapData(ServerRequestInterface $request): array 'coordinates' => [$longitude, $latitude], ], 'properties' => [ - 'polyline' => $polyline, 'iconcolor' => $color, 'tooltip' => $fact->place()->gedcomName(), 'summary' => view('modules/pedigree-map/events', [ @@ -297,7 +293,10 @@ private function getMapData(ServerRequestInterface $request): array } } - return $geojson; + return [ + 'geoJSON' => $geojson, + 'polylines' => $lines, + ]; } /** diff --git a/resources/views/modules/pedigree-map/chart.phtml b/resources/views/modules/pedigree-map/chart.phtml index 54742521ebd..d9a08657e0e 100644 --- a/resources/views/modules/pedigree-map/chart.phtml +++ b/resources/views/modules/pedigree-map/chart.phtml @@ -20,7 +20,8 @@ use Fisharebest\Webtrees\View; (function () { const config = ; - const geoJson_data = ; + const geoJson_data = ; + const polylines = ; const sidebar = document.querySelector('.wt-pedigree-map-sidebar'); const scrollOptions = { @@ -42,18 +43,17 @@ use Fisharebest\Webtrees\View; tree: null } - geoJson_data.features.forEach((feature) => { - if (feature.properties.polyline) { - features.layer.addLayer(L.polyline(feature.properties.polyline.points, feature.properties.polyline.options)); - if (!features.tree) { - features.tree = { - label: '', - layer: features.layer - } - } - } + polylines.forEach((line) => { + features.layer.addLayer(L.polyline(line.points, line.options)); }); + if (polylines.length) { + features.tree = { + label: '', + layer: features.layer + } + } + /** * Passed to resetControl to * perform necessary reset actions on map