How do I save the current map view an an image, or print it?
OpenLayers itself doesn't handle printing, nor saving the image to a single image. This is because OpenLayers is actually an illusion, created by many different images being creatively overlaid in your browser's div. The only place the entire map exists, is in your browser's imagination. Nevertheless, there are a few options.
The Print button
The following mechanism works if you're using UMN Mapserver. It's not very flexible, but it does work. It constructs a mapserv query containing all of the active layers and the view's extent and size.
- Your layers are either WMS or MapServer layers.
- All layers are being served from the same mapfile, be they WMS or MapServer layers.
- This mechanism will not use TileCache, and will instead make a direct query to mapserv. If you have a layer that's very slow to render, then this method may take a long time.
"Tile stitching" using a server-side program
This method involves the OpenLayers Map composing a list of the visible tiles and sending them to a server-side program. The server-side program downloads the tiles' images and composes them into a finished image.
This method has been well-developed and moved to its own page due to the volume of content.
MapFish is a framework based on OpenLayers that provides additional GUI elements and server side components. On of those components is a print service. Mappings exist for Java, Python and PHP. More information about this component here:
wkhtmltopdf is a command-line tool which converts a HTMl document into a PDF document. We have had significant success with implementing a web page in jQuery and OpenLayers: setting up an OpenLayers Map with a given extent, Bing basemap, WMS layers, and Markers, and then converting this HTML to PDF. The resulting PDF even includes OpenLayers Controls such as ScaleLine.
**Untested** http://cutycapt.sourceforge.net/ is a tool with a similar implementation to wkhtmltopdf above.