bumbu / svg-pan-zoom

JavaScript library that enables panning and zooming of an SVG in an HTML document, with mouse events or custom JavaScript hooks
https://github.com/ariutta/svg-pan-zoom#demos
BSD 2-Clause "Simplified" License
1.74k stars 390 forks source link

Feature Request: Add functions for centering and zooming on elements #413

Open ajdubovoy opened 2 years ago

ajdubovoy commented 2 years ago

Hi folks, I really love this package, so thanks for your awesome work! It's been particularly useful for implementing SVG maps.

Two functions I've needed have been something like:

  1. centerOn({ x, y }) pans to center the map on a certain point. Basically the same thing as the existing pan function but centering that point in the viewport, instead of locating it at the top left.
  2. zoomToEl(el) zoom to fit and center an element in the viewport, via its bounding box

I've been able to implement this on my own perfectly fine. But it'd, of course, be more elegant as part of the API on a panzoom instance.

I was wondering, if these functions are relevant for others, if it makes sense to add to the API? I'd be potentially able to help with that.

Thanks so much!

Iftahh commented 2 years ago

See this: https://github.com/bumbu/svg-pan-zoom/issues/381