The CORS error seen is:
Uncaught SecurityError: Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported
All this doesn't work:
OpenLayers 3: Cross-Origin Request Blocked: The Same Origin Policy disallows
https://stackoverflow.com/questions/20260620/openlayers-3-and-xyz-layer ( the exemple jsfiddle don't even work)
Can't do this (I don't own the server):
I'm tring to save my map as PNG (http://openlayers.org/en/v3.0.0/examples/export-map.html).
The example works nice in my server with only the OSM layer, but when I add one more layer from anywhere, I got the CORS error.
My application allow the user to add arbitrary layers from any getMap link, so I have no control over the source Geoserver.
I have an addLayer function to do the job (add the user's layer to the map).
function addLayer( serverUrl, serverLayers, layerName ) {
var newLayer = new ol.layer.Tile({
source: new ol.source.TileWMS({
url: serverUrl,
isBaseLayer : false,
crossOrigin: 'anonymous', <<<<--- PROBLLEM
params: {
'layers': serverLayers,
'format': 'image/png'
},
projection: ol.proj.get('EPSG:4326')
})
});
newLayer.set('name', layerName);
map.addLayer( newLayer );
return newLayer;
}
When I add the crossOrigin: 'anonymous' nothing works anymore. Without crossOrigin it work if the map have only the OSM layer. By adding any other layer I got the CORS error.
Is there any other way to get the Map as image than using the canvas?
I've searched over all this site and found many different answers but none worked.
I cannot configure server side.
This is my export function:
function exportMap() {
map.once('postcompose', function(event) {
var canvas = event.context.canvas;
var xx = canvas.toDataURL('image/png'); <<------- CORS Error !!
console.log( xx );
});
map.renderSync();
}
