Skip to content

Commit

Permalink
Make code in webtrees.js more generic by shifting creation of overlay…
Browse files Browse the repository at this point in the history
… to the pedigree map view
  • Loading branch information
ddrury committed Feb 12, 2022
1 parent 711b632 commit cbf14da
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
23 changes: 8 additions & 15 deletions resources/js/webtrees.js
Original file line number Diff line number Diff line change
Expand Up @@ -623,10 +623,10 @@
* @param {string} id
* @param {object} config
* @param {function} resetCallback
* @param {array|undefined} polylines
* @param {array|undefined} overlay
* @returns Map
*/
webtrees.buildLeafletJsMap = function (id, config, resetCallback, polylines) {
webtrees.buildLeafletJsMap = function (id, config, resetCallback, overlay) {

const zoomControl = new L.control.zoom({
zoomInTitle: config.i18n.zoomIn,
Expand Down Expand Up @@ -673,18 +673,11 @@
let defaultLayer = config.mapProviders[0].children[0].layer;
}

let featureLayer = new L.LayerGroup();
let overlaysTree = null;
if (polylines !== undefined && polylines.length) {
polylines.forEach((line) => {
featureLayer.addLayer(L.polyline(line.points, line.options));
});

overlaysTree = {
label: config.i18n.showLines ?? '?',
layer: featureLayer,
//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, {
Expand All @@ -693,8 +686,8 @@
.addControl(zoomControl)
.addControl(new resetControl())
.addLayer(defaultLayer)
.addLayer(featureLayer)
.addControl(L.control.layers.tree(config.mapProviders, overlaysTree, {
.addLayer(overlay.layer)
.addControl(L.control.layers.tree(config.mapProviders, overlay.tree, {
closedSymbol: config.icons.expand,
openedSymbol: config.icons.collapse,
}));
Expand Down
20 changes: 14 additions & 6 deletions resources/views/modules/pedigree-map/chart.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ use Fisharebest\Webtrees\View;
const geoJson_data = <?= json_encode($data, JSON_THROW_ON_ERROR) ?>;
const sidebar = document.querySelector('.wt-pedigree-map-sidebar');

config.i18n.showLines = '<?= I18N::translate("Show/Hide parent to child lines") ?>';

const scrollOptions = {
behavior: "smooth",
block: "start",
Expand All @@ -38,11 +36,21 @@ use Fisharebest\Webtrees\View;
showCoverageOnHover: false,
});

let polyLines = [];
// Add the polylines to a separate layer
let features = {
layer: new L.LayerGroup(),
tree: null
}

geoJson_data.features.forEach((feature) => {
if (feature.properties.polyline) {
polyLines.push(feature.properties.polyline);
if (feature.properties.polyline) {
features.layer.addLayer(L.polyline(feature.properties.polyline.points, feature.properties.polyline.options));
if (!features.tree) {
features.tree = {
label: '<?= I18N::translate("Show/Hide parent to child lines") ?>',
layer: features.layer
}
}
}
});

Expand All @@ -60,7 +68,7 @@ use Fisharebest\Webtrees\View;
* @private
*/
let _drawMap = function () {
map = webtrees.buildLeafletJsMap('wt-map', config, resetCallback, polyLines);
map = webtrees.buildLeafletJsMap('wt-map', config, resetCallback, features);
};

/**
Expand Down

0 comments on commit cbf14da

Please sign in to comment.