Merge branch 'master' of github.com:openlayers/ol3 into vector

This commit is contained in:
Tim Schaub
2013-02-18 10:11:00 -07:00
39 changed files with 2739 additions and 79 deletions

View File

@@ -0,0 +1,113 @@
goog.provide('ol.source.ImageSource');
goog.require('goog.array');
goog.require('ol.Attribution');
goog.require('ol.Extent');
goog.require('ol.Image');
goog.require('ol.ImageUrlFunction');
goog.require('ol.ImageUrlFunctionType');
goog.require('ol.Projection');
goog.require('ol.Size');
goog.require('ol.array');
goog.require('ol.source.Source');
/**
* @typedef {{attributions: (Array.<ol.Attribution>|undefined),
* crossOrigin: (null|string|undefined),
* extent: (null|ol.Extent|undefined),
* projection: (ol.Projection|undefined),
* resolutions: (Array.<number>|undefined),
* imageUrlFunction: (ol.ImageUrlFunctionType|
* undefined)}}
*/
ol.source.ImageSourceOptions;
/**
* @constructor
* @extends {ol.source.Source}
* @param {ol.source.ImageSourceOptions} options Single
* image source options.
*/
ol.source.ImageSource = function(options) {
goog.base(this, {
attributions: options.attributions,
extent: options.extent,
projection: options.projection
});
/**
* @protected
* @type {ol.ImageUrlFunctionType}
*/
this.imageUrlFunction =
goog.isDef(options.imageUrlFunction) ?
options.imageUrlFunction :
ol.ImageUrlFunction.nullImageUrlFunction;
/**
* @private
* @type {?string}
*/
this.crossOrigin_ =
goog.isDef(options.crossOrigin) ? options.crossOrigin : 'anonymous';
/**
* @private
* @type {Array.<number>}
*/
this.resolutions_ = goog.isDef(options.resolutions) ?
options.resolutions : null;
goog.asserts.assert(goog.isNull(this.resolutions_) ||
goog.array.isSorted(this.resolutions_,
function(a, b) {
return b - a;
}, true));
};
goog.inherits(ol.source.ImageSource, ol.source.Source);
/**
* @protected
* @param {ol.Extent} extent Extent.
* @param {number} resolution Resolution.
* @param {ol.Size} size Size.
* @return {ol.Image} Single image.
*/
ol.source.ImageSource.prototype.createImage =
function(extent, resolution, size) {
var image = null;
var imageUrl = this.imageUrlFunction(extent, size);
if (goog.isDef(imageUrl)) {
image = new ol.Image(
extent, resolution, imageUrl, this.crossOrigin_);
}
return image;
};
/**
* @protected
* @param {number} resolution Resolution.
* @return {number} Resolution.
*/
ol.source.ImageSource.prototype.findNearestResolution =
function(resolution) {
if (!goog.isNull(this.resolutions_)) {
var idx = ol.array.linearFindNearest(this.resolutions_, resolution);
resolution = this.resolutions_[idx];
}
return resolution;
};
/**
* @param {ol.Extent} extent Extent.
* @param {number} resolution Resolution.
* @return {ol.Image} Single image.
*/
ol.source.ImageSource.prototype.getImage = goog.abstractMethod;

View File

@@ -0,0 +1 @@
@exportSymbol ol.source.SingleImageWMS

View File

@@ -0,0 +1,99 @@
goog.provide('ol.source.SingleImageWMS');
goog.require('ol.Extent');
goog.require('ol.Image');
goog.require('ol.ImageUrlFunction');
goog.require('ol.Projection');
goog.require('ol.Size');
goog.require('ol.source.ImageSource');
/**
* @constructor
* @extends {ol.source.ImageSource}
* @param {ol.source.SingleImageWMSOptions} options Options.
*/
ol.source.SingleImageWMS = function(options) {
var projection = ol.Projection.createProjection(
options.projection, 'EPSG:3857');
var projectionExtent = projection.getExtent();
var extent = goog.isDef(options.extent) ?
options.extent : projectionExtent;
var version = goog.isDef(options.version) ?
options.version : '1.3';
var baseParams = {
'SERVICE': 'WMS',
'VERSION': version,
'REQUEST': 'GetMap',
'STYLES': '',
'FORMAT': 'image/png',
'TRANSPARENT': true
};
baseParams[version >= '1.3' ? 'CRS' : 'SRS'] = projection.getCode();
goog.object.extend(baseParams, options.params);
var imageUrlFunction;
if (options.url) {
var url = goog.uri.utils.appendParamsFromMap(
options.url, baseParams);
imageUrlFunction = ol.ImageUrlFunction.createBboxParam(url);
} else {
imageUrlFunction =
ol.ImageUrlFunction.nullImageUrlFunction;
}
goog.base(this, {
attributions: options.attributions,
crossOrigin: options.crossOrigin,
extent: extent,
projection: projection,
resolutions: options.resolutions,
imageUrlFunction: imageUrlFunction
});
/**
* @private
* @type {ol.Image}
*/
this.image_ = null;
/**
* FIXME configurable?
* @private
* @type {number}
*/
this.ratio_ = 1.5;
};
goog.inherits(ol.source.SingleImageWMS, ol.source.ImageSource);
/**
* @inheritDoc
*/
ol.source.SingleImageWMS.prototype.getImage =
function(extent, resolution) {
resolution = this.findNearestResolution(resolution);
var image = this.image_;
if (!goog.isNull(image) &&
image.getResolution() == resolution &&
image.getExtent().containsExtent(extent)) {
return image;
}
extent = new ol.Extent(extent.minX, extent.minY,
extent.maxX, extent.maxY);
extent.scaleFromCenter(this.ratio_);
var width = extent.getWidth() / resolution;
var height = extent.getHeight() / resolution;
var size = new ol.Size(width, height);
this.image_ = this.createImage(extent, resolution, size);
return this.image_;
};

View File

@@ -0,0 +1 @@
@exportSymbol ol.source.StaticImage

View File

@@ -0,0 +1,61 @@
goog.provide('ol.source.StaticImage');
goog.require('ol.Image');
goog.require('ol.ImageUrlFunctionType');
goog.require('ol.source.ImageSource');
/**
* @constructor
* @extends {ol.source.ImageSource}
* @param {ol.source.StaticImageOptions} options Options.
*/
ol.source.StaticImage = function(options) {
var imageFunction = ol.source.StaticImage.createImageFunction(
options.url);
var imageExtent = options.imageExtent;
var imageSize = options.imageSize;
var imageResolution = imageExtent.getHeight() / imageSize.height;
goog.base(this, {
attributions: options.attributions,
crossOrigin: options.crossOrigin,
extent: options.extent,
projection: options.projection,
imageUrlFunction: imageFunction,
resolutions: [imageResolution]
});
/**
* @private
* @type {ol.Image}
*/
this.image_ = this.createImage(imageExtent, imageResolution, imageSize);
};
goog.inherits(ol.source.StaticImage, ol.source.ImageSource);
/**
* @inheritDoc
*/
ol.source.StaticImage.prototype.getImage = function(extent, resolution) {
if (extent.intersects(this.image_.getExtent())) {
return this.image_;
}
return null;
};
/**
* @param {string|undefined} url URL.
* @return {ol.ImageUrlFunctionType} Function.
*/
ol.source.StaticImage.createImageFunction = function(url) {
return function(extent, size) {
return url;
};
};