Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about coordinate system of translateTo #3

Closed
zzorba opened this issue Aug 6, 2022 · 2 comments
Closed

Question about coordinate system of translateTo #3

zzorba opened this issue Aug 6, 2022 · 2 comments
Labels
good first issue Good for newcomers

Comments

@zzorba
Copy link

zzorba commented Aug 6, 2022

I'm trying to use this library to perform pans, but am having the hardest time figuring out what coordinate system the translateTo method is expecting?

As far as I can tell, it is dependent on the current scale, but I can't seem to figure out what coordinates it is expecting to make logical sense.

Would it be possible to get a more concrete example, perhaps using the following variables:

  const logicalX = 0.5; // logical X coordinate, from [0,1];
  const logicalY = 0.5; // logical Y coordinate, from [0,1];
  // scale, contentWidth, contentHeight, containerWidth, containerHeight
  ref.translateTo(???,???, true);

My goal is to get the point represented by logicalX/logicalY to be 'centered' on the screen, at the current zoom level.

If it matters, my contentWidth/contentHeight are always larger than both containerWidth/containerHeight.

@fakeheal
Copy link
Owner

fakeheal commented Aug 15, 2022

Hi, @zzorba,

First of all thanks for trying out the package!

Are your containerWidth/containerHeight variables representing the size of the device's screen?

Basically, to center the content inside the container, you need to set x to be: containerWidth / 2 - contentWidth / 2 and y to be: containerHeight / 2 - contentHeight / 2. Here's the source code in the example app that shows centering the content inside its container.

I looked around the source code of your app, but I just got back from vacation and will have more time during the weekend. I will try building it and if you're still having issues, I'd more than happy to help with your specific case.

@fakeheal fakeheal added the good first issue Good for newcomers label Aug 16, 2022
@zzorba
Copy link
Author

zzorba commented Oct 6, 2022

Thank you, this worked as expected!

@zzorba zzorba closed this as completed Oct 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants