Skip to content

Pan to object and zoom to fit viewport #6883

Answered by asturur
emorling asked this question in Q&A
Discussion options

You must be logged in to vote

Is for sure possible, you have 2 tasks, calculating the destination viewport and then animating it.
To animate a viewport is sufficient to animate the 6 numbers that are part of it.
To calculate the destination viewport, that may be a little effort on your side to understand positioning and geometries.

you can use fabric.util.calcScaleToFit to get the zoom level, passing as destination the canvas and source the object.getBoundingRect.
For the panning, i think the final panning will be something like the object.getCenterPoint() to which you have to subtract half of the canvas dimensions.

I m not entirely sure but a combination of those things will do the trick.

Replies: 1 comment 11 replies

Comment options

You must be logged in to vote
11 replies
@asturur
Comment options

@emorling
Comment options

@emorling
Comment options

@asturur
Comment options

@LiamPerson
Comment options

Answer selected by emorling
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #6879 on February 20, 2021 12:32.