0

I am using svgpanzoom library (link on github repository) in my project . I was setting some initial value:

var minValue = 0.8;
var maxValue = 6;
var numberOfSteps = 5;

instance.setMinZoom(minValue);    
instance.setMaxZoom(maxValue);

After that i was trying calculate and set new value for zoomScaleSensitivity:

var newValueForZoomScale = (maxValue - minValue) / numberOfSteps;
instance.setZoomScaleSensitivity(newValueForZoomScale);

Unfortunately , in this case i have 6 or 7 zoom's steps (depends of screen resolution). My question is how i can set correct value for zoomScaleSensitivity and always have only 5 (numberOfSteps) zoom's steps?

Ihar
  • 1
  • 2

1 Answers1

0

Try

var newValueForZoomScale = (maxValue - minValue) / (numberOfSteps - 1);

That's because if you divide by N, you'll get N+1 steps like:

  • if start is 1
  • if end is 6
  • divide by 5 (number of steps you want) and get (6-1)/5 = 1 for step distance
  • you'll get 6 steps: 1, 2, 3, 4, 5, 6

So you have to divide by 4, then you'll get (6-1)/4 = 1.25 and 5 steps: 1, 2.25, 3.5, 4.75, 6

bumbu
  • 1,297
  • 11
  • 29