Hittest not working after 2.2?
See original GitHub issueI’ve used ‘hitTest’ code to auto-center on items in collections. And it works with 2.2.0, but nothing later. Could someone point me in the right direction to enable it in newer versions?
Example of working using 2.2.0 -> https://chattanoogahistory.com/marr-field
Example of same page using 2.4.1 (not working / not throwing errors): -> https://chattanoogahistory.com/marr
hitTest code:
var hitTest = function(position) {
var box;
var count = viewer.world.getItemCount();
for (var i = 0; i < count; i++) {
box = viewer.world.getItemAt(i).getBounds();
if (position.x > box.x &&
position.y > box.y &&
position.x < box.x + box.width &&
position.y < box.y + box.height) {
return i;
}
}
return -1;
};
var $viewerElement = $('#openseadragon-canvas')
.on('mousemove', function(event) {
var pixel = new OpenSeadragon.Point(event.clientX, event.clientY);
pixel.y -= $viewerElement.position().top;
var index = hitTest(viewer.viewport.pointFromPixel(pixel));
$('.output').text(index === -1 ? '' : 'Image ' + index);
}
);
viewer.addHandler('canvas-click', function(event) {
if (!event.quick) {
return;
}
var index = hitTest(viewer.viewport.pointFromPixel(event.position));
if (index !== -1) {
viewer.viewport.fitBounds(viewer.world.getItemAt(index).getBounds());
}
}
);
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (4 by maintainers)
Top Results From Across the Web
CustomPainter.hitTest missing size argument #28206 - GitHub
CustomPainter.hitTest is missing the size of the widget, making it impossible to specify custom hit test behaviour when paint uses its size ...
Read more >Hittest not working properly when view is not the size of the ...
Ok, when using the UIView hitTest It ONLY returns the TestView and never its children. When using the CALayer hitTest it seems like...
Read more >Why is my hitTest() not working every time? [closed]
I have a code segment in which I use hitTest() a couple of times but at a particular section the hitTest stops working....
Read more >WPF Diagram 2.2.1.21626 HitTest Exception - MindFusion
We just found the following - it occurred when drag-highliting over a node that contained a 3D control. Is the exception information listed ......
Read more >Hit test not working as expected - MSDN - Microsoft
The problem is not how to perform the hit test. The problem is that the hit test behavior returns false positives.
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
I still don’t understand what you mean by it not working. If you don’t disable
clickToZoom
, the hit detection doesn’t happen at all? Or the hit detection happens, but in response it doesn’t zoom correctly? If it’s the latter, that makes sense, because the click to zoom behavior would override any additional navigation you might be adding.If you want to override the click to zoom behavior dynamically, you can use
event.preventDefaultAction = true
like so:Excellent 😃