More context for url functions
With this change, url functions are called in the scope of the source they are configured for. This allows us to simplify the url function generation for WMS, using a more generic createFromParamsFunction factory, and the source's new params member. Note that there is also a new url member for WMS sources. This is the WMS base url (the first one in case there is an array of urls for faster tile access). This can be used for accessing other WMS services (especially GetFeatureInfo).
This commit is contained in:
@@ -82,7 +82,7 @@ goog.inherits(ol.source.ImageSource, ol.source.Source);
|
||||
ol.source.ImageSource.prototype.createImage =
|
||||
function(extent, resolution, size, projection) {
|
||||
var image = null;
|
||||
var imageUrl = this.imageUrlFunction(extent, size, projection);
|
||||
var imageUrl = this.imageUrlFunction.call(this, extent, size, projection);
|
||||
if (goog.isDef(imageUrl)) {
|
||||
image = new ol.Image(
|
||||
extent, resolution, imageUrl, this.crossOrigin_,
|
||||
|
||||
@@ -94,7 +94,8 @@ ol.source.ImageTileSource.prototype.getTile =
|
||||
} else {
|
||||
goog.asserts.assert(tileGrid);
|
||||
goog.asserts.assert(projection);
|
||||
var tileUrl = this.tileUrlFunction(tileCoord, tileGrid, projection);
|
||||
var tileUrl = this.tileUrlFunction.call(this,
|
||||
tileCoord, tileGrid, projection);
|
||||
var tile = new ol.ImageTile(
|
||||
tileCoord,
|
||||
goog.isDef(tileUrl) ? ol.TileState.IDLE : ol.TileState.EMPTY,
|
||||
|
||||
@@ -5,17 +5,20 @@ goog.require('ol.Image');
|
||||
goog.require('ol.ImageUrlFunction');
|
||||
goog.require('ol.Size');
|
||||
goog.require('ol.source.ImageSource');
|
||||
goog.require('ol.source.wms');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {ol.source.IWMS}
|
||||
* @extends {ol.source.ImageSource}
|
||||
* @param {ol.source.SingleImageWMSOptions} options Options.
|
||||
*/
|
||||
ol.source.SingleImageWMS = function(options) {
|
||||
var imageUrlFunction = goog.isDef(options.url) ?
|
||||
ol.ImageUrlFunction.createWMSParams(options.url, options.params) :
|
||||
ol.ImageUrlFunction.createFromParamsFunction(
|
||||
options.url, ol.source.wms.getUrl) :
|
||||
ol.ImageUrlFunction.nullImageUrlFunction;
|
||||
|
||||
goog.base(this, {
|
||||
@@ -27,6 +30,16 @@ ol.source.SingleImageWMS = function(options) {
|
||||
imageUrlFunction: imageUrlFunction
|
||||
});
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
this.url = options.url;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
this.params = options.params;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.Image}
|
||||
|
||||
@@ -8,11 +8,13 @@ goog.require('ol.Extent');
|
||||
goog.require('ol.TileCoord');
|
||||
goog.require('ol.TileUrlFunction');
|
||||
goog.require('ol.source.ImageTileSource');
|
||||
goog.require('ol.source.wms');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {ol.source.IWMS}
|
||||
* @extends {ol.source.ImageTileSource}
|
||||
* @param {ol.source.TiledWMSOptions} tiledWMSOptions options.
|
||||
*/
|
||||
@@ -30,12 +32,13 @@ ol.source.TiledWMS = function(tiledWMSOptions) {
|
||||
if (goog.isDef(urls)) {
|
||||
var tileUrlFunctions = goog.array.map(
|
||||
urls, function(url) {
|
||||
return ol.TileUrlFunction.createWMSParams(
|
||||
url, tiledWMSOptions.params);
|
||||
return ol.TileUrlFunction.createFromParamsFunction(
|
||||
url, ol.source.wms.getUrl);
|
||||
});
|
||||
tileUrlFunction = ol.TileUrlFunction.createFromTileUrlFunctions(
|
||||
tileUrlFunctions);
|
||||
}
|
||||
|
||||
var transparent = goog.isDef(tiledWMSOptions.params['TRANSPARENT']) ?
|
||||
tiledWMSOptions.params['TRANSPARENT'] : true;
|
||||
var extent = tiledWMSOptions.extent;
|
||||
@@ -65,6 +68,16 @@ ol.source.TiledWMS = function(tiledWMSOptions) {
|
||||
return new ol.TileCoord(tileCoord.z, x, tileCoord.y);
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
this.url = goog.isDef(urls) ? urls[0] : undefined;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
this.params = tiledWMSOptions.params;
|
||||
|
||||
goog.base(this, {
|
||||
attributions: tiledWMSOptions.attributions,
|
||||
crossOrigin: tiledWMSOptions.crossOrigin,
|
||||
|
||||
@@ -1,6 +1,29 @@
|
||||
goog.provide('ol.source.IWMS');
|
||||
goog.provide('ol.source.wms');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Interface for WMS
|
||||
* @interface
|
||||
*/
|
||||
ol.source.IWMS = function() {};
|
||||
|
||||
|
||||
/**
|
||||
* @type {string|undefined} The url for this source.
|
||||
*/
|
||||
ol.source.IWMS.prototype.url;
|
||||
|
||||
|
||||
/**
|
||||
* @type {Object.<string,*>} Parameters for WMS requests. 'LAYERS' is mandatory.
|
||||
* 'STYLES' defaults to ''. 'VERSION' defaults to '1.3.0'. 'CRS'/'SRS',
|
||||
* 'BBOX' and 'SIZE' are added dynamically.
|
||||
*/
|
||||
ol.source.IWMS.prototype.params;
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} baseUrl WMS base url.
|
||||
* @param {Object.<string, string|number>} params Request parameters.
|
||||
|
||||
Reference in New Issue
Block a user