1

I'm using OpenLayers 2.13 with GeoExt and mapfish print module for GeoServer. I've a map composed of a WMS layer and a vector layer. On my web browser everything is fine but when I print this map into a PDF file with mapfish print, layers are shifted and I can't figure out why. Any ideas?

How the map is rendered by OpenLayers/GeoExt How the map is rendered by OpenLayers/GeoExt

How the map is rendered in PDF file generated by Mapfish print enter image description here

Part of my code : Map creation part:

map = new OpenLayers.Map("map", options);
var layer_dpt = new OpenLayers.Layer.WMS("dpt", "linkToGeoserver",
    {
        layers:'base_layer'
    },
    {
        singleTile: 'true'
    }
);
map.addLayer(layer_dpt);
layer_comm = new OpenLayers.Layer.Vector( 'communes',{
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.HTTP({
url: 'GeoServer WFS URL',
format: new OpenLayers.Format.GeoJSON()
})  
});
map.addLayer(layer_comm);

Printing part:

var printProvider = new GeoExt.data.PrintProvider({
    method: "POST", // "POST" recommended for production use
    capabilities: printCapabilities // from the info.json script in the html
});
printProvider.setDpi(printProvider.dpis.getAt(2));
// Our print page. Tells the PrintProvider about the scale and center of
// our page.
printPage = new GeoExt.data.PrintPage({
    printProvider: printProvider,
    customParams: {
        mapTitle: "",
        comment: ""
    }
});
mapPanel = new GeoExt.MapPanel({
    region: "center",
    map: map,
    center: [map.getCenter().lon, map.getCenter().lat],
    zoom: map.zoom
});
new Ext.Panel({
    renderTo: "map",
    layout: "border",
    width: 1200,
    height: 950,
    items: [mapPanel],
    bbar: ["->", {
        text: "Print",
        id: "imprimer",
        handler: function() {
            // convenient way to fit the print page to the visible map area
            var opt = {"mode":"closest"};
            printPage.fit(mapPanel, opt);
            // print the page, optionally including the legend
            printProvider.print(mapPanel, printPage, false);
        }
    }]
});

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.