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.

Invalid position of the viewport visualization in navigator

See original GitHub issue

I was trying to implement viewport tracking, and noticed my tracked positions are off. Further inspection led me to realize the OSD’s implementation does not display the viewport correctly.

I shouldn’t have modified the navigator in any way that would cause this, but I am not 100% sure.

What I am doing:

        const size = 250;
        this.record = document.createElement("canvas");

        const homeBounds = VIEWER.viewport.getHomeBounds();
        homeBounds.width += 2*homeBounds.x; //consider setting 1 since it is computed to be 1 anyway
        homeBounds.height += 2*homeBounds.y;
        homeBounds.x = 0;
        homeBounds.y = 0;

        const w = size * homeBounds.width, h = size * homeBounds.height;
        this.record.width = w;
        this.record.height = h;
        this.recordCtx = this.record.getContext('2d');
        this.recordCtx.globalCompositeOperation = "lighten";

        ....

        VIEWER.addHandler("update-viewport", e => {
                const viewport = e.eventSource.viewport;

                ....

                const bounds = viewport.getBoundsNoRotate(true);
                _this.recordCtx.fillRect(size*bounds.x, size*bounds.y, size*bounds.width, size*bounds.height);
        });

(tissue blurred) image If you look closer you can see that while the whole bottom part of the tissue is visible, the viewport position indicator is off. Note that the display is cut and the OSD renders behind the menu too, the reason the rectangle is so wide.

I tried loading just a single TiledImage with the same result.

What OSD is doing (for reference):

            bounds      = viewport.getBoundsNoRotate(true);
            topleft     = this.viewport.pixelFromPointNoRotate(bounds.getTopLeft(), false);
            bottomright = this.viewport.pixelFromPointNoRotate(bounds.getBottomRight(), false)
                .minus( this.totalBorderWidths );

            //update style for navigator-box
            var style = this.displayRegion.style;
            style.display = this.world.getItemCount() ? 'block' : 'none';

            style.top    = Math.round( topleft.y ) + 'px';
            style.left   = Math.round( topleft.x ) + 'px';

            var width = Math.abs( topleft.x - bottomright.x );
            var height = Math.abs( topleft.y - bottomright.y );
            // make sure width and height are non-negative so IE doesn't throw
            style.width  = Math.round( Math.max( width, 0 ) ) + 'px';
            style.height = Math.round( Math.max( height, 0 ) ) + 'px';

Any ideas? Thanks.

Issue Analytics

  • State:closed
  • Created 9 months ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
pearcetmcommented, Dec 29, 2022

Aha! In your example, I disabled box-sizing: border-box in the CSS for the navigator panel (can be found with selector #panel-navigator-displayregion.displayregion (among others) ) and the bottom right positioning seems much better.

0reactions
pearcetmcommented, Dec 29, 2022

I feel like it might be worth considering how to make the indicator rectangle robust to external CSS like this. I can’t imagine why it would be beneficial for a user to intentionally apply a different box-sizing model that makes it inaccurate, and it is highly likely to happen by accident like it did to you.

@iangilman Thoughts? Perhaps inline CSS defined on the element itself could be used to override any such changes made by an external stylesheet…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Position center of viewport · Issue #164 · davidfig/pixi ... - GitHub
I draw a network visualization; I set the zoom to fit it in the screen with .setZoom(.5); I don't understand how to center...
Read more >
Troubleshoot Viewport 2.0 | Maya 2022
The viewport is not updating the contents of the scene or incorrect materials or instances are displaying. For example, textures, geometry, or ...
Read more >
Positioning errors - Pozyx Knowledge Center
Positioning result is considered invalid. The system was able to calculate a position but this calculated position was considered invalid.
Read more >
Why did my test fail? - Testim overview
This error occurs when the target element exists on the page but is not visible. Common Causes: The target element is currently not...
Read more >
UGameViewportClient - Unreal Engine Documentation
Name Description FString ConsoleCommand. ( const FString& Command ) Process Console Co... FSceneViewpo... CreateGameViewport. ( TSharedPtr< SViewport > In... Create the game vie... void DrawTransition. (...
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