Skip to content

Commit

Permalink
add a module to handle the full-screen mode of the map container for …
Browse files Browse the repository at this point in the history
…different desktop browsers
  • Loading branch information
sergeiown committed May 27, 2024
1 parent 7ad0fac commit b90070a
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
56 changes: 56 additions & 0 deletions js/fullScreen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* Copyright (c) 2023-2024 Serhii I. Myshko
https://github.com/sergeiown/Map_with_Marker_Clusters/blob/main/LICENSE */

export function toggleFullScreen(element) {
function handleFullScreenRequest(promise) {
promise
.then(() => {
console.log('Entered full-screen mode.');
})
.catch((err) => {
console.error(`Error attempting to enable full-screen mode: ${err.message} (${err.name})`);
});
}

function handleFullScreenExit(promise) {
promise
.then(() => {
console.log('Exited full-screen mode.');
})
.catch((err) => {
console.error(`Error attempting to disable full-screen mode: ${err.message} (${err.name})`);
});
}

if (!document.fullscreenElement) {
if (element.requestFullscreen) {
handleFullScreenRequest(element.requestFullscreen());
} else if (element.mozRequestFullScreen) {
// Firefox
handleFullScreenRequest(element.mozRequestFullScreen());
} else if (element.webkitRequestFullscreen) {
// Chrome, Safari, and Opera
handleFullScreenRequest(element.webkitRequestFullscreen());
} else if (element.msRequestFullscreen) {
// IE/Edge
handleFullScreenRequest(element.msRequestFullscreen());
} else {
console.error('Fullscreen API is not supported by this browser.');
}
} else {
if (document.exitFullscreen) {
handleFullScreenExit(document.exitFullscreen());
} else if (document.mozCancelFullScreen) {
// Firefox
handleFullScreenExit(document.mozCancelFullScreen());
} else if (document.webkitExitFullscreen) {
// Chrome, Safari, and Opera
handleFullScreenExit(document.webkitExitFullscreen());
} else if (document.msExitFullscreen) {
// IE/Edge
handleFullScreenExit(document.msExitFullscreen());
} else {
console.error('Fullscreen API is not supported by this browser.');
}
}
}
14 changes: 14 additions & 0 deletions js/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as layers from '../js/layers.js';
import { isMobile } from '../js/mobileDetector.js';
import { createControlButton } from '../js/buttons.js';
import { addLegend } from '../js/legend.js';
import { toggleFullScreen } from '../js/fullScreen.js';
import { updateControlStyle, updateLayer, gradualOpacityAnimation } from '../js/mapUtils.js';

export function initializeMap() {
Expand All @@ -25,6 +26,19 @@ export function initializeMap() {
});
map.addControl(new centerButton());

if (!isMobile) {
const fullScreenButton = createControlButton({
position: 'topleft',
title: 'Set full screen mode',
imageSrc: './markers/full_screen.png',
onClick: function () {
const mapContainer = document.getElementById('map');
toggleFullScreen(mapContainer);
},
});
map.addControl(new fullScreenButton());
}

const frontButton = createControlButton({
position: 'bottomleft',
title: 'Front line map',
Expand Down
Binary file added markers/full_screen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b90070a

Please sign in to comment.