Add clip-change event.

This commit is contained in:
Antoine Vandecreme 2016-08-28 14:39:14 +02:00
parent 33332bf774
commit 62c96ebad7
5 changed files with 43 additions and 1712 deletions

View File

@ -341,9 +341,12 @@ $.extend( $.Navigator.prototype, $.EventSource.prototype, $.Viewer.prototype, /*
myItem._originalForNavigator = original; myItem._originalForNavigator = original;
_this._matchBounds(myItem, original, true); _this._matchBounds(myItem, original, true);
original.addHandler('bounds-change', function() { function matchBounds() {
_this._matchBounds(myItem, original); _this._matchBounds(myItem, original);
}); }
original.addHandler('bounds-change', matchBounds);
original.addHandler('clip-change', matchBounds);
} }
}); });

View File

@ -739,13 +739,12 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag
* @param {OpenSeadragon.Rect|null} newClip - An area, in image pixels, to clip to * @param {OpenSeadragon.Rect|null} newClip - An area, in image pixels, to clip to
* (portions of the image outside of this area will not be visible). Only works on * (portions of the image outside of this area will not be visible). Only works on
* browsers that support the HTML5 canvas. * browsers that support the HTML5 canvas.
* @fires OpenSeadragon.TiledImage.event:clip-change
*/ */
setClip: function(newClip) { setClip: function(newClip) {
$.console.assert(!newClip || newClip instanceof $.Rect, $.console.assert(!newClip || newClip instanceof $.Rect,
"[TiledImage.setClip] newClip must be an OpenSeadragon.Rect or null"); "[TiledImage.setClip] newClip must be an OpenSeadragon.Rect or null");
//TODO: should this._raiseBoundsChange(); be called?
if (newClip instanceof $.Rect) { if (newClip instanceof $.Rect) {
this._clip = newClip.clone(); this._clip = newClip.clone();
} else { } else {
@ -753,6 +752,16 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag
} }
this._needsDraw = true; this._needsDraw = true;
/**
* Raised when the TiledImage's clip is changed.
* @event clip-change
* @memberOf OpenSeadragon.TiledImage
* @type {object}
* @property {OpenSeadragon.TiledImage} eventSource - A reference to the
* TiledImage which raised the event.
* @property {?Object} userData - Arbitrary subscriber-defined object.
*/
this.raiseEvent('clip-change');
}, },
/** /**
@ -781,6 +790,7 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag
/** /**
* Set the current rotation of this tiled image in degrees. * Set the current rotation of this tiled image in degrees.
* @param {Number} degrees the rotation in degrees. * @param {Number} degrees the rotation in degrees.
* @fires OpenSeadragon.TiledImage.event:bounds-change
*/ */
setRotation: function(degrees) { setRotation: function(degrees) {
degrees = $.positiveModulo(degrees, 360); degrees = $.positiveModulo(degrees, 360);
@ -860,7 +870,8 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag
* @event bounds-change * @event bounds-change
* @memberOf OpenSeadragon.TiledImage * @memberOf OpenSeadragon.TiledImage
* @type {object} * @type {object}
* @property {OpenSeadragon.World} eventSource - A reference to the TiledImage which raised the event. * @property {OpenSeadragon.TiledImage} eventSource - A reference to the
* TiledImage which raised the event.
* @property {?Object} userData - Arbitrary subscriber-defined object. * @property {?Object} userData - Arbitrary subscriber-defined object.
*/ */
this.raiseEvent('bounds-change'); this.raiseEvent('bounds-change');

File diff suppressed because it is too large Load Diff

View File

@ -94,6 +94,7 @@ $.extend( $.World.prototype, $.EventSource.prototype, /** @lends OpenSeadragon.W
this._needsDraw = true; this._needsDraw = true;
item.addHandler('bounds-change', this._delegatedFigureSizes); item.addHandler('bounds-change', this._delegatedFigureSizes);
item.addHandler('clip-change', this._delegatedFigureSizes);
/** /**
* Raised when an item is added to the World. * Raised when an item is added to the World.
@ -194,6 +195,7 @@ $.extend( $.World.prototype, $.EventSource.prototype, /** @lends OpenSeadragon.W
} }
item.removeHandler('bounds-change', this._delegatedFigureSizes); item.removeHandler('bounds-change', this._delegatedFigureSizes);
item.removeHandler('clip-change', this._delegatedFigureSizes);
item.destroy(); item.destroy();
this._items.splice( index, 1 ); this._items.splice( index, 1 );
this._figureSizes(); this._figureSizes();
@ -213,6 +215,7 @@ $.extend( $.World.prototype, $.EventSource.prototype, /** @lends OpenSeadragon.W
for (var i = 0; i < this._items.length; i++) { for (var i = 0; i < this._items.length; i++) {
item = this._items[i]; item = this._items[i];
item.removeHandler('bounds-change', this._delegatedFigureSizes); item.removeHandler('bounds-change', this._delegatedFigureSizes);
item.removeHandler('clip-change', this._delegatedFigureSizes);
item.destroy(); item.destroy();
} }

View File

@ -222,6 +222,27 @@
}); });
}); });
// ----------
asyncTest('clip-change event', function() {
expect(0);
var clip = new OpenSeadragon.Rect(100, 100, 800, 800);
viewer.addHandler('open', function() {
var image = viewer.world.getItemAt(0);
image.addOnceHandler('clip-change', function() {
image.addOnceHandler('clip-change', function() {
start();
});
image.setClip(clip);
});
image.setClip(null);
});
viewer.open({
tileSource: '/test/data/testpattern.dzi'
});
});
// ---------- // ----------
asyncTest('getClipBounds', function() { asyncTest('getClipBounds', function() {
var clip = new OpenSeadragon.Rect(100, 200, 800, 500); var clip = new OpenSeadragon.Rect(100, 200, 800, 500);