brunob / leaflet.fullscreen

Leaflet.Control.FullScreen for Leaflet
https://brunob.github.io/leaflet.fullscreen/
MIT License
380 stars 110 forks source link

map.toggleFullScreen is not a function #104

Closed hairman closed 2 years ago

hairman commented 2 years ago

Hello. Please tell me what am I doing wrong.

      var map = L.map('map', {
        layers: [
          L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'),
        ],
        fullscreenControl: true,
        fullscreenControlOptions: {
          position: 'topleft',
        },
      }).setView([51.505, -0.09], 13);

      map.toggleFullScreen();

 The button on the map is added and it works. But I am getting an error: Uncaught TypeError: map.toggleFullScreen is not a function

Tested on leaflet version 1.7.1 and 1.8.0

brunob commented 2 years ago

Does the example file works from your side ? Can you share a link to your code online in order to help you ?

hairman commented 2 years ago

Thanks for the help. My test page. https://cto.softmax.by/map_test_fs/

brunob commented 2 years ago

Ok, i see as stated in https://github.com/Leaflet/Leaflet.fullscreen/issues/28#issuecomment-50845790 and here https://developer.mozilla.org/en-US/docs/Web/API/Element/requestFullscreen

Note: This method must be called while responding to a user interaction or a device orientation change; otherwise it will fail.

You can't call toggleFullScreen() directly, maybe i should add a not about this in the readme ?

hairman commented 2 years ago

ОК. What is meant by "while responding to a user interaction"? I added a button to call a function and that doesn't work either.

test page updated

I need to toggle FullScreen from an external function. How to do it right? Thanks.

hairman commented 2 years ago

Please see this implementation. A similar method works there.

brunob commented 2 years ago

Haaa my bad, toggleFullscreen != toggleFullScreen cf https://github.com/brunob/leaflet.fullscreen/blob/master/Control.FullScreen.js#L322

I'll fix the readme on this point :)