2

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

ol.Map.updateSize()

has to be called. So I tried this function:

$(window).resize(function () {
        map.updateSize();
});

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

1

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.setSize(newSize);
    map.getView().fit(extent, {size: newSize});
    
  2. Start printing when the map is completly rerendered:

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

        map.setSize(orgSize);
        map.getView().fit(extent, {size: size});
    } );
    
  • I'm getting extent is not defined error, do you have any ideas ? – Capan May 20 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.