I have a slider tool that will "zoom into the map", the slider tool gives me values from 0 to 100, and I have to translate this to a zoom level.
What I did was I took the farthest zoomed out (smallest scale factor) and the farthest zoomed in (largest scale factor)
The farthest zoomed in is Y
The farthest zoomed out is X
Let's say X = 0 and Y = 10, let's also assume A is the current zoom factor
A/Y = the % on the slider
but if X is anything other then 0 I need
(A-X) / (Y-X)
when I plug in the current zoom level for A it returns the % the slider should jump to for this current zoom level.
And to go the other way around:
(N(Y-X))+X
Where N is the % on the slider, this returns the zoom level we should move to (calculated after the user adjusts the slider)
OK all good, except now comes the hard part (for me at least)
The slider is too sensitive for zooming in, that is going from a view of the entire earth down to the state level takes up 65% of the slider, where it should take only 20%, so I took the log base 10 of every value before it goes into this equation:
(a-x) / (y-x)
This works great, the slider moves to the right position based on the current zoom level...
Now I have to undo this process. I have to take the percent and convert it back to zoom level, taking into account the log I used to get the % in the first place..
I tried sticking pow(10, X) for every variable (i really have no idea what i'm doing at this point)
Here is the code I'm using to get the percents based on the logarithm:
this works with the logarithms
Code: Select all
percent = ((Math.log(view_width) / Math.log(10)) - (Math.log(minzoom) / Math.log(10)) ) / ((Math.log(maxzoom)/Math.log(10)) - (Math.log(minzoom)/ Math.log(10) ));this works on a linear scale only, i need this to undo the code above
Code: Select all
zoomlevel = ( percent * (minzoom - maxzoom) +maxzoom);Who remembers their Algebra 2? Not me...
Edit:::
Code: Select all
zoomlevel=
Math.pow(10,
percent
*
(
(Math.log(minzoom) / Math.log(10))
-
(Math.log(maxzoom) / Math.log(10))
)
+
(Math.log(maxzoom) / Math.log(10))
);