Merge pull request #1533 from twpayne/vector-api-tile-hidpi
[vector-api] HiDPI support for tile layers
This commit is contained in:
@@ -101,10 +101,11 @@ ol.source.BingMaps.prototype.handleImageryMetadataResponse =
|
||||
/**
|
||||
* @this {ol.source.BingMaps}
|
||||
* @param {ol.TileCoord} tileCoord Tile coordinate.
|
||||
* @param {number} pixelRatio Pixel ratio.
|
||||
* @param {ol.proj.Projection} projection Projection.
|
||||
* @return {string|undefined} Tile URL.
|
||||
*/
|
||||
function(tileCoord, projection) {
|
||||
function(tileCoord, pixelRatio, projection) {
|
||||
goog.asserts.assert(ol.proj.equivalent(
|
||||
projection, this.getProjection()));
|
||||
if (goog.isNull(tileCoord)) {
|
||||
|
||||
@@ -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, 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.
|
||||
*/
|
||||
@@ -158,6 +159,32 @@ ol.source.Tile.prototype.getTileGrid = function() {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.proj.Projection} projection Projection.
|
||||
* @return {ol.tilegrid.TileGrid} Tile grid.
|
||||
*/
|
||||
ol.source.Tile.prototype.getTileGridForProjection = function(projection) {
|
||||
if (goog.isNull(this.tileGrid)) {
|
||||
return ol.tilegrid.getForProjection(projection);
|
||||
} else {
|
||||
return this.tileGrid;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} z Z.
|
||||
* @param {number} pixelRatio Pixel ratio.
|
||||
* @param {ol.proj.Projection} projection Projection.
|
||||
* @return {number} Tile size.
|
||||
*/
|
||||
ol.source.Tile.prototype.getTilePixelSize =
|
||||
function(z, pixelRatio, projection) {
|
||||
var tileGrid = this.getTileGridForProjection(projection);
|
||||
return tileGrid.getTileSize(z);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Marks a tile coord as being used, without triggering a load.
|
||||
* @param {number} z Tile coordinate z.
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
goog.provide('ol.source.TileWMS');
|
||||
|
||||
goog.require('goog.array');
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.math');
|
||||
goog.require('goog.object');
|
||||
goog.require('goog.string');
|
||||
@@ -13,6 +14,7 @@ goog.require('ol.TileUrlFunction');
|
||||
goog.require('ol.extent');
|
||||
goog.require('ol.source.TileImage');
|
||||
goog.require('ol.source.wms');
|
||||
goog.require('ol.source.wms.ServerType');
|
||||
|
||||
|
||||
|
||||
@@ -71,6 +73,18 @@ ol.source.TileWMS = function(opt_options) {
|
||||
*/
|
||||
this.v13_ = true;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.source.wms.ServerType|undefined}
|
||||
*/
|
||||
this.serverType_ = options.serverType;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.hidpi_ = goog.isDef(options.hidpi) ? options.hidpi : true;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {string}
|
||||
@@ -117,6 +131,23 @@ ol.source.TileWMS.prototype.getParams = function() {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} z Z.
|
||||
* @param {number} pixelRatio Pixel ratio.
|
||||
* @param {ol.proj.Projection} projection Projection.
|
||||
* @return {number} Size.
|
||||
*/
|
||||
ol.source.TileWMS.prototype.getTilePixelSize =
|
||||
function(z, pixelRatio, projection) {
|
||||
var tileSize = goog.base(this, 'getTilePixelSize', z, pixelRatio, projection);
|
||||
if (pixelRatio == 1 || !this.hidpi_ || !goog.isDef(this.serverType_)) {
|
||||
return tileSize;
|
||||
} else {
|
||||
return (tileSize * pixelRatio + 0.5) | 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
@@ -132,11 +163,13 @@ ol.source.TileWMS.prototype.resetCoordKeyPrefix_ = function() {
|
||||
|
||||
/**
|
||||
* @param {ol.TileCoord} tileCoord Tile coordinate.
|
||||
* @param {number} pixelRatio Pixel ratio.
|
||||
* @param {ol.proj.Projection} projection Projection.
|
||||
* @private
|
||||
* @return {string|undefined} Tile URL.
|
||||
*/
|
||||
ol.source.TileWMS.prototype.tileUrlFunction_ = function(tileCoord, projection) {
|
||||
ol.source.TileWMS.prototype.tileUrlFunction_ =
|
||||
function(tileCoord, pixelRatio, projection) {
|
||||
|
||||
var urls = this.urls_;
|
||||
if (!goog.isDef(urls) || goog.array.isEmpty(urls)) {
|
||||
@@ -145,7 +178,7 @@ ol.source.TileWMS.prototype.tileUrlFunction_ = function(tileCoord, projection) {
|
||||
|
||||
var tileGrid = this.getTileGrid();
|
||||
if (goog.isNull(tileGrid)) {
|
||||
tileGrid = ol.tilegrid.getForProjection(projection);
|
||||
tileGrid = this.getTileGridForProjection(projection);
|
||||
}
|
||||
|
||||
if (tileGrid.getResolutions().length <= tileCoord.z) {
|
||||
@@ -164,17 +197,21 @@ ol.source.TileWMS.prototype.tileUrlFunction_ = function(tileCoord, projection) {
|
||||
goog.object.extend(params, this.params_);
|
||||
|
||||
var tileResolution = tileGrid.getResolution(tileCoord.z);
|
||||
if (pixelRatio != 1 && (!this.hidpi_ || !goog.isDef(this.serverType_))) {
|
||||
pixelRatio = 1;
|
||||
}
|
||||
var tileSize = tileGrid.getTileSize(tileCoord.z);
|
||||
var gutter = this.gutter_;
|
||||
if (gutter === 0) {
|
||||
goog.object.set(params, 'WIDTH', tileSize);
|
||||
goog.object.set(params, 'HEIGHT', tileSize);
|
||||
} else {
|
||||
goog.object.set(params, 'WIDTH', tileSize + 2 * gutter);
|
||||
goog.object.set(params, 'HEIGHT', tileSize + 2 * gutter);
|
||||
if (gutter !== 0) {
|
||||
tileSize += 2 * gutter;
|
||||
tileExtent =
|
||||
ol.extent.buffer(tileExtent, tileResolution * gutter, this.tmpExtent_);
|
||||
}
|
||||
if (pixelRatio != 1) {
|
||||
tileSize = (tileSize * pixelRatio + 0.5) | 0;
|
||||
}
|
||||
goog.object.set(params, 'WIDTH', tileSize);
|
||||
goog.object.set(params, 'HEIGHT', tileSize);
|
||||
|
||||
params[this.v13_ ? 'CRS' : 'SRS'] = projection.getCode();
|
||||
|
||||
@@ -182,6 +219,24 @@ ol.source.TileWMS.prototype.tileUrlFunction_ = function(tileCoord, projection) {
|
||||
goog.object.set(params, 'STYLES', new String(''));
|
||||
}
|
||||
|
||||
if (pixelRatio != 1) {
|
||||
switch (this.serverType_) {
|
||||
case ol.source.wms.ServerType.GEOSERVER:
|
||||
var dpi = (90 * pixelRatio + 0.5) | 0;
|
||||
goog.object.set(params, 'FORMAT_OPTIONS', 'dpi:' + dpi);
|
||||
break;
|
||||
case ol.source.wms.ServerType.MAPSERVER:
|
||||
goog.object.set(params, 'MAP_RESOLUTION', 90 * pixelRatio);
|
||||
break;
|
||||
case ol.source.wms.ServerType.QGIS:
|
||||
goog.object.set(params, 'DPI', 90 * pixelRatio);
|
||||
break;
|
||||
default:
|
||||
goog.asserts.fail();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var axisOrientation = projection.getAxisOrientation();
|
||||
var bbox;
|
||||
if (this.v13_ && axisOrientation.substr(0, 2) == 'ne') {
|
||||
|
||||
@@ -96,10 +96,11 @@ ol.source.WMTS = function(options) {
|
||||
/**
|
||||
* @this {ol.source.WMTS}
|
||||
* @param {ol.TileCoord} tileCoord Tile coordinate.
|
||||
* @param {number} pixelRatio Pixel ratio.
|
||||
* @param {ol.proj.Projection} projection Projection.
|
||||
* @return {string|undefined} Tile URL.
|
||||
*/
|
||||
function(tileCoord, projection) {
|
||||
function(tileCoord, pixelRatio, projection) {
|
||||
if (goog.isNull(tileCoord)) {
|
||||
return undefined;
|
||||
} else {
|
||||
|
||||
@@ -61,10 +61,11 @@ ol.source.Zoomify = function(opt_options) {
|
||||
/**
|
||||
* @this {ol.source.TileImage}
|
||||
* @param {ol.TileCoord} tileCoord Tile Coordinate.
|
||||
* @param {number} pixelRatio Pixel ratio.
|
||||
* @param {ol.proj.Projection} projection Projection.
|
||||
* @return {string|undefined} Tile URL.
|
||||
*/
|
||||
function(tileCoord, projection) {
|
||||
function(tileCoord, pixelRatio, projection) {
|
||||
if (goog.isNull(tileCoord)) {
|
||||
return undefined;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user