Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onSelection rect parameter is in pixels? #7

Closed
SuneRadich opened this issue Dec 2, 2015 · 3 comments
Closed

onSelection rect parameter is in pixels? #7

SuneRadich opened this issue Dec 2, 2015 · 3 comments

Comments

@SuneRadich
Copy link

I am trying to add an overlay after a successful selection. I want the overlay be positioned and sized like the selection.

My thought was to use the Rect object that is being passed to the onSelection function, like so

onSelection: function(rect) {
    viewer.addOverlay({
        element: $('<div class="overlay" style="background-color: red"></div>')[0],
        location: rect
    });
}

It seems that the overlay is being positioned way off screen somewhere, maybe because the rect that is being passed in has values for x, y, width, and height in pixels, and that the addOverlay location option expects the values to be in percentages.

If I instead set the location to

location: new OpenSeadragon.Rect(0.33, 0.75, 0.5, 0.25)

I can hardcode an overlay.

How can I correctly add an overlay to the selected area? Do I need to tell OpenSeadragon to accept pixel values? Or should I somehow convert the values?

And yes, this is my first time working with OpenSeadragon, so I might have missed something very obvious :)

@MindFreeze
Copy link
Contributor

Just added a new option that should help you (returnPixelCoordinates). Set it to false to get the selection in percentages. I don't see you using rotation but if you need rotation to work you will have to use a SelectionOverlay. See src/selection.js:282 for that.

@SuneRadich
Copy link
Author

I actually figured out that I could use

viewer.viewport.imageToViewportRectangle(rect)

on the selection rect instance to get the correct values for the overlay.

@MindFreeze
Copy link
Contributor

I was going to suggest that at first but decided that having this as an option made sense anyway ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants