question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

imageToViewportRectangle not working as expected

See original GitHub issue

I am using OpenSeadragon to view an image and crop regions from it. The cropped regions are stored in a database using their image coordinates (in pixels). I want the cropped images to appear when I reopen the page.

I can add the overlay if I do the following

var overlayElement = document.createElement('div');
overlayElement.id = 'region_box_' + String(region_num);
overlayElement.style.border = "4px solid green";
var rect = new OpenSeadragon.Rect({{region.x}}/viewer.source.width;, {{region.y}}/ viewer.source.height, {{region.width}}/viewer.source.width;, {{region.height}}/viewer.source.height)

viewer.addOverlay(overlayElement, rect);

Is there a better way to do this? I had expected this to work, but it does not transform the coordinates at all so I must be using it incorrectly: rect = viewer.viewport.imageToViewportRectangle({{region.x}}, {{region.y}}, {{region.width}}, {{region.height}})

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
shyamkumaryadavcommented, Jan 19, 2022

Happy to know that you resolve the issue!

1reaction
gregster7commented, Jan 26, 2022

Yeah, you’ll definitely want to make sure the image is loaded. Put it inside a viewer.addHandler('open', function() { ... }).

That fixed it - thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Overlay to Image Rectangle · Issue #787 - GitHub
I'd like to be able to pass the pixels back to allow for cropping, etc. ... var overlay = viewer.viewport.imageToViewportRectangle(x, y, w, h);...
Read more >
openseadragon/openseadragon - Gitter
I understand the various 'points' displayed on the coordinates page, but I'm struggling to make sense of the rectangles I need to work...
Read more >
Adding/positioning independent overlays to openseadragon ...
Looks like this is a bug with OpenSeadragon! Here's the issue ticket: https://github.com/openseadragon/openseadragon/issues/1412.
Read more >
Source: openseadragon.js
NOTE: usually, post data is expected to be ampersand-separated (just ... Preexisting formats that are not being updated are left unchanged.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found