question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Auto-detect changes to map size (and invalidateSize)

See original GitHub issue

I 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:closed
  • Created 11 years ago
  • Reactions:3
  • Comments:16 (7 by maintainers)

github_iconTop GitHub Comments

4reactions
danzelcommented, Aug 27, 2012

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

    map.invalidateSize();​

after making it display:block

2reactions
mournercommented, Jun 30, 2013

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).

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found