Merge pull request #6077 from bartvde/bing-hidpi

Optionally enable hidpi support for Bing
This commit is contained in:
Bart van den Eijnden
2016-11-11 09:17:08 +01:00
committed by GitHub
2 changed files with 23 additions and 2 deletions

View File

@@ -4135,6 +4135,7 @@ olx.source;
/**
* @typedef {{cacheSize: (number|undefined),
* culture: (string|undefined),
* hidpi: (boolean|undefined),
* key: string,
* imagerySet: string,
* maxZoom: (number|undefined),
@@ -4153,6 +4154,14 @@ olx.source.BingMapsOptions;
olx.source.BingMapsOptions.prototype.cacheSize;
/**
* If `true` hidpi tiles will be requested. Default is `false`.
* @type {boolean|undefined}
* @api
*/
olx.source.BingMapsOptions.prototype.hidpi;
/**
* Culture code. Default is `en-us`.
* @type {string|undefined}

View File

@@ -23,6 +23,12 @@ goog.require('ol.tilegrid');
*/
ol.source.BingMaps = function(options) {
/**
* @private
* @type {boolean}
*/
this.hidpi_ = options.hidpi !== undefined ? options.hidpi : false;
ol.source.TileImage.call(this, {
cacheSize: options.cacheSize,
crossOrigin: 'anonymous',
@@ -31,6 +37,7 @@ ol.source.BingMaps = function(options) {
reprojectionErrorThreshold: options.reprojectionErrorThreshold,
state: ol.source.State.LOADING,
tileLoadFunction: options.tileLoadFunction,
tilePixelRatio: this.hidpi_ ? 2 : 1,
wrapX: options.wrapX !== undefined ? options.wrapX : true
});
@@ -137,11 +144,12 @@ ol.source.BingMaps.prototype.handleImageryMetadataResponse = function(response)
extent: extent,
minZoom: resource.zoomMin,
maxZoom: maxZoom,
tileSize: tileSize
tileSize: tileSize / this.getTilePixelRatio()
});
this.tileGrid = tileGrid;
var culture = this.culture_;
var hidpi = this.hidpi_;
this.tileUrlFunction = ol.TileUrlFunction.createFromTileUrlFunctions(
resource.imageUrlSubdomains.map(function(subdomain) {
var quadKeyTileCoord = [0, 0, 0];
@@ -164,7 +172,11 @@ ol.source.BingMaps.prototype.handleImageryMetadataResponse = function(response)
} else {
ol.tilecoord.createOrUpdate(tileCoord[0], tileCoord[1],
-tileCoord[2] - 1, quadKeyTileCoord);
return imageUrl.replace('{quadkey}', ol.tilecoord.quadKey(
var url = imageUrl;
if (hidpi) {
url += '&dpi=d1&device=mobile';
}
return url.replace('{quadkey}', ol.tilecoord.quadKey(
quadKeyTileCoord));
}
});