How to embed a Leaflet map into a Reveal.js presentation?

前端 未结 2 1842
慢半拍i
慢半拍i 2021-01-19 07:35

I am trying to create a presentation running on top of Reveal.js, which would include a Leaflet.js map within one of the slides. I have included all necessary Javascript &am

2条回答
  •  迷失自我
    2021-01-19 08:05

    It might be happening because the #map element is hidden (due to the hidden slide) when it is initialized, so it cannot read the dimensions..

    Try using map.invalidateSize(false); once your slide becomes visible..

    Reveal.addEventListener( 'slidechanged', function( event ) {
        // event.previousSlide, event.currentSlide, event.indexh, event.indexv
        if (event.indexh == 5){ // assuming your 5th slide is the one with the map
            map.invalidateSize(false); // assuming that map holds the the reference to your leaflet instance
        }
    } );
    

提交回复
热议问题