[OpenLayers-Users] Printing openlayers using javascript and php

David Quinn daithiquinn at gmail.com
Sun Feb 12 16:32:04 EST 2012


I'm trying to use an example of printing from openlayers, using javacript
and php: http://trac.osgeo.org/openlayers/wiki/Printing

A jpg is being generated of the correct size using php, but there is no
layer information there. When I look at the post content in Firebug I see:

height    681
tiles    []
width    1276

It looks like there is no content for the files being gathered. The
relevant javascript seems to be the following:

    var tiles = [];
    for (layername in map.layers) {
        // if the layer isn't visible at this range, or is turned off, skip
it
        var layer = map.layers[layername];
        if (!layer.getVisibility()) continue;
        if (!layer.calculateInRange()) continue;
        // iterate through their grid's tiles, collecting each tile's
extent and pixel location at this moment
        for (tilerow in layer.grid) {
            for (tilei in layer.grid[tilerow]) {
                var tile     = layer.grid[tilerow][tilei]
                var url      = layer.getURL(tile.bounds);
                var position = tile.position;
                var opacity  = layer.opacity ? parseInt(100*layer.opacity)
: 100;
                tiles[tiles.length] = {url:url, x:position.x, y:position.y,
opacity:opacity};
            }
        }
    }

    // hand off the list to our server-side script, which will do the heavy
lifting
    var tiles_json = JSON.stringify(tiles);

I'm not certain if this approach enables me to print the basemap and the
layers (both vector and WMS), or whether this code is out of date. Is this
the best approach to generate an image of what is seen in the browser?

Thanks,
David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20120212/28295ac9/attachment.html


More information about the Users mailing list