I need to print a map with a fixed scale of 1:500 horizontally on a A4 paper (297x210mm). The map is done with Openlayers, the print request is sent to QGIS server using WMS getPrint function.

Till now I used a variable scale, printing the map in the actual visible resolution:

var dpi = 120;
var a4_width = 297;
var a4_height = 210;
var inch = 25.4;

var width = Math.round(a4_width * dpi / inch);
var height = Math.round(a4_height * dpi / inch);

var extent = map.getView().calculateExtent([width, height]);

window.open("http://localhost/cgi-bin/qgis_mapserv.fcgi?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetPrint&FORMAT=pdf&TRANSPARENT=true&LAYERS=all&CRS=EPSG:3857&map0:STYLES=&map0:extent="+extent+"&TEMPLATE=DIN_A4_horizontal (1:500)&DPI=120");

How can I calculate the extend of the printing area using the center part of the actual view?

Probably the solution is part of this answer, but I can't figure out how.

Your Answer

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

Browse other questions tagged or ask your own question.