[ol.layer.TileLayer, ol.layer.XYZ] add a getMaxResolution func to TileLayer, and make ol.layer.XYZ be just a projection and a number of zoom levels
This commit is contained in:
@@ -153,15 +153,44 @@ ol.layer.TileLayer.prototype.getTileOrigin = function() {
|
||||
return null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get max resolution. Return undefined if the layer has no maxResolution,
|
||||
* and no extent from which maxResolution could be derived.
|
||||
* @return {number|undefined}
|
||||
*/
|
||||
ol.layer.TileLayer.prototype.getMaxResolution = function() {
|
||||
if (!goog.isDef(this.maxResolution_)) {
|
||||
var extent = this.getExtent();
|
||||
if (!goog.isNull(extent)) {
|
||||
this.maxResolution_ = Math.max(
|
||||
(extent.getMaxX() - extent.getMinX()) / this.tileWidth_,
|
||||
(extent.getMaxY() - extent.getMaxX()) / this.tileHeight_);
|
||||
}
|
||||
}
|
||||
return this.maxResolution_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the number of the zoom levels.
|
||||
* @return {number|undefined}
|
||||
*/
|
||||
ol.layer.TileLayer.prototype.getNumZoomLevels = function() {
|
||||
return this.numZoomLevels_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get layer resolutions. Return null if the layer has no resolutions.
|
||||
* @return {Array.<number>}
|
||||
*/
|
||||
ol.layer.TileLayer.prototype.getResolutions = function() {
|
||||
if (goog.isNull(this.resolutions_) && goog.isDef(this.maxResolution_)) {
|
||||
this.resolutions_ = [];
|
||||
for (var i = 0; i < this.numZoomLevels_; i++) {
|
||||
this.resolutions_[i] = this.maxResolution_ / Math.pow(2, i);
|
||||
if (goog.isNull(this.resolutions_)) {
|
||||
var maxResolution = this.getMaxResolution(),
|
||||
numZoomLevels = this.getNumZoomLevels();
|
||||
if (goog.isDef(maxResolution) && goog.isDef(numZoomLevels)) {
|
||||
this.resolutions_ = [];
|
||||
for (var i = 0; i < numZoomLevels; i++) {
|
||||
this.resolutions_[i] = maxResolution / Math.pow(2, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
return this.resolutions_;
|
||||
|
||||
@@ -18,7 +18,8 @@ ol.layer.XYZ = function(url) {
|
||||
goog.base(this);
|
||||
|
||||
this.setUrl(url);
|
||||
this.setMaxResolution(156543.03390625);
|
||||
this.setProjection(new ol.Projection("EPSG:3857"));
|
||||
this.setNumZoomLevels(22);
|
||||
};
|
||||
|
||||
goog.inherits(ol.layer.XYZ, ol.layer.TileLayer);
|
||||
|
||||
@@ -134,6 +134,38 @@ describe('ol.layer.TileLayer', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('get max resolution', function() {
|
||||
var layer;
|
||||
|
||||
beforeEach(function() {
|
||||
layer = new ol.layer.TileLayer();
|
||||
});
|
||||
|
||||
describe('with max resolution', function() {
|
||||
|
||||
beforeEach(function() {
|
||||
layer.setMaxResolution(156543.03390625);
|
||||
});
|
||||
|
||||
it('returns the expected maxResolution', function() {
|
||||
var maxResolution = layer.getMaxResolution();
|
||||
expect(maxResolution).toEqual(156543.03390625);
|
||||
});
|
||||
});
|
||||
|
||||
describe('with projection', function() {
|
||||
|
||||
beforeEach(function() {
|
||||
layer.setProjection(new ol.Projection("EPSG:3857"));
|
||||
});
|
||||
|
||||
it('returns the expected maxResolution', function() {
|
||||
var maxResolution = layer.getMaxResolution();
|
||||
expect(maxResolution).toEqual(156543.03390625);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('get data from the layer', function() {
|
||||
var layer;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user