[ol.layer.TileLayer] move getData from layer.XYZ to layer.TileLayer
This commit is contained in:
@@ -10,6 +10,12 @@ goog.require('ol.TileCache');
|
||||
*/
|
||||
ol.layer.TileLayer = function() {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {string|undefined}
|
||||
*/
|
||||
this.url_ = undefined;
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {ol.Projection}
|
||||
@@ -161,6 +167,14 @@ ol.layer.TileLayer.prototype.getResolutions = function() {
|
||||
return this.resolutions_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the layer URL.
|
||||
* @param {string} url
|
||||
*/
|
||||
ol.layer.TileLayer.prototype.setUrl = function(url) {
|
||||
this.url_ = url;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set layer projection.
|
||||
* @param {ol.Projection} projection
|
||||
@@ -233,3 +247,84 @@ ol.layer.TileLayer.prototype.getTile = function(url, bounds) {
|
||||
}
|
||||
return tile;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get data from the layer. This is the layer's main API function.
|
||||
* @param {ol.Bounds} bounds
|
||||
* @param {number} resolution
|
||||
*/
|
||||
ol.layer.TileLayer.prototype.getData = function(bounds, resolution) {
|
||||
var me = this,
|
||||
zoomAndRes = me.getZoomAndRes(resolution),
|
||||
zoom = zoomAndRes[0];
|
||||
resolution = zoomAndRes[1];
|
||||
|
||||
// define some values used for the actual tiling
|
||||
var boundsMinX = bounds.getMinX(),
|
||||
boundsMaxX = bounds.getMaxX(),
|
||||
boundsMinY = bounds.getMinY(),
|
||||
boundsMaxY = bounds.getMaxY(),
|
||||
|
||||
tileWidth = me.tileWidth_,
|
||||
tileHeight = me.tileHeight_,
|
||||
|
||||
tileOrigin = me.getTileOrigin(),
|
||||
tileOriginX = tileOrigin[0],
|
||||
tileOriginY = tileOrigin[1],
|
||||
|
||||
tileWidthGeo = tileWidth * resolution,
|
||||
tileHeightGeo = tileHeight * resolution,
|
||||
|
||||
offsetX = Math.floor(
|
||||
(boundsMinX - tileOriginX) / tileWidthGeo),
|
||||
offsetY = Math.floor(
|
||||
(tileOriginY - boundsMaxY) / tileHeightGeo),
|
||||
|
||||
gridLeft = tileOriginX + tileWidthGeo * offsetX,
|
||||
gridTop = tileOriginY - tileHeightGeo * offsetY;
|
||||
|
||||
// now tile
|
||||
var tiles = [],
|
||||
tile,
|
||||
url,
|
||||
tileBottom, tileRight, tileBounds;
|
||||
for (var y=0, tileTop=gridTop; tileTop > boundsMinY;
|
||||
++y, tileTop-=tileHeightGeo) {
|
||||
tiles[y] = [];
|
||||
tileBottom = tileTop - tileHeightGeo;
|
||||
for (var x=0, tileLeft=gridLeft; tileLeft < boundsMaxX;
|
||||
++x, tileLeft+=tileWidthGeo) {
|
||||
tileRight = tileLeft + tileWidthGeo;
|
||||
tileBounds = new ol.Bounds(tileLeft, tileBottom,
|
||||
tileRight, tileTop, this.projection_);
|
||||
url = me.url_.replace('{x}', offsetX + x + '')
|
||||
.replace('{y}', offsetY + y + '')
|
||||
.replace('{z}', zoom + '');
|
||||
tile = this.getTile(url, tileBounds);
|
||||
tiles[y][x] = tile;
|
||||
}
|
||||
}
|
||||
|
||||
return new ol.TileSet(tiles, tileWidth, tileHeight, resolution);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the zoom level (z) and layer resolution for the given resolution.
|
||||
* @param {number} resolution
|
||||
* @return {Array.<number>}
|
||||
*/
|
||||
ol.layer.TileLayer.prototype.getZoomAndRes = function(resolution) {
|
||||
var delta = Number.POSITIVE_INFINITY,
|
||||
currentDelta,
|
||||
resolutions = this.getResolutions(),
|
||||
zoom;
|
||||
for (var i=resolutions.length-1; i>=0; --i) {
|
||||
currentDelta = Math.abs(resolutions[i] - resolution);
|
||||
if (currentDelta > delta) {
|
||||
break;
|
||||
}
|
||||
delta = currentDelta;
|
||||
}
|
||||
zoom = i + 1;
|
||||
return [zoom, resolutions[zoom]];
|
||||
};
|
||||
|
||||
@@ -15,96 +15,11 @@ goog.require('ol.TileSet');
|
||||
*/
|
||||
ol.layer.XYZ = function(url) {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {string}
|
||||
*/
|
||||
this.url_ = url;
|
||||
|
||||
goog.base(this);
|
||||
|
||||
this.setUrl(url);
|
||||
this.setMaxResolution(156543.03390625);
|
||||
};
|
||||
|
||||
goog.inherits(ol.layer.XYZ, ol.layer.TileLayer);
|
||||
|
||||
/**
|
||||
* Get data from the layer. This is the layer's main API function.
|
||||
* @param {ol.Bounds} bounds
|
||||
* @param {number} resolution
|
||||
*/
|
||||
ol.layer.XYZ.prototype.getData = function(bounds, resolution) {
|
||||
var me = this,
|
||||
zoomAndRes = me.getZoomAndRes(resolution),
|
||||
zoom = zoomAndRes[0];
|
||||
resolution = zoomAndRes[1];
|
||||
|
||||
// define some values used for the actual tiling
|
||||
var boundsMinX = bounds.getMinX(),
|
||||
boundsMaxX = bounds.getMaxX(),
|
||||
boundsMinY = bounds.getMinY(),
|
||||
boundsMaxY = bounds.getMaxY(),
|
||||
|
||||
tileWidth = me.tileWidth_,
|
||||
tileHeight = me.tileHeight_,
|
||||
|
||||
tileOrigin = me.getTileOrigin(),
|
||||
tileOriginX = tileOrigin[0],
|
||||
tileOriginY = tileOrigin[1],
|
||||
|
||||
tileWidthGeo = tileWidth * resolution,
|
||||
tileHeightGeo = tileHeight * resolution,
|
||||
|
||||
offsetX = Math.floor(
|
||||
(boundsMinX - tileOriginX) / tileWidthGeo),
|
||||
offsetY = Math.floor(
|
||||
(tileOriginY - boundsMaxY) / tileHeightGeo),
|
||||
|
||||
gridLeft = tileOriginX + tileWidthGeo * offsetX,
|
||||
gridTop = tileOriginY - tileHeightGeo * offsetY;
|
||||
|
||||
// now tile
|
||||
var tiles = [],
|
||||
tile,
|
||||
url,
|
||||
tileBottom, tileRight, tileBounds;
|
||||
for (var y=0, tileTop=gridTop; tileTop > boundsMinY;
|
||||
++y, tileTop-=tileHeightGeo) {
|
||||
tiles[y] = [];
|
||||
tileBottom = tileTop - tileHeightGeo;
|
||||
for (var x=0, tileLeft=gridLeft; tileLeft < boundsMaxX;
|
||||
++x, tileLeft+=tileWidthGeo) {
|
||||
tileRight = tileLeft + tileWidthGeo;
|
||||
tileBounds = new ol.Bounds(tileLeft, tileBottom,
|
||||
tileRight, tileTop, this.projection_);
|
||||
url = me.url_.replace('{x}', offsetX + x + '')
|
||||
.replace('{y}', offsetY + y + '')
|
||||
.replace('{z}', zoom + '');
|
||||
tile = this.getTile(url, tileBounds);
|
||||
tiles[y][x] = tile;
|
||||
}
|
||||
}
|
||||
|
||||
return new ol.TileSet(tiles, tileWidth, tileHeight, resolution);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the zoom level (z) and layer resolution for the given resolution.
|
||||
* @param {number} resolution
|
||||
* @return {Array.<number>}
|
||||
*/
|
||||
ol.layer.XYZ.prototype.getZoomAndRes = function(resolution) {
|
||||
var delta = Number.POSITIVE_INFINITY,
|
||||
currentDelta,
|
||||
resolutions = this.getResolutions(),
|
||||
zoom;
|
||||
for (var i=resolutions.length-1; i>=0; --i) {
|
||||
currentDelta = Math.abs(resolutions[i] - resolution);
|
||||
if (currentDelta > delta) {
|
||||
break;
|
||||
}
|
||||
delta = currentDelta;
|
||||
}
|
||||
zoom = i + 1;
|
||||
return [zoom, resolutions[zoom]];
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user