Is it possible to clean a tainted canvas?
I have an Openlayers map where user can add layer with CORS restriction. I can't bypass the cors by my proxy config and crossOrigin='anonymus' is not an option.
What I need, it's to be able to remove the " bad " layer and let the user produces the map image.
So I try to:
But I always get the cors error. How can I make my map great again without refreshing the browser?
No there is no way to clean a tainted canvas.
Once tainted, it will remain tainted for its whole life.
Not only this, but also drawing this canvas on a second canvas will taint that second canvas too. Even if that canvas has been completely cleared.
So, the only way for you, is to start again from a new canvas element, and to filter out the bad layers before they are drawn.
There is a property crossOrigin in the source of added layer so you can give it the value crossOrigin: "Anonymous"
as the following sample
var basemap = new ol.layer.Tile({
source: new ol.source.TileArcGISRest({
ratio: 1,
params: {},
crossOrigin: "Anonymous",
url: "http://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer"
})
})
I hope this will fit
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.