mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-22 05:06:09 +03:00
Merge pull request #1937 from ronnymikalsen/1763-a11y-browser-zoom
fix(a11y): draw the level based on pixel density ratio
This commit is contained in:
commit
0a78916ff7
@ -986,7 +986,7 @@ function OpenSeadragon( options ){
|
|||||||
* @member {Number} pixelDensityRatio
|
* @member {Number} pixelDensityRatio
|
||||||
* @memberof OpenSeadragon
|
* @memberof OpenSeadragon
|
||||||
*/
|
*/
|
||||||
$.pixelDensityRatio = (function () {
|
$.getCurrentPixelDensityRatio = function() {
|
||||||
if ( $.supportsCanvas ) {
|
if ( $.supportsCanvas ) {
|
||||||
var context = document.createElement('canvas').getContext('2d');
|
var context = document.createElement('canvas').getContext('2d');
|
||||||
var devicePixelRatio = window.devicePixelRatio || 1;
|
var devicePixelRatio = window.devicePixelRatio || 1;
|
||||||
@ -999,7 +999,13 @@ function OpenSeadragon( options ){
|
|||||||
} else {
|
} else {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}());
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @member {Number} pixelDensityRatio
|
||||||
|
* @memberof OpenSeadragon
|
||||||
|
*/
|
||||||
|
$.pixelDensityRatio = $.getCurrentPixelDensityRatio();
|
||||||
|
|
||||||
}( OpenSeadragon ));
|
}( OpenSeadragon ));
|
||||||
|
|
||||||
|
@ -313,8 +313,8 @@ $.TileSource.prototype = {
|
|||||||
*/
|
*/
|
||||||
getPixelRatio: function( level ) {
|
getPixelRatio: function( level ) {
|
||||||
var imageSizeScaled = this.dimensions.times( this.getLevelScale( level ) ),
|
var imageSizeScaled = this.dimensions.times( this.getLevelScale( level ) ),
|
||||||
rx = 1.0 / imageSizeScaled.x,
|
rx = 1.0 / imageSizeScaled.x * $.pixelDensityRatio,
|
||||||
ry = 1.0 / imageSizeScaled.y;
|
ry = 1.0 / imageSizeScaled.y * $.pixelDensityRatio;
|
||||||
|
|
||||||
return new $.Point(rx, ry);
|
return new $.Point(rx, ry);
|
||||||
},
|
},
|
||||||
|
@ -220,6 +220,7 @@ $.Viewer = function( options ) {
|
|||||||
this._updateRequestId = null;
|
this._updateRequestId = null;
|
||||||
this._loadQueue = [];
|
this._loadQueue = [];
|
||||||
this.currentOverlays = [];
|
this.currentOverlays = [];
|
||||||
|
this._updatePixelDensityRatioBind = null;
|
||||||
|
|
||||||
this._lastScrollTime = $.now(); // variable used to help normalize the scroll event speed of different devices
|
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
|
//Instantiate a navigator if configured
|
||||||
if ( this.showNavigator){
|
if ( this.showNavigator){
|
||||||
this.navigator = new $.Navigator({
|
this.navigator = new $.Navigator({
|
||||||
@ -748,6 +751,8 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this._removeUpdatePixelDensityRatioEvent();
|
||||||
|
|
||||||
this.close();
|
this.close();
|
||||||
|
|
||||||
this.clearOverlays();
|
this.clearOverlays();
|
||||||
@ -2268,6 +2273,38 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
|
|||||||
} else {
|
} else {
|
||||||
$.console.warn('Attempting to display a reference strip while "sequenceMode" is off.');
|
$.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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user