leaflet.fullscreen icon indicating copy to clipboard operation
leaflet.fullscreen copied to clipboard

Full screen is not toggled when exiting full screen using the browser interface with fullscreenElement

Open rbertucat opened this issue 1 year ago • 6 comments

When specifying the Dom element to render in full screen using fullscreenElement, and exiting the full screen mode either by pressing ESC or by using the browser "X" button, the full screen is not toggled.

It seems like the event _handleFullscreenChange doesn't update properly. https://github.com/brunob/leaflet.fullscreen/blob/f1a6ca62e90a5742cd5e39d31190cfc9be34eb48/Control.FullScreen.js#L256

It seems like the condition ev.target === map.getContainer() should be updated to consider fullscreenElement instead of map.getContainer().

rbertucat avatar Jan 08 '25 11:01 rbertucat

Nice catch, would you like to provide a PR to fix that ?

brunob avatar Jan 09 '25 18:01 brunob

Bruno, thanks for the suggestion! Unfortunately, I won’t be able to provide a PR for this at the moment.

rbertucat avatar Jan 14 '25 07:01 rbertucat

This simple patch should do the job, any thought @BePo65 & @KristjanESPERANTO ?

diff --git a/Control.FullScreen.js b/Control.FullScreen.js
index e90484a..f43dff3 100644
--- a/Control.FullScreen.js
+++ b/Control.FullScreen.js
@@ -255,7 +255,7 @@
 
 		_handleFullscreenChange(ev) {
 			const map = this._map;
-			if (ev.target === map.getContainer() && !this._screenfull.isFullscreen && !map._exitFired) {
+			if (ev.target === (this.options.fullscreenElement || map.getContainer()) && !this._screenfull.isFullscreen && !map._exitFired) {
 				this._screenfull.exit().then(() => map.invalidateSize());
 				map.fire('exitFullscreen');
 				map._exitFired = true;

brunob avatar May 15 '25 18:05 brunob

I do not completely understand when the problem occurs. @rbertucat could you show the html and js you used to generate the map? Do you use a programming framework like react or angular?

I created a minimal demo to reproduce the issue at stackblitz, but I can see no problem with entering and exiting the fullscreen mode.

BePo65 avatar May 16 '25 05:05 BePo65

@BePo65, somehow stackblitz doesn't allow me to run the example in its own windows.

The error really occurs when you use fullscreenElement, and when you exit the full screen mode either by pressing ESC or by using the browser "X" button.

rbertucat avatar May 16 '25 08:05 rbertucat

somehow stackblitz doesn't allow me to run the example in its own windows. I know this problem all too well ;-(

map.getContainer() should always return the container of the map (i.e. html element to set / reset to fullscreen), but I have to admit that I never used this feature.

What do you use as a container? Can you provide the relevant part of your application? This should help me reproduce the problem 😄 .

BePo65 avatar May 16 '25 09:05 BePo65