Make ol.source.Tile#getTilePixelRatio work for all sources
Even for sources which serve dynamic tile sizes based on devicePixelRatio
This commit is contained in:
@@ -94,7 +94,7 @@ ol.renderer.canvas.VectorTileLayer.prototype.composeFrame =
|
|||||||
var source = layer.getSource();
|
var source = layer.getSource();
|
||||||
goog.asserts.assertInstanceof(source, ol.source.VectorTile,
|
goog.asserts.assertInstanceof(source, ol.source.VectorTile,
|
||||||
'Source is an ol.source.VectorTile');
|
'Source is an ol.source.VectorTile');
|
||||||
var tilePixelRatio = source.getTilePixelRatio();
|
var tilePixelRatio = source.getTilePixelRatio(pixelRatio);
|
||||||
var maxScale = tilePixelRatio / pixelRatio;
|
var maxScale = tilePixelRatio / pixelRatio;
|
||||||
|
|
||||||
var transform = this.getTransform(frameState, 0);
|
var transform = this.getTransform(frameState, 0);
|
||||||
@@ -240,7 +240,8 @@ ol.renderer.canvas.VectorTileLayer.prototype.createReplayGroup = function(tile,
|
|||||||
extent = tileGrid.getTileCoordExtent(tileCoord);
|
extent = tileGrid.getTileCoordExtent(tileCoord);
|
||||||
}
|
}
|
||||||
var resolution = tileGrid.getResolution(tileCoord[0]);
|
var resolution = tileGrid.getResolution(tileCoord[0]);
|
||||||
var tileResolution = pixelSpace ? source.getTilePixelRatio() : resolution;
|
var tileResolution =
|
||||||
|
pixelSpace ? source.getTilePixelRatio(pixelRatio) : resolution;
|
||||||
replayState.dirty = false;
|
replayState.dirty = false;
|
||||||
var replayGroup = new ol.render.canvas.ReplayGroup(0, extent,
|
var replayGroup = new ol.render.canvas.ReplayGroup(0, extent,
|
||||||
tileResolution, layer.getRenderBuffer());
|
tileResolution, layer.getRenderBuffer());
|
||||||
@@ -294,6 +295,7 @@ ol.renderer.canvas.VectorTileLayer.prototype.createReplayGroup = function(tile,
|
|||||||
*/
|
*/
|
||||||
ol.renderer.canvas.VectorTileLayer.prototype.forEachFeatureAtCoordinate =
|
ol.renderer.canvas.VectorTileLayer.prototype.forEachFeatureAtCoordinate =
|
||||||
function(coordinate, frameState, callback, thisArg) {
|
function(coordinate, frameState, callback, thisArg) {
|
||||||
|
var pixelRatio = frameState.pixelRatio;
|
||||||
var resolution = frameState.viewState.resolution;
|
var resolution = frameState.viewState.resolution;
|
||||||
var rotation = frameState.viewState.rotation;
|
var rotation = frameState.viewState.rotation;
|
||||||
var layer = this.getLayer();
|
var layer = this.getLayer();
|
||||||
@@ -319,7 +321,7 @@ ol.renderer.canvas.VectorTileLayer.prototype.forEachFeatureAtCoordinate =
|
|||||||
}
|
}
|
||||||
if (tile.getProjection().getUnits() === ol.proj.Units.TILE_PIXELS) {
|
if (tile.getProjection().getUnits() === ol.proj.Units.TILE_PIXELS) {
|
||||||
origin = ol.extent.getTopLeft(tileExtent);
|
origin = ol.extent.getTopLeft(tileExtent);
|
||||||
tilePixelRatio = source.getTilePixelRatio();
|
tilePixelRatio = source.getTilePixelRatio(pixelRatio);
|
||||||
tileResolution = tileGrid.getResolution(tileCoord[0]) / tilePixelRatio;
|
tileResolution = tileGrid.getResolution(tileCoord[0]) / tilePixelRatio;
|
||||||
tileSpaceCoordinate = [
|
tileSpaceCoordinate = [
|
||||||
(coordinate[0] - origin[0]) / tileResolution,
|
(coordinate[0] - origin[0]) / tileResolution,
|
||||||
|
|||||||
@@ -134,19 +134,10 @@ ol.source.TileArcGISRest.prototype.getRequestUrl_ =
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {number} z Z.
|
* @inheritDoc
|
||||||
* @param {number} pixelRatio Pixel ratio.
|
|
||||||
* @param {ol.proj.Projection} projection Projection.
|
|
||||||
* @return {ol.Size} Size.
|
|
||||||
*/
|
*/
|
||||||
ol.source.TileArcGISRest.prototype.getTilePixelSize =
|
ol.source.TileArcGISRest.prototype.getTilePixelRatio = function(pixelRatio) {
|
||||||
function(z, pixelRatio, projection) {
|
return pixelRatio;
|
||||||
var tileSize = goog.base(this, 'getTilePixelSize', z, pixelRatio, projection);
|
|
||||||
if (pixelRatio == 1) {
|
|
||||||
return tileSize;
|
|
||||||
} else {
|
|
||||||
return ol.size.scale(tileSize, pixelRatio, this.tmpSize);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -217,7 +217,7 @@ ol.source.TileImage.prototype.getTile =
|
|||||||
var tile = new ol.reproj.Tile(
|
var tile = new ol.reproj.Tile(
|
||||||
sourceProjection, sourceTileGrid,
|
sourceProjection, sourceTileGrid,
|
||||||
projection, targetTileGrid,
|
projection, targetTileGrid,
|
||||||
tileCoord, wrappedTileCoord, this.getTilePixelRatio(),
|
tileCoord, wrappedTileCoord, this.getTilePixelRatio(pixelRatio),
|
||||||
goog.bind(function(z, x, y, pixelRatio) {
|
goog.bind(function(z, x, y, pixelRatio) {
|
||||||
return this.getTileInternal(z, x, y, pixelRatio, sourceProjection);
|
return this.getTileInternal(z, x, y, pixelRatio, sourceProjection);
|
||||||
}, this), this.reprojectionErrorThreshold_,
|
}, this), this.reprojectionErrorThreshold_,
|
||||||
|
|||||||
@@ -243,9 +243,10 @@ ol.source.Tile.prototype.getTileCacheForProjection = function(projection) {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param {number} pixelRatio Pixel ratio.
|
||||||
* @return {number} Tile pixel ratio.
|
* @return {number} Tile pixel ratio.
|
||||||
*/
|
*/
|
||||||
ol.source.Tile.prototype.getTilePixelRatio = function() {
|
ol.source.Tile.prototype.getTilePixelRatio = function(pixelRatio) {
|
||||||
return this.tilePixelRatio_;
|
return this.tilePixelRatio_;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -259,8 +260,13 @@ ol.source.Tile.prototype.getTilePixelRatio = function() {
|
|||||||
ol.source.Tile.prototype.getTilePixelSize =
|
ol.source.Tile.prototype.getTilePixelSize =
|
||||||
function(z, pixelRatio, projection) {
|
function(z, pixelRatio, projection) {
|
||||||
var tileGrid = this.getTileGridForProjection(projection);
|
var tileGrid = this.getTileGridForProjection(projection);
|
||||||
return ol.size.scale(ol.size.toSize(tileGrid.getTileSize(z), this.tmpSize),
|
var tilePixelRatio = this.getTilePixelRatio(pixelRatio);
|
||||||
this.tilePixelRatio_, this.tmpSize);
|
var tileSize = ol.size.toSize(tileGrid.getTileSize(z), this.tmpSize);
|
||||||
|
if (tilePixelRatio == 1) {
|
||||||
|
return tileSize;
|
||||||
|
} else {
|
||||||
|
return ol.size.scale(tileSize, tilePixelRatio, this.tmpSize);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -275,19 +275,10 @@ ol.source.TileWMS.prototype.getRequestUrl_ =
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {number} z Z.
|
* @inheritDoc
|
||||||
* @param {number} pixelRatio Pixel ratio.
|
|
||||||
* @param {ol.proj.Projection} projection Projection.
|
|
||||||
* @return {ol.Size} Size.
|
|
||||||
*/
|
*/
|
||||||
ol.source.TileWMS.prototype.getTilePixelSize =
|
ol.source.TileWMS.prototype.getTilePixelRatio = function(pixelRatio) {
|
||||||
function(z, pixelRatio, projection) {
|
return (!this.hidpi_ || this.serverType_ === undefined) ? 1 : pixelRatio;
|
||||||
var tileSize = goog.base(this, 'getTilePixelSize', z, pixelRatio, projection);
|
|
||||||
if (pixelRatio == 1 || !this.hidpi_ || this.serverType_ === undefined) {
|
|
||||||
return tileSize;
|
|
||||||
} else {
|
|
||||||
return ol.size.scale(tileSize, pixelRatio, this.tmpSize);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user