Add pixelRatio to ol.source.Tile#getTile
This commit is contained in:
@@ -164,6 +164,7 @@ ol.renderer.canvas.TileLayer.prototype.prepareFrame =
|
||||
// composition and positioning.
|
||||
//
|
||||
|
||||
var pixelRatio = frameState.pixelRatio;
|
||||
var view2DState = frameState.view2DState;
|
||||
var projection = view2DState.projection;
|
||||
|
||||
@@ -261,7 +262,7 @@ ol.renderer.canvas.TileLayer.prototype.prepareFrame =
|
||||
|
||||
var getTileIfLoaded = this.createGetTileIfLoadedFunction(function(tile) {
|
||||
return !goog.isNull(tile) && tile.getState() == ol.TileState.LOADED;
|
||||
}, tileSource, projection);
|
||||
}, tileSource, pixelRatio, projection);
|
||||
var findLoadedTiles = goog.bind(tileSource.findLoadedTiles, tileSource,
|
||||
tilesToDrawByZ, getTileIfLoaded);
|
||||
|
||||
@@ -271,7 +272,7 @@ ol.renderer.canvas.TileLayer.prototype.prepareFrame =
|
||||
for (x = tileRange.minX; x <= tileRange.maxX; ++x) {
|
||||
for (y = tileRange.minY; y <= tileRange.maxY; ++y) {
|
||||
|
||||
tile = tileSource.getTile(z, x, y, projection);
|
||||
tile = tileSource.getTile(z, x, y, pixelRatio, projection);
|
||||
tileState = tile.getState();
|
||||
if (tileState == ol.TileState.LOADED ||
|
||||
tileState == ol.TileState.EMPTY ||
|
||||
@@ -377,12 +378,11 @@ ol.renderer.canvas.TileLayer.prototype.prepareFrame =
|
||||
}
|
||||
|
||||
this.updateUsedTiles(frameState.usedTiles, tileSource, z, tileRange);
|
||||
this.manageTilePyramid(frameState, tileSource, tileGrid, projection, extent,
|
||||
z, tileLayer.getPreload());
|
||||
this.manageTilePyramid(frameState, tileSource, tileGrid, pixelRatio,
|
||||
projection, extent, z, tileLayer.getPreload());
|
||||
this.scheduleExpireCache(frameState, tileSource);
|
||||
this.updateLogos(frameState, tileSource);
|
||||
|
||||
var pixelRatio = frameState.pixelRatio;
|
||||
ol.vec.Mat4.makeTransform2D(this.imageTransform_,
|
||||
pixelRatio * frameState.size[0] / 2,
|
||||
pixelRatio * frameState.size[1] / 2,
|
||||
|
||||
@@ -81,6 +81,7 @@ ol.renderer.dom.TileLayer.prototype.prepareFrame =
|
||||
return;
|
||||
}
|
||||
|
||||
var pixelRatio = frameState.pixelRatio;
|
||||
var view2DState = frameState.view2DState;
|
||||
var projection = view2DState.projection;
|
||||
|
||||
@@ -113,7 +114,7 @@ ol.renderer.dom.TileLayer.prototype.prepareFrame =
|
||||
|
||||
var getTileIfLoaded = this.createGetTileIfLoadedFunction(function(tile) {
|
||||
return !goog.isNull(tile) && tile.getState() == ol.TileState.LOADED;
|
||||
}, tileSource, projection);
|
||||
}, tileSource, pixelRatio, projection);
|
||||
var findLoadedTiles = goog.bind(tileSource.findLoadedTiles, tileSource,
|
||||
tilesToDrawByZ, getTileIfLoaded);
|
||||
|
||||
@@ -123,7 +124,7 @@ ol.renderer.dom.TileLayer.prototype.prepareFrame =
|
||||
for (x = tileRange.minX; x <= tileRange.maxX; ++x) {
|
||||
for (y = tileRange.minY; y <= tileRange.maxY; ++y) {
|
||||
|
||||
tile = tileSource.getTile(z, x, y, projection);
|
||||
tile = tileSource.getTile(z, x, y, pixelRatio, projection);
|
||||
tileState = tile.getState();
|
||||
if (tileState == ol.TileState.LOADED) {
|
||||
tilesToDrawByZ[z][tile.tileCoord.toString()] = tile;
|
||||
@@ -241,8 +242,8 @@ ol.renderer.dom.TileLayer.prototype.prepareFrame =
|
||||
}
|
||||
|
||||
this.updateUsedTiles(frameState.usedTiles, tileSource, z, tileRange);
|
||||
this.manageTilePyramid(frameState, tileSource, tileGrid, projection, extent,
|
||||
z, tileLayer.getPreload());
|
||||
this.manageTilePyramid(frameState, tileSource, tileGrid, pixelRatio,
|
||||
projection, extent, z, tileLayer.getPreload());
|
||||
this.scheduleExpireCache(frameState, tileSource);
|
||||
this.updateLogos(frameState, tileSource);
|
||||
|
||||
|
||||
@@ -197,13 +197,14 @@ ol.renderer.Layer.prototype.updateUsedTiles =
|
||||
* @param {function(ol.Tile): boolean} isLoadedFunction Function to
|
||||
* determine if the tile is loaded.
|
||||
* @param {ol.source.Tile} tileSource Tile source.
|
||||
* @param {number} pixelRatio Pixel ratio.
|
||||
* @param {ol.proj.Projection} projection Projection.
|
||||
* @protected
|
||||
* @return {function(number, number, number): ol.Tile} Returns a tile if it is
|
||||
* loaded.
|
||||
*/
|
||||
ol.renderer.Layer.prototype.createGetTileIfLoadedFunction =
|
||||
function(isLoadedFunction, tileSource, projection) {
|
||||
function(isLoadedFunction, tileSource, pixelRatio, projection) {
|
||||
return (
|
||||
/**
|
||||
* @param {number} z Z.
|
||||
@@ -212,7 +213,7 @@ ol.renderer.Layer.prototype.createGetTileIfLoadedFunction =
|
||||
* @return {ol.Tile} Tile.
|
||||
*/
|
||||
function(z, x, y) {
|
||||
var tile = tileSource.getTile(z, x, y, projection);
|
||||
var tile = tileSource.getTile(z, x, y, pixelRatio, projection);
|
||||
return isLoadedFunction(tile) ? tile : null;
|
||||
});
|
||||
};
|
||||
@@ -244,6 +245,7 @@ ol.renderer.Layer.prototype.snapCenterToPixel =
|
||||
* @param {ol.FrameState} frameState Frame state.
|
||||
* @param {ol.source.Tile} tileSource Tile source.
|
||||
* @param {ol.tilegrid.TileGrid} tileGrid Tile grid.
|
||||
* @param {number} pixelRatio Pixel ratio.
|
||||
* @param {ol.proj.Projection} projection Projection.
|
||||
* @param {ol.Extent} extent Extent.
|
||||
* @param {number} currentZ Current Z.
|
||||
@@ -254,8 +256,8 @@ ol.renderer.Layer.prototype.snapCenterToPixel =
|
||||
* @template T
|
||||
*/
|
||||
ol.renderer.Layer.prototype.manageTilePyramid = function(
|
||||
frameState, tileSource, tileGrid, projection, extent, currentZ, preload,
|
||||
opt_tileCallback, opt_this) {
|
||||
frameState, tileSource, tileGrid, pixelRatio, projection, extent,
|
||||
currentZ, preload, opt_tileCallback, opt_this) {
|
||||
var tileSourceKey = goog.getUid(tileSource).toString();
|
||||
if (!(tileSourceKey in frameState.wantedTiles)) {
|
||||
frameState.wantedTiles[tileSourceKey] = {};
|
||||
@@ -270,7 +272,7 @@ ol.renderer.Layer.prototype.manageTilePyramid = function(
|
||||
for (x = tileRange.minX; x <= tileRange.maxX; ++x) {
|
||||
for (y = tileRange.minY; y <= tileRange.maxY; ++y) {
|
||||
if (currentZ - z <= preload) {
|
||||
tile = tileSource.getTile(z, x, y, projection);
|
||||
tile = tileSource.getTile(z, x, y, pixelRatio, projection);
|
||||
if (tile.getState() == ol.TileState.IDLE) {
|
||||
wantedTiles[tile.tileCoord.toString()] = true;
|
||||
if (!tileQueue.isKeyQueued(tile.getKey())) {
|
||||
|
||||
@@ -114,6 +114,7 @@ ol.renderer.webgl.TileLayer.prototype.prepareFrame =
|
||||
var context = mapRenderer.getContext();
|
||||
var gl = mapRenderer.getGL();
|
||||
|
||||
var pixelRatio = frameState.pixelRatio;
|
||||
var view2DState = frameState.view2DState;
|
||||
var projection = view2DState.projection;
|
||||
|
||||
@@ -196,7 +197,7 @@ ol.renderer.webgl.TileLayer.prototype.prepareFrame =
|
||||
var getTileIfLoaded = this.createGetTileIfLoadedFunction(function(tile) {
|
||||
return !goog.isNull(tile) && tile.getState() == ol.TileState.LOADED &&
|
||||
mapRenderer.isTileTextureLoaded(tile);
|
||||
}, tileSource, projection);
|
||||
}, tileSource, pixelRatio, projection);
|
||||
var findLoadedTiles = goog.bind(tileSource.findLoadedTiles, tileSource,
|
||||
tilesToDrawByZ, getTileIfLoaded);
|
||||
|
||||
@@ -207,7 +208,7 @@ ol.renderer.webgl.TileLayer.prototype.prepareFrame =
|
||||
for (x = tileRange.minX; x <= tileRange.maxX; ++x) {
|
||||
for (y = tileRange.minY; y <= tileRange.maxY; ++y) {
|
||||
|
||||
tile = tileSource.getTile(z, x, y, projection);
|
||||
tile = tileSource.getTile(z, x, y, pixelRatio, projection);
|
||||
tileState = tile.getState();
|
||||
if (tileState == ol.TileState.LOADED) {
|
||||
if (mapRenderer.isTileTextureLoaded(tile)) {
|
||||
@@ -276,7 +277,7 @@ ol.renderer.webgl.TileLayer.prototype.prepareFrame =
|
||||
this.updateUsedTiles(frameState.usedTiles, tileSource, z, tileRange);
|
||||
var tileTextureQueue = mapRenderer.getTileTextureQueue();
|
||||
this.manageTilePyramid(
|
||||
frameState, tileSource, tileGrid, projection, extent, z,
|
||||
frameState, tileSource, tileGrid, pixelRatio, projection, extent, z,
|
||||
tileLayer.getPreload(),
|
||||
/**
|
||||
* @param {ol.Tile} tile Tile.
|
||||
|
||||
@@ -119,14 +119,15 @@ ol.source.TileImage.prototype.expireCache = function(usedTiles) {
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.source.TileImage.prototype.getTile = function(z, x, y, projection) {
|
||||
ol.source.TileImage.prototype.getTile =
|
||||
function(z, x, y, pixelRatio, projection) {
|
||||
var tileCoordKey = this.getKeyZXY(z, x, y);
|
||||
if (this.tileCache.containsKey(tileCoordKey)) {
|
||||
return /** @type {!ol.Tile} */ (this.tileCache.get(tileCoordKey));
|
||||
} else {
|
||||
goog.asserts.assert(projection);
|
||||
var tileCoord = new ol.TileCoord(z, x, y);
|
||||
var tileUrl = this.tileUrlFunction(tileCoord, 1, projection);
|
||||
var tileUrl = this.tileUrlFunction(tileCoord, pixelRatio, projection);
|
||||
var tile = new this.tileClass(
|
||||
tileCoord,
|
||||
goog.isDef(tileUrl) ? ol.TileState.IDLE : ol.TileState.EMPTY,
|
||||
|
||||
@@ -144,6 +144,7 @@ ol.source.Tile.prototype.getResolutions = function() {
|
||||
* @param {number} z Tile coordinate z.
|
||||
* @param {number} x Tile coordinate x.
|
||||
* @param {number} y Tile coordinate y.
|
||||
* @param {number} pixelRatio Pixel ratio.
|
||||
* @param {ol.proj.Projection=} opt_projection Projection.
|
||||
* @return {!ol.Tile} Tile.
|
||||
*/
|
||||
|
||||
@@ -17,7 +17,7 @@ describe('ol.source.TileWMS', function() {
|
||||
|
||||
it('returns a tile with the expected URL', function() {
|
||||
var source = new ol.source.TileWMS(options);
|
||||
var tile = source.getTile(3, 2, 1, ol.proj.get('EPSG:3857'));
|
||||
var tile = source.getTile(3, 2, 1, 1, ol.proj.get('EPSG:3857'));
|
||||
expect(tile).to.be.an(ol.ImageTile);
|
||||
var uri = new goog.Uri(tile.src_);
|
||||
expect(uri.getScheme()).to.be('http');
|
||||
@@ -44,7 +44,7 @@ describe('ol.source.TileWMS', function() {
|
||||
it('returns a larger tile when a gutter is specified', function() {
|
||||
options.gutter = 16;
|
||||
var source = new ol.source.TileWMS(options);
|
||||
var tile = source.getTile(3, 2, 1, ol.proj.get('EPSG:3857'));
|
||||
var tile = source.getTile(3, 2, 1, 1, ol.proj.get('EPSG:3857'));
|
||||
expect(tile).to.be.an(ol.ImageTile);
|
||||
var uri = new goog.Uri(tile.src_);
|
||||
var queryData = uri.getQueryData();
|
||||
@@ -58,7 +58,7 @@ describe('ol.source.TileWMS', function() {
|
||||
it('sets the SRS query value instead of CRS if version < 1.3', function() {
|
||||
options.params.VERSION = '1.2';
|
||||
var source = new ol.source.TileWMS(options);
|
||||
var tile = source.getTile(3, 2, 1, ol.proj.get('EPSG:4326'));
|
||||
var tile = source.getTile(3, 2, 1, 1, ol.proj.get('EPSG:4326'));
|
||||
var uri = new goog.Uri(tile.src_);
|
||||
var queryData = uri.getQueryData();
|
||||
expect(queryData.get('CRS')).to.be(undefined);
|
||||
@@ -69,7 +69,7 @@ describe('ol.source.TileWMS', function() {
|
||||
options.params.FORMAT = 'image/jpeg';
|
||||
options.params.TRANSPARENT = false;
|
||||
var source = new ol.source.TileWMS(options);
|
||||
var tile = source.getTile(3, 2, 1, ol.proj.get('EPSG:4326'));
|
||||
var tile = source.getTile(3, 2, 1, 1, ol.proj.get('EPSG:4326'));
|
||||
var uri = new goog.Uri(tile.src_);
|
||||
var queryData = uri.getQueryData();
|
||||
expect(queryData.get('FORMAT')).to.be('image/jpeg');
|
||||
@@ -79,7 +79,7 @@ describe('ol.source.TileWMS', function() {
|
||||
it('does not add a STYLES= option if one is specified', function() {
|
||||
options.params.STYLES = 'foo';
|
||||
var source = new ol.source.TileWMS(options);
|
||||
var tile = source.getTile(3, 2, 1, ol.proj.get('EPSG:4326'));
|
||||
var tile = source.getTile(3, 2, 1, 1, ol.proj.get('EPSG:4326'));
|
||||
var uri = new goog.Uri(tile.src_);
|
||||
var queryData = uri.getQueryData();
|
||||
expect(queryData.get('STYLES')).to.be('foo');
|
||||
@@ -87,7 +87,7 @@ describe('ol.source.TileWMS', function() {
|
||||
|
||||
it('changes the BBOX order for EN axis orientations', function() {
|
||||
var source = new ol.source.TileWMS(options);
|
||||
var tile = source.getTile(3, 2, 1, ol.proj.get('EPSG:4326'));
|
||||
var tile = source.getTile(3, 2, 1, 1, ol.proj.get('EPSG:4326'));
|
||||
var uri = new goog.Uri(tile.src_);
|
||||
var queryData = uri.getQueryData();
|
||||
expect(queryData.get('BBOX')).to.be('-45,-90,0,-45');
|
||||
@@ -96,7 +96,7 @@ describe('ol.source.TileWMS', function() {
|
||||
it('uses EN BBOX order if version < 1.3', function() {
|
||||
options.params.VERSION = '1.1.0';
|
||||
var source = new ol.source.TileWMS(options);
|
||||
var tile = source.getTile(3, 2, 1, ol.proj.get('CRS:84'));
|
||||
var tile = source.getTile(3, 2, 1, 1, ol.proj.get('CRS:84'));
|
||||
var uri = new goog.Uri(tile.src_);
|
||||
var queryData = uri.getQueryData();
|
||||
expect(queryData.get('BBOX')).to.be('-90,-45,-45,0');
|
||||
|
||||
Reference in New Issue
Block a user