[GIS] Problem with map tiles loading with Leaflet and Bootstrap

bootstrap-frameworkjavascriptleaflet

I want to create website with Leaflet map placed in bootstap tab. If I switch into tab where is Leaflet instantion tiles are not loading correct(I see the grey background). I guess there is a problem with size of a because if resize the browsers window tiles load correctly. Any ideas?
Here is my basic concept.

https://jsfiddle.net/rjper9nz/6/

Best Answer

Your map's tiles have to be realoaded, which can be done with the method invalidateSize:

map.invalidateSize();

Which is not sufficient to solve the issue because firing this method right at the beginning does not have any effect.

You only want to fire it after the tab container has loaded, so you need to know when that happens.

The following code does that and fixes your issue:

 $("a[href='#menu1']").on('shown.bs.tab', function(e) {
      map.invalidateSize();
 });


PS: I have renamed your variable mymap to map, because most people looking this up will call it map, so make sure to change that.