[GIS] openlayers – export map to canvas problem

exportjavascriptmapcontrolopenlayers-2

I am trying to make a export control to export the map as image file.
I found this example:
http://dev.openlayers.org/sandbox/camptocamp/canvas/openlayers/examples/exportMapCanvas.html
so i added the control to the map and the function

function exportMap() {
    var canvas = OpenLayers.Util.getElement("exportedImage");
    exportMapControl.trigger(canvas);
}

I also added the ExportMap.js file:

http://dev.openlayers.org/sandbox/camptocamp/canvas/openlayers/lib/OpenLayers/Control/ExportMap.js

but, i am getting this error, when i am trying to run exportMap():

Uncaught TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': No function was found that matched the signature provided. ExportMap.js:128

What that mean? how can i fix it?

Best Answer

You have to set useCanvas property for every layer you want to export with ExportMap.js.

useCanvas: OpenLayers.Layer.Grid.ONECANVASPERLAYER

See this example and its source code: Export map as image

I have successfully exported WMS , WFS and Vector layers but can't export Google Maps layer. If you can export Google Maps layer then let me know that.

Related Question