mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-22 13:16:10 +03:00
Set overlays position and size with floating point values.
This commit is contained in:
parent
f6c09ca716
commit
33bd943b7a
@ -241,9 +241,6 @@
|
||||
var size = this.size = positionAndSize.size;
|
||||
var rotate = positionAndSize.rotate;
|
||||
|
||||
position = position.apply(Math.round);
|
||||
size = size.apply(Math.round);
|
||||
|
||||
// call the onDraw callback if it exists to allow one to overwrite
|
||||
// the drawing/positioning/sizing of the overlay
|
||||
if (this.onDraw) {
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
( function() {
|
||||
var viewer;
|
||||
// jQuery.position can give results quite different than what set in style.left
|
||||
var epsilon = 1;
|
||||
|
||||
module( "Overlays", {
|
||||
setup: function() {
|
||||
@ -241,26 +243,34 @@
|
||||
var viewport = viewer.viewport;
|
||||
|
||||
var expPosition = viewport.imageToViewerElementCoordinates(
|
||||
new OpenSeadragon.Point( 13, 120 ) ).apply( Math.round );
|
||||
new OpenSeadragon.Point(13, 120));
|
||||
var actPosition = $("#overlay").position();
|
||||
equal( actPosition.left, expPosition.x, "X position mismatch " + contextMessage );
|
||||
equal( actPosition.top, expPosition.y, "Y position mismatch " + contextMessage );
|
||||
Util.assessNumericValue(actPosition.left, expPosition.x, epsilon,
|
||||
"X position mismatch " + contextMessage);
|
||||
Util.assessNumericValue(actPosition.top, expPosition.y, epsilon,
|
||||
"Y position mismatch " + contextMessage);
|
||||
|
||||
var zoom = viewport.viewportToImageZoom(viewport.getZoom(true));
|
||||
var expectedWidth = Math.round( 124 * zoom );
|
||||
var expectedHeight = Math.round( 132 * zoom );
|
||||
equal( $( "#overlay" ).width(), expectedWidth, "Width mismatch " + contextMessage );
|
||||
equal( $( "#overlay" ).height( ), expectedHeight, "Height mismatch " + contextMessage );
|
||||
var expectedWidth = 124 * zoom;
|
||||
var expectedHeight = 132 * zoom;
|
||||
Util.assessNumericValue($("#overlay").width(), expectedWidth, epsilon,
|
||||
"Width mismatch " + contextMessage);
|
||||
Util.assessNumericValue($("#overlay").height(), expectedHeight, epsilon,
|
||||
"Height mismatch " + contextMessage);
|
||||
|
||||
|
||||
expPosition = viewport.imageToViewerElementCoordinates(
|
||||
new OpenSeadragon.Point( 400, 500 ) ).apply( Math.round );
|
||||
new OpenSeadragon.Point(400, 500));
|
||||
actPosition = $("#fixed-overlay").position();
|
||||
equal( actPosition.left, expPosition.x, "Fixed overlay X position mismatch " + contextMessage );
|
||||
equal( actPosition.top, expPosition.y, "Fixed overlay Y position mismatch " + contextMessage );
|
||||
Util.assessNumericValue(actPosition.left, expPosition.x, epsilon,
|
||||
"Fixed overlay X position mismatch " + contextMessage);
|
||||
Util.assessNumericValue(actPosition.top, expPosition.y, epsilon,
|
||||
"Fixed overlay Y position mismatch " + contextMessage);
|
||||
|
||||
equal( $( "#fixed-overlay" ).width(), 70, "Fixed overlay width mismatch " + contextMessage );
|
||||
equal( $( "#fixed-overlay" ).height( ), 60, "Fixed overlay height mismatch " + contextMessage );
|
||||
Util.assessNumericValue($("#fixed-overlay").width(), 70, epsilon,
|
||||
"Fixed overlay width mismatch " + contextMessage);
|
||||
Util.assessNumericValue($("#fixed-overlay").height(), 60, epsilon,
|
||||
"Fixed overlay height mismatch " + contextMessage);
|
||||
}
|
||||
|
||||
waitForViewer( function() {
|
||||
@ -305,25 +315,33 @@
|
||||
var viewport = viewer.viewport;
|
||||
|
||||
var expPosition = viewport.viewportToViewerElementCoordinates(
|
||||
new OpenSeadragon.Point( 0.2, 0.1 ) ).apply( Math.round );
|
||||
new OpenSeadragon.Point(0.2, 0.1));
|
||||
var actPosition = $( "#overlay" ).position();
|
||||
equal( actPosition.left, expPosition.x, "X position mismatch " + contextMessage );
|
||||
equal( actPosition.top, expPosition.y, "Y position mismatch " + contextMessage );
|
||||
Util.assessNumericValue(actPosition.left, expPosition.x, epsilon,
|
||||
"X position mismatch " + contextMessage);
|
||||
Util.assessNumericValue(actPosition.top, expPosition.y, epsilon,
|
||||
"Y position mismatch " + contextMessage);
|
||||
|
||||
var expectedSize = viewport.deltaPixelsFromPoints(
|
||||
new OpenSeadragon.Point(0.5, 0.1));
|
||||
equal( $( "#overlay" ).width(), expectedSize.x, "Width mismatch " + contextMessage );
|
||||
equal( $( "#overlay" ).height(), expectedSize.y, "Height mismatch " + contextMessage );
|
||||
Util.assessNumericValue($("#overlay").width(), expectedSize.x, epsilon,
|
||||
"Width mismatch " + contextMessage);
|
||||
Util.assessNumericValue($("#overlay").height(), expectedSize.y, epsilon,
|
||||
"Height mismatch " + contextMessage);
|
||||
|
||||
|
||||
expPosition = viewport.viewportToViewerElementCoordinates(
|
||||
new OpenSeadragon.Point( 0.5, 0.6 ) ).apply( Math.round );
|
||||
new OpenSeadragon.Point(0.5, 0.6));
|
||||
actPosition = $("#fixed-overlay").position();
|
||||
equal( actPosition.left, expPosition.x, "Fixed overlay X position mismatch " + contextMessage );
|
||||
equal( actPosition.top, expPosition.y, "Fixed overlay Y position mismatch " + contextMessage );
|
||||
Util.assessNumericValue(actPosition.left, expPosition.x, epsilon,
|
||||
"Fixed overlay X position mismatch " + contextMessage);
|
||||
Util.assessNumericValue(actPosition.top, expPosition.y, epsilon,
|
||||
"Fixed overlay Y position mismatch " + contextMessage);
|
||||
|
||||
equal( $( "#fixed-overlay" ).width(), 70, "Fixed overlay width mismatch " + contextMessage );
|
||||
equal( $( "#fixed-overlay" ).height( ), 60, "Fixed overlay height mismatch " + contextMessage );
|
||||
Util.assessNumericValue($("#fixed-overlay").width(), 70, epsilon,
|
||||
"Fixed overlay width mismatch " + contextMessage);
|
||||
Util.assessNumericValue($("#fixed-overlay").height(), 60, epsilon,
|
||||
"Fixed overlay height mismatch " + contextMessage);
|
||||
}
|
||||
|
||||
waitForViewer( function() {
|
||||
@ -373,10 +391,12 @@
|
||||
var viewport = viewer.viewport;
|
||||
|
||||
var expPosition = viewport.viewportToViewerElementCoordinates(
|
||||
new OpenSeadragon.Point( 0.2, 0.1 ) ).apply( Math.round );
|
||||
new OpenSeadragon.Point(0.2, 0.1));
|
||||
var actPosition = $("#overlay").position();
|
||||
equal( actPosition.left, expPosition.x, "X position mismatch " + contextMessage );
|
||||
equal( actPosition.top, expPosition.y, "Y position mismatch " + contextMessage );
|
||||
Util.assessNumericValue(actPosition.left, expPosition.x, epsilon,
|
||||
"X position mismatch " + contextMessage);
|
||||
Util.assessNumericValue(actPosition.top, expPosition.y, epsilon,
|
||||
"Y position mismatch " + contextMessage);
|
||||
}
|
||||
|
||||
function checkFixedOverlayPosition( expectedOffset, contextMessage ) {
|
||||
@ -384,11 +404,12 @@
|
||||
|
||||
var expPosition = viewport.viewportToViewerElementCoordinates(
|
||||
new OpenSeadragon.Point(0.5, 0.6))
|
||||
.apply( Math.round )
|
||||
.plus(expectedOffset);
|
||||
var actPosition = $("#fixed-overlay").position();
|
||||
equal( actPosition.left, expPosition.x, "Fixed overlay X position mismatch " + contextMessage );
|
||||
equal( actPosition.top, expPosition.y, "Fixed overlay Y position mismatch " + contextMessage );
|
||||
Util.assessNumericValue(actPosition.left, expPosition.x, epsilon,
|
||||
"Fixed overlay X position mismatch " + contextMessage);
|
||||
Util.assessNumericValue(actPosition.top, expPosition.y, epsilon,
|
||||
"Fixed overlay Y position mismatch " + contextMessage);
|
||||
}
|
||||
|
||||
waitForViewer( function() {
|
||||
@ -449,11 +470,12 @@
|
||||
|
||||
var expPosition = viewport.viewportToViewerElementCoordinates(
|
||||
new OpenSeadragon.Point(0.5, 0.6))
|
||||
.apply( Math.round )
|
||||
.plus(expectedOffset);
|
||||
var actPosition = $("#fixed-overlay").position();
|
||||
equal( actPosition.left, expPosition.x, "Fixed overlay X position mismatch " + contextMessage );
|
||||
equal( actPosition.top, expPosition.y, "Fixed overlay Y position mismatch " + contextMessage );
|
||||
Util.assessNumericValue(actPosition.left, expPosition.x, epsilon,
|
||||
"Fixed overlay X position mismatch " + contextMessage);
|
||||
Util.assessNumericValue(actPosition.top, expPosition.y, epsilon,
|
||||
"Fixed overlay Y position mismatch " + contextMessage);
|
||||
}
|
||||
|
||||
waitForViewer( function() {
|
||||
@ -503,11 +525,12 @@
|
||||
|
||||
var expPosition = viewport.viewportToViewerElementCoordinates(
|
||||
new OpenSeadragon.Point(0.5, 0.6))
|
||||
.apply( Math.round )
|
||||
.plus(expectedOffset);
|
||||
var actPosition = $( "#fixed-overlay" ).position();
|
||||
equal( actPosition.left, expPosition.x, "Fixed overlay X position mismatch " + contextMessage );
|
||||
equal( actPosition.top, expPosition.y, "Fixed overlay Y position mismatch " + contextMessage );
|
||||
Util.assessNumericValue(actPosition.left, expPosition.x, epsilon,
|
||||
"Fixed overlay X position mismatch " + contextMessage);
|
||||
Util.assessNumericValue(actPosition.top, expPosition.y, epsilon,
|
||||
"Fixed overlay Y position mismatch " + contextMessage);
|
||||
}
|
||||
|
||||
waitForViewer( function() {
|
||||
|
Loading…
Reference in New Issue
Block a user