diff --git a/externs/olx.js b/externs/olx.js index 7808ae5948..c7f326e4cb 100644 --- a/externs/olx.js +++ b/externs/olx.js @@ -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} diff --git a/src/ol/source/bingmaps.js b/src/ol/source/bingmaps.js index ec42b10232..a236388f40 100644 --- a/src/ol/source/bingmaps.js +++ b/src/ol/source/bingmaps.js @@ -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)); } });