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/js/webtrees.js b/resources/js/webtrees.js index 3486fd22475..e8d86bcd37c 100644 --- a/resources/js/webtrees.js +++ b/resources/js/webtrees.js @@ -623,9 +623,11 @@ * @param {string} id * @param {object} config * @param {function} resetCallback + * @param {array|undefined} overlay * @returns Map */ - webtrees.buildLeafletJsMap = function (id, config, resetCallback) { + webtrees.buildLeafletJsMap = function (id, config, resetCallback, overlay) { + const zoomControl = new L.control.zoom({ zoomInTitle: config.i18n.zoomIn, zoomoutTitle: config.i18n.zoomOut, @@ -671,6 +673,11 @@ let defaultLayer = config.mapProviders[0].children[0].layer; } + //Create a dummy overlay if not defined + overlay = overlay || { + layer: new L.LayerGroup(), + tree: null + }; // Create the map with all controls and layers return L.map(id, { @@ -679,7 +686,8 @@ .addControl(zoomControl) .addControl(new resetControl()) .addLayer(defaultLayer) - .addControl(L.control.layers.tree(config.mapProviders, null, { + .addLayer(overlay.layer) + .addControl(L.control.layers.tree(config.mapProviders, overlay.tree, { closedSymbol: config.icons.expand, openedSymbol: config.icons.collapse, })); diff --git a/resources/views/modules/pedigree-map/chart.phtml b/resources/views/modules/pedigree-map/chart.phtml index 89f4cc7d6ba..be3ed562fd4 100644 --- a/resources/views/modules/pedigree-map/chart.phtml +++ b/resources/views/modules/pedigree-map/chart.phtml @@ -20,6 +20,7 @@ use Fisharebest\Webtrees\View; (function () { const config = ; + const polylines = ; const sidebar = document.querySelector('.wt-pedigree-map-sidebar'); const scrollOptions = { @@ -35,6 +36,23 @@ use Fisharebest\Webtrees\View; showCoverageOnHover: false, }); + // Add the polylines to a separate layer + let features = { + layer: new L.LayerGroup(), + tree: null + } + + 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 @@ -49,7 +67,7 @@ use Fisharebest\Webtrees\View; * @private */ let _drawMap = function () { - map = webtrees.buildLeafletJsMap('wt-map', config, resetCallback); + map = webtrees.buildLeafletJsMap('wt-map', config, resetCallback, features); }; /** @@ -57,7 +75,7 @@ use Fisharebest\Webtrees\View; * @private */ let _buildMapData = function () { - let geoJson_data = ; + const geoJson_data = ; if (geoJson_data.features.length === 0) { map.fitWorld(); @@ -89,10 +107,6 @@ use Fisharebest\Webtrees\View; }); }, onEachFeature: function (feature, layer) { - if (feature.properties.polyline) { - let pline = L.polyline(feature.properties.polyline.points, feature.properties.polyline.options); - markers.addLayer(pline); - } layer.bindPopup(feature.properties.summary); sidebar.innerHTML += `
  • ${feature.properties.summary}
  • `; },