openseadragon/test/demo/collections/main.js

382 lines
12 KiB
JavaScript
Raw Normal View History

/* globals $, App */
2014-07-18 03:24:28 +04:00
(function() {
window.App = {
2014-07-18 03:24:28 +04:00
init: function() {
var self = this;
2014-12-04 23:00:04 +03:00
var testInitialOpen = true;
2014-11-22 02:18:25 +03:00
var testOverlays = false;
var testMargins = false;
var testNavigator = false;
var margins;
2014-10-17 01:00:07 +04:00
var config = {
2014-11-06 03:39:35 +03:00
// debugMode: true,
2014-07-22 22:13:22 +04:00
zoomPerScroll: 1.02,
showNavigator: testNavigator,
// defaultZoomLevel: 2,
// homeFillsViewer: true,
2014-11-21 01:25:17 +03:00
// sequenceMode: true,
// showReferenceStrip: true,
2014-11-18 00:17:24 +03:00
// referenceStripScroll: 'vertical',
2014-11-15 03:51:02 +03:00
navPrevNextWrap: false,
preserveViewport: false,
// collectionMode: true,
// collectionRows: 1,
2014-11-15 03:51:02 +03:00
// collectionLayout: 'vertical',
// collectionTileSize: 10,
// collectionTileMargin: 10,
// wrapHorizontal: true,
// wrapVertical: true,
2014-07-18 03:24:28 +04:00
id: "contentDiv",
2014-07-22 22:13:22 +04:00
prefixUrl: "../../../build/openseadragon/images/"
2014-10-17 01:00:07 +04:00
};
2014-07-18 03:24:28 +04:00
var highsmith = {
Image: {
xmlns: "http://schemas.microsoft.com/deepzoom/2008",
Url: "http://openseadragon.github.io/example-images/highsmith/highsmith_files/",
Format: "jpg",
Overlap: "2",
TileSize: "256",
Size: {
Height: "9221",
Width: "7026"
}
}
};
if (testInitialOpen) {
config.tileSources = [
2014-11-22 02:18:25 +03:00
{
tileSource: "../../data/testpattern.dzi",
x: 4,
y: 2,
width: 2
},
2014-11-15 04:19:04 +03:00
{
tileSource: "../../data/tall.dzi",
x: 1.5,
y: 0,
width: 1
},
{
tileSource: '../../data/wide.dzi',
opacity: 1,
x: 0,
y: 1.5,
height: 1
}
];
// config.tileSources = {
// tileSource: highsmith,
// width: 1
// };
}
2014-07-18 03:24:28 +04:00
if (testOverlays) {
2014-11-06 03:54:03 +03:00
config.overlays = [
{
id: "overlay1",
x: 2,
2014-11-06 03:54:03 +03:00
y: 0,
width: 0.25,
height: 0.25
},
{
px: 13,
py: 120,
width: 124,
height: 132,
id: "overlay"
},
{
px: 400,
py: 500,
width: 400,
height: 400,
id: "fixed-overlay",
placement: "TOP_LEFT"
}
];
}
if (testMargins) {
margins = {
top: 250,
left: 250,
right: 250,
bottom: 250
};
config.viewportMargins = margins;
}
2014-10-18 01:27:24 +04:00
2014-10-17 01:00:07 +04:00
this.viewer = OpenSeadragon(config);
if (testInitialOpen) {
2014-12-13 03:28:02 +03:00
function openHandler() {
self.viewer.removeHandler('open', openHandler);
}
this.viewer.addHandler( "open", openHandler);
}
if (testMargins) {
this.viewer.addHandler('animation', function() {
var box = new OpenSeadragon.Rect(margins.left, margins.top,
$('#contentDiv').width() - (margins.left + margins.right),
$('#contentDiv').height() - (margins.top + margins.bottom));
2024-01-10 20:13:00 +03:00
// If drawDebuggingRect is implemented, use it to show the box.
// This is not implemented by all drawers however.
2023-03-11 19:38:21 +03:00
self.viewer.drawer.drawDebuggingRect(box);
});
}
2014-11-04 04:14:17 +03:00
2014-11-18 01:03:14 +03:00
if (!testInitialOpen) {
2014-12-03 00:17:56 +03:00
this.basicTest();
2014-11-18 01:03:14 +03:00
}
2014-10-17 01:00:07 +04:00
},
2014-12-02 22:44:02 +03:00
// ----------
shrink: function(index) {
index = index || 0;
var image = this.viewer.world.getItemAt(index);
image.setWidth(image.getBounds().width * 0.3);
},
// ----------
move: function(index) {
index = index || 0;
var image = this.viewer.world.getItemAt(index);
var point = image.getBounds().getTopLeft();
point.x += image.getBounds().width * 0.3;
image.setPosition(point);
},
2014-12-03 00:17:56 +03:00
// ----------
add: function() {
var self = this;
this.viewer.addTiledImage({
tileSource: "../../data/testpattern.dzi",
width: 1,
success: function() {
self.viewer.viewport.goHome();
}
});
},
2014-12-02 03:29:21 +03:00
// ----------
toggle: function() {
var $el = $(this.viewer.element);
$el.toggleClass('small');
},
2014-10-17 01:00:07 +04:00
// ----------
basicTest: function() {
var self = this;
this.viewer.addHandler('open', function() {
});
this.viewer.open({
2014-12-02 22:44:02 +03:00
tileSource: "../../data/testpattern.dzi",
width: 1
});
},
// ----------
crossTest: function() {
var self = this;
2014-07-18 03:24:28 +04:00
this.viewer.addHandler( "open", function() {
var options = {
tileSource: '../../data/wide.dzi',
opacity: 1,
x: 0,
y: 1.5,
height: 1
};
var addItemHandler = function( event ) {
if ( event.options === options ) {
self.viewer.world.removeHandler( "add-item", addItemHandler );
self.viewer.viewport.goHome();
}
};
self.viewer.world.addHandler( "add-item", addItemHandler );
self.viewer.addTiledImage( options );
2014-07-18 03:24:28 +04:00
});
2014-07-22 22:13:22 +04:00
this.viewer.open({
tileSource: "../../data/tall.dzi",
2014-07-22 22:13:22 +04:00
x: 1.5,
y: 0,
width: 1
2014-07-22 22:13:22 +04:00
});
2014-07-18 03:24:28 +04:00
},
2014-10-30 02:11:21 +03:00
// ----------
crossTest2: function() {
this.viewer.open([
{
tileSource: "../../data/tall.dzi",
x: 1.5,
y: 0,
width: 1
},
2014-10-30 02:11:21 +03:00
{
tileSource: '../../data/wide.dzi',
x: 0,
y: 1.5,
height: 1
}
]);
},
// ----------
crossTest3: function() {
var self = this;
var expected = 2;
var loaded = 0;
this.viewer.world.addHandler('add-item', function() {
loaded++;
if (loaded === expected) {
// self.viewer.viewport.goHome();
}
});
this.viewer.addTiledImage({
tileSource: "../../data/tall.dzi",
x: 1.5,
y: 0,
width: 1
});
this.viewer.addTiledImage({
tileSource: '../../data/wide.dzi',
opacity: 1,
x: 0,
y: 1.5,
height: 1
});
},
2014-11-12 04:14:48 +03:00
// ----------
collectionTest: function() {
var tileSources = [];
var random;
2014-11-12 04:14:48 +03:00
for (var i = 0; i < 10; i++) {
random = Math.random();
if (random < 0.33) {
tileSources.push('../../data/testpattern.dzi');
} else if (random < 0.66) {
tileSources.push('../../data/tall.dzi');
} else {
tileSources.push('../../data/wide.dzi');
}
2014-11-12 04:14:48 +03:00
}
this.viewer.open(tileSources);
},
2014-07-18 03:24:28 +04:00
// ----------
gridTest: function() {
2014-07-18 03:24:28 +04:00
var self = this;
var startX = -3;
var expected = 0;
var loaded = 0;
this.viewer.addHandler( "open", function() {
self.viewer.world.addHandler('add-item', function() {
loaded++;
if (loaded === expected) {
self.viewer.viewport.goHome(true);
}
});
2014-07-18 03:24:28 +04:00
var x, y;
for (y = 0; y < 6; y++) {
for (x = 0; x < 6; x++) {
if (!x && !y) {
continue;
}
var options = {
tileSource: '../../data/testpattern.dzi',
x: startX + x,
y: y,
width: 1
};
expected++;
self.viewer.addTiledImage( options );
}
2014-07-18 03:24:28 +04:00
}
});
this.viewer.open({
tileSource: "../../data/testpattern.dzi",
x: startX,
y: 0,
width: 1
});
},
// ----------
bigTest: function() {
this.viewer.open({
tileSource: "../../data/testpattern.dzi",
x: -2,
y: -2,
width: 6
});
2014-10-17 01:00:07 +04:00
},
// ----------
cjTest: function() {
var imageKey = "e-pluribus-unum";
var imageXML = '<?xml version="1.0" encoding="UTF-8"?><Image TileSize="254" Overlap="1" Format="png" xmlns="http://schemas.microsoft.com/deepzoom/2008"><Size Width="88560" Height="88560"/></Image>';
var $xml = $($.parseXML(imageXML));
var $image = $xml.find('Image');
var $size = $xml.find('Size');
var dzi = {
Image: {
xmlns: $image.attr('xmlns'),
Url: "http://chrisjordan.com/dzi/" + imageKey + '_files/',
Format: $image.attr('Format'),
Overlap: $image.attr('Overlap'),
TileSize: $image.attr('TileSize'),
Size: {
Height: $size.attr('Height'),
Width: $size.attr('Width')
}
}
};
this.viewer.open({
tileSource: dzi,
2014-10-17 01:00:07 +04:00
width: 100
});
},
// ----------
stanfordTest: function() {
var info = {"@context":"http://library.stanford.edu/iiif/image-api/1.1/context.json","@id":"http://ids.lib.harvard.edu/ids/iiif/48530377","width":6251,"height":109517,"scale_factors":[1,2,4,8,16,32],"tile_width":256,"tile_height":256,"formats":["jpg"],"qualities":["native"],"profile":"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1"};
this.viewer.open(info);
2014-07-18 03:24:28 +04:00
}
};
$(document).ready(function() {
App.init();
});
})();