openlayers: Map doesn't reappear after hiding the container, resizing the viewport and displaying the container again

Hi there,

it seems like the map canvas is being hidden and disabled when I hide its container, resize the viewport and display the container again. I have a self contained example here:

 https://gist.github.com/codemusings/dae2c4edc16edd6ea708

It seems that when the viewport is resized and the map canvas is off-screen it gains the attribute “display: none”. Even if I remove it manually the map doesn’t respond to input events anymore. Is there any way to work around this?

I’ve reproduced this in Firefox 44, Chrome 47, Chromium 47, Chrome for Android.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 19 (5 by maintainers)

Most upvoted comments

For those having an issue with updating size, see https://github.com/openlayers/openlayers/issues/4601

You need to give OL some time to resize the map before updating, as shown below :

setTimeout(function() {
    map.updateSize();
}, 100);

This is not the cleanest solution but it does work.

For those having an issue with updating size, see #4601

You need to give OL some time to resize the map before updating, as shown below :

setTimeout(function() {
    map.updateSize();
}, 100);

This is not the cleanest solution but it does work.

This solution worked for me as well. The map.updateSize() without time didn’t. Thanks.

What kind of fix are you suggesting? Calling updateSize() on the map is a common practice when container dimensions change.