New crossOriginKeyword property.

Set to 'anonymous' for Layer.OSM and Layer.Bing, and not used by default for other layers.
This commit is contained in:
ahocevar
2012-02-10 12:50:13 +01:00
parent b34f272fa7
commit 342d624616
3 changed files with 23 additions and 2 deletions

View File

@@ -87,6 +87,16 @@ OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, {
* the tile image.
*/
canvasContext: null,
/**
* APIProperty: crossOriginKeyword
* The value of the crossorigin keyword to use when loading images. This is
* only relevant when using <getCanvasContext> for tiles from remote
* origins and should be set to either 'anonymous' or 'use-credentials'
* for servers that send Access-Control-Allow-Origin headers with their
* tiles.
*/
crossOriginKeyword: null,
/** TBD 3.0 - reorder the parameters to the init function to remove
* URL. the getUrl() function on the layer gets called on
@@ -305,7 +315,7 @@ OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, {
} else {
OpenLayers.Event.observe(img, "load", load);
OpenLayers.Event.observe(img, "error", load);
img.crossOrigin = null;
delete img.crossOrigin;
img.src = this.blankImageUrl;
}
}
@@ -324,7 +334,9 @@ OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, {
img.style.opacity = 0;
if (url) {
// don't set crossOrigin if the url is a data URL
img.crossOrigin = url.substr(0, 5) === 'data:' ? null : '';
if (this.crossOriginKeyword && url.substr(0, 5 !== 'data:')) {
img.crossOrigin = this.crossOriginKeyword;
}
img.src = url;
}
},