These are chat archives for openseadragon/openseadragon

13th
Mar 2017
sickrandir
@sickrandir
Mar 13 2017 06:59
Hi guy, still haven't found a solution to this. The click event causes the zoom to happen. Maybe I'm tryng to block the wrong event or the event has already propagated when I block it. I still don't understand fully the event management in OSD
foobarable
@foobarable
Mar 13 2017 07:29
@sickrandir I used to osd option to prevent zoom by default and implemented my own zoom function in the canvas-click handler
gestureSettingsMouse: { "clickToZoom": false },
sickrandir
@sickrandir
Mar 13 2017 10:37
@foobarable thanks for the suggestion. I'll try that. Is there a function to call to get a "standard" zoom in event or do I have to manage the zoom levels?
foobarable
@foobarable
Mar 13 2017 10:39
@sickrandir I jus get the bounds of the object i want to zoom to and call scope.osd.viewport.fitBounds(bounds);
you can get the bounds via var bounds = osd.world.getItemAt(index).getBounds(); for example
sickrandir
@sickrandir
Mar 13 2017 10:51
yes, I can understande doing that. I was wondering, since I wanted to get the standard zoom-in around the clicked point, if there was a more automated way to do it
foobarable
@foobarable
Mar 13 2017 10:52
maybe my solution is not good either. lets wait for the osd gods to comment
sickrandir
@sickrandir
Mar 13 2017 11:03
I think your solution is good, just a bit different use case
sickrandir
@sickrandir
Mar 13 2017 11:35
another unrelated issue that I'm seeing is this: after implementing the solution for pan with the mouse cursor contained here: http://codepen.io/imoskvin/pen/RaeWaL
everything works except that constrainDuringPan is not enforced anymore
and the image gets panned around even if completely zoomed out
Jake
@jakeparis
Mar 13 2017 15:37
Hi all. Now sure if this is the best venue for a newbie question. Can openseadragon be used for zooming a jpg without createing DZI tiles? The docs are a little vague, and I don't seem to be able to get it to work in a stripped down test.
OpenSeadragon({
    id: "ImageID",
    tileSources: {
        type: 'image',
        url: "cat.jpg"
    },
    overlays: []
})
Ian Gilman
@iangilman
Mar 13 2017 17:02
@jakeparis That should work, assuming there's a div on your page with a width and height and id ImageID and that cat.jpg exists in the same folder as your web page
Are there any errors in the console?
But yes, you don't need to turn it into tiles.
@sickrandir Unfortunately the OSD click event doesn't have a facility for canceling the default click... seems like that would be a good thing though, if someone wanted to add it
Jake
@jakeparis
Mar 13 2017 17:06
@iangilman Thank you for that. It was the style of the div I was trying to inject osd into was causing me the problems, I was thinking of the output in terms of an image and hadn't set an explicit height/width.
sickrandir
@sickrandir
Mar 13 2017 17:06
so basically when the canvas-click event fires it's too late to cancel the click right?
Ian Gilman
@iangilman
Mar 13 2017 17:06
@sickrandir Correct. As for replicating the existing zoom functionality, it's just viewer.viewport.zoomBy(viewer.zoomPerClick, viewer.viewport.pointFromPixel(event.position, true));
sickrandir
@sickrandir
Mar 13 2017 17:07
@iangilman nice!
Ian Gilman
@iangilman
Mar 13 2017 17:07
(It probably wouldn't be too hard to add cancel ability to OSD, though, if you wanted to look into it)
@jakeparis Cool, that's an easy mistake to make
sickrandir
@sickrandir
Mar 13 2017 17:08
@iangilman is there any other event for which a similar facility is implemented? just to get an idea and look at the code...
Ian Gilman
@iangilman
Mar 13 2017 17:09
Here's the click code... you can see that the event is actually fired after the zooming happens: https://github.com/openseadragon/openseadragon/blob/master/src/viewer.js#L2456-L2497
Ian Gilman
@iangilman
Mar 13 2017 17:16
@sickrandir Looks like we're using event.preventDefaultAction as our flag. You set it to true inside your event handler. Here's an example of implementation: https://github.com/openseadragon/openseadragon/blob/master/src/viewer.js#L880-L898
Btw, I suppose another hack would be to monkey patch the click handler:
var originalClickHandler = viewer.innerTracker.clickHandler;
viewer.innerTracker.clickHandler = OpenSeadragon.delegate(viewer, function(event) {
    if (...) {
      return;
    }

    originalClickHandler(event);
});
...but it would be nice to have the functionality built into OSD, of course
@sickrandir As for your other question (About mouse panning with constraints), you need to use fitBoundsWithConstraints instead of fitBounds in your code, and that should work
sickrandir
@sickrandir
Mar 13 2017 17:24
@iangilman fitBoundsWithConstraints works perfectly!
@iangilman ok I'm looking at the code right now to see how to insert preventDefault for the standard click
Ian Gilman
@iangilman
Mar 13 2017 17:27
Awesome :)
sickrandir
@sickrandir
Mar 13 2017 17:46
 if ( !event.preventDefaultAction && this.viewport && event.quick ) {
        gestureSettings = this.gestureSettingsByDeviceType( event.pointerType );
        if ( gestureSettings.clickToZoom ) {
            this.viewport.zoomBy(
                event.shift ? 1.0 / this.zoomPerClick : this.zoomPerClick,
                this.viewport.pointFromPixel( event.position, true )
            );
            this.viewport.applyConstraints();
        }
    }
line 2466
it seems that the onCanvasClick function already takes preventDefaultAction into account
so, correct me if I'm wrong, it's just a matter of adding the attribute to the event
right?
Ian Gilman
@iangilman
Mar 13 2017 17:48
Well, the problem is the raiseEvent is after that... so there's no chance to set it in your canvas-click handler.
So yeah, just moving the raiseEventabove that section might be all that's necessary
I'm not sure what's supposed to have been able to set preventDefaultAction as it currently stands
And yeah, explicitly adding preventDefaultAction to the canvas-click event would probably be good (though the default of undefined would be okay, it's good to be explicit), and definitely it needs to be added to the doc comments.
Also, the canvas-click event isn't the same object as the event that's getting tested for preventDefaultAction in the code above, so you'd want to test both
The preventDefaultAction that's currently being tested has something to do with the MouseTracker, but like I said I don't really understand when/where you would have a chance to set it
...but it's probably good to keep it around just in case
Ian Gilman
@iangilman
Mar 13 2017 20:10
@sickrandir ^