mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-22 05:06:09 +03:00
Getter & setter for Viewport.maxZoomPixelRatio
This commit is contained in:
parent
63d8d63c1f
commit
b0926b3e69
@ -1789,7 +1789,43 @@ $.Viewport.prototype = {
|
|||||||
*/
|
*/
|
||||||
this.viewer.raiseEvent('flip', {flipped: state});
|
this.viewer.raiseEvent('flip', {flipped: state});
|
||||||
return this;
|
return this;
|
||||||
}
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets current max zoom pixel ratio
|
||||||
|
* @function
|
||||||
|
* @returns {Number} Max zoom pixel ratio
|
||||||
|
*/
|
||||||
|
getMaxZoomPixelRatio: function() {
|
||||||
|
return this.maxZoomPixelRatio;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets max zoom pixel ratio
|
||||||
|
* @function
|
||||||
|
* @param {Number} ratio - Max zoom pixel ratio
|
||||||
|
* @param {Boolean} [constraints=false] - Apply constraints after setting ratio;
|
||||||
|
* Takes effect only if current zoom is greater than set max zoom pixel ratio
|
||||||
|
* @param {Boolean} [immediately=false] - Whether to animate to new zoom
|
||||||
|
*/
|
||||||
|
setMaxZoomPixelRatio: function(ratio, constraints, immediately) {
|
||||||
|
constraints = constraints || false;
|
||||||
|
immediately = immediately || false;
|
||||||
|
|
||||||
|
$.console.assert(!isNaN(ratio), "[Viewport.setMaxZoomPixelRatio] ratio must be a number");
|
||||||
|
|
||||||
|
if (isNaN(ratio)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.maxZoomPixelRatio = ratio;
|
||||||
|
|
||||||
|
if (constraints) {
|
||||||
|
if (this.getZoom() > this.getMaxZoom()) {
|
||||||
|
this.applyConstraints(immediately);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1407,4 +1407,25 @@
|
|||||||
viewer.open(DZI_PATH);
|
viewer.open(DZI_PATH);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
QUnit.test('setMaxZoomPixelRatio', function(assert) {
|
||||||
|
var done = assert.async();
|
||||||
|
var openHandler = function(event) {
|
||||||
|
viewer.removeHandler('open', openHandler);
|
||||||
|
var viewport = viewer.viewport;
|
||||||
|
|
||||||
|
for (var i = 0; i < testZoomLevels.length; i++) {
|
||||||
|
viewport.setMaxZoomPixelRatio(testZoomLevels[i])
|
||||||
|
assert.equal(viewport.getMaxZoomPixelRatio(), testZoomLevels[i], "Max zoom pixel ratio is set correctly.");
|
||||||
|
}
|
||||||
|
|
||||||
|
viewport.zoomTo(viewport.getMaxZoom())
|
||||||
|
viewport.setMaxZoomPixelRatio(testZoomLevels[0], true)
|
||||||
|
assert.equal(viewport.getZoom(), viewport.getMaxZoom(), "Zoom should be adjusted to max zoom level.");
|
||||||
|
|
||||||
|
done();
|
||||||
|
};
|
||||||
|
viewer.addHandler('open', openHandler);
|
||||||
|
viewer.open(DZI_PATH);
|
||||||
|
});
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
Loading…
Reference in New Issue
Block a user