Is it possible to enable Cross-Origin Resource Sharing (CORS) in OpenLayers? If so, how?
I have a web map in OpenLayers, and I'm using an HTML canvas to render it as a PNG image. My script works great, but due to the browser's same-origin policy, I can only convert my canvas to an image if all the map tiles I've drawn to it come from the same host (e.g. sub.domain.com
).
To boost my map's loading speed, I pull tiles from an array of subdomains: a.domain.com
, b.domain.com
, etc. This greatly improves performance, working around the browser's limit of four simultaneous connections per host, but prevents me from ever converting my canvas to an image, as the tiles come from multiple hosts.
I'm trying to use CORS to work around this problem. I've set the appropriate Access-Control-Allow-Origin
response header for the tileset I serve with PHP, but this doesn't have an effect. I suspect this is due to not having the Origin
header in the request (as shown in the example on the Wiki page). It would seem that some OpenLayers configuration is required. But what? Has anyone else done this successfully?