Search This Blog

Monday, December 29, 2008

Creating Universial Zoom levels

Creating Universial Zoom levels to use across Google/ Yahoo / and Virutal Earth APIs

From http://code.davidjanes.com/blog/2008/11/08/switching-between-mapping-apis-and-universal-map-levels/

Table of map zoom level equivalents

Google Maps and Virtual Earth the same zoom levels, excepting that Google has a level 0. Bigger numbers are closer to the ground, smaller numbers are up into space. Yahoo Maps has fewer levels to work with - it doesn’t let you drill down below the block level. Yahoo numbers its zoom levels the opposite of Google and Virtual Earth, small numbers being closer to the ground and so on and so forth.

To allow seamless switching of data between APIs, I propose here universal zoom levels, which can be used as-is on any of these mapping APIs. To avoid confusion of which type of zoom level one is using, we use the negative number range for universal zoom levels. As Google and Microsoft are using the same zoom levels, I’ve decided that the universal zoom levels should simply be the inverse of their zoom levels, bounded by (-1, -19) inclusive.

Conversion Formulae

Here’s Javascript to convert between your favorite mapping API’s zoom levels and universal zoom levels. Note that all to_native functions accept positive numbers as-is.

zoom = {
google : {
to_univeral : function(native) {
return Math.min(-1, -native);
},

to_native : function(universal) {
return universal > 0 ? universal : -universal;
}
},

virtual_earth : {
to_univeral : function(native) {
return Math.min(-1, -native);
},

to_native : function(universal) {
return universal > 0 ? universal : -universal;
}
},

yahoo : {
to_univeral : function(native) {
return Math.min(-1, native - 18);
},

to_native : function(universal) {
return universal > 0 ? universal : Math.max(universal + 18, 1);
}
}
};


End Notes

A truly universal zoom level would just use altitude; dealing with a simple integer is easier and less complication prone though. MapQuest is not included in this post as its tiles do not line up with the other APIs.

No comments: