[GIS] How to print only a selection of the map using MapFish Printing Module

extentsgeoservermapfishopenlayers-2printing

I am working on a GIS API that uses OpenLayers 2. I want to make snapshots of a selected region. For example. I draw a rectangle, and the MapFish Printing Module would print only the selected region.

Selected area to print

I have been trying to use the bbox property, but I get the wrong image, i.e., instead of a rectangle near Lisbon, I get a rectangle with south Europe and North/Center Africa.

Here are my print options:

var printOptions = {
    units: 'm',
    srs: 'EPSG:900913',
    layout: options.layout,
    dpi: '300',
    mapTitle: options.mapTitle,
    comment: options.comment,
    layers: [
        {
            baseURL: 'http://a.tile.openstreetmap.org/',
            opacity: 1,
            singleTile: false,
            type: 'OSM',
            maxExtent: [-20037508.3392, -20037508.3392, 20037508.3392, 20037508.3392],
            tileSize: [256, 256],
            extension: 'png',
            resolutions: [156543.03390625, 78271.516953125, 39135.7584765625, 19567.87923828125, 9783.939619140625, 4891.9698095703125, 2445.9849047851562, 1222.9924523925781, 611.4962261962891, 305.74811309814453, 152.87405654907226, 76.43702827453613, 38.218514137268066, 19.109257068634033, 9.554628534317017, 4.777314267158508, 2.388657133579254, 1.194328566789627, 0.5971642833948135]
        }
    ],
    pages: [
        {
            bbox: [-1050091.8944356, -990623.88643799, 4675576.582525099, 4733515.8499572]
        }
    ]
};

I am assuming that the bbox array is defined like this: [minX, maxX, minY, maxY].

Is this correct?


I managed to make it work using Thomas B's answer.

I draw a box, I get the bounds of it, and then I get the BBOX value in an array, like this:

var printBbox = geometry.getBounds().toArray();

And the, in the printing module definitions, I do this:

pages: [
    {
        bbox: printBbox
    }
]

Best Answer

"Normally" the bbox should be:

left, bottom, right, top

west, south, east, north

minX, minY, maxX, maxY

so I would try:

bbox: [-1050091.8944356, 4675576.582525099, -990623.88643799, 4733515.8499572]

PS: there is a nice BBOX-Cheatsheet: https://github.com/perrygeo/bbox-cheatsheet/blob/master/reference.md Even if OpenLayers/Geoserver is missing there I think it can be helpful sometimes.

Related Question