Merge branch 'master' into utfgrid
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
|
||||
/**
|
||||
* @requires OpenLayers/Tile.js
|
||||
* @requires OpenLayers/Animation.js
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -81,6 +82,23 @@ OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, {
|
||||
*/
|
||||
maxGetUrlLength: null,
|
||||
|
||||
/**
|
||||
* Property: canvasContext
|
||||
* {CanvasRenderingContext2D} A canvas context associated with
|
||||
* 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
|
||||
* each draw(), so no need to specify it here.
|
||||
@@ -203,6 +221,7 @@ OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, {
|
||||
* it can be reused in a new location.
|
||||
*/
|
||||
clear: function() {
|
||||
OpenLayers.Tile.prototype.clear.apply(this, arguments);
|
||||
var img = this.imgDiv;
|
||||
if (img) {
|
||||
OpenLayers.Event.stopObservingElement(img);
|
||||
@@ -216,6 +235,7 @@ OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, {
|
||||
}
|
||||
OpenLayers.Element.removeClass(img, "olImageLoadError");
|
||||
}
|
||||
this.canvasContext = null;
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -297,6 +317,9 @@ OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, {
|
||||
} else {
|
||||
OpenLayers.Event.observe(img, "load", load);
|
||||
OpenLayers.Event.observe(img, "error", load);
|
||||
if (img.crossOrigin) {
|
||||
img.crossOrigin = null;
|
||||
}
|
||||
img.src = this.blankImageUrl;
|
||||
}
|
||||
}
|
||||
@@ -314,6 +337,10 @@ OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, {
|
||||
img.style.visibility = 'hidden';
|
||||
img.style.opacity = 0;
|
||||
if (url) {
|
||||
// don't set crossOrigin if the url is a data URL
|
||||
if (this.crossOriginKeyword && url.substr(0, 5 !== 'data:')) {
|
||||
img.crossOrigin = this.crossOriginKeyword;
|
||||
}
|
||||
img.src = url;
|
||||
}
|
||||
},
|
||||
@@ -366,6 +393,7 @@ OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, {
|
||||
img.style.opacity = this.layer.opacity;
|
||||
|
||||
this.isLoading = false;
|
||||
this.canvasContext = null;
|
||||
this.events.triggerEvent("loadend");
|
||||
|
||||
// IE<7 needs a reflow when the tiles are loaded because of the
|
||||
@@ -406,6 +434,38 @@ OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, {
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: getCanvasContext
|
||||
* Returns a canvas context associated with the tile image (with
|
||||
* the image drawn on it).
|
||||
* Returns undefined if the browser does not support canvas, if
|
||||
* the tile has no image or if it's currently loading.
|
||||
*
|
||||
* The function returns a canvas context instance but the
|
||||
* underlying canvas is still available in the 'canvas' property:
|
||||
* (code)
|
||||
* var context = tile.getCanvasContext();
|
||||
* if (context) {
|
||||
* var data = context.canvas.toDataURL('image/jpeg');
|
||||
* }
|
||||
* (end)
|
||||
*
|
||||
* Returns:
|
||||
* {Boolean}
|
||||
*/
|
||||
getCanvasContext: function() {
|
||||
if (OpenLayers.CANVAS_SUPPORTED && this.imgDiv && !this.isLoading) {
|
||||
if (!this.canvasContext) {
|
||||
var canvas = document.createElement("canvas");
|
||||
canvas.width = this.size.w;
|
||||
canvas.height = this.size.h;
|
||||
this.canvasContext = canvas.getContext("2d");
|
||||
this.canvasContext.drawImage(this.imgDiv, 0, 0);
|
||||
}
|
||||
return this.canvasContext;
|
||||
}
|
||||
},
|
||||
|
||||
CLASS_NAME: "OpenLayers.Tile.Image"
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user