问题描述:

I'm trying to implement an interface between 1) a custom-built UI device that generates various events (scroll, click, etc) and 2) the OpenSeadragon viewer, so that the external device can be used to navigate the image. The device sends events that can be detected in a browser (javascript, of course). The online documentation shows how to intercept mouse/keyboard events to provide custom handling, but I don't see an obvious way to trigger the behavior I want (zoom, scroll) programmatically, rather than directly through the standard UI system (mouse, keyboard).

My question is, what is the right way to hook into the OpenSeadragon viewer to trigger scroll or zoom behavior?

网友答案:

You can use viewport.panBy and viewport.zoomBy methods. See: http://openseadragon.github.io/docs/OpenSeadragon.Viewport.html

var viewer = new OpenSeadragon({...});

viewer.addHandler("open", function() {
    viewer.viewport.panBy(...);
    viewer.viewport.zoomBy(1.1);
});

The default values are 1.1 for zoom in, and 0.9 for zoom out. For the pan, you might want to look into this function: https://github.com/openseadragon/openseadragon/blob/master/src/viewer.js#L2398

相关阅读:
Top