Image source refactoring

This commit is contained in:
Éric Lemoine
2013-09-22 09:58:05 +01:00
parent 0cc844a169
commit 5af738593e
14 changed files with 343 additions and 190 deletions

View File

@@ -2,6 +2,7 @@ goog.provide('ol.source.MapGuide');
goog.require('goog.object');
goog.require('goog.uri.utils');
goog.require('ol.Image');
goog.require('ol.ImageUrlFunction');
goog.require('ol.extent');
goog.require('ol.source.Image');
@@ -15,6 +16,26 @@ goog.require('ol.source.Image');
*/
ol.source.MapGuide = function(options) {
goog.base(this, {
extent: options.extent,
projection: options.projection,
resolutions: options.resolutions
});
/**
* @private
* @type {?string}
*/
this.crossOrigin_ =
goog.isDef(options.crossOrigin) ? options.crossOrigin : null;
/**
* @private
* @type {number}
*/
this.displayDpi_ = goog.isDef(options.displayDpi) ?
options.displayDpi : 96;
var imageUrlFunction;
if (goog.isDef(options.url)) {
var params = goog.isDef(options.params) ? options.params : {};
@@ -24,12 +45,11 @@ ol.source.MapGuide = function(options) {
imageUrlFunction = ol.ImageUrlFunction.nullImageUrlFunction;
}
goog.base(this, {
extent: options.extent,
projection: options.projection,
resolutions: options.resolutions,
imageUrlFunction: imageUrlFunction
});
/**
* @private
* @type {ol.ImageUrlFunctionType}
*/
this.imageUrlFunction_ = imageUrlFunction;
/**
* @private
@@ -37,13 +57,6 @@ ol.source.MapGuide = function(options) {
*/
this.hidpi_ = goog.isDef(options.hidpi) ? options.hidpi : true;
/**
* @private
* @type {number}
*/
this.displayDpi_ = goog.isDef(options.displayDpi) ?
options.displayDpi : 96;
/**
* @private
* @type {number}
@@ -98,9 +111,16 @@ ol.source.MapGuide.prototype.getImage =
var height = (extent[3] - extent[1]) / resolution;
var size = [width * pixelRatio, height * pixelRatio];
this.image_ = this.createImage(
extent, resolution, pixelRatio, size, projection);
return this.image_;
var imageUrl = this.imageUrlFunction_(extent, size, projection);
if (goog.isDef(imageUrl)) {
image = new ol.Image(extent, resolution, pixelRatio,
this.getAttributions(), imageUrl, this.crossOrigin_);
} else {
image = null;
}
this.image_ = image;
return image;
};