Skip to content

Commit

Permalink
Resize map to fit viewport on enter/exit of fullscreen
Browse files Browse the repository at this point in the history
  • Loading branch information
ddrury committed Apr 24, 2023
1 parent f02df12 commit ff1e598
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
13 changes: 11 additions & 2 deletions resources/js/webtrees.js
Expand Up @@ -676,6 +676,15 @@
* @returns Map
*/
webtrees.buildLeafletJsMap = function (id, config, resetCallback) {
// Resize map on enter/exit fullscreen
document.addEventListener("fullscreenchange", (event) => {
map.closePopup();
//wait for fullscreen transition to complete
setTimeout(() => {
resetCallback(event);
}, 25);
});

const zoomControl = new L.control.zoom({
zoomInTitle: config.i18n.zoomIn,
zoomoutTitle: config.i18n.zoomOut,
Expand Down Expand Up @@ -737,9 +746,8 @@
defaultLayer = config.mapProviders[0].children[0].layer;
}


// Create the map with all controls and layers
return L.map(id, {
const map = L.map(id, {
zoomControl: false,
})
.addControl(zoomControl)
Expand All @@ -751,6 +759,7 @@
openedSymbol: config.icons.collapse,
}));

return map;
};

/**
Expand Down
2 changes: 1 addition & 1 deletion resources/views/modules/place-hierarchy/map.phtml
Expand Up @@ -95,7 +95,7 @@ use Fisharebest\Webtrees\View;

map.fitBounds(<?= json_encode($data['bounds'], JSON_THROW_ON_ERROR) ?>, { padding: [50, 30] });
sidebar.innerHTML = <?= json_encode($data['sidebar'], JSON_THROW_ON_ERROR) ?>;
};
};

window.onload = function() {
// Activate marker popup when sidebar entry clicked
Expand Down
2 changes: 1 addition & 1 deletion resources/views/modules/places/tab.phtml
Expand Up @@ -102,7 +102,7 @@ use Fisharebest\Webtrees\I18N;
}
};

// Can't use window.onload here. seems to be because of AJAX loading
// Cannot use window.onload here. seems to be because of AJAX loading
const _loadListeners = function() {
// Activate marker popup when sidebar entry clicked
sidebar.querySelectorAll('.gchart').forEach((element) => {
Expand Down

0 comments on commit ff1e598

Please sign in to comment.