Moved Viewport.goHome to Viewer.goHome.

This commit is contained in:
Ian Gilman 2014-08-12 16:44:53 -07:00
parent 66b8d7e191
commit 5c7c1d5b6c
6 changed files with 51 additions and 41 deletions

View File

@ -333,7 +333,7 @@ $.Viewer = function( options ) {
_this.viewport.applyConstraints();
return false;
case 48://0|)
_this.viewport.goHome();
_this.goHome();
_this.viewport.applyConstraints();
return false;
case 119://w
@ -622,6 +622,28 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
this.element = null;
},
/**
* @function
* @param {Boolean} immediately
* @fires OpenSeadragon.Viewer.event:home
*/
goHome: function(immediately) {
/**
* Raised when the "home" operation occurs (see {@link OpenSeadragon.Viewport#goHome}).
*
* @event home
* @memberof OpenSeadragon.Viewer
* @type {object}
* @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised this event.
* @property {Boolean} immediately
* @property {?Object} userData - Arbitrary subscriber-defined object.
*/
this.raiseEvent( 'home', {
immediately: immediately
});
this.viewport.fitBounds( this.world.getHomeBounds(), immediately );
},
/**
* @function
@ -1929,6 +1951,7 @@ function openTileSource( viewer, source, options ) {
});
_this.world.addItem( tiledImage );
_this.goHome( true );
// Now that we have a drawer, see if it supports rotate. If not we need to remove the rotate buttons
if (!_this.drawer.canRotate()) {
@ -2793,9 +2816,7 @@ function lightUp() {
function onHome() {
if ( this.viewport ) {
this.viewport.goHome();
}
this.goHome();
}

View File

@ -105,7 +105,6 @@ $.Viewport = function( options ) {
});
this.resetContentSize( this.contentSize );
this.goHome( true );
this.update();
};
@ -178,26 +177,15 @@ $.Viewport.prototype = /** @lends OpenSeadragon.Viewport.prototype */{
/**
* @function
* @param {Boolean} immediately
* @fires OpenSeadragon.Viewer.event:home
* @private
*/
goHome: function( immediately ) {
$.console.error("[Viewport.goHome] this function is deprecated; use Viewer.goHome instead");
if( this.viewer ){
/**
* Raised when the "home" operation occurs (see {@link OpenSeadragon.Viewport#goHome}).
*
* @event home
* @memberof OpenSeadragon.Viewer
* @type {object}
* @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised this event.
* @property {Boolean} immediately
* @property {?Object} userData - Arbitrary subscriber-defined object.
*/
this.viewer.raiseEvent( 'home', {
immediately: immediately
});
this.viewer.goHome(immediately);
}
return this.fitBounds( this.getHomeBounds(), immediately );
return this;
},
/**

View File

@ -133,7 +133,7 @@
};
viewer.addHandler('animation-finish', homeHandler);
viewport.goHome(true);
viewer.goHome(true);
}
viewer.addHandler("open", opener);

View File

@ -38,6 +38,7 @@
var addLayerHandler = function( event ) {
if ( event.options === options ) {
self.viewer.removeHandler( "add-layer", addLayerHandler );
self.viewer.goHome();
}
};
this.viewer.addHandler( "add-layer", addLayerHandler );

View File

@ -13,7 +13,7 @@
#highlights li {
cursor: pointer;
}
</style>
</head>
<body>
@ -23,33 +23,33 @@
<div id="contentDiv" class="openseadragon1"></div>
<div id="highlights"></div>
<select onchange="changeMethod(this.value);">
<option value=0>viewport.fitBoundsWithConstraints(bounds);</option>
<option value=1>viewport.fitBounds(bounds);</option>
<option value=2>viewport.fitBounds(bounds).applyConstraints();</option>
</select>
<input type="button" value="Go home" onclick="goHome()"/>
<script type="text/javascript">
var _viewer;
var _fittingMethod = 0;
var _highlights = [
{"queryPoint":[0.13789887359998443,0.43710575899579285], "radius":0.004479581945070337,"text":"Pipe"},
{"queryPoint":[0.5923298766583593,0.6461653354541856], "radius":0.013175241014912752,"text":"Fuel here"},
{"queryPoint":[0.43920338711232304,0.7483181389302148], "radius":0.09222668710438928, "text":"Wheel"},
{"queryPoint":[0.07341677959486298,0.9028719921872319], "radius":0.08996845561083797, "text":"Nothing special"}
];
];
var generateUniqueHash = (function() {
var counter = 0;
return function() {
return "openseadragon_" + (counter++);
};
})();
var _viewer = OpenSeadragon({
element: document.getElementById("contentDiv"),
showNavigationControl: false,
@ -59,8 +59,8 @@
Image: {
xmlns: "http://schemas.microsoft.com/deepzoom/2008",
Url: 'http://cdn.photosynth.net/ps2/19d5cf2b-77ed-439f-ac21-d3046320384c/packet/undistorted/img0043/',
Format: "jpg",
Overlap: 1,
Format: "jpg",
Overlap: 1,
TileSize: 510,
Size: {
Width: 4592,
@ -78,17 +78,17 @@
str += "</ul>";
document.getElementById("highlights").innerHTML = str;
});
function gotoHighlight(index) {
var highlight = _highlights[index];
var viewport = _viewer.viewport;
var contentSize = viewport.contentSize;
var scaling = 1.0 / viewport.viewportToImageZoom(viewport.getZoom());
var radius = highlight.radius*Math.min(contentSize.x, contentSize.y);/*annotation.accurateRadius*scaling;*/
var center = new OpenSeadragon.Point(contentSize.x*highlight.queryPoint[0], contentSize.y*highlight.queryPoint[1]);
var center = new OpenSeadragon.Point(contentSize.x*highlight.queryPoint[0], contentSize.y*highlight.queryPoint[1]);
var bounds = viewport.imageToViewportRectangle(new OpenSeadragon.Rect(center.x-radius, center.y-radius, radius*2, radius*2));
if (_fittingMethod === 0) {
viewport.fitBoundsWithConstraints(bounds, false);
}
@ -97,15 +97,15 @@
}
else if (_fittingMethod === 2) {
viewport.fitBounds(bounds, false).applyConstraints();
}
}
}
function changeMethod(value) {
_fittingMethod = parseInt(value, 10);
}
function goHome() {
_viewer.viewport.goHome();
_viewer.goHome();
}
</script>

View File

@ -270,7 +270,7 @@
waitForViewer( function() {
checkOverlayPosition( "after zoom and pan using image coordinates" );
viewer.viewport.goHome();
viewer.goHome();
waitForViewer( function() {
checkOverlayPosition( "after goHome using image coordinates" );
start();
@ -333,7 +333,7 @@
waitForViewer( function() {
checkOverlayPosition( "after zoom and pan using viewport coordinates" );
viewer.viewport.goHome();
viewer.goHome();
waitForViewer( function() {
checkOverlayPosition( "after goHome using viewport coordinates" );
start();