svgpanzoom - add padding on reset

602 Views Asked by At

Tell me please is there a way to set some padding for svg when pressing reset?

enter image description here

The lib scales it as close as possible to the border, I'd like to make reset works like shown on the right side of the screen.

2

There are 2 best solutions below

0
On BEST ANSWER

Currently there is no way to achieve that from configs. Some possible solutions:

Use custom controls:

  • Disable default controls
  • Add your own controls (example).
  • On initialisation - store SVG pan and zoom values
  • When clicking on reset button - zoom and pan with such values so that it will be padded

Adjust the SVG:

You can add an invisible rectangle that would be of the size of your SVG plus the padding. This way the library will think that SVG size is a bit wider, so reset will look like it has padding.

0
On

Use zoomBy function of svgpanzoom:

// Zoom by 98%
panZoomTiger.zoomBy(0.98)