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

Please add a method to pan svg programmatically #98

Open
qingyun1988 opened this issue Sep 4, 2023 · 7 comments
Open

Please add a method to pan svg programmatically #98

qingyun1988 opened this issue Sep 4, 2023 · 7 comments

Comments

@qingyun1988
Copy link

I can't find any method for this purpose. Could you add one? thank you.

@Fuzzyma
Copy link
Member

Fuzzyma commented Sep 4, 2023

you would use the viewbox function for that purpose.
e.f. if you want to center a point, you get your current viewbox, get its center, substract it from the point taht should be centered and move the viewbox by that amount

const p = { x: 200, y: 200 } // center this point
const vb = canvas.viewbox()

const {cx, cy} = vb
const deltaX = p.x - cx
const deltaY = p.y - c.y

canvas.viewbox({
  ...vb,
  x: vb.x - deltaX,
  y: vb.y - deltaY
})

Didnt test that code. Probably have some flipped negative signs there

@qingyun1988
Copy link
Author

Thank you very much! But it's better if you can provide a pan() method based on your thoughts above.

@Fuzzyma
Copy link
Member

Fuzzyma commented Sep 4, 2023

Feel free to create a PR to contribute this method. Unfortunately I cannot do open source full time and I am also not quite sure if a method is neccessary. For now, you can just use the code I provided :)

@qingyun1988
Copy link
Author

Feel free to create a PR to contribute this method. Unfortunately I cannot do open source full time and I am also not quite sure if a method is necessary. For now, you can just use the code I provided :)

I am not talented as you are at coding. Thank you very much!

@Fuzzyma
Copy link
Member

Fuzzyma commented Sep 5, 2023

If you are able to use this library you are also able to create a PR

@pjfsilva
Copy link

pjfsilva commented Nov 9, 2023

I also need something similar to this and seems like a good fit for this plugin.

What I'm thinking is to isolate the 'core' code inside panning that actually 'moves' the map by X pixels into a private method and the new public method and panning event would use that code. Does that sound good @Fuzzyma ?

@Fuzzyma
Copy link
Member

Fuzzyma commented Nov 9, 2023

I wouldnt use a private method since its only a few lines long. Just inline it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants