Leafletjs map - map.invalidateSize is not working

前端 未结 2 781
温柔的废话
温柔的废话 2021-01-08 00:14

I use Leafletjs with google map tiles in my application. Here is my HTML markup:

相关标签:
2条回答
  • 2021-01-08 00:19

    My recommendation for you is to use the following plugin: https://github.com/brunob/leaflet.fullscreen , it adds a button for full screen, which expand the map automatically, as in the following map:enter image description here.

    0 讨论(0)
  • 2021-01-08 00:29

    Thanks Yehoshaphat. I did not want a full screen map. I just wanted to expand the map a little bit.

    Finally, I got it working using the below code:

    $.expandMap = function()    {
        if ($(".rightNav").is(':visible')){
                $(".map-wrap").animate({width:'70%'},'400');
                $(".rightNav").hide(0);
                setTimeout(function(){ map.invalidateSize()}, 400);
            }
     }
    

    The map now expands to fill the expanded space of the outer container. It is not very smooth; but it works.

    0 讨论(0)
提交回复
热议问题