diff --git a/src/openseadragon.js b/src/openseadragon.js index ff011fb7..f7467ee2 100644 --- a/src/openseadragon.js +++ b/src/openseadragon.js @@ -986,7 +986,7 @@ function OpenSeadragon( options ){ * @member {Number} pixelDensityRatio * @memberof OpenSeadragon */ - $.pixelDensityRatio = (function () { + $.getCurrentPixelDensityRatio = function() { if ( $.supportsCanvas ) { var context = document.createElement('canvas').getContext('2d'); var devicePixelRatio = window.devicePixelRatio || 1; @@ -999,7 +999,13 @@ function OpenSeadragon( options ){ } else { return 1; } - }()); + }; + + /** + * @member {Number} pixelDensityRatio + * @memberof OpenSeadragon + */ + $.pixelDensityRatio = $.getCurrentPixelDensityRatio(); }( OpenSeadragon )); diff --git a/src/tilesource.js b/src/tilesource.js index fcf2be82..aab7f134 100644 --- a/src/tilesource.js +++ b/src/tilesource.js @@ -313,8 +313,8 @@ $.TileSource.prototype = { */ getPixelRatio: function( level ) { var imageSizeScaled = this.dimensions.times( this.getLevelScale( level ) ), - rx = 1.0 / imageSizeScaled.x, - ry = 1.0 / imageSizeScaled.y; + rx = 1.0 / imageSizeScaled.x * $.pixelDensityRatio, + ry = 1.0 / imageSizeScaled.y * $.pixelDensityRatio; return new $.Point(rx, ry); }, diff --git a/src/viewer.js b/src/viewer.js index 9592abf9..57b16e4f 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -220,6 +220,7 @@ $.Viewer = function( options ) { this._updateRequestId = null; this._loadQueue = []; this.currentOverlays = []; + this._updatePixelDensityRatioBind = null; this._lastScrollTime = $.now(); // variable used to help normalize the scroll event speed of different devices @@ -426,6 +427,8 @@ $.Viewer = function( options ) { } } + this._addUpdatePixelDensityRatioEvent(); + //Instantiate a navigator if configured if ( this.showNavigator){ this.navigator = new $.Navigator({ @@ -748,6 +751,8 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, return; } + this._removeUpdatePixelDensityRatioEvent(); + this.close(); this.clearOverlays(); @@ -2268,6 +2273,38 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, } else { $.console.warn('Attempting to display a reference strip while "sequenceMode" is off.'); } + }, + + /** + * Adds _updatePixelDensityRatio to the window resize event. + * @private + */ + _addUpdatePixelDensityRatioEvent: function() { + this._updatePixelDensityRatioBind = this._updatePixelDensityRatio.bind(this); + $.addEvent( window, 'resize', this._updatePixelDensityRatioBind ); + }, + + /** + * Removes _updatePixelDensityRatio from the window resize event. + * @private + */ + _removeUpdatePixelDensityRatioEvent: function() { + $.removeEvent( window, 'resize', this._updatePixelDensityRatioBind ); + }, + + /** + * Update pixel density ratio, clears all tiles and triggers updates for + * all items if the ratio has changed. + * @private + */ + _updatePixelDensityRatio: function() { + var previusPixelDensityRatio = $.pixelDensityRatio; + var currentPixelDensityRatio = $.getCurrentPixelDensityRatio(); + if (previusPixelDensityRatio !== currentPixelDensityRatio) { + $.pixelDensityRatio = currentPixelDensityRatio; + this.world.resetItems(); + this.forceRedraw(); + } } });