Auto-detect changes to map size (and invalidateSize)
See original GitHub issueI have a map that’s styled like this:
#map {position: absolute; top: 10px; left: 10px; right: 10px; bottom: 90px;}
… i.e. it has no explicit height. So, of course, leaflet isn’t rendering all of the tiles. However I do setTimeout(map.invalidateSize.bind(map))
, after creating the map it renders properly.
This has me thinking that it’s not actually necessary for the map to have an explicit height - it’s just a question of insuring Leaflet is smart about detecting the height at the appropriate time.
Issue Analytics
- State:
- Created 11 years ago
- Reactions:3
- Comments:16 (7 by maintainers)
Top Results From Across the Web
Documentation - a JavaScript library for interactive maps
invalidateSize (<Zoom/pan options> options), this. Checks if the map container size changed and updates the map if so — call it after you've...
Read more >Leaflet: map invalidatesize not working - Stack Overflow
First you initiate your map with var map = L.map('mapdiv'). ... You can use invalidateSize() as soon as the map container size has...
Read more >Leaflet invalidate size - is not a function (undefined)
I have change the name of my Dom object. The issue now is that I call map.invalidatesize when my tab is clicked, and...
Read more >Show/Hide Div In Bootstrap 4 While Resizing Height Of Leaflet ...
Checks if the map container size changed and updates the map if so call it after you've changed the map size Default will...
Read more >Leaflet widget - Map invalidation - surveyjs Support
openPopup(); // Function below invalidates the Map size and refetches necessary tiles map.invalidateSize(); // Tried the below but does not ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I believe this is the same issue as seen on #926 The hidden element causes it, you can’t measure a display:none element.
You can simplify the code a bit: http://jsfiddle.net/dCK8j/6/ Just need to do
after making it display:block
Closing the issue as we don’t want to implement this for performance, browser support and insignificance reasons (you can easily just use invalidateSize when necessary).