Use ol.dom.createCanvasContext2D in ol.source.ImageStatic
This commit is contained in:
@@ -5,6 +5,7 @@ goog.require('ol.events.EventType');
|
|||||||
goog.require('ol.Image');
|
goog.require('ol.Image');
|
||||||
goog.require('ol.ImageLoadFunctionType');
|
goog.require('ol.ImageLoadFunctionType');
|
||||||
goog.require('ol.ImageState');
|
goog.require('ol.ImageState');
|
||||||
|
goog.require('ol.dom');
|
||||||
goog.require('ol.extent');
|
goog.require('ol.extent');
|
||||||
goog.require('ol.proj');
|
goog.require('ol.proj');
|
||||||
goog.require('ol.source.Image');
|
goog.require('ol.source.Image');
|
||||||
@@ -78,17 +79,16 @@ ol.source.ImageStatic.prototype.handleImageChange = function(evt) {
|
|||||||
imageWidth = this.imageSize_[0];
|
imageWidth = this.imageSize_[0];
|
||||||
imageHeight = this.imageSize_[1];
|
imageHeight = this.imageSize_[1];
|
||||||
} else {
|
} else {
|
||||||
imageWidth = image.width;
|
// TODO: remove the type cast when a closure-compiler > 20160315 is used.
|
||||||
imageHeight = image.height;
|
// see: https://github.com/google/closure-compiler/pull/1664
|
||||||
|
imageWidth = /** @type {number} */ (image.width);
|
||||||
|
imageHeight = /** @type {number} */ (image.height);
|
||||||
}
|
}
|
||||||
var resolution = ol.extent.getHeight(imageExtent) / imageHeight;
|
var resolution = ol.extent.getHeight(imageExtent) / imageHeight;
|
||||||
var targetWidth = Math.ceil(ol.extent.getWidth(imageExtent) / resolution);
|
var targetWidth = Math.ceil(ol.extent.getWidth(imageExtent) / resolution);
|
||||||
if (targetWidth != imageWidth) {
|
if (targetWidth != imageWidth) {
|
||||||
var canvas = /** @type {HTMLCanvasElement} */
|
var context = ol.dom.createCanvasContext2D(targetWidth, imageHeight);
|
||||||
(document.createElement('canvas'));
|
var canvas = context.canvas;
|
||||||
canvas.width = targetWidth;
|
|
||||||
canvas.height = /** @type {number} */ (imageHeight);
|
|
||||||
var context = canvas.getContext('2d');
|
|
||||||
context.drawImage(image, 0, 0, imageWidth, imageHeight,
|
context.drawImage(image, 0, 0, imageWidth, imageHeight,
|
||||||
0, 0, canvas.width, canvas.height);
|
0, 0, canvas.width, canvas.height);
|
||||||
this.image_.setImage(canvas);
|
this.image_.setImage(canvas);
|
||||||
|
|||||||
Reference in New Issue
Block a user