Most of our uses of source extent were cargo cult programming. The source extent was seldom and inconsistently used. Instead, layers can now be configured with an extent, and layer renderers limit rendering (and data requests) to the layer extent. For vector sources, the `getExtent` method returns the extent of currently loaded features (this was the case before and after this change). For tile based sources, we will likely want to allow easy construction of tile grids based on an extent (this is not possible before or after this change, but could be added later).
88 lines
2.0 KiB
JavaScript
88 lines
2.0 KiB
JavaScript
goog.provide('ol.source.XYZ');
|
|
|
|
goog.require('ol.Attribution');
|
|
goog.require('ol.TileUrlFunction');
|
|
goog.require('ol.source.TileImage');
|
|
goog.require('ol.tilegrid.XYZ');
|
|
|
|
|
|
|
|
/**
|
|
* @classdesc
|
|
* Layer source for tile data with URLs in a set XYZ format.
|
|
*
|
|
* @constructor
|
|
* @extends {ol.source.TileImage}
|
|
* @param {olx.source.XYZOptions} options XYZ options.
|
|
* @api
|
|
*/
|
|
ol.source.XYZ = function(options) {
|
|
|
|
var projection = goog.isDef(options.projection) ?
|
|
options.projection : 'EPSG:3857';
|
|
|
|
var maxZoom = goog.isDef(options.maxZoom) ? options.maxZoom : 18;
|
|
|
|
var tileGrid = new ol.tilegrid.XYZ({
|
|
maxZoom: maxZoom
|
|
});
|
|
|
|
goog.base(this, {
|
|
attributions: options.attributions,
|
|
crossOrigin: options.crossOrigin,
|
|
logo: options.logo,
|
|
projection: projection,
|
|
tileGrid: tileGrid,
|
|
tileLoadFunction: options.tileLoadFunction,
|
|
tilePixelRatio: options.tilePixelRatio,
|
|
tileUrlFunction: ol.TileUrlFunction.nullTileUrlFunction
|
|
});
|
|
|
|
/**
|
|
* @private
|
|
* @type {ol.TileCoordTransformType}
|
|
*/
|
|
this.tileCoordTransform_ = tileGrid.createTileCoordTransform({
|
|
wrapX: options.wrapX
|
|
});
|
|
|
|
if (goog.isDef(options.tileUrlFunction)) {
|
|
this.setTileUrlFunction(options.tileUrlFunction);
|
|
} else if (goog.isDef(options.urls)) {
|
|
this.setUrls(options.urls);
|
|
} else if (goog.isDef(options.url)) {
|
|
this.setUrl(options.url);
|
|
}
|
|
|
|
};
|
|
goog.inherits(ol.source.XYZ, ol.source.TileImage);
|
|
|
|
|
|
/**
|
|
* @inheritDoc
|
|
* @api
|
|
*/
|
|
ol.source.XYZ.prototype.setTileUrlFunction = function(tileUrlFunction) {
|
|
goog.base(this, 'setTileUrlFunction',
|
|
ol.TileUrlFunction.withTileCoordTransform(
|
|
this.tileCoordTransform_, tileUrlFunction));
|
|
};
|
|
|
|
|
|
/**
|
|
* @param {string} url URL.
|
|
* @api
|
|
*/
|
|
ol.source.XYZ.prototype.setUrl = function(url) {
|
|
this.setTileUrlFunction(ol.TileUrlFunction.createFromTemplates(
|
|
ol.TileUrlFunction.expandUrl(url)));
|
|
};
|
|
|
|
|
|
/**
|
|
* @param {Array.<string>} urls URLs.
|
|
*/
|
|
ol.source.XYZ.prototype.setUrls = function(urls) {
|
|
this.setTileUrlFunction(ol.TileUrlFunction.createFromTemplates(urls));
|
|
};
|