Reputation: 1030
I'm trying to calculate a variable based on a zoom level.
For example I have a 4x4 grid of tiles at zoom level 1. Now I zoom in once it will become 8 * 8 at zoom level 2. Zoom in once again and it will be 16 * 16 at zoom level 3. etc.
Now the only thing I store are the two numbers from zoom level 1 which can change to for example 5x4 or even 1x1.
So my question is how do I calculate the width and height of zoom level's 2 and 3 and beyond with just those two numbers and the zoom level?
Thanks in advance.
Upvotes: 2
Views: 479
Reputation: 3475
A slicker way of doing the same thing is to use bit shifting since you're always multiplying by a power of 2 with each zoom level.
var x = this.data.Size.X;
var y = this.data.Size.Y;
x = x << (zoom-1);
y = y << (zoom-1);
Upvotes: 1
Reputation: 1030
Thanks to jmstoker I've figured out how to get it working properly
var x = this.data.Size.X;
var y = this.data.Size.Y;
for (var i = 1; i < zoom; i++) {
x += x;
y += y;
}
I just get the count of tiles on each side and go through the amount of zoom levels excluding level 1 and adding the count to itself for each zoom level.
Upvotes: 0