Resizing a leaflet map on container resize
The problem is that the resizing of the #map-container
div
is done via a css transition. The transition hasn't started yet, let alone ended, when the call to invalidateSize happens so the leaflet map cannot recognize any change of dimensions of its surrounding div
.
Triggering the map-container-resize
event with a delay solved the problem. This way :
setTimeout(function(){ map.invalidateSize()}, 400);
L.Map.invalidateSize()
only informs leaflet map object that its container size has been changed, and therefore is should draw less or more map tiles. It does not actually change any dimensions, e.g. of its containing <div>
, and does not move the map. You should do it yourself.
You can use below code after resize that
map.invalidateSize()
https://github.com/Leaflet/Leaflet/issues/690