javascript - OpenLayers: 'Failed to execute 'toDataURL' on 'HTMLCanvasElement' -


i have problem when try export map multiple layer created using openlayer.
js code:

map.once('postcompose', function(event) {        var img = new image,        canvas = event.context.canvas;         img.crossorigin = "anonymous";        img.src = canvas.todataurl('image/png'); }); 

where map javascript variable of openlayers map.
when map composed of more 1 level, receive kind of error:

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

if try same thing without adding level map (just using default openlayer map) able generate data url , download map in png format.
it seems crossorigin problem, cors should enabled on server.
help? thanks!

edit
here js code example add layer map causing issues.

var layer = new ol.layer.image({      source: new ol.source.imagewms({         url: 'http://pubblicazioni.provincia.fi.it/geoserver/wms',         params: {                 'layers': 'layer_name',                 'format': 'image/png',                 'transparent': 'true'         },         crossorigin: null      }) }); map.addlayer(layer); 

i solved problem implementing local proxy on server suggested michaeljs.
i'm running django app, developed customized proxy starting code:
https://github.com/mjumbewu/django-proxy

then in urls.py defined rule:

url(r'^proxy/(?p<url>.*)$', views.proxy_view, name='proxy'), 

and proxed request wms service changing js code way:

var layer = new ol.layer.image({      source: new ol.source.imagewms({         url: '/proxy/http://pubblicazioni.provincia.fi.it/geoserver/wms',         params: {                 'layers': 'layer_name',                 'format': 'image/png',                 'transparent': 'true'         },         crossorigin: null      }) }); map.addlayer(layer); 

crossorigin issue solved!


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -