Handle urls and templates in ol.source.UrlTile
This makes url templates available for ol.source.VectorTile.
This commit is contained in:
@@ -3976,6 +3976,8 @@ olx.source.TileUTFGridOptions.prototype.url;
|
||||
* tileLoadFunction: (ol.TileLoadFunctionType|undefined),
|
||||
* tilePixelRatio: (number|undefined),
|
||||
* tileUrlFunction: (ol.TileUrlFunctionType|undefined),
|
||||
* url: (string|undefined),
|
||||
* urls: (Array.<string>|undefined),
|
||||
* wrapX: (boolean|undefined)}}
|
||||
* @api
|
||||
*/
|
||||
@@ -4088,6 +4090,24 @@ olx.source.TileImageOptions.prototype.tilePixelRatio;
|
||||
olx.source.TileImageOptions.prototype.tileUrlFunction;
|
||||
|
||||
|
||||
/**
|
||||
* URL template. Must include `{x}`, `{y}` or `{-y}`, and `{z}` placeholders.
|
||||
* A `{?-?}` template pattern, for example `subdomain{a-f}.domain.com`, may be
|
||||
* used instead of defining each one separately in the `urls` option.
|
||||
* @type {string|undefined}
|
||||
* @api stable
|
||||
*/
|
||||
olx.source.TileImageOptions.prototype.url;
|
||||
|
||||
|
||||
/**
|
||||
* An array of URL templates.
|
||||
* @type {Array.<string>|undefined}
|
||||
* @api
|
||||
*/
|
||||
olx.source.TileImageOptions.prototype.urls;
|
||||
|
||||
|
||||
/**
|
||||
* Whether to wrap the world horizontally. The default, `undefined`, is to
|
||||
* request out-of-bounds tiles from the server. When set to `false`, only one
|
||||
@@ -4101,11 +4121,11 @@ olx.source.TileImageOptions.prototype.wrapX;
|
||||
|
||||
/**
|
||||
* @typedef {{attributions: (Array.<ol.Attribution>|undefined),
|
||||
* format: (ol.format.Feature|undefined),
|
||||
* logo: (string|olx.LogoOptions|undefined),
|
||||
* opaque: (boolean|undefined),
|
||||
* projection: ol.proj.ProjectionLike,
|
||||
* state: (ol.source.State|string|undefined),
|
||||
* format: (ol.format.Feature|undefined),
|
||||
* tileClass: (function(new: ol.VectorTile, ol.TileCoord,
|
||||
* ol.TileState, string, ol.format.Feature,
|
||||
* ol.TileLoadFunctionType)|undefined),
|
||||
@@ -4113,6 +4133,8 @@ olx.source.TileImageOptions.prototype.wrapX;
|
||||
* tileLoadFunction: (ol.TileLoadFunctionType|undefined),
|
||||
* tilePixelRatio: (number|undefined),
|
||||
* tileUrlFunction: (ol.TileUrlFunctionType|undefined),
|
||||
* url: (string|undefined),
|
||||
* urls: (Array.<string>|undefined),
|
||||
* wrapX: (boolean|undefined)}}
|
||||
* @api
|
||||
*/
|
||||
@@ -4128,6 +4150,14 @@ olx.source.VectorTileOptions;
|
||||
olx.source.VectorTileOptions.prototype.attributions;
|
||||
|
||||
|
||||
/**
|
||||
* Feature format for tiles. Used and required by the default
|
||||
* `tileLoadFunction`.
|
||||
* @type {ol.format.Feature|undefined}
|
||||
*/
|
||||
olx.source.VectorTileOptions.prototype.format;
|
||||
|
||||
|
||||
/**
|
||||
* Logo.
|
||||
* @type {string|olx.LogoOptions|undefined}
|
||||
@@ -4160,14 +4190,6 @@ olx.source.VectorTileOptions.prototype.projection;
|
||||
olx.source.VectorTileOptions.prototype.state;
|
||||
|
||||
|
||||
/**
|
||||
* Feature format for tiles. Used and required by the default
|
||||
* `tileLoadFunction`.
|
||||
* @type {ol.format.Feature|undefined}
|
||||
*/
|
||||
olx.source.VectorTileOptions.prototype.format;
|
||||
|
||||
|
||||
/**
|
||||
* Class used to instantiate image tiles. Default is {@link ol.VectorTile}.
|
||||
* @type {function(new: ol.VectorTile, ol.TileCoord,
|
||||
@@ -4214,10 +4236,27 @@ olx.source.VectorTileOptions.prototype.tileUrlFunction;
|
||||
|
||||
|
||||
/**
|
||||
* Whether to wrap the world horizontally. The default, `undefined`, is to
|
||||
* request out-of-bounds tiles from the server. When set to `false`, only one
|
||||
* world will be rendered. When set to `true`, tiles will be requested for one
|
||||
* world only, but they will be wrapped horizontally to render multiple worlds.
|
||||
* URL template. Must include `{x}`, `{y}` or `{-y}`, and `{z}` placeholders.
|
||||
* A `{?-?}` template pattern, for example `subdomain{a-f}.domain.com`, may be
|
||||
* used instead of defining each one separately in the `urls` option.
|
||||
* @type {string|undefined}
|
||||
* @api stable
|
||||
*/
|
||||
olx.source.VectorTileOptions.prototype.url;
|
||||
|
||||
|
||||
/**
|
||||
* An array of URL templates.
|
||||
* @type {Array.<string>|undefined}
|
||||
* @api
|
||||
*/
|
||||
olx.source.VectorTileOptions.prototype.urls;
|
||||
|
||||
|
||||
/**
|
||||
* Whether to wrap the world horizontally. When set to `false`, only one world
|
||||
* will be rendered. When set to `true`, tiles will be wrapped horizontally to
|
||||
* render multiple worlds. Default is `true`.
|
||||
* @type {boolean|undefined}
|
||||
* @api
|
||||
*/
|
||||
|
||||
@@ -7,7 +7,6 @@ goog.require('goog.string');
|
||||
goog.require('goog.uri.utils');
|
||||
goog.require('ol');
|
||||
goog.require('ol.TileCoord');
|
||||
goog.require('ol.TileUrlFunction');
|
||||
goog.require('ol.extent');
|
||||
goog.require('ol.proj');
|
||||
goog.require('ol.size');
|
||||
@@ -45,20 +44,11 @@ ol.source.TileArcGISRest = function(opt_options) {
|
||||
tileGrid: options.tileGrid,
|
||||
tileLoadFunction: options.tileLoadFunction,
|
||||
tileUrlFunction: goog.bind(this.tileUrlFunction_, this),
|
||||
url: options.url,
|
||||
urls: options.urls,
|
||||
wrapX: options.wrapX !== undefined ? options.wrapX : true
|
||||
});
|
||||
|
||||
var urls = options.urls;
|
||||
if (urls === undefined && options.url !== undefined) {
|
||||
urls = ol.TileUrlFunction.expandUrl(options.url);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {!Array.<string>}
|
||||
*/
|
||||
this.urls_ = urls || [];
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Object}
|
||||
@@ -100,7 +90,7 @@ ol.source.TileArcGISRest.prototype.getRequestUrl_ =
|
||||
function(tileCoord, tileSize, tileExtent,
|
||||
pixelRatio, projection, params) {
|
||||
|
||||
var urls = this.urls_;
|
||||
var urls = this.urls;
|
||||
if (urls.length === 0) {
|
||||
return undefined;
|
||||
}
|
||||
@@ -158,38 +148,6 @@ ol.source.TileArcGISRest.prototype.getTilePixelSize =
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return the URLs used for this ArcGIS source.
|
||||
* @return {!Array.<string>} URLs.
|
||||
* @api stable
|
||||
*/
|
||||
ol.source.TileArcGISRest.prototype.getUrls = function() {
|
||||
return this.urls_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the URL to use for requests.
|
||||
* @param {string|undefined} url URL.
|
||||
* @api stable
|
||||
*/
|
||||
ol.source.TileArcGISRest.prototype.setUrl = function(url) {
|
||||
var urls = url !== undefined ? ol.TileUrlFunction.expandUrl(url) : null;
|
||||
this.setUrls(urls);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the URLs to use for requests.
|
||||
* @param {Array.<string>|undefined} urls URLs.
|
||||
* @api stable
|
||||
*/
|
||||
ol.source.TileArcGISRest.prototype.setUrls = function(urls) {
|
||||
this.urls_ = urls || [];
|
||||
this.changed();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.TileCoord} tileCoord Tile coordinate.
|
||||
* @param {number} pixelRatio Pixel ratio.
|
||||
|
||||
@@ -38,6 +38,8 @@ ol.source.TileImage = function(options) {
|
||||
options.tileLoadFunction : ol.source.TileImage.defaultTileLoadFunction,
|
||||
tilePixelRatio: options.tilePixelRatio,
|
||||
tileUrlFunction: options.tileUrlFunction,
|
||||
url: options.url,
|
||||
urls: options.urls,
|
||||
wrapX: options.wrapX
|
||||
});
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ goog.require('goog.string');
|
||||
goog.require('goog.uri.utils');
|
||||
goog.require('ol');
|
||||
goog.require('ol.TileCoord');
|
||||
goog.require('ol.TileUrlFunction');
|
||||
goog.require('ol.extent');
|
||||
goog.require('ol.proj');
|
||||
goog.require('ol.size');
|
||||
@@ -49,20 +48,11 @@ ol.source.TileWMS = function(opt_options) {
|
||||
tileGrid: options.tileGrid,
|
||||
tileLoadFunction: options.tileLoadFunction,
|
||||
tileUrlFunction: goog.bind(this.tileUrlFunction_, this),
|
||||
url: options.url,
|
||||
urls: options.urls,
|
||||
wrapX: options.wrapX !== undefined ? options.wrapX : true
|
||||
});
|
||||
|
||||
var urls = options.urls;
|
||||
if (urls === undefined && options.url !== undefined) {
|
||||
urls = ol.TileUrlFunction.expandUrl(options.url);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {!Array.<string>}
|
||||
*/
|
||||
this.urls_ = urls || [];
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
@@ -221,7 +211,7 @@ ol.source.TileWMS.prototype.getRequestUrl_ =
|
||||
function(tileCoord, tileSize, tileExtent,
|
||||
pixelRatio, projection, params) {
|
||||
|
||||
var urls = this.urls_;
|
||||
var urls = this.urls;
|
||||
if (urls.length === 0) {
|
||||
return undefined;
|
||||
}
|
||||
@@ -301,16 +291,6 @@ ol.source.TileWMS.prototype.getTilePixelSize =
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return the URLs used for this WMS source.
|
||||
* @return {!Array.<string>} URLs.
|
||||
* @api stable
|
||||
*/
|
||||
ol.source.TileWMS.prototype.getUrls = function() {
|
||||
return this.urls_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
@@ -319,8 +299,8 @@ ol.source.TileWMS.prototype.resetCoordKeyPrefix_ = function() {
|
||||
var res = [];
|
||||
|
||||
var j, jj;
|
||||
for (j = 0, jj = this.urls_.length; j < jj; ++j) {
|
||||
res[i++] = this.urls_[j];
|
||||
for (j = 0, jj = this.urls.length; j < jj; ++j) {
|
||||
res[i++] = this.urls[j];
|
||||
}
|
||||
|
||||
var key;
|
||||
@@ -332,29 +312,6 @@ ol.source.TileWMS.prototype.resetCoordKeyPrefix_ = function() {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the URL to use for requests.
|
||||
* @param {string|undefined} url URL.
|
||||
* @api stable
|
||||
*/
|
||||
ol.source.TileWMS.prototype.setUrl = function(url) {
|
||||
var urls = url !== undefined ? ol.TileUrlFunction.expandUrl(url) : null;
|
||||
this.setUrls(urls);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the URLs to use for requests.
|
||||
* @param {Array.<string>|undefined} urls URLs.
|
||||
* @api stable
|
||||
*/
|
||||
ol.source.TileWMS.prototype.setUrls = function(urls) {
|
||||
this.urls_ = urls || [];
|
||||
this.resetCoordKeyPrefix_();
|
||||
this.changed();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.TileCoord} tileCoord Tile coordinate.
|
||||
* @param {number} pixelRatio Pixel ratio.
|
||||
|
||||
@@ -5,6 +5,7 @@ goog.require('ol.TileLoadFunctionType');
|
||||
goog.require('ol.TileState');
|
||||
goog.require('ol.TileUrlFunction');
|
||||
goog.require('ol.TileUrlFunctionType');
|
||||
goog.require('ol.proj');
|
||||
goog.require('ol.source.Tile');
|
||||
goog.require('ol.source.TileEvent');
|
||||
|
||||
@@ -20,6 +21,8 @@ goog.require('ol.source.TileEvent');
|
||||
* tileLoadFunction: ol.TileLoadFunctionType,
|
||||
* tilePixelRatio: (number|undefined),
|
||||
* tileUrlFunction: (ol.TileUrlFunctionType|undefined),
|
||||
* url: (string|undefined),
|
||||
* urls: (Array.<string>|undefined),
|
||||
* wrapX: (boolean|undefined)}}
|
||||
*/
|
||||
ol.source.UrlTileOptions;
|
||||
@@ -51,19 +54,38 @@ ol.source.UrlTile = function(options) {
|
||||
wrapX: options.wrapX
|
||||
});
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {ol.TileLoadFunctionType}
|
||||
*/
|
||||
this.tileLoadFunction = options.tileLoadFunction;
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {ol.TileUrlFunctionType}
|
||||
*/
|
||||
this.tileUrlFunction = goog.isDef(options.tileUrlFunction) ?
|
||||
this.tileUrlFunction = options.tileUrlFunction ?
|
||||
options.tileUrlFunction :
|
||||
ol.TileUrlFunction.nullTileUrlFunction;
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {ol.TileLoadFunctionType}
|
||||
* @type {!Array.<string>|null}
|
||||
*/
|
||||
this.tileLoadFunction = options.tileLoadFunction;
|
||||
this.urls = null;
|
||||
|
||||
if (options.urls) {
|
||||
if (options.tileUrlFunction) {
|
||||
this.urls = options.urls;
|
||||
} else {
|
||||
this.setUrls(options.urls);
|
||||
}
|
||||
} else if (options.url) {
|
||||
this.setUrl(options.url);
|
||||
}
|
||||
if (options.tileUrlFunction) {
|
||||
this.setTileUrlFunction(options.tileUrlFunction);
|
||||
}
|
||||
|
||||
};
|
||||
goog.inherits(ol.source.UrlTile, ol.source.Tile);
|
||||
@@ -89,6 +111,18 @@ ol.source.UrlTile.prototype.getTileUrlFunction = function() {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return the URLs used for this XYZ source.
|
||||
* When a tileUrlFunction is used instead of url or urls,
|
||||
* null will be returned.
|
||||
* @return {!Array.<string>|null} URLs.
|
||||
* @api
|
||||
*/
|
||||
ol.source.UrlTile.prototype.getUrls = function() {
|
||||
return this.urls;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Handle tile change events.
|
||||
* @param {goog.events.Event} event Event.
|
||||
@@ -140,6 +174,30 @@ ol.source.UrlTile.prototype.setTileUrlFunction = function(tileUrlFunction) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the URL to use for requests.
|
||||
* @param {string} url URL.
|
||||
* @api stable
|
||||
*/
|
||||
ol.source.UrlTile.prototype.setUrl = function(url) {
|
||||
this.setTileUrlFunction(ol.TileUrlFunction.createFromTemplates(
|
||||
ol.TileUrlFunction.expandUrl(url), this.tileGrid));
|
||||
this.urls = [url];
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the URLs to use for requests.
|
||||
* @param {Array.<string>} urls URLs.
|
||||
* @api stable
|
||||
*/
|
||||
ol.source.UrlTile.prototype.setUrls = function(urls) {
|
||||
this.setTileUrlFunction(ol.TileUrlFunction.createFromTemplates(
|
||||
urls, this.tileGrid));
|
||||
this.urls = urls;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
|
||||
@@ -42,6 +42,8 @@ ol.source.VectorTile = function(options) {
|
||||
options.tileLoadFunction : ol.source.VectorTile.defaultTileLoadFunction,
|
||||
tileUrlFunction: options.tileUrlFunction,
|
||||
tilePixelRatio: options.tilePixelRatio,
|
||||
url: options.url,
|
||||
urls: options.urls,
|
||||
wrapX: options.wrapX === undefined ? true : options.wrapX
|
||||
});
|
||||
|
||||
|
||||
@@ -87,12 +87,6 @@ ol.source.WMTS = function(options) {
|
||||
urls = ol.TileUrlFunction.expandUrl(options.url);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {!Array.<string>}
|
||||
*/
|
||||
this.urls_ = urls || [];
|
||||
|
||||
// FIXME: should we guess this requestEncoding from options.url(s)
|
||||
// structure? that would mean KVP only if a template is not provided.
|
||||
|
||||
@@ -175,9 +169,9 @@ ol.source.WMTS = function(options) {
|
||||
});
|
||||
}
|
||||
|
||||
var tileUrlFunction = this.urls_.length > 0 ?
|
||||
var tileUrlFunction = (urls && urls.length > 0) ?
|
||||
ol.TileUrlFunction.createFromTileUrlFunctions(
|
||||
this.urls_.map(createFromWMTSTemplate)) :
|
||||
urls.map(createFromWMTSTemplate)) :
|
||||
ol.TileUrlFunction.nullTileUrlFunction;
|
||||
|
||||
goog.base(this, {
|
||||
@@ -191,6 +185,7 @@ ol.source.WMTS = function(options) {
|
||||
tileLoadFunction: options.tileLoadFunction,
|
||||
tilePixelRatio: options.tilePixelRatio,
|
||||
tileUrlFunction: tileUrlFunction,
|
||||
urls: urls,
|
||||
wrapX: options.wrapX !== undefined ? options.wrapX : false
|
||||
});
|
||||
|
||||
@@ -268,16 +263,6 @@ ol.source.WMTS.prototype.getStyle = function() {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return the URLs used for this WMTS source.
|
||||
* @return {!Array.<string>} URLs.
|
||||
* @api
|
||||
*/
|
||||
ol.source.WMTS.prototype.getUrls = function() {
|
||||
return this.urls_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return the version of the WMTS source.
|
||||
* @return {string} Version.
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
goog.provide('ol.source.XYZ');
|
||||
|
||||
goog.require('ol.TileUrlFunction');
|
||||
goog.require('ol.source.TileImage');
|
||||
|
||||
|
||||
@@ -38,12 +37,6 @@ ol.source.XYZ = function(options) {
|
||||
tileSize: options.tileSize
|
||||
});
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {!Array.<string>|null}
|
||||
*/
|
||||
this.urls_ = null;
|
||||
|
||||
goog.base(this, {
|
||||
attributions: options.attributions,
|
||||
crossOrigin: options.crossOrigin,
|
||||
@@ -53,52 +46,11 @@ ol.source.XYZ = function(options) {
|
||||
tileGrid: tileGrid,
|
||||
tileLoadFunction: options.tileLoadFunction,
|
||||
tilePixelRatio: options.tilePixelRatio,
|
||||
tileUrlFunction: ol.TileUrlFunction.nullTileUrlFunction,
|
||||
tileUrlFunction: options.tileUrlFunction,
|
||||
url: options.url,
|
||||
urls: options.urls,
|
||||
wrapX: options.wrapX !== undefined ? options.wrapX : true
|
||||
});
|
||||
|
||||
if (options.tileUrlFunction !== undefined) {
|
||||
this.setTileUrlFunction(options.tileUrlFunction);
|
||||
} else if (options.urls !== undefined) {
|
||||
this.setUrls(options.urls);
|
||||
} else if (options.url !== undefined) {
|
||||
this.setUrl(options.url);
|
||||
}
|
||||
|
||||
};
|
||||
goog.inherits(ol.source.XYZ, ol.source.TileImage);
|
||||
|
||||
|
||||
/**
|
||||
* Return the URLs used for this XYZ source.
|
||||
* When a tileUrlFunction is used instead of url or urls,
|
||||
* null will be returned.
|
||||
* @return {!Array.<string>|null} URLs.
|
||||
* @api
|
||||
*/
|
||||
ol.source.XYZ.prototype.getUrls = function() {
|
||||
return this.urls_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the URL to use for requests.
|
||||
* @param {string} url URL.
|
||||
* @api stable
|
||||
*/
|
||||
ol.source.XYZ.prototype.setUrl = function(url) {
|
||||
this.setTileUrlFunction(ol.TileUrlFunction.createFromTemplates(
|
||||
ol.TileUrlFunction.expandUrl(url), this.tileGrid));
|
||||
this.urls_ = [url];
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the URLs to use for requests.
|
||||
* @param {Array.<string>} urls URLs.
|
||||
*/
|
||||
ol.source.XYZ.prototype.setUrls = function(urls) {
|
||||
this.setTileUrlFunction(
|
||||
ol.TileUrlFunction.createFromTemplates(urls, this.tileGrid));
|
||||
this.urls_ = urls;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user