Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to add FULLSCREEN control properly?

I am trying to add a full screen control (I had a switcher too). when i create this control inside map creation new ol.MAP...(following documentation) i dont get errors but they(layersSwitcher and Fullscreen control) dont appear.

map = new ol.Map({
        controls:[new ol.control.LayerSwitcher({
            tipLabel: 'Leyenda',
    
        }),
        new ol.control.defaults().extend([new ol.control.FullScreen()])],
        layers: [
            new ol.layer.Group({
                'title': 'Mapas de base',
                layers: [grisOSM, mapaOSM]
            }),

I also tried creating the map, then create and add controls like this:

 map = new ol.Map({
        layers: [
            new ol.layer.Group({
                'title': 'Mapas de base',
                layers: [grisOSM, mapaOSM]
            }),

    const layerSwitcher = new ol.control.LayerSwitcher({
        tipLabel: 'Leyenda',

    });
    map.addControl(layerSwitcher);
    const fullScreen = new ol.control.defaults().extend([new ol.control.FullScreen()]);

    map.addControl(fullScreen);

I get Uncaught TypeError: t.element.setMap is not a function error and can’t see none of them

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Either

 map = new ol.Map({
        controls: ol.control.defaults().extend([new ol.control.FullScreen()]),
        layers: [
            new ol.layer.Group({
                'title': 'Mapas de base',
                layers: [grisOSM, mapaOSM]
            }),
         ],
     });

or

 map = new ol.Map({
        layers: [
            new ol.layer.Group({
                'title': 'Mapas de base',
                layers: [grisOSM, mapaOSM]
            })
        ],
    });

    map.addControl(new ol.control.FullScreen());

ol.control.defaults is not a constructor so does not need new

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading