Leaflet map not showing properly in bootstrap 3.0 modal

后端 未结 7 1582
迷失自我
迷失自我 2020-12-03 07:47

i have a big problem. i want to open a leaflet map in a modal. but the map is not showing properly. the tiles are not loading.

here is the script:

http://boo

7条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-03 08:02

    You should probably avoid using setTimeout with a randomly chosen delay. A better way using the 'shown.bs.modal' event instead of 'show.bs.modal':

    modal.on('shown.bs.modal', function(){
        setTimeout(function() {
            map.invalidateSize();
       }, 1);
    })
    

    Or use underscore's defer :

    modal.on('shown.bs.modal', function(){
        _.defer(map.invalidateSize.bind(map));
    })
    

提交回复
热议问题