We are using OpenLayers on mobile devices. When ever the keyboard is shown, OpenLayers resizes the map. This gives us performance issues when there are many features on that map. It takes a long time for the keyboard to appear/disappear.

Is there a way to prevent OpenLayers from resizing the map? Or are there any other ideas how avoid performance issues?

EDIT: A user can click on a feature and an overlay is opened, where he can edit some of the values. The map is only in the background, mostly not visible for the user. So, the problem is not so much that the map gets bigger/smaller, but that the map is re-rendered / reloaded. So every time the keyboard is shown, the whole map is re-rendered (although invisible). Is there a way to stop re-rendering / reloading?

| improve this question | | | | |
  • This has to do with your browser window, not Openlayers. You should try to find a solution for that issue, if any. – Ulas Jan 29 '19 at 14:08

After opening the map fix the size of the map div to the current size in pixels, as by default it will be based on the size of the document, which will reduce when the keyboard is displayed

var size = map.getSize();
map.getTargetElement().style.width = size[0] + 'px';
map.getTargetElement().style.height = size[1] + 'px';
| improve this answer | | | | |
  • How is this an answer to "Is there a way to prevent openlayer from resizing the map?" – Ulas Jan 29 '19 at 14:55
  • 3
    It's not OpenLayers which is resizing the map, but it answers the headline question "prevent map from resizing". – Mike Jan 29 '19 at 15:15
  • @Mike: your code snipped fixes the size - which is great - but the map is still rendered and the performance issue is there. Is there a way to stop rendering the map? – Jeremy Benks Jan 30 '19 at 11:52
  • It seems OpenLayers listens for window.onresize and then renders regardless of whether the map size has changed. It fires a map change:size event with the same value each time, so it is possible to detect when it is about to happen, but I don't know how to stop the render. – Mike Jan 30 '19 at 19:25
  • There doesn't seem to be a way to stop rendering because it is normal for a map to render whenever there is any interaction. Performance issues with multiple features can often be resolved by optimising the way features are styled stackoverflow.com/questions/39125958/… github.com/openlayers/openlayers/issues/8514 – Mike Jan 31 '19 at 11:52

Not the answer you're looking for? Browse other questions tagged or ask your own question.