* You can now change viewport margins after the viewer is created (#721)

This commit is contained in:
Ian Gilman 2015-10-29 14:29:59 -07:00
parent 6be51a5d82
commit 6b208f8a75
2 changed files with 39 additions and 8 deletions

View File

@ -33,6 +33,7 @@ OPENSEADRAGON CHANGELOG
* Fixed overlays position (use rounding instead of flooring and ceiling) (#741)
* Fixed issue with including overlays in your tileSources array when creating/opening in the viewer (#745)
* Fixed issue in iOS devices that would cause all touch events to fail after a Multitasking Gesture was triggered (#744)
* You can now change viewport margins after the viewer is created (#721)
2.0.0:

View File

@ -111,10 +111,7 @@ $.Viewport = function( options ) {
}, options );
this._containerInnerSize = new $.Point(
Math.max(1, this.containerSize.x - (this._margins.left + this._margins.right)),
Math.max(1, this.containerSize.y - (this._margins.top + this._margins.bottom))
);
this._updateContainerInnerSize();
this.centerSpringX = new $.Spring({
initial: 0,
@ -314,6 +311,34 @@ $.Viewport.prototype = /** @lends OpenSeadragon.Viewport.prototype */{
);
},
/**
* @function
* The margins push the "home" region in from the sides by the specified amounts.
* @returns {Object} Properties (Numbers, in screen coordinates): left, top, right, bottom.
*/
getMargins: function() {
return $.extend({}, this._margins); // Make a copy so we are not returning our original
},
/**
* @function
* The margins push the "home" region in from the sides by the specified amounts.
* @param {Object} margins - Properties (Numbers, in screen coordinates): left, top, right, bottom.
*/
setMargins: function(margins) {
$.console.assert($.type(margins) === 'object', '[Viewport.setMargins] margins must be an object');
this._margins = $.extend({
left: 0,
top: 0,
right: 0,
bottom: 0
}, margins);
this._updateContainerInnerSize();
this.viewer.forceRedraw();
},
/**
* @function
* @param {Boolean} current - Pass true for the current location; defaults to false (target location).
@ -830,10 +855,7 @@ $.Viewport.prototype = /** @lends OpenSeadragon.Viewport.prototype */{
this.containerSize.x = newContainerSize.x;
this.containerSize.y = newContainerSize.y;
this._containerInnerSize = new $.Point(
Math.max(1, newContainerSize.x - (this._margins.left + this._margins.right)),
Math.max(1, newContainerSize.y - (this._margins.top + this._margins.bottom))
);
this._updateContainerInnerSize();
if ( maintain ) {
// TODO: widthDeltaFactor will always be 1; probably not what's intended
@ -863,6 +885,14 @@ $.Viewport.prototype = /** @lends OpenSeadragon.Viewport.prototype */{
return this.fitBounds( newBounds, true );
},
// private
_updateContainerInnerSize: function() {
this._containerInnerSize = new $.Point(
Math.max(1, this.containerSize.x - (this._margins.left + this._margins.right)),
Math.max(1, this.containerSize.y - (this._margins.top + this._margins.bottom))
);
},
/**
* @function
*/