Possible overlays location issue
See original GitHub issueWe have this code snippet but:
var bd = viewer.viewport.getBounds()
viewer.addOverlay(
element: element,
location: new OpenSeadragon.Rect(p.x, p.y * bd.height, p.w, p.h * bd.height)
checkResize: true
)
The overlays methods is reference to the runtime overlays from the examples.
The question here is why we need to multiply the bd.height
factor for p.y
and p.h
part?
I mean we have correct x, y, w, h
values, but why we only needs to adjust the height related variable?
Thanks.
Issue Analytics
- State:
- Created 8 years ago
- Reactions:2
- Comments:18 (9 by maintainers)
Top Results From Across the Web
Fix Screen Overlay Detected Error - Android - Verizon
Screen Overlay Detected Error. From a Home screen, navigate: Apps. Settings . If you're unable to access settings, first place your device into...
Read more >How to Fix the “Screen Overlay Detected” Error on Android
Open Settings > Apps · Tap the Gear icon on the top right of the Settings page · Scroll down and tap “Special...
Read more >How to Fix Screen Overlay Error on Android - YouTube
Experiencing annoying “screen overlay ” errors on your Android device? Watch this video to learn how to fix Android screen overlay errors.
Read more >Why am I seeing a 'Screen overlay detected' error on Android?
Why am I seeing a 'Screen overlay detected' error on Android? · Go to the phone's 'Settings' · Find the 'Device' section and...
Read more >Problem setting up custom positioned overlays
I use the custom position which allow me to drag and drop the overlay in the exact area I want but then I...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
No worries… we’ll get to the bottom of this!
So, in your diagram, all of those values are in image coordinates, right? In other words, they are based on the actual pixels of the image? Also, I assume 0, 0 is the upper left corner of the image?
When putting the overlays on, you need to do that in viewport coordinates, which is not the same as image coordinates, so you need to convert between the two. By default viewport coordinates also start with 0, 0 in the upper left corner of the image and go to 1 on the right side of the image (the bottom coordinate is based on the aspect ratio). Because the origins of the two coordinate systems are the same, and since we’re just scaling between the two, we just need to find out what the ratio is between the two in order to convert any of the coordinates. In the case of the default, with viewport X of the right side of the image being 1, that ratio is 1 / image width. Once you have that ratio you can multiply any of the above image coordinates by it to find out the viewport coordinate version.
Does that make sense? If not, which part doesn’t make sense?
I realize dealing with different coordinate systems can be challenging, but unfortunately it’s a necessary part of any kind of zooming system.
BTW, we’ve been focusing on just one strategy, but there are lots of ways to handle the conversion. At the risk of confusing things more, here are a few:
px
andpy
instead ofx
andy
. This is mentioned on http://openseadragon.github.io/examples/ui-overlays/ but probably not prominently enough.imageToViewportRectangle
(unless you are using multiple image in the same viewer, in which case you need to use the TiledImage’s version).@iangilman that’s an important issue which should be mentioned in the documents. @speed-of-light Yes, I can confirm that you need to multiply both
top
andheight
values withviewer.viewport.getBounds().height
otherwise the overlay shifts to bottom depending on the image dimensions.