mirror of
https://github.com/openseadragon/openseadragon.git
synced 2025-02-16 14:53:14 +03:00
First version of clip feature
This commit is contained in:
parent
eb39e4072e
commit
e1d36ffb14
@ -258,6 +258,34 @@ $.Drawer.prototype = /** @lends OpenSeadragon.Drawer.prototype */{
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// private
|
||||||
|
saveContext: function() {
|
||||||
|
if (!this.useCanvas) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.context.save();
|
||||||
|
},
|
||||||
|
|
||||||
|
// private
|
||||||
|
restoreContext: function() {
|
||||||
|
if (!this.useCanvas) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.context.restore();
|
||||||
|
},
|
||||||
|
|
||||||
|
// private
|
||||||
|
setClip: function(rect) {
|
||||||
|
if (!this.useCanvas) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.context.rect(rect.x, rect.y, rect.width, rect.height);
|
||||||
|
this.context.clip();
|
||||||
|
},
|
||||||
|
|
||||||
// private
|
// private
|
||||||
drawDebugInfo: function( tile, count, i ){
|
drawDebugInfo: function( tile, count, i ){
|
||||||
if ( this.useCanvas ) {
|
if ( this.useCanvas ) {
|
||||||
|
@ -72,6 +72,8 @@ $.TiledImage = function( options ) {
|
|||||||
$.console.assert( options.viewer, "[TiledImage] options.viewer is required" );
|
$.console.assert( options.viewer, "[TiledImage] options.viewer is required" );
|
||||||
$.console.assert( options.imageLoader, "[TiledImage] options.imageLoader is required" );
|
$.console.assert( options.imageLoader, "[TiledImage] options.imageLoader is required" );
|
||||||
$.console.assert( options.source, "[TiledImage] options.source is required" );
|
$.console.assert( options.source, "[TiledImage] options.source is required" );
|
||||||
|
$.console.assert(!options.clip || options.clip instanceof $.Rect,
|
||||||
|
"[TiledImage] options.clip must be an OpenSeadragon.Rect if present");
|
||||||
|
|
||||||
$.EventSource.call( this );
|
$.EventSource.call( this );
|
||||||
|
|
||||||
@ -84,6 +86,9 @@ $.TiledImage = function( options ) {
|
|||||||
this._imageLoader = options.imageLoader;
|
this._imageLoader = options.imageLoader;
|
||||||
delete options.imageLoader;
|
delete options.imageLoader;
|
||||||
|
|
||||||
|
this._clip = options.clip;
|
||||||
|
delete options.clip;
|
||||||
|
|
||||||
var x = options.x || 0;
|
var x = options.x || 0;
|
||||||
delete options.x;
|
delete options.x;
|
||||||
var y = options.y || 0;
|
var y = options.y || 0;
|
||||||
@ -1116,6 +1121,20 @@ function drawTiles( tiledImage, lastDrawn ){
|
|||||||
position,
|
position,
|
||||||
tileSource;
|
tileSource;
|
||||||
|
|
||||||
|
var usedClip = false;
|
||||||
|
if (tiledImage._clip) {
|
||||||
|
tiledImage._drawer.saveContext();
|
||||||
|
var box = tiledImage.imageToViewportRectangle(tiledImage._clip, true);
|
||||||
|
var topLeft = tiledImage.viewport.pixelFromPoint(box.getTopLeft(), true);
|
||||||
|
var size = tiledImage.viewport.deltaPixelsFromPoints(box.getSize(), true);
|
||||||
|
box = new OpenSeadragon.Rect(Math.round(topLeft.x * $.pixelDensityRatio),
|
||||||
|
Math.round(topLeft.y * $.pixelDensityRatio),
|
||||||
|
Math.round(size.x * $.pixelDensityRatio),
|
||||||
|
Math.round(size.y * $.pixelDensityRatio));
|
||||||
|
tiledImage._drawer.setClip(box);
|
||||||
|
usedClip = true;
|
||||||
|
}
|
||||||
|
|
||||||
for ( i = lastDrawn.length - 1; i >= 0; i-- ) {
|
for ( i = lastDrawn.length - 1; i >= 0; i-- ) {
|
||||||
tile = lastDrawn[ i ];
|
tile = lastDrawn[ i ];
|
||||||
tiledImage._drawer.drawTile( tile, tiledImage._drawingHandler );
|
tiledImage._drawer.drawTile( tile, tiledImage._drawingHandler );
|
||||||
@ -1147,6 +1166,10 @@ function drawTiles( tiledImage, lastDrawn ){
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (usedClip) {
|
||||||
|
tiledImage._drawer.restoreContext();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}( OpenSeadragon ));
|
}( OpenSeadragon ));
|
||||||
|
@ -1280,6 +1280,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
|
|||||||
y: queueItem.options.y,
|
y: queueItem.options.y,
|
||||||
width: queueItem.options.width,
|
width: queueItem.options.width,
|
||||||
height: queueItem.options.height,
|
height: queueItem.options.height,
|
||||||
|
clip: queueItem.options.clip,
|
||||||
springStiffness: _this.springStiffness,
|
springStiffness: _this.springStiffness,
|
||||||
animationTime: _this.animationTime,
|
animationTime: _this.animationTime,
|
||||||
minZoomImageRatio: _this.minZoomImageRatio,
|
minZoomImageRatio: _this.minZoomImageRatio,
|
||||||
|
@ -22,7 +22,10 @@
|
|||||||
this.pages = this.createPages();
|
this.pages = this.createPages();
|
||||||
|
|
||||||
var tileSources = $.map(this.pages, function(v, i) {
|
var tileSources = $.map(this.pages, function(v, i) {
|
||||||
return v.starter.tileSource;
|
return {
|
||||||
|
tileSource: v.starter.tileSource,
|
||||||
|
clip: v.starter.clip
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
this.viewer = OpenSeadragon({
|
this.viewer = OpenSeadragon({
|
||||||
@ -543,11 +546,11 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.panBounds = null;
|
||||||
|
|
||||||
box = new OpenSeadragon.Rect(x, y, width, height);
|
box = new OpenSeadragon.Rect(x, y, width, height);
|
||||||
this.viewer.viewport.fitBounds(box, config.immediately);
|
this.viewer.viewport.fitBounds(box, config.immediately);
|
||||||
|
|
||||||
this.panBounds = null;
|
|
||||||
|
|
||||||
var setPanBounds = function() {
|
var setPanBounds = function() {
|
||||||
if (self.mode === 'page' || self.mode === 'book') {
|
if (self.mode === 'page' || self.mode === 'book') {
|
||||||
self.panBounds = box;
|
self.panBounds = box;
|
||||||
|
@ -19,6 +19,11 @@
|
|||||||
tileSource: config.tileSource
|
tileSource: config.tileSource
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (config.clip) {
|
||||||
|
this.starter.clip = new OpenSeadragon.Rect(config.clip.x, config.clip.y,
|
||||||
|
config.clip.width, config.clip.height);
|
||||||
|
}
|
||||||
|
|
||||||
this.main = {};
|
this.main = {};
|
||||||
|
|
||||||
this.alternateIndex = -1;
|
this.alternateIndex = -1;
|
||||||
@ -56,6 +61,7 @@
|
|||||||
App.viewer.world.removeItem(this.main.tiledImage);
|
App.viewer.world.removeItem(this.main.tiledImage);
|
||||||
App.viewer.addTiledImage({
|
App.viewer.addTiledImage({
|
||||||
tileSource: itemInfo.tileSource,
|
tileSource: itemInfo.tileSource,
|
||||||
|
clip: itemInfo.clip,
|
||||||
index: this.pageIndex,
|
index: this.pageIndex,
|
||||||
success: function(event) {
|
success: function(event) {
|
||||||
self.setDetail(self.main, itemInfo, event.item);
|
self.setDetail(self.main, itemInfo, event.item);
|
||||||
@ -81,6 +87,7 @@
|
|||||||
|
|
||||||
App.viewer.addTiledImage({
|
App.viewer.addTiledImage({
|
||||||
tileSource: v.tileSource,
|
tileSource: v.tileSource,
|
||||||
|
clip: v.clip,
|
||||||
success: function(event) {
|
success: function(event) {
|
||||||
v.tiledImage = event.item;
|
v.tiledImage = event.item;
|
||||||
self.placeDetail(v, true);
|
self.placeDetail(v, true);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user