2017-12-05 05:01:30 +03:00
|
|
|
/* global QUnit, Util, $, console, testLog */
|
2014-02-05 02:09:12 +04:00
|
|
|
|
2016-03-31 20:25:59 +03:00
|
|
|
(function() {
|
2014-02-05 23:57:47 +04:00
|
|
|
var viewer;
|
2016-03-29 22:29:36 +03:00
|
|
|
// jQuery.position can give results quite different than what set in style.left
|
|
|
|
var epsilon = 1;
|
2014-02-05 02:09:12 +04:00
|
|
|
|
2017-12-05 05:01:30 +03:00
|
|
|
QUnit.module("Overlays", {
|
|
|
|
beforeEach: function() {
|
2016-03-31 20:25:59 +03:00
|
|
|
var example = $('<div id="example-overlays"></div>').appendTo("#qunit-fixture");
|
|
|
|
var fixedOverlay = $('<div id="fixed-overlay"></div>').appendTo(example);
|
|
|
|
fixedOverlay.width(70);
|
|
|
|
fixedOverlay.height(60);
|
2014-02-05 02:09:12 +04:00
|
|
|
|
|
|
|
testLog.reset();
|
|
|
|
},
|
2017-12-05 05:01:30 +03:00
|
|
|
afterEach: function() {
|
2014-02-05 02:09:12 +04:00
|
|
|
resetTestVariables();
|
2024-01-10 20:13:00 +03:00
|
|
|
|
|
|
|
if (viewer){
|
2023-06-27 04:29:08 +03:00
|
|
|
viewer.destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
viewer = null;
|
2014-02-05 02:09:12 +04:00
|
|
|
}
|
2016-03-31 20:25:59 +03:00
|
|
|
});
|
2014-02-05 02:09:12 +04:00
|
|
|
|
|
|
|
var resetTestVariables = function() {
|
2024-01-18 01:07:25 +03:00
|
|
|
if (viewer){
|
|
|
|
let errors = viewer.drawer._numGlMaxTextureErrors;
|
|
|
|
if(errors > 0){
|
|
|
|
console.log('Number of times MAX_TEXTURE_IMAGE_UNITS had a bad value:', errors);
|
|
|
|
}
|
|
|
|
viewer.destroy();
|
2014-02-05 02:09:12 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-03-31 20:25:59 +03:00
|
|
|
function waitForViewer(handler, count) {
|
|
|
|
if (typeof count !== "number") {
|
2014-02-05 02:09:12 +04:00
|
|
|
count = 0;
|
|
|
|
}
|
|
|
|
var ready = viewer.isOpen() &&
|
|
|
|
viewer.drawer !== null &&
|
2014-12-02 22:44:02 +03:00
|
|
|
!viewer.world.needsDraw() &&
|
2016-03-31 20:25:59 +03:00
|
|
|
Util.equalsWithVariance(viewer.viewport.getBounds(true).x,
|
|
|
|
viewer.viewport.getBounds().x, 0.000) &&
|
|
|
|
Util.equalsWithVariance(viewer.viewport.getBounds(true).y,
|
|
|
|
viewer.viewport.getBounds().y, 0.000) &&
|
|
|
|
Util.equalsWithVariance(viewer.viewport.getBounds(true).width,
|
|
|
|
viewer.viewport.getBounds().width, 0.000);
|
|
|
|
|
|
|
|
if (ready) {
|
2014-02-05 02:09:12 +04:00
|
|
|
handler();
|
2016-03-31 20:25:59 +03:00
|
|
|
} else if (count < 50) {
|
2014-02-05 02:09:12 +04:00
|
|
|
count++;
|
2016-03-31 20:25:59 +03:00
|
|
|
setTimeout(function() {
|
|
|
|
waitForViewer(handler, count);
|
|
|
|
}, 100);
|
2014-02-05 02:09:12 +04:00
|
|
|
} else {
|
2016-03-31 20:25:59 +03:00
|
|
|
console.log("waitForViewer:" + viewer.isOpen( ) + ":" + viewer.drawer +
|
|
|
|
":" + viewer.world.needsDraw());
|
2014-02-05 02:09:12 +04:00
|
|
|
handler();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-05 05:01:30 +03:00
|
|
|
QUnit.test('Overlays via viewer options', function(assert) {
|
|
|
|
var done = assert.async();
|
2016-03-31 20:25:59 +03:00
|
|
|
viewer = OpenSeadragon({
|
2014-02-05 02:09:12 +04:00
|
|
|
id: 'example-overlays',
|
|
|
|
prefixUrl: '/build/openseadragon/images/',
|
2016-03-31 20:25:59 +03:00
|
|
|
tileSources: ['/test/data/testpattern.dzi', '/test/data/testpattern.dzi'],
|
2014-02-05 02:09:12 +04:00
|
|
|
springStiffness: 100, // Faster animation = faster tests
|
2016-03-31 20:25:59 +03:00
|
|
|
overlays: [{
|
2014-02-05 02:09:12 +04:00
|
|
|
x: 0.1,
|
|
|
|
y: 0.4,
|
|
|
|
width: 0.09,
|
|
|
|
height: 0.09,
|
|
|
|
id: "overlay"
|
2016-03-31 20:25:59 +03:00
|
|
|
}]
|
|
|
|
});
|
|
|
|
viewer.addHandler('open', openHandler);
|
2014-02-05 02:09:12 +04:00
|
|
|
|
|
|
|
function openHandler() {
|
2016-03-31 20:25:59 +03:00
|
|
|
viewer.removeHandler('open', openHandler);
|
2014-02-05 02:09:12 +04:00
|
|
|
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.equal(viewer.overlays.length, 1, "Global overlay should be added.");
|
|
|
|
assert.equal(viewer.currentOverlays.length, 1, "Global overlay should be open.");
|
2014-02-05 02:09:12 +04:00
|
|
|
|
2016-03-31 20:25:59 +03:00
|
|
|
viewer.addHandler('open', openPageHandler);
|
|
|
|
viewer.goToPage(1);
|
2014-02-05 02:09:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function openPageHandler() {
|
2016-03-31 20:25:59 +03:00
|
|
|
viewer.removeHandler('open', openPageHandler);
|
2014-02-05 02:09:12 +04:00
|
|
|
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.equal(viewer.overlays.length, 1, "Global overlay should stay after page switch.");
|
|
|
|
assert.equal(viewer.currentOverlays.length, 1, "Global overlay should re-open after page switch.");
|
2014-02-05 02:09:12 +04:00
|
|
|
|
2016-03-31 20:25:59 +03:00
|
|
|
viewer.addHandler('close', closeHandler);
|
2014-02-05 02:09:12 +04:00
|
|
|
viewer.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
function closeHandler() {
|
2016-03-31 20:25:59 +03:00
|
|
|
viewer.removeHandler('close', closeHandler);
|
2014-02-05 02:09:12 +04:00
|
|
|
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.equal(viewer.overlays.length, 1, "Global overlay should not be removed on close.");
|
|
|
|
assert.equal(viewer.currentOverlays.length, 0, "Global overlay should be closed on close.");
|
2014-02-05 02:09:12 +04:00
|
|
|
|
2017-12-05 05:01:30 +03:00
|
|
|
done();
|
2014-02-05 02:09:12 +04:00
|
|
|
}
|
2016-03-31 20:25:59 +03:00
|
|
|
});
|
2014-02-05 02:09:12 +04:00
|
|
|
|
2017-12-05 05:01:30 +03:00
|
|
|
QUnit.test('Page Overlays via viewer options', function(assert) {
|
|
|
|
var done = assert.async();
|
2016-03-31 20:25:59 +03:00
|
|
|
viewer = OpenSeadragon({
|
2014-02-05 02:09:12 +04:00
|
|
|
id: 'example-overlays',
|
|
|
|
prefixUrl: '/build/openseadragon/images/',
|
2016-03-31 20:25:59 +03:00
|
|
|
tileSources: [{
|
2014-02-05 02:09:12 +04:00
|
|
|
Image: {
|
|
|
|
xmlns: "http://schemas.microsoft.com/deepzoom/2008",
|
|
|
|
Url: "/test/data/testpattern_files/",
|
|
|
|
Format: "jpg",
|
|
|
|
Overlap: "1",
|
|
|
|
TileSize: "254",
|
|
|
|
Size: {
|
|
|
|
Width: 1000,
|
|
|
|
Height: 1000
|
|
|
|
}
|
|
|
|
},
|
2016-03-31 20:25:59 +03:00
|
|
|
overlays: [{
|
2014-02-05 02:09:12 +04:00
|
|
|
x: 0.1,
|
|
|
|
y: 0.4,
|
|
|
|
width: 0.09,
|
|
|
|
height: 0.09,
|
|
|
|
id: "overlay"
|
2016-03-31 20:25:59 +03:00
|
|
|
}]
|
2014-02-05 02:09:12 +04:00
|
|
|
}, {
|
|
|
|
Image: {
|
|
|
|
xmlns: "http://schemas.microsoft.com/deepzoom/2008",
|
|
|
|
Url: "/test/data/testpattern_files/",
|
|
|
|
Format: "jpg",
|
|
|
|
Overlap: "1",
|
|
|
|
TileSize: "254",
|
|
|
|
Size: {
|
|
|
|
Width: 1000,
|
|
|
|
Height: 1000
|
|
|
|
}
|
|
|
|
}
|
2016-03-31 20:25:59 +03:00
|
|
|
}],
|
2014-02-05 02:09:12 +04:00
|
|
|
springStiffness: 100 // Faster animation = faster tests
|
2016-03-31 20:25:59 +03:00
|
|
|
});
|
|
|
|
viewer.addHandler('open', openHandler);
|
2014-02-05 02:09:12 +04:00
|
|
|
|
|
|
|
function openHandler() {
|
2016-03-31 20:25:59 +03:00
|
|
|
viewer.removeHandler('open', openHandler);
|
2014-02-05 02:09:12 +04:00
|
|
|
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.equal(viewer.overlays.length, 0, "No global overlay should be added.");
|
|
|
|
assert.equal(viewer.currentOverlays.length, 1, "Page overlay should be open.");
|
2014-02-05 02:09:12 +04:00
|
|
|
|
2016-03-31 20:25:59 +03:00
|
|
|
viewer.addHandler('open', openPageHandler);
|
|
|
|
viewer.goToPage(1);
|
2014-02-05 02:09:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function openPageHandler() {
|
2016-03-31 20:25:59 +03:00
|
|
|
viewer.removeHandler('open', openPageHandler);
|
2014-02-05 02:09:12 +04:00
|
|
|
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.equal(viewer.overlays.length, 0, "No global overlay should be added after page switch.");
|
|
|
|
assert.equal(viewer.currentOverlays.length, 0, "No page overlay should be opened after page switch.");
|
2014-02-05 02:09:12 +04:00
|
|
|
|
2016-03-31 20:25:59 +03:00
|
|
|
viewer.addHandler('close', closeHandler);
|
2014-02-05 02:09:12 +04:00
|
|
|
viewer.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
function closeHandler() {
|
2016-03-31 20:25:59 +03:00
|
|
|
viewer.removeHandler('close', closeHandler);
|
2014-02-05 02:09:12 +04:00
|
|
|
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.equal(viewer.overlays.length, 0, "No global overlay should be added on close.");
|
|
|
|
assert.equal(viewer.currentOverlays.length, 0, "Page overlay should be closed on close.");
|
2014-02-05 02:09:12 +04:00
|
|
|
|
2017-12-05 05:01:30 +03:00
|
|
|
done();
|
2014-02-05 02:09:12 +04:00
|
|
|
}
|
2016-03-31 20:25:59 +03:00
|
|
|
});
|
2014-02-05 02:09:12 +04:00
|
|
|
|
2017-12-05 05:01:30 +03:00
|
|
|
QUnit.test('Overlays via addOverlay method', function(assert) {
|
|
|
|
var done = assert.async();
|
2016-03-31 20:25:59 +03:00
|
|
|
viewer = OpenSeadragon({
|
2014-02-05 02:09:12 +04:00
|
|
|
id: 'example-overlays',
|
|
|
|
prefixUrl: '/build/openseadragon/images/',
|
2016-03-31 20:25:59 +03:00
|
|
|
tileSources: ['/test/data/testpattern.dzi', '/test/data/testpattern.dzi'],
|
2014-02-05 02:09:12 +04:00
|
|
|
springStiffness: 100 // Faster animation = faster tests
|
2016-03-31 20:25:59 +03:00
|
|
|
});
|
|
|
|
viewer.addHandler('open', openHandler);
|
2014-02-05 02:09:12 +04:00
|
|
|
|
|
|
|
function openHandler() {
|
2016-03-31 20:25:59 +03:00
|
|
|
viewer.removeHandler('open', openHandler);
|
2014-02-05 02:09:12 +04:00
|
|
|
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.equal(viewer.overlays.length, 0, "No global overlay should be added.");
|
|
|
|
assert.equal(viewer.currentOverlays.length, 0, "No overlay should be open.");
|
2014-02-05 02:09:12 +04:00
|
|
|
|
2016-03-31 20:25:59 +03:00
|
|
|
var rect = new OpenSeadragon.Rect(0.1, 0.1, 0.1, 0.1);
|
|
|
|
var overlay = $("<div/>").prop("id", "overlay").get(0);
|
|
|
|
viewer.addOverlay(overlay, rect);
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.equal(viewer.overlays.length, 0, "No manual overlay should be added as global overlay.");
|
|
|
|
assert.equal(viewer.currentOverlays.length, 1, "A manual overlay should be open.");
|
2014-02-05 02:09:12 +04:00
|
|
|
|
2016-03-31 20:25:59 +03:00
|
|
|
viewer.addHandler('open', openPageHandler);
|
|
|
|
viewer.goToPage(1);
|
2014-02-05 02:09:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function openPageHandler() {
|
2016-03-31 20:25:59 +03:00
|
|
|
viewer.removeHandler('open', openPageHandler);
|
2014-02-05 02:09:12 +04:00
|
|
|
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.equal(viewer.overlays.length, 0, "No global overlay should be added after page switch.");
|
|
|
|
assert.equal(viewer.currentOverlays.length, 0, "Manual overlay should be removed after page switch.");
|
2014-02-05 02:09:12 +04:00
|
|
|
|
2016-03-31 20:25:59 +03:00
|
|
|
viewer.addHandler('close', closeHandler);
|
2014-02-05 02:09:12 +04:00
|
|
|
viewer.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
function closeHandler() {
|
2016-03-31 20:25:59 +03:00
|
|
|
viewer.removeHandler('close', closeHandler);
|
2014-02-05 02:09:12 +04:00
|
|
|
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.equal(viewer.overlays.length, 0, "No global overlay should be added on close.");
|
|
|
|
assert.equal(viewer.currentOverlays.length, 0, "Manual overlay should be removed on close.");
|
2014-02-05 02:09:12 +04:00
|
|
|
|
2017-12-05 05:01:30 +03:00
|
|
|
done();
|
2014-02-05 02:09:12 +04:00
|
|
|
}
|
|
|
|
|
2016-03-31 20:25:59 +03:00
|
|
|
});
|
2014-02-05 02:09:12 +04:00
|
|
|
|
2017-12-05 05:01:30 +03:00
|
|
|
QUnit.test('Overlays size in pixels', function(assert) {
|
|
|
|
var done = assert.async();
|
2016-03-31 20:25:59 +03:00
|
|
|
viewer = OpenSeadragon({
|
2014-02-05 02:09:12 +04:00
|
|
|
id: 'example-overlays',
|
|
|
|
prefixUrl: '/build/openseadragon/images/',
|
2014-03-21 23:55:04 +04:00
|
|
|
tileSources: '/test/data/testpattern.dzi',
|
2014-02-05 02:09:12 +04:00
|
|
|
springStiffness: 100, // Faster animation = faster tests
|
2016-03-31 20:25:59 +03:00
|
|
|
overlays: [{
|
2014-02-05 02:09:12 +04:00
|
|
|
px: 13,
|
|
|
|
py: 120,
|
|
|
|
width: 124,
|
|
|
|
height: 132,
|
|
|
|
id: "overlay"
|
2014-02-05 23:57:47 +04:00
|
|
|
}, {
|
|
|
|
px: 400,
|
|
|
|
py: 500,
|
2014-03-21 23:55:04 +04:00
|
|
|
id: "fixed-overlay",
|
|
|
|
placement: "TOP_LEFT"
|
2016-03-31 20:25:59 +03:00
|
|
|
}]
|
|
|
|
});
|
2014-02-05 02:09:12 +04:00
|
|
|
|
2016-03-29 22:29:36 +03:00
|
|
|
function checkOverlayPosition(contextMessage) {
|
2014-02-05 02:09:12 +04:00
|
|
|
var viewport = viewer.viewport;
|
|
|
|
|
|
|
|
var expPosition = viewport.imageToViewerElementCoordinates(
|
2016-03-29 22:29:36 +03:00
|
|
|
new OpenSeadragon.Point(13, 120));
|
2024-09-17 14:16:00 +03:00
|
|
|
var actPosition = $("#overlay-wrapper-overlay").position();
|
2017-12-05 05:01:30 +03:00
|
|
|
Util.assessNumericValue(assert, actPosition.left, expPosition.x, epsilon,
|
2016-03-29 22:29:36 +03:00
|
|
|
"X position mismatch " + contextMessage);
|
2017-12-05 05:01:30 +03:00
|
|
|
Util.assessNumericValue(assert, actPosition.top, expPosition.y, epsilon,
|
2016-03-29 22:29:36 +03:00
|
|
|
"Y position mismatch " + contextMessage);
|
|
|
|
|
|
|
|
var zoom = viewport.viewportToImageZoom(viewport.getZoom(true));
|
|
|
|
var expectedWidth = 124 * zoom;
|
|
|
|
var expectedHeight = 132 * zoom;
|
2024-09-17 14:16:00 +03:00
|
|
|
Util.assessNumericValue(assert, $("#overlay-wrapper-overlay").width(), expectedWidth, epsilon,
|
2016-03-29 22:29:36 +03:00
|
|
|
"Width mismatch " + contextMessage);
|
2024-09-17 14:16:00 +03:00
|
|
|
Util.assessNumericValue(assert, $("#overlay-wrapper-overlay").height(), expectedHeight, epsilon,
|
2016-03-29 22:29:36 +03:00
|
|
|
"Height mismatch " + contextMessage);
|
2014-02-05 23:57:47 +04:00
|
|
|
|
|
|
|
|
|
|
|
expPosition = viewport.imageToViewerElementCoordinates(
|
2016-03-29 22:29:36 +03:00
|
|
|
new OpenSeadragon.Point(400, 500));
|
2024-09-17 14:16:00 +03:00
|
|
|
actPosition = $("#overlay-wrapper-fixed-overlay").position();
|
2017-12-05 05:01:30 +03:00
|
|
|
Util.assessNumericValue(assert, actPosition.left, expPosition.x, epsilon,
|
2016-03-29 22:29:36 +03:00
|
|
|
"Fixed overlay X position mismatch " + contextMessage);
|
2017-12-05 05:01:30 +03:00
|
|
|
Util.assessNumericValue(assert, actPosition.top, expPosition.y, epsilon,
|
2016-03-29 22:29:36 +03:00
|
|
|
"Fixed overlay Y position mismatch " + contextMessage);
|
|
|
|
|
2024-09-17 14:16:00 +03:00
|
|
|
Util.assessNumericValue(assert, $("#overlay-wrapper-fixed-overlay").width(), 70, epsilon,
|
2016-03-29 22:29:36 +03:00
|
|
|
"Fixed overlay width mismatch " + contextMessage);
|
2024-09-17 14:16:00 +03:00
|
|
|
Util.assessNumericValue(assert, $("#overlay-wrapper-fixed-overlay").height(), 60, epsilon,
|
2016-03-29 22:29:36 +03:00
|
|
|
"Fixed overlay height mismatch " + contextMessage);
|
2014-02-05 02:09:12 +04:00
|
|
|
}
|
|
|
|
|
2016-03-31 20:25:59 +03:00
|
|
|
waitForViewer(function() {
|
|
|
|
checkOverlayPosition("after opening using image coordinates");
|
2014-02-05 02:09:12 +04:00
|
|
|
|
2016-03-31 20:25:59 +03:00
|
|
|
viewer.viewport.zoomBy(1.1).panBy(new OpenSeadragon.Point(0.1, 0.2));
|
|
|
|
waitForViewer(function() {
|
|
|
|
checkOverlayPosition("after zoom and pan using image coordinates");
|
2014-02-05 02:09:12 +04:00
|
|
|
|
|
|
|
viewer.viewport.goHome();
|
2016-03-31 20:25:59 +03:00
|
|
|
waitForViewer(function() {
|
|
|
|
checkOverlayPosition("after goHome using image coordinates");
|
2017-12-05 05:01:30 +03:00
|
|
|
done();
|
2016-03-31 20:25:59 +03:00
|
|
|
});
|
|
|
|
});
|
2014-02-05 02:09:12 +04:00
|
|
|
|
2016-03-31 20:25:59 +03:00
|
|
|
});
|
|
|
|
});
|
2014-02-05 02:09:12 +04:00
|
|
|
|
2017-12-05 05:01:30 +03:00
|
|
|
QUnit.test('Overlays size in points', function(assert) {
|
|
|
|
var done = assert.async();
|
2016-03-31 20:25:59 +03:00
|
|
|
viewer = OpenSeadragon({
|
2014-02-05 23:57:47 +04:00
|
|
|
id: 'example-overlays',
|
|
|
|
prefixUrl: '/build/openseadragon/images/',
|
2014-03-21 23:55:04 +04:00
|
|
|
tileSources: '/test/data/testpattern.dzi',
|
2014-02-05 23:57:47 +04:00
|
|
|
springStiffness: 100, // Faster animation = faster tests
|
2016-03-31 20:25:59 +03:00
|
|
|
overlays: [{
|
2014-02-05 23:57:47 +04:00
|
|
|
x: 0.2,
|
|
|
|
y: 0.1,
|
|
|
|
width: 0.5,
|
|
|
|
height: 0.1,
|
|
|
|
id: "overlay"
|
2014-03-21 23:55:04 +04:00
|
|
|
}, {
|
2014-02-05 23:57:47 +04:00
|
|
|
x: 0.5,
|
|
|
|
y: 0.6,
|
2014-03-21 23:55:04 +04:00
|
|
|
id: "fixed-overlay",
|
|
|
|
placement: "TOP_LEFT"
|
2016-03-31 20:25:59 +03:00
|
|
|
}]
|
|
|
|
});
|
2014-02-05 23:57:47 +04:00
|
|
|
|
2016-03-31 20:25:59 +03:00
|
|
|
function checkOverlayPosition(contextMessage) {
|
2014-02-05 23:57:47 +04:00
|
|
|
var viewport = viewer.viewport;
|
|
|
|
|
|
|
|
var expPosition = viewport.viewportToViewerElementCoordinates(
|
2016-03-29 22:29:36 +03:00
|
|
|
new OpenSeadragon.Point(0.2, 0.1));
|
2024-09-17 14:16:00 +03:00
|
|
|
var actPosition = $("#overlay-wrapper-overlay").position();
|
2017-12-05 05:01:30 +03:00
|
|
|
Util.assessNumericValue(assert, actPosition.left, expPosition.x, epsilon,
|
2016-03-29 22:29:36 +03:00
|
|
|
"X position mismatch " + contextMessage);
|
2017-12-05 05:01:30 +03:00
|
|
|
Util.assessNumericValue(assert, actPosition.top, expPosition.y, epsilon,
|
2016-03-29 22:29:36 +03:00
|
|
|
"Y position mismatch " + contextMessage);
|
2014-02-05 23:57:47 +04:00
|
|
|
|
|
|
|
var expectedSize = viewport.deltaPixelsFromPoints(
|
2016-03-29 22:29:36 +03:00
|
|
|
new OpenSeadragon.Point(0.5, 0.1));
|
2024-09-17 14:16:00 +03:00
|
|
|
Util.assessNumericValue(assert, $("#overlay-wrapper-overlay").width(), expectedSize.x, epsilon,
|
2016-03-29 22:29:36 +03:00
|
|
|
"Width mismatch " + contextMessage);
|
2024-09-17 14:16:00 +03:00
|
|
|
Util.assessNumericValue(assert, $("#overlay-wrapper-overlay").height(), expectedSize.y, epsilon,
|
2016-03-29 22:29:36 +03:00
|
|
|
"Height mismatch " + contextMessage);
|
2014-02-05 23:57:47 +04:00
|
|
|
|
|
|
|
|
|
|
|
expPosition = viewport.viewportToViewerElementCoordinates(
|
2016-03-29 22:29:36 +03:00
|
|
|
new OpenSeadragon.Point(0.5, 0.6));
|
2024-09-17 14:16:00 +03:00
|
|
|
actPosition = $("#overlay-wrapper-fixed-overlay").position();
|
2017-12-05 05:01:30 +03:00
|
|
|
Util.assessNumericValue(assert, actPosition.left, expPosition.x, epsilon,
|
2016-03-29 22:29:36 +03:00
|
|
|
"Fixed overlay X position mismatch " + contextMessage);
|
2017-12-05 05:01:30 +03:00
|
|
|
Util.assessNumericValue(assert, actPosition.top, expPosition.y, epsilon,
|
2016-03-29 22:29:36 +03:00
|
|
|
"Fixed overlay Y position mismatch " + contextMessage);
|
|
|
|
|
2024-09-17 14:16:00 +03:00
|
|
|
Util.assessNumericValue(assert, $("#overlay-wrapper-fixed-overlay").width(), 70, epsilon,
|
2016-03-29 22:29:36 +03:00
|
|
|
"Fixed overlay width mismatch " + contextMessage);
|
2024-09-17 14:16:00 +03:00
|
|
|
Util.assessNumericValue(assert, $("#overlay-wrapper-fixed-overlay").height(), 60, epsilon,
|
2016-03-29 22:29:36 +03:00
|
|
|
"Fixed overlay height mismatch " + contextMessage);
|
2014-02-05 23:57:47 +04:00
|
|
|
}
|
|
|
|
|
2016-03-31 20:25:59 +03:00
|
|
|
waitForViewer(function() {
|
|
|
|
checkOverlayPosition("after opening using viewport coordinates");
|
2014-02-05 23:57:47 +04:00
|
|
|
|
2016-03-31 20:25:59 +03:00
|
|
|
viewer.viewport.zoomBy(1.1).panBy(new OpenSeadragon.Point(0.1, 0.2));
|
|
|
|
waitForViewer(function() {
|
|
|
|
checkOverlayPosition("after zoom and pan using viewport coordinates");
|
2014-02-05 23:57:47 +04:00
|
|
|
|
|
|
|
viewer.viewport.goHome();
|
2016-03-31 20:25:59 +03:00
|
|
|
waitForViewer(function() {
|
|
|
|
checkOverlayPosition("after goHome using viewport coordinates");
|
2017-12-05 05:01:30 +03:00
|
|
|
done();
|
2016-03-31 20:25:59 +03:00
|
|
|
});
|
|
|
|
});
|
2014-02-05 23:57:47 +04:00
|
|
|
|
2016-03-31 20:25:59 +03:00
|
|
|
});
|
|
|
|
});
|
2014-02-05 23:57:47 +04:00
|
|
|
|
2017-12-05 05:01:30 +03:00
|
|
|
QUnit.test('Overlays placement', function(assert) {
|
|
|
|
var done = assert.async();
|
2016-03-31 20:25:59 +03:00
|
|
|
var scalableOverlayLocation = new OpenSeadragon.Rect(0.2, 0.1, 0.5, 0.1);
|
|
|
|
var fixedOverlayLocation = new OpenSeadragon.Point(0.5, 0.6);
|
2014-03-21 23:55:04 +04:00
|
|
|
|
2016-03-31 20:25:59 +03:00
|
|
|
viewer = OpenSeadragon({
|
2014-03-21 23:55:04 +04:00
|
|
|
id: 'example-overlays',
|
|
|
|
prefixUrl: '/build/openseadragon/images/',
|
|
|
|
tileSources: '/test/data/testpattern.dzi',
|
|
|
|
springStiffness: 100, // Faster animation = faster tests
|
2016-03-31 20:25:59 +03:00
|
|
|
overlays: [{
|
2014-03-21 23:55:04 +04:00
|
|
|
x: scalableOverlayLocation.x,
|
|
|
|
y: scalableOverlayLocation.y,
|
|
|
|
width: scalableOverlayLocation.width,
|
|
|
|
height: scalableOverlayLocation.height,
|
|
|
|
id: "overlay",
|
|
|
|
placement: "TOP_LEFT"
|
|
|
|
}, {
|
|
|
|
x: fixedOverlayLocation.x,
|
|
|
|
y: fixedOverlayLocation.y,
|
|
|
|
id: "fixed-overlay",
|
|
|
|
placement: "TOP_LEFT"
|
2016-03-31 20:25:59 +03:00
|
|
|
}]
|
|
|
|
});
|
2014-03-21 23:55:04 +04:00
|
|
|
|
|
|
|
// Scalable overlays are always TOP_LEFT
|
2016-03-31 20:25:59 +03:00
|
|
|
function checkScalableOverlayPosition(contextMessage) {
|
2014-03-21 23:55:04 +04:00
|
|
|
var viewport = viewer.viewport;
|
|
|
|
|
|
|
|
var expPosition = viewport.viewportToViewerElementCoordinates(
|
2016-03-29 22:29:36 +03:00
|
|
|
new OpenSeadragon.Point(0.2, 0.1));
|
2024-09-17 14:16:00 +03:00
|
|
|
var actPosition = $("#overlay-wrapper-overlay").position();
|
2017-12-05 05:01:30 +03:00
|
|
|
Util.assessNumericValue(assert, actPosition.left, expPosition.x, epsilon,
|
2016-03-29 22:29:36 +03:00
|
|
|
"X position mismatch " + contextMessage);
|
2017-12-05 05:01:30 +03:00
|
|
|
Util.assessNumericValue(assert, actPosition.top, expPosition.y, epsilon,
|
2016-03-29 22:29:36 +03:00
|
|
|
"Y position mismatch " + contextMessage);
|
2014-03-21 23:55:04 +04:00
|
|
|
}
|
|
|
|
|
2016-03-31 20:25:59 +03:00
|
|
|
function checkFixedOverlayPosition(expectedOffset, contextMessage) {
|
2014-03-21 23:55:04 +04:00
|
|
|
var viewport = viewer.viewport;
|
|
|
|
|
|
|
|
var expPosition = viewport.viewportToViewerElementCoordinates(
|
2016-03-29 22:29:36 +03:00
|
|
|
new OpenSeadragon.Point(0.5, 0.6))
|
|
|
|
.plus(expectedOffset);
|
2024-09-17 14:16:00 +03:00
|
|
|
var actPosition = $("#overlay-wrapper-fixed-overlay").position();
|
2017-12-05 05:01:30 +03:00
|
|
|
Util.assessNumericValue(assert, actPosition.left, expPosition.x, epsilon,
|
2016-03-29 22:29:36 +03:00
|
|
|
"Fixed overlay X position mismatch " + contextMessage);
|
2017-12-05 05:01:30 +03:00
|
|
|
Util.assessNumericValue(assert, actPosition.top, expPosition.y, epsilon,
|
2016-03-29 22:29:36 +03:00
|
|
|
"Fixed overlay Y position mismatch " + contextMessage);
|
2014-03-21 23:55:04 +04:00
|
|
|
}
|
|
|
|
|
2016-03-31 20:25:59 +03:00
|
|
|
waitForViewer(function() {
|
2014-03-21 23:55:04 +04:00
|
|
|
|
2016-03-31 20:25:59 +03:00
|
|
|
checkScalableOverlayPosition("with TOP_LEFT placement.");
|
|
|
|
checkFixedOverlayPosition(new OpenSeadragon.Point(0, 0),
|
|
|
|
"with TOP_LEFT placement.");
|
2014-03-21 23:55:04 +04:00
|
|
|
|
2016-03-22 22:50:48 +03:00
|
|
|
// Check that legacy OpenSeadragon.OverlayPlacement is still working
|
2016-03-31 20:25:59 +03:00
|
|
|
viewer.updateOverlay("overlay", scalableOverlayLocation,
|
|
|
|
OpenSeadragon.OverlayPlacement.CENTER);
|
|
|
|
viewer.updateOverlay("fixed-overlay", fixedOverlayLocation,
|
|
|
|
OpenSeadragon.OverlayPlacement.CENTER);
|
2014-03-21 23:55:04 +04:00
|
|
|
|
2016-03-31 20:25:59 +03:00
|
|
|
setTimeout(function() {
|
|
|
|
checkScalableOverlayPosition("with CENTER placement.");
|
|
|
|
checkFixedOverlayPosition(new OpenSeadragon.Point(-35, -30),
|
|
|
|
"with CENTER placement.");
|
2014-03-21 23:55:04 +04:00
|
|
|
|
2016-03-22 22:50:48 +03:00
|
|
|
// Check that new OpenSeadragon.Placement is working
|
2016-03-31 20:25:59 +03:00
|
|
|
viewer.updateOverlay("overlay", scalableOverlayLocation,
|
|
|
|
OpenSeadragon.Placement.BOTTOM_RIGHT);
|
|
|
|
viewer.updateOverlay("fixed-overlay", fixedOverlayLocation,
|
|
|
|
OpenSeadragon.Placement.BOTTOM_RIGHT);
|
|
|
|
setTimeout(function() {
|
|
|
|
checkScalableOverlayPosition("with BOTTOM_RIGHT placement.");
|
|
|
|
checkFixedOverlayPosition(new OpenSeadragon.Point(-70, -60),
|
|
|
|
"with BOTTOM_RIGHT placement.");
|
2014-03-21 23:55:04 +04:00
|
|
|
|
2017-12-05 05:01:30 +03:00
|
|
|
done();
|
2016-03-31 20:25:59 +03:00
|
|
|
}, 100);
|
2014-03-21 23:55:04 +04:00
|
|
|
|
2016-03-31 20:25:59 +03:00
|
|
|
}, 100);
|
2014-03-21 23:55:04 +04:00
|
|
|
|
2016-03-31 20:25:59 +03:00
|
|
|
});
|
|
|
|
});
|
2014-03-21 23:55:04 +04:00
|
|
|
|
2017-12-05 05:01:30 +03:00
|
|
|
QUnit.test('Overlays placement and resizing check', function(assert) {
|
|
|
|
var done = assert.async();
|
2016-03-31 20:25:59 +03:00
|
|
|
var fixedOverlayLocation = new OpenSeadragon.Point(0.5, 0.6);
|
2014-03-21 23:55:04 +04:00
|
|
|
|
2016-03-31 20:25:59 +03:00
|
|
|
viewer = OpenSeadragon({
|
2014-03-21 23:55:04 +04:00
|
|
|
id: 'example-overlays',
|
|
|
|
prefixUrl: '/build/openseadragon/images/',
|
|
|
|
tileSources: '/test/data/testpattern.dzi',
|
|
|
|
springStiffness: 100, // Faster animation = faster tests
|
2016-03-31 20:25:59 +03:00
|
|
|
overlays: [{
|
2014-03-21 23:55:04 +04:00
|
|
|
x: fixedOverlayLocation.x,
|
|
|
|
y: fixedOverlayLocation.y,
|
|
|
|
id: "fixed-overlay",
|
|
|
|
placement: "CENTER",
|
|
|
|
checkResize: true
|
2016-03-31 20:25:59 +03:00
|
|
|
}]
|
|
|
|
});
|
2014-03-21 23:55:04 +04:00
|
|
|
|
2016-03-31 20:25:59 +03:00
|
|
|
function checkFixedOverlayPosition(expectedOffset, contextMessage) {
|
2014-03-21 23:55:04 +04:00
|
|
|
var viewport = viewer.viewport;
|
|
|
|
|
|
|
|
var expPosition = viewport.viewportToViewerElementCoordinates(
|
2016-03-29 22:29:36 +03:00
|
|
|
new OpenSeadragon.Point(0.5, 0.6))
|
|
|
|
.plus(expectedOffset);
|
2024-09-17 14:16:00 +03:00
|
|
|
var actPosition = $("#overlay-wrapper-fixed-overlay").position();
|
2017-12-05 05:01:30 +03:00
|
|
|
Util.assessNumericValue(assert, actPosition.left, expPosition.x, epsilon,
|
2016-03-29 22:29:36 +03:00
|
|
|
"Fixed overlay X position mismatch " + contextMessage);
|
2017-12-05 05:01:30 +03:00
|
|
|
Util.assessNumericValue(assert, actPosition.top, expPosition.y, epsilon,
|
2016-03-29 22:29:36 +03:00
|
|
|
"Fixed overlay Y position mismatch " + contextMessage);
|
2014-03-21 23:55:04 +04:00
|
|
|
}
|
|
|
|
|
2016-03-31 20:25:59 +03:00
|
|
|
waitForViewer(function() {
|
|
|
|
checkFixedOverlayPosition(new OpenSeadragon.Point(-35, -30),
|
|
|
|
"with overlay of size 70,60.");
|
2014-03-21 23:55:04 +04:00
|
|
|
|
2024-09-17 14:16:00 +03:00
|
|
|
$("#overlay-wrapper-fixed-overlay").width(50);
|
|
|
|
$("#overlay-wrapper-fixed-overlay").height(40);
|
2014-03-21 23:55:04 +04:00
|
|
|
|
|
|
|
// The resizing of the overlays is not detected by the viewer's loop.
|
|
|
|
viewer.forceRedraw();
|
|
|
|
|
2016-03-31 20:25:59 +03:00
|
|
|
setTimeout(function() {
|
|
|
|
checkFixedOverlayPosition(new OpenSeadragon.Point(-25, -20),
|
|
|
|
"with overlay of size 50,40.");
|
2014-03-21 23:55:04 +04:00
|
|
|
|
|
|
|
// Restore original size
|
2024-09-17 14:16:00 +03:00
|
|
|
$("#overlay-wrapper-fixed-overlay").width(70);
|
|
|
|
$("#overlay-wrapper-fixed-overlay").height(60);
|
2014-03-21 23:55:04 +04:00
|
|
|
|
2017-12-05 05:01:30 +03:00
|
|
|
done();
|
2016-03-31 20:25:59 +03:00
|
|
|
}, 100);
|
|
|
|
});
|
2014-03-21 23:55:04 +04:00
|
|
|
|
2016-03-31 20:25:59 +03:00
|
|
|
});
|
2014-03-21 23:55:04 +04:00
|
|
|
|
2017-12-05 05:01:30 +03:00
|
|
|
QUnit.test('Overlays placement and no resizing check', function(assert) {
|
|
|
|
var done = assert.async();
|
2016-03-31 20:25:59 +03:00
|
|
|
var fixedOverlayLocation = new OpenSeadragon.Point(0.5, 0.6);
|
2014-03-21 23:55:04 +04:00
|
|
|
|
2016-03-31 20:25:59 +03:00
|
|
|
viewer = OpenSeadragon({
|
2014-03-21 23:55:04 +04:00
|
|
|
id: 'example-overlays',
|
|
|
|
prefixUrl: '/build/openseadragon/images/',
|
|
|
|
tileSources: '/test/data/testpattern.dzi',
|
|
|
|
springStiffness: 100, // Faster animation = faster tests
|
2016-03-31 20:25:59 +03:00
|
|
|
overlays: [{
|
2014-03-21 23:55:04 +04:00
|
|
|
x: fixedOverlayLocation.x,
|
|
|
|
y: fixedOverlayLocation.y,
|
|
|
|
id: "fixed-overlay",
|
|
|
|
placement: "CENTER",
|
|
|
|
checkResize: false
|
2016-03-31 20:25:59 +03:00
|
|
|
}]
|
|
|
|
});
|
2014-03-21 23:55:04 +04:00
|
|
|
|
2016-03-31 20:25:59 +03:00
|
|
|
function checkFixedOverlayPosition(expectedOffset, contextMessage) {
|
2014-03-21 23:55:04 +04:00
|
|
|
var viewport = viewer.viewport;
|
|
|
|
|
|
|
|
var expPosition = viewport.viewportToViewerElementCoordinates(
|
2016-03-29 22:29:36 +03:00
|
|
|
new OpenSeadragon.Point(0.5, 0.6))
|
|
|
|
.plus(expectedOffset);
|
2024-09-17 14:16:00 +03:00
|
|
|
var actPosition = $("#overlay-wrapper-fixed-overlay").position();
|
2017-12-05 05:01:30 +03:00
|
|
|
Util.assessNumericValue(assert, actPosition.left, expPosition.x, epsilon,
|
2016-03-29 22:29:36 +03:00
|
|
|
"Fixed overlay X position mismatch " + contextMessage);
|
2017-12-05 05:01:30 +03:00
|
|
|
Util.assessNumericValue(assert, actPosition.top, expPosition.y, epsilon,
|
2016-03-29 22:29:36 +03:00
|
|
|
"Fixed overlay Y position mismatch " + contextMessage);
|
2014-03-21 23:55:04 +04:00
|
|
|
}
|
|
|
|
|
2016-03-31 20:25:59 +03:00
|
|
|
waitForViewer(function() {
|
|
|
|
checkFixedOverlayPosition(new OpenSeadragon.Point(-35, -30),
|
|
|
|
"with overlay of size 70,60.");
|
2014-03-21 23:55:04 +04:00
|
|
|
|
2024-09-17 14:16:00 +03:00
|
|
|
$("#overlay-wrapper-fixed-overlay").width(50);
|
|
|
|
$("#overlay-wrapper-fixed-overlay").height(40);
|
2014-03-21 23:55:04 +04:00
|
|
|
|
|
|
|
// The resizing of the overlays is not detected by the viewer's loop.
|
|
|
|
viewer.forceRedraw();
|
|
|
|
|
2016-03-31 20:25:59 +03:00
|
|
|
setTimeout(function() {
|
|
|
|
checkFixedOverlayPosition(new OpenSeadragon.Point(-35, -30),
|
|
|
|
"with overlay of size 50,40.");
|
2014-03-21 23:55:04 +04:00
|
|
|
|
|
|
|
// Restore original size
|
2024-09-17 14:16:00 +03:00
|
|
|
$("#overlay-wrapper-fixed-overlay").width(70);
|
|
|
|
$("#overlay-wrapper-fixed-overlay").height(60);
|
2014-03-21 23:55:04 +04:00
|
|
|
|
2017-12-05 05:01:30 +03:00
|
|
|
done();
|
2016-03-31 20:25:59 +03:00
|
|
|
}, 100);
|
|
|
|
});
|
2014-03-21 23:55:04 +04:00
|
|
|
|
2016-03-31 20:25:59 +03:00
|
|
|
});
|
2014-03-21 23:55:04 +04:00
|
|
|
|
2014-11-21 02:33:13 +03:00
|
|
|
// ----------
|
2017-12-05 05:01:30 +03:00
|
|
|
QUnit.test('overlays appear immediately', function(assert) {
|
|
|
|
var done = assert.async();
|
|
|
|
assert.equal($('#immediate-overlay0').length, 0, 'overlay 0 does not exist');
|
|
|
|
assert.equal($('#immediate-overlay1').length, 0, 'overlay 1 does not exist');
|
2014-11-21 02:33:13 +03:00
|
|
|
|
2016-03-31 20:25:59 +03:00
|
|
|
viewer = OpenSeadragon({
|
2014-11-21 02:33:13 +03:00
|
|
|
id: 'example-overlays',
|
|
|
|
prefixUrl: '/build/openseadragon/images/',
|
|
|
|
tileSources: '/test/data/testpattern.dzi',
|
|
|
|
springStiffness: 100, // Faster animation = faster tests
|
2016-03-31 20:25:59 +03:00
|
|
|
overlays: [{
|
2014-11-21 02:33:13 +03:00
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
id: "immediate-overlay0"
|
2016-03-31 20:25:59 +03:00
|
|
|
}]
|
|
|
|
});
|
2014-11-21 02:33:13 +03:00
|
|
|
|
|
|
|
viewer.addHandler('open', function() {
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.equal($('#immediate-overlay0').length, 1, 'overlay 0 exists');
|
2014-11-21 02:33:13 +03:00
|
|
|
|
2016-03-31 20:25:59 +03:00
|
|
|
viewer.addOverlay({
|
2014-11-21 02:33:13 +03:00
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
id: "immediate-overlay1"
|
2016-03-31 20:25:59 +03:00
|
|
|
});
|
2014-11-21 02:33:13 +03:00
|
|
|
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.equal($('#immediate-overlay1').length, 1, 'overlay 1 exists');
|
|
|
|
done();
|
2014-11-21 02:33:13 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-03-31 20:25:59 +03:00
|
|
|
// ----------
|
2017-12-05 05:01:30 +03:00
|
|
|
QUnit.test('Overlay scaled horizontally only', function(assert) {
|
|
|
|
var done = assert.async();
|
2016-03-31 20:25:59 +03:00
|
|
|
viewer = OpenSeadragon({
|
|
|
|
id: 'example-overlays',
|
|
|
|
prefixUrl: '/build/openseadragon/images/',
|
|
|
|
tileSources: '/test/data/testpattern.dzi',
|
|
|
|
springStiffness: 100 // Faster animation = faster tests
|
|
|
|
});
|
|
|
|
|
|
|
|
viewer.addHandler('open', function() {
|
|
|
|
viewer.addOverlay({
|
|
|
|
id: "horizontally-scaled-overlay",
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
width: 1
|
|
|
|
});
|
|
|
|
|
|
|
|
var width = $("#horizontally-scaled-overlay").width();
|
|
|
|
var height = 100;
|
|
|
|
var zoom = 1.1;
|
|
|
|
$("#horizontally-scaled-overlay").get(0).style.height = height + "px";
|
|
|
|
|
|
|
|
viewer.viewport.zoomBy(zoom);
|
|
|
|
|
|
|
|
waitForViewer(function() {
|
|
|
|
var newWidth = $("#horizontally-scaled-overlay").width();
|
|
|
|
var newHeight = $("#horizontally-scaled-overlay").height();
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.equal(newWidth, width * zoom, "Width should be scaled.");
|
|
|
|
assert.equal(newHeight, height, "Height should not be scaled.");
|
2016-03-31 20:25:59 +03:00
|
|
|
|
2017-12-05 05:01:30 +03:00
|
|
|
done();
|
2016-03-31 20:25:59 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// ----------
|
2017-12-05 05:01:30 +03:00
|
|
|
QUnit.test('Overlay scaled vertically only', function(assert) {
|
|
|
|
var done = assert.async();
|
2016-03-31 20:25:59 +03:00
|
|
|
viewer = OpenSeadragon({
|
|
|
|
id: 'example-overlays',
|
|
|
|
prefixUrl: '/build/openseadragon/images/',
|
|
|
|
tileSources: '/test/data/testpattern.dzi',
|
|
|
|
springStiffness: 100 // Faster animation = faster tests
|
|
|
|
});
|
|
|
|
|
|
|
|
viewer.addHandler('open', function() {
|
|
|
|
viewer.addOverlay({
|
|
|
|
id: "vertically-scaled-overlay",
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
height: 1
|
|
|
|
});
|
|
|
|
|
|
|
|
var width = 100;
|
|
|
|
var height = $("#vertically-scaled-overlay").height();
|
|
|
|
var zoom = 1.1;
|
|
|
|
$("#vertically-scaled-overlay").get(0).style.width = width + "px";
|
|
|
|
|
|
|
|
viewer.viewport.zoomBy(zoom);
|
|
|
|
|
|
|
|
waitForViewer(function() {
|
|
|
|
var newWidth = $("#vertically-scaled-overlay").width();
|
|
|
|
var newHeight = $("#vertically-scaled-overlay").height();
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.equal(newWidth, width, "Width should not be scaled.");
|
|
|
|
assert.equal(newHeight, height * zoom, "Height should be scaled.");
|
2016-03-31 20:25:59 +03:00
|
|
|
|
2017-12-05 05:01:30 +03:00
|
|
|
done();
|
2016-03-31 20:25:59 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-04-01 20:29:09 +03:00
|
|
|
// ----------
|
2017-12-05 05:01:30 +03:00
|
|
|
QUnit.test('Overlay.getBounds', function(assert) {
|
|
|
|
var done = assert.async();
|
2016-03-31 20:25:59 +03:00
|
|
|
viewer = OpenSeadragon({
|
|
|
|
id: 'example-overlays',
|
|
|
|
prefixUrl: '/build/openseadragon/images/',
|
|
|
|
tileSources: '/test/data/testpattern.dzi',
|
|
|
|
springStiffness: 100 // Faster animation = faster tests
|
|
|
|
});
|
|
|
|
|
|
|
|
viewer.addHandler('open', function() {
|
|
|
|
viewer.addOverlay({
|
|
|
|
id: "fully-scaled-overlay",
|
|
|
|
x: 1,
|
|
|
|
y: 1,
|
|
|
|
width: 1,
|
|
|
|
height: 1,
|
|
|
|
placement: OpenSeadragon.Placement.BOTTOM_RIGHT
|
|
|
|
});
|
|
|
|
viewer.addOverlay({
|
|
|
|
id: "horizontally-scaled-overlay",
|
|
|
|
x: 0.5,
|
|
|
|
y: 0.5,
|
|
|
|
width: 1,
|
|
|
|
placement: OpenSeadragon.Placement.CENTER
|
|
|
|
});
|
|
|
|
viewer.addOverlay({
|
|
|
|
id: "vertically-scaled-overlay",
|
|
|
|
x: 0,
|
|
|
|
y: 0.5,
|
|
|
|
height: 1,
|
|
|
|
placement: OpenSeadragon.Placement.LEFT
|
|
|
|
});
|
|
|
|
viewer.addOverlay({
|
|
|
|
id: "not-scaled-overlay",
|
|
|
|
x: 1,
|
|
|
|
y: 0,
|
|
|
|
placement: OpenSeadragon.Placement.TOP_RIGHT
|
|
|
|
});
|
|
|
|
|
|
|
|
var notScaledWidth = 100;
|
|
|
|
var notScaledHeight = 100;
|
|
|
|
$("#horizontally-scaled-overlay").get(0).style.height = notScaledHeight + "px";
|
|
|
|
$("#vertically-scaled-overlay").get(0).style.width = notScaledWidth + "px";
|
|
|
|
$("#not-scaled-overlay").get(0).style.width = notScaledWidth + "px";
|
|
|
|
$("#not-scaled-overlay").get(0).style.height = notScaledHeight + "px";
|
|
|
|
|
|
|
|
var notScaledSize = viewer.viewport.deltaPointsFromPixelsNoRotate(
|
|
|
|
new OpenSeadragon.Point(notScaledWidth, notScaledHeight));
|
|
|
|
|
|
|
|
// Force refresh to takes new dimensions into account.
|
|
|
|
viewer._drawOverlays();
|
|
|
|
|
|
|
|
var actualBounds = viewer.getOverlayById("fully-scaled-overlay")
|
2016-04-01 20:29:09 +03:00
|
|
|
.getBounds(viewer.viewport);
|
2016-03-31 20:25:59 +03:00
|
|
|
var expectedBounds = new OpenSeadragon.Rect(0, 0, 1, 1);
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.ok(expectedBounds.equals(actualBounds),
|
2016-03-31 20:25:59 +03:00
|
|
|
"The fully scaled overlay should have bounds " +
|
2016-04-01 23:54:29 +03:00
|
|
|
expectedBounds + " but found " + actualBounds);
|
2016-03-31 20:25:59 +03:00
|
|
|
|
|
|
|
|
|
|
|
actualBounds = viewer.getOverlayById("horizontally-scaled-overlay")
|
|
|
|
.getBounds(viewer.viewport);
|
|
|
|
expectedBounds = new OpenSeadragon.Rect(
|
|
|
|
0, 0.5 - notScaledSize.y / 2, 1, notScaledSize.y);
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.ok(expectedBounds.equals(actualBounds),
|
2016-03-31 20:25:59 +03:00
|
|
|
"The horizontally scaled overlay should have bounds " +
|
2016-04-01 23:54:29 +03:00
|
|
|
expectedBounds + " but found " + actualBounds);
|
2016-03-31 20:25:59 +03:00
|
|
|
|
|
|
|
actualBounds = viewer.getOverlayById("vertically-scaled-overlay")
|
|
|
|
.getBounds(viewer.viewport);
|
|
|
|
expectedBounds = new OpenSeadragon.Rect(
|
|
|
|
0, 0, notScaledSize.x, 1);
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.ok(expectedBounds.equals(actualBounds),
|
2016-03-31 20:25:59 +03:00
|
|
|
"The vertically scaled overlay should have bounds " +
|
2016-04-01 23:54:29 +03:00
|
|
|
expectedBounds + " but found " + actualBounds);
|
2016-03-31 20:25:59 +03:00
|
|
|
|
|
|
|
actualBounds = viewer.getOverlayById("not-scaled-overlay")
|
|
|
|
.getBounds(viewer.viewport);
|
|
|
|
expectedBounds = new OpenSeadragon.Rect(
|
|
|
|
1 - notScaledSize.x, 0, notScaledSize.x, notScaledSize.y);
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.ok(expectedBounds.equals(actualBounds),
|
2016-03-31 20:25:59 +03:00
|
|
|
"The not scaled overlay should have bounds " +
|
2016-04-01 23:54:29 +03:00
|
|
|
expectedBounds + " but found " + actualBounds);
|
2016-03-31 20:25:59 +03:00
|
|
|
|
2017-12-05 05:01:30 +03:00
|
|
|
done();
|
2016-03-31 20:25:59 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-04-01 20:29:09 +03:00
|
|
|
// ----------
|
2017-12-05 05:01:30 +03:00
|
|
|
QUnit.test('Fully scaled overlay rotation mode NO_ROTATION', function(assert) {
|
|
|
|
var done = assert.async();
|
2016-04-01 20:29:09 +03:00
|
|
|
viewer = OpenSeadragon({
|
|
|
|
id: 'example-overlays',
|
|
|
|
prefixUrl: '/build/openseadragon/images/',
|
|
|
|
tileSources: '/test/data/testpattern.dzi',
|
|
|
|
springStiffness: 100, // Faster animation = faster tests
|
|
|
|
degrees: 45,
|
|
|
|
overlays: [{
|
|
|
|
id: "fully-scaled-overlay",
|
|
|
|
x: 1,
|
|
|
|
y: 1,
|
|
|
|
width: 1,
|
|
|
|
height: 1,
|
|
|
|
placement: OpenSeadragon.Placement.BOTTOM_RIGHT,
|
|
|
|
rotationMode: OpenSeadragon.OverlayRotationMode.NO_ROTATION
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
|
|
|
|
viewer.addOnceHandler('open', function() {
|
|
|
|
var viewport = viewer.viewport;
|
|
|
|
|
2024-09-17 14:16:00 +03:00
|
|
|
var $overlay = $("#overlay-wrapper-fully-scaled-overlay");
|
2016-04-01 20:29:09 +03:00
|
|
|
var expectedSize = viewport.deltaPixelsFromPointsNoRotate(
|
|
|
|
new OpenSeadragon.Point(1, 1));
|
|
|
|
var expectedPosition = viewport.viewportToViewerElementCoordinates(
|
|
|
|
new OpenSeadragon.Point(1, 1))
|
|
|
|
.minus(expectedSize);
|
|
|
|
var actualPosition = $overlay.position();
|
2017-12-05 05:01:30 +03:00
|
|
|
Util.assessNumericValue(assert, actualPosition.left, expectedPosition.x, epsilon,
|
2016-04-01 20:29:09 +03:00
|
|
|
"Scaled overlay position.x should adjust to rotation.");
|
2017-12-05 05:01:30 +03:00
|
|
|
Util.assessNumericValue(assert, actualPosition.top, expectedPosition.y, epsilon,
|
2016-04-01 20:29:09 +03:00
|
|
|
"Scaled overlay position.y should adjust to rotation.");
|
|
|
|
|
|
|
|
var actualWidth = $overlay.width();
|
|
|
|
var actualHeight = $overlay.height();
|
2017-12-05 05:01:30 +03:00
|
|
|
Util.assessNumericValue(assert, actualWidth, expectedSize.x, epsilon,
|
2016-04-01 20:29:09 +03:00
|
|
|
"Scaled overlay width should not adjust to rotation.");
|
2017-12-05 05:01:30 +03:00
|
|
|
Util.assessNumericValue(assert, actualHeight, expectedSize.y, epsilon,
|
2016-04-01 20:29:09 +03:00
|
|
|
"Scaled overlay height should not adjust to rotation.");
|
|
|
|
|
|
|
|
var actualBounds = viewer.getOverlayById("fully-scaled-overlay")
|
|
|
|
.getBounds(viewport);
|
|
|
|
var expectedBounds = new OpenSeadragon.Rect(0, 0, 1, 1)
|
|
|
|
.rotate(-45, new OpenSeadragon.Point(1, 1));
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.ok(expectedBounds.equals(actualBounds),
|
2016-04-01 20:29:09 +03:00
|
|
|
"The fully scaled overlay should have bounds " +
|
2016-04-01 23:54:29 +03:00
|
|
|
expectedBounds + " but found " + actualBounds);
|
2016-04-01 20:29:09 +03:00
|
|
|
|
2017-12-05 05:01:30 +03:00
|
|
|
done();
|
2016-04-01 20:29:09 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// ----------
|
2017-12-05 05:01:30 +03:00
|
|
|
QUnit.test('Horizontally scaled overlay rotation mode NO_ROTATION', function(assert) {
|
|
|
|
var done = assert.async();
|
2016-04-01 20:29:09 +03:00
|
|
|
viewer = OpenSeadragon({
|
|
|
|
id: 'example-overlays',
|
|
|
|
prefixUrl: '/build/openseadragon/images/',
|
|
|
|
tileSources: '/test/data/testpattern.dzi',
|
|
|
|
springStiffness: 100, // Faster animation = faster tests
|
|
|
|
degrees: 45,
|
|
|
|
overlays: [{
|
|
|
|
id: "horizontally-scaled-overlay",
|
|
|
|
x: 0.5,
|
|
|
|
y: 0.5,
|
|
|
|
width: 1,
|
|
|
|
placement: OpenSeadragon.Placement.CENTER,
|
|
|
|
rotationMode: OpenSeadragon.OverlayRotationMode.NO_ROTATION
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
|
|
|
|
viewer.addOnceHandler('open', function() {
|
2024-09-17 14:16:00 +03:00
|
|
|
var $overlay = $("#overlay-wrapper-horizontally-scaled-overlay");
|
2016-04-01 20:29:09 +03:00
|
|
|
var notScaledWidth = 100;
|
|
|
|
var notScaledHeight = 100;
|
|
|
|
$overlay.get(0).style.height = notScaledHeight + "px";
|
|
|
|
|
|
|
|
var viewport = viewer.viewport;
|
|
|
|
var notScaledSize = viewport.deltaPointsFromPixelsNoRotate(
|
|
|
|
new OpenSeadragon.Point(notScaledWidth, notScaledHeight));
|
|
|
|
|
|
|
|
// Force refresh to takes new dimensions into account.
|
|
|
|
viewer._drawOverlays();
|
|
|
|
|
|
|
|
var expectedWidth = viewport.deltaPixelsFromPointsNoRotate(
|
|
|
|
new OpenSeadragon.Point(1, 1)).x;
|
|
|
|
var expectedPosition = viewport.viewportToViewerElementCoordinates(
|
|
|
|
new OpenSeadragon.Point(0.5, 0.5))
|
|
|
|
.minus(new OpenSeadragon.Point(expectedWidth / 2, notScaledHeight / 2));
|
|
|
|
var actualPosition = $overlay.position();
|
2017-12-05 05:01:30 +03:00
|
|
|
Util.assessNumericValue(assert, actualPosition.left, expectedPosition.x, epsilon,
|
2016-04-01 20:29:09 +03:00
|
|
|
"Horizontally scaled overlay position.x should adjust to rotation.");
|
2017-12-05 05:01:30 +03:00
|
|
|
Util.assessNumericValue(assert, actualPosition.top, expectedPosition.y, epsilon,
|
2016-04-01 20:29:09 +03:00
|
|
|
"Horizontally scaled overlay position.y should adjust to rotation.");
|
|
|
|
|
|
|
|
var actualWidth = $overlay.width();
|
|
|
|
var actualHeight = $overlay.height();
|
2017-12-05 05:01:30 +03:00
|
|
|
Util.assessNumericValue(assert, actualWidth, expectedWidth, epsilon,
|
2016-04-01 20:29:09 +03:00
|
|
|
"Horizontally scaled overlay width should not adjust to rotation.");
|
2017-12-05 05:01:30 +03:00
|
|
|
Util.assessNumericValue(assert, actualHeight, notScaledHeight, epsilon,
|
2016-04-01 20:29:09 +03:00
|
|
|
"Horizontally scaled overlay height should not adjust to rotation.");
|
|
|
|
|
|
|
|
var actualBounds = viewer.getOverlayById("horizontally-scaled-overlay")
|
|
|
|
.getBounds(viewport);
|
|
|
|
var expectedBounds = new OpenSeadragon.Rect(
|
|
|
|
0, 0.5 - notScaledSize.y / 2, 1, notScaledSize.y)
|
|
|
|
.rotate(-45, new OpenSeadragon.Point(0.5, 0.5));
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.ok(expectedBounds.equals(actualBounds),
|
2016-04-01 20:29:09 +03:00
|
|
|
"The horizontally scaled overlay should have bounds " +
|
2016-04-01 23:54:29 +03:00
|
|
|
expectedBounds + " but found " + actualBounds);
|
2016-04-01 20:29:09 +03:00
|
|
|
|
2017-12-05 05:01:30 +03:00
|
|
|
done();
|
2016-04-01 20:29:09 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// ----------
|
2017-12-05 05:01:30 +03:00
|
|
|
QUnit.test('Vertically scaled overlay rotation mode NO_ROTATION', function(assert) {
|
|
|
|
var done = assert.async();
|
2016-04-01 20:29:09 +03:00
|
|
|
viewer = OpenSeadragon({
|
|
|
|
id: 'example-overlays',
|
|
|
|
prefixUrl: '/build/openseadragon/images/',
|
|
|
|
tileSources: '/test/data/testpattern.dzi',
|
|
|
|
springStiffness: 100, // Faster animation = faster tests
|
|
|
|
degrees: 45,
|
|
|
|
overlays: [{
|
|
|
|
id: "vertically-scaled-overlay",
|
|
|
|
x: 0,
|
|
|
|
y: 0.5,
|
|
|
|
height: 1,
|
|
|
|
placement: OpenSeadragon.Placement.LEFT,
|
|
|
|
rotationMode: OpenSeadragon.OverlayRotationMode.NO_ROTATION
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
|
|
|
|
viewer.addOnceHandler('open', function() {
|
2024-09-17 14:16:00 +03:00
|
|
|
var $overlay = $("#overlay-wrapper-vertically-scaled-overlay");
|
2016-04-01 20:29:09 +03:00
|
|
|
var notScaledWidth = 100;
|
|
|
|
var notScaledHeight = 100;
|
|
|
|
$overlay.get(0).style.width = notScaledWidth + "px";
|
|
|
|
|
|
|
|
var viewport = viewer.viewport;
|
|
|
|
var notScaledSize = viewport.deltaPointsFromPixelsNoRotate(
|
|
|
|
new OpenSeadragon.Point(notScaledWidth, notScaledHeight));
|
|
|
|
|
|
|
|
// Force refresh to takes new dimensions into account.
|
|
|
|
viewer._drawOverlays();
|
|
|
|
|
|
|
|
var expectedHeight = viewport.deltaPixelsFromPointsNoRotate(
|
|
|
|
new OpenSeadragon.Point(1, 1)).y;
|
|
|
|
var expectedPosition = viewport.viewportToViewerElementCoordinates(
|
|
|
|
new OpenSeadragon.Point(0, 0.5))
|
|
|
|
.minus(new OpenSeadragon.Point(0, expectedHeight / 2));
|
|
|
|
var actualPosition = $overlay.position();
|
2017-12-05 05:01:30 +03:00
|
|
|
Util.assessNumericValue(assert, actualPosition.left, expectedPosition.x, epsilon,
|
2016-04-01 20:29:09 +03:00
|
|
|
"Vertically scaled overlay position.x should adjust to rotation.");
|
2017-12-05 05:01:30 +03:00
|
|
|
Util.assessNumericValue(assert, actualPosition.top, expectedPosition.y, epsilon,
|
2016-04-01 20:29:09 +03:00
|
|
|
"Vertically scaled overlay position.y should adjust to rotation.");
|
|
|
|
|
|
|
|
var actualWidth = $overlay.width();
|
|
|
|
var actualHeight = $overlay.height();
|
2017-12-05 05:01:30 +03:00
|
|
|
Util.assessNumericValue(assert, actualWidth, notScaledWidth, epsilon,
|
2016-04-01 20:29:09 +03:00
|
|
|
"Vertically scaled overlay width should not adjust to rotation.");
|
2017-12-05 05:01:30 +03:00
|
|
|
Util.assessNumericValue(assert, actualHeight, expectedHeight, epsilon,
|
2016-04-01 20:29:09 +03:00
|
|
|
"Vertically scaled overlay height should not adjust to rotation.");
|
|
|
|
|
|
|
|
var actualBounds = viewer.getOverlayById("vertically-scaled-overlay")
|
|
|
|
.getBounds(viewport);
|
|
|
|
var expectedBounds = new OpenSeadragon.Rect(
|
|
|
|
0, 0, notScaledSize.x, 1)
|
|
|
|
.rotate(-45, new OpenSeadragon.Point(0, 0.5));
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.ok(expectedBounds.equals(actualBounds),
|
2016-04-01 20:29:09 +03:00
|
|
|
"The vertically scaled overlay should have bounds " +
|
2016-04-01 23:54:29 +03:00
|
|
|
expectedBounds + " but found " + actualBounds);
|
2016-04-01 20:29:09 +03:00
|
|
|
|
2017-12-05 05:01:30 +03:00
|
|
|
done();
|
2016-04-01 20:29:09 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// ----------
|
2017-12-05 05:01:30 +03:00
|
|
|
QUnit.test('Not scaled overlay rotation mode NO_ROTATION', function(assert) {
|
|
|
|
var done = assert.async();
|
2016-04-01 20:29:09 +03:00
|
|
|
viewer = OpenSeadragon({
|
|
|
|
id: 'example-overlays',
|
|
|
|
prefixUrl: '/build/openseadragon/images/',
|
|
|
|
tileSources: '/test/data/testpattern.dzi',
|
|
|
|
springStiffness: 100, // Faster animation = faster tests
|
|
|
|
degrees: 45,
|
|
|
|
overlays: [{
|
|
|
|
id: "not-scaled-overlay",
|
|
|
|
x: 1,
|
|
|
|
y: 0,
|
|
|
|
placement: OpenSeadragon.Placement.TOP_RIGHT,
|
|
|
|
rotationMode: OpenSeadragon.OverlayRotationMode.NO_ROTATION
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
|
|
|
|
viewer.addOnceHandler('open', function() {
|
2024-09-17 14:16:00 +03:00
|
|
|
var $overlay = $("#overlay-wrapper-not-scaled-overlay");
|
2016-04-01 20:29:09 +03:00
|
|
|
var notScaledWidth = 100;
|
|
|
|
var notScaledHeight = 100;
|
|
|
|
$overlay.get(0).style.width = notScaledWidth + "px";
|
|
|
|
$overlay.get(0).style.height = notScaledHeight + "px";
|
|
|
|
|
|
|
|
var viewport = viewer.viewport;
|
|
|
|
var notScaledSize = viewport.deltaPointsFromPixelsNoRotate(
|
|
|
|
new OpenSeadragon.Point(notScaledWidth, notScaledHeight));
|
|
|
|
|
|
|
|
// Force refresh to takes new dimensions into account.
|
|
|
|
viewer._drawOverlays();
|
|
|
|
|
|
|
|
var expectedPosition = viewport.viewportToViewerElementCoordinates(
|
|
|
|
new OpenSeadragon.Point(1, 0))
|
|
|
|
.minus(new OpenSeadragon.Point(notScaledWidth, 0));
|
|
|
|
var actualPosition = $overlay.position();
|
2017-12-05 05:01:30 +03:00
|
|
|
Util.assessNumericValue(assert, actualPosition.left, expectedPosition.x, epsilon,
|
2016-04-01 20:29:09 +03:00
|
|
|
"Not scaled overlay position.x should adjust to rotation.");
|
2017-12-05 05:01:30 +03:00
|
|
|
Util.assessNumericValue(assert, actualPosition.top, expectedPosition.y, epsilon,
|
2016-04-01 20:29:09 +03:00
|
|
|
"Not scaled overlay position.y should adjust to rotation.");
|
|
|
|
|
|
|
|
var actualWidth = $overlay.width();
|
|
|
|
var actualHeight = $overlay.height();
|
2017-12-05 05:01:30 +03:00
|
|
|
Util.assessNumericValue(assert, actualWidth, notScaledWidth, epsilon,
|
2016-04-01 20:29:09 +03:00
|
|
|
"Not scaled overlay width should not adjust to rotation.");
|
2017-12-05 05:01:30 +03:00
|
|
|
Util.assessNumericValue(assert, actualHeight, notScaledHeight, epsilon,
|
2016-04-01 20:29:09 +03:00
|
|
|
"Not scaled overlay height should not adjust to rotation.");
|
|
|
|
|
|
|
|
var actualBounds = viewer.getOverlayById("not-scaled-overlay")
|
|
|
|
.getBounds(viewport);
|
|
|
|
var expectedBounds = new OpenSeadragon.Rect(
|
|
|
|
1 - notScaledSize.x, 0, notScaledSize.x, notScaledSize.y)
|
|
|
|
.rotate(-45, new OpenSeadragon.Point(1, 0));
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.ok(expectedBounds.equals(actualBounds),
|
2016-04-01 20:29:09 +03:00
|
|
|
"Not scaled overlay should have bounds " +
|
2016-04-01 23:54:29 +03:00
|
|
|
expectedBounds + " but found " + actualBounds);
|
2016-04-01 20:29:09 +03:00
|
|
|
|
2017-12-05 05:01:30 +03:00
|
|
|
done();
|
2016-04-01 20:29:09 +03:00
|
|
|
});
|
|
|
|
});
|
2016-04-01 22:46:43 +03:00
|
|
|
|
|
|
|
// ----------
|
2017-12-05 05:01:30 +03:00
|
|
|
QUnit.test('Fully scaled overlay rotation mode BOUNDING_BOX', function(assert) {
|
|
|
|
var done = assert.async();
|
2016-04-01 22:46:43 +03:00
|
|
|
viewer = OpenSeadragon({
|
|
|
|
id: 'example-overlays',
|
|
|
|
prefixUrl: '/build/openseadragon/images/',
|
|
|
|
tileSources: '/test/data/testpattern.dzi',
|
|
|
|
springStiffness: 100, // Faster animation = faster tests
|
|
|
|
degrees: 45,
|
|
|
|
overlays: [{
|
|
|
|
id: "fully-scaled-overlay",
|
|
|
|
x: 1,
|
|
|
|
y: 1,
|
|
|
|
width: 1,
|
|
|
|
height: 1,
|
|
|
|
placement: OpenSeadragon.Placement.BOTTOM_RIGHT,
|
|
|
|
rotationMode: OpenSeadragon.OverlayRotationMode.BOUNDING_BOX
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
|
|
|
|
viewer.addOnceHandler('open', function() {
|
|
|
|
var viewport = viewer.viewport;
|
|
|
|
|
2024-09-17 14:16:00 +03:00
|
|
|
var $overlay = $("#overlay-wrapper-fully-scaled-overlay");
|
2016-04-01 22:46:43 +03:00
|
|
|
var expectedRect = viewport.viewportToViewerElementRectangle(
|
|
|
|
new OpenSeadragon.Rect(0, 0, 1, 1)).getBoundingBox();
|
|
|
|
var actualPosition = $overlay.position();
|
2017-12-05 05:01:30 +03:00
|
|
|
Util.assessNumericValue(assert, actualPosition.left, expectedRect.x, epsilon,
|
2016-04-01 22:46:43 +03:00
|
|
|
"Scaled overlay position.x should adjust to rotation.");
|
2017-12-05 05:01:30 +03:00
|
|
|
Util.assessNumericValue(assert, actualPosition.top, expectedRect.y, epsilon,
|
2016-04-01 22:46:43 +03:00
|
|
|
"Scaled overlay position.y should adjust to rotation.");
|
|
|
|
|
|
|
|
var actualWidth = $overlay.width();
|
|
|
|
var actualHeight = $overlay.height();
|
2017-12-05 05:01:30 +03:00
|
|
|
Util.assessNumericValue(assert, actualWidth, expectedRect.width, epsilon,
|
2016-04-01 22:46:43 +03:00
|
|
|
"Scaled overlay width should not adjust to rotation.");
|
2017-12-05 05:01:30 +03:00
|
|
|
Util.assessNumericValue(assert, actualHeight, expectedRect.height, epsilon,
|
2016-04-01 22:46:43 +03:00
|
|
|
"Scaled overlay height should not adjust to rotation.");
|
|
|
|
|
|
|
|
var actualBounds = viewer.getOverlayById("fully-scaled-overlay")
|
|
|
|
.getBounds(viewport);
|
|
|
|
var expectedBounds = new OpenSeadragon.Rect(
|
|
|
|
0.5, -0.5, Math.sqrt(2), Math.sqrt(2), 45);
|
|
|
|
var boundsEpsilon = 0.000001;
|
2017-12-05 05:01:30 +03:00
|
|
|
Util.assessNumericValue(assert, actualBounds.x, expectedBounds.x, boundsEpsilon,
|
2016-04-01 22:46:43 +03:00
|
|
|
"The fully scaled overlay should have adjusted bounds.x");
|
2017-12-05 05:01:30 +03:00
|
|
|
Util.assessNumericValue(assert, actualBounds.y, expectedBounds.y, boundsEpsilon,
|
2016-04-01 22:46:43 +03:00
|
|
|
"The fully scaled overlay should have adjusted bounds.y");
|
2017-12-05 05:01:30 +03:00
|
|
|
Util.assessNumericValue(assert, actualBounds.width, expectedBounds.width, boundsEpsilon,
|
2016-04-01 22:46:43 +03:00
|
|
|
"The fully scaled overlay should have adjusted bounds.width");
|
2017-12-05 05:01:30 +03:00
|
|
|
Util.assessNumericValue(assert, actualBounds.height, expectedBounds.height, boundsEpsilon,
|
2016-04-01 22:46:43 +03:00
|
|
|
"The fully scaled overlay should have adjusted bounds.height");
|
2017-12-05 05:01:30 +03:00
|
|
|
Util.assessNumericValue(assert, actualBounds.degrees, expectedBounds.degrees, boundsEpsilon,
|
2016-04-01 22:46:43 +03:00
|
|
|
"The fully scaled overlay should have adjusted bounds.degrees");
|
|
|
|
|
2017-12-05 05:01:30 +03:00
|
|
|
done();
|
2016-04-01 22:46:43 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2024-09-17 14:16:00 +03:00
|
|
|
|
|
|
|
// ----------
|
|
|
|
QUnit.test('Remove Child from Overlay', function(assert){
|
|
|
|
var done = assert.async();
|
|
|
|
viewer = OpenSeadragon({
|
|
|
|
id: 'example-overlays',
|
|
|
|
prefixUrl: '/build/openseadragon/images/',
|
|
|
|
tileSources: '/test/data/testpattern.dzi'
|
|
|
|
});
|
|
|
|
|
|
|
|
viewer.addOnceHandler('open', function() {
|
|
|
|
var $overlay = document.createElement("div");
|
|
|
|
var something = document.createElement("p");
|
|
|
|
$overlay.appendChild(something);
|
|
|
|
viewer.addOverlay($overlay);
|
|
|
|
$overlay.removeChild(something);
|
|
|
|
something.innerHTML = '...';
|
|
|
|
assert.equal(something.innerHTML, '...');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-04-01 23:54:29 +03:00
|
|
|
// ----------
|
2017-12-05 05:01:30 +03:00
|
|
|
QUnit.test('Fully scaled overlay rotation mode EXACT', function(assert) {
|
|
|
|
var done = assert.async();
|
2016-04-01 23:54:29 +03:00
|
|
|
viewer = OpenSeadragon({
|
|
|
|
id: 'example-overlays',
|
|
|
|
prefixUrl: '/build/openseadragon/images/',
|
|
|
|
tileSources: '/test/data/testpattern.dzi',
|
|
|
|
springStiffness: 100, // Faster animation = faster tests
|
|
|
|
degrees: 45,
|
|
|
|
overlays: [{
|
|
|
|
id: "fully-scaled-overlay",
|
|
|
|
x: 1,
|
|
|
|
y: 1,
|
|
|
|
width: 1,
|
|
|
|
height: 1,
|
|
|
|
placement: OpenSeadragon.Placement.BOTTOM_RIGHT,
|
|
|
|
rotationMode: OpenSeadragon.OverlayRotationMode.EXACT
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
|
|
|
|
viewer.addOnceHandler('open', function() {
|
|
|
|
var viewport = viewer.viewport;
|
2024-09-17 14:16:00 +03:00
|
|
|
var $overlay = $("#overlay-wrapper-fully-scaled-overlay");
|
2016-04-01 23:54:29 +03:00
|
|
|
var expectedSize = viewport.deltaPixelsFromPointsNoRotate(
|
|
|
|
new OpenSeadragon.Point(1, 1));
|
|
|
|
var expectedPosition = viewport.pixelFromPoint(
|
|
|
|
new OpenSeadragon.Point(1, 1))
|
|
|
|
.minus(expectedSize);
|
|
|
|
// We can't rely on jQuery.position with transforms.
|
|
|
|
var actualStyle = $overlay.get(0).style;
|
|
|
|
var left = Number(actualStyle.left.replace("px", ""));
|
|
|
|
var top = Number(actualStyle.top.replace("px", ""));
|
2017-12-05 05:01:30 +03:00
|
|
|
Util.assessNumericValue(assert, left, expectedPosition.x, epsilon,
|
2016-04-01 23:54:29 +03:00
|
|
|
"Scaled overlay position.x should adjust to rotation.");
|
2017-12-05 05:01:30 +03:00
|
|
|
Util.assessNumericValue(assert, top, expectedPosition.y, epsilon,
|
2016-04-01 23:54:29 +03:00
|
|
|
"Scaled overlay position.y should adjust to rotation.");
|
|
|
|
|
|
|
|
var actualWidth = $overlay.width();
|
|
|
|
var actualHeight = $overlay.height();
|
2017-12-05 05:01:30 +03:00
|
|
|
Util.assessNumericValue(assert, actualWidth, expectedSize.x, epsilon,
|
2016-04-01 23:54:29 +03:00
|
|
|
"Scaled overlay width should not adjust to rotation.");
|
2017-12-05 05:01:30 +03:00
|
|
|
Util.assessNumericValue(assert, actualHeight, expectedSize.y, epsilon,
|
2016-04-01 23:54:29 +03:00
|
|
|
"Scaled overlay height should not adjust to rotation.");
|
|
|
|
|
|
|
|
var transformOriginProp = OpenSeadragon.getCssPropertyWithVendorPrefix(
|
|
|
|
'transformOrigin');
|
|
|
|
var transformProp = OpenSeadragon.getCssPropertyWithVendorPrefix(
|
|
|
|
'transform');
|
|
|
|
var transformOrigin = actualStyle[transformOriginProp];
|
|
|
|
// Some browsers replace "right bottom" by "100% 100%"
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.ok(transformOrigin.match(/(100% 100%)|(right bottom)/),
|
2016-04-01 23:54:29 +03:00
|
|
|
"Transform origin should be right bottom. Got: " + transformOrigin);
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.equal(actualStyle[transformProp], "rotate(45deg)",
|
2016-04-01 23:54:29 +03:00
|
|
|
"Transform should be rotate(45deg).");
|
|
|
|
|
|
|
|
var actualBounds = viewer.getOverlayById("fully-scaled-overlay")
|
|
|
|
.getBounds(viewport);
|
|
|
|
var expectedBounds = new OpenSeadragon.Rect(0, 0, 1, 1);
|
2017-12-05 05:01:30 +03:00
|
|
|
assert.ok(expectedBounds.equals(actualBounds),
|
2016-04-01 23:54:29 +03:00
|
|
|
"The fully scaled overlay should have bounds " +
|
|
|
|
expectedBounds + " but found " + actualBounds);
|
|
|
|
|
2017-12-05 05:01:30 +03:00
|
|
|
done();
|
2016-04-01 23:54:29 +03:00
|
|
|
});
|
|
|
|
});
|
2016-03-31 20:25:59 +03:00
|
|
|
})();
|