Having trouble to exportmap in OpenLayer 3 + Javascript -


i'm trying export map, i'm getting same error:

failed execute 'todataurl' on 'htmlcanvaselement': tainted canvases may not exported. 

i have following code:

var canvas = event.context.canvas; var exportpngelement = document.createelement('a'); exportpngelement.download = 'mapa.png'; exportpngelement.href = canvas.todataurl('image/png'); document.body.appendchild(exportpngelement); exportpngelement.click(); document.body.removechild(exportpngelement); 

what wrong? have idea?

to honest not answering question. did not check why example not work. propose using different approach:

canvas.todataurl unreliable browser crashes depending on size of exported file. works lightweight maps. real life applications have use canvas.toblob instead.

more info on canvas.toblob: https://developer.mozilla.org/en-us/docs/web/api/htmlcanvaselement/toblob

canvas.toblob works in firefox (https://developer.mozilla.org/en-us/docs/web/api/htmlcanvaselement/toblob#browser_compatibility) , implemented in chrome (https://code.google.com/p/chromium/issues/detail?id=67587#c101).

in meantime can use canvas-toblob (https://github.com/eligrey/canvas-toblob.js) , filesaver.js (https://github.com/eligrey/filesaver.js).

see examples here:

i have downloaded 8mb png-files using method.

i have opened issue requesting add example using canvas.toblob: https://github.com/openlayers/ol3/issues/2968


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -