[GIS] How to call Leaflet FullScreen plug-in from code

javascriptleaflet

I'm currently using Leaflet along with leaflet.fullscreen to provide a full screen map.

I've got it working nicely with the button but I can't work out how to "call" the function manually from my JavaScript code.

I've tried: map.fullscreenControl.toogleFullScreen(); but get the following error and a "broken" fullscreen:

TypeError: this.invalidateSize is not a function
this.invalidateSize();

Best Answer

You could trigger a click on its fullscreen button. For example with jQuery:

$(".leaflet-control-zoom-fullscreen")[0].click();