[GIS] printing openlayers map

geoextopenlayers-2printingtilecache

What i've got is a map served by the tilecache and shown by openlayers and geoext.

Now i need to print this map, so what i've done is:

made a button which creates (window.open()) a new window with my map in it and window.print() on body onload.

This works well exept that i'm getting a second blank page. So the question is: how (and where) do i set map size and proportions to have it printed correctly?

map is created this way:

map = new OpenLayers.Map("map", {
    maxExtent : new OpenLayers.Bounds(-20037508.34, -20037508.34, 20037508.34, 20037508.34),
    maxResolution : 156543.03125 / 64,
    numZoomLevels : 11,
    units : 'm',
    projection : "EPSG:900913",
    displayProjection : new OpenLayers.Projection("EPSG:4326"),
});

Best Answer

i think you can achieve this with some css bindings which is not a gis solution. in css there are lots of css media types and one of these is print element. you can add this to your index page with this way:

<link rel="stylesheet" type="text/css" media="print" href="print.css">

and with some css code may help you.

body {
    background: white;
        size: A4 landscape;
    }

#menu {
    display: none;
    }

#map-panel{
        left: 0;
        top: 0;
    width: 500px;
        height: 500px;
        display: block;
        visiblity: visible;
    }
* {
    overflow: visible !important;
        position: relative;
    }

i hope it helps you.

Related Question