I have an OpenLayers map container defined as

#preview_cont {
    width: 100%;
    height: 15cm;

It looks OK on screen, but when I print it, the map is distorted. I assume it's because map container proportions are changed when printing. As far as I know, in such a case


has to be called. So I tried this function:

$(window).resize(function () {

Unfortunately, it's not called for printing. Is there a way, how to do it?


The approach I use is to:

  1. Adapt the size of the view with something like:

    var orgSize = map.getSize();
    var newSize = [newWidth, newHeight];
    map.getView().fit(extent, {size: newSize});
  2. Start printing when the map is completly rerendered:

    map.once('rendercomplete', function(event) { 
  3. And finally render it again with the original size:

        map.getView().fit(extent, {size: size});
    } );
  • I'm getting extent is not defined error, do you have any ideas ? – Capan May 20 '19 at 10:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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