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");

I also added the ExportMap.js file:


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?


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.

  • Thanks I'll try it, what about osm layer? And how I add it to the osm layer?
    – Jordan
    May 12 '14 at 12:24
  • I didn't try OSM yet. @Jordan
    – Moshii
    May 12 '14 at 13:15
  • @Moshii What OpenLayers version are you using?
    – GreyHippo
    Jun 19 '14 at 17:15
  • 1
    @Jordan Did you ever get it working? I am having the same problem as you.
    – GreyHippo
    Jun 19 '14 at 17:16

I bump this post.

The answer given by Moshii works only if you use a custom version of OpenLayers (the same as here), because in a standard version of OpenLayers 2 such as 2.13, the ONECANVASPERLAYER does not exist in OpenLayers.Layer.Grid, same for useCanvas.

The possibility of using canvas for WMS Layer was actually an experimentation as you can read here.

Anyway, OpenLayers 3 has a built-in export function right now.

  • 1
    Too bad OpenLayers 3 is missing so much other features only found on 2.x. Would be nice to be able to use this export functionality on OpenLayers 2.x. Apr 30 '15 at 20:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.