VE’s quadkey tiles and tilecache

Since my company acquired a real life Virtual Earth server; a hefty beast with a few TBs of data for just .nl, I decided to dive into VE. The people from Microsoft produced some excellent documents explaining how the tilescheme of VE works.

The original idea was that we could insert our own data into the server, but that seems to be difficult. So I decided to see if TileCache could do the honors. We already deploy TC in various projects and the nice bit is that the generated cache can be used outside VE, for instance with OL and/or google maps.

Of course it is possible to use OpenLayers to add your own data on top of VE, but OL doesn’t support the 3D view and AFAIK neither does it do birdseye. To show your own data in VE you need to serve the tiles using a quadkey construction. The logic of a quad key is very easy: At the lowest zoomlevel divide the world in 4 parts: 0, 1, 2, 3 (left top, right top, left bottom, right bottom) so a tile called 0.png would be in the left top at zoomlevel 0. In the next zoomlevel divide the four tiles in four parts again. And so on and so on. Stealing from msdn site:

quadkey explanation

So it is immediately clear that file 12020.jpg is at zoomlevel 5 and somewhere at the north-eastern hemisphere, actually it’s in .nl. Tilecache however works with x,y,z so you need to recalculate the quadkeys to/from xyz system. Taking into account that VE (0,0) is top left whereas TC uses bottom left for (0,0).

Tilecache has three components: client (which retrieves the data), service (which serves the tiles) and cache (which stores the tiles). I first wrote a cache which stored all tiles in a flat quad-file structure. This way you could put the entire cache online and VE could automatically place the tiles at the correct place. However as long as the cache is not complete and put online the data is not accessible by VE. Also all TC’s cachemanagement features are gone as well. So I decided to write a VETMS service instead, which takes quadkeys and turns them into any of the supported backends, be it WMS, Mapnik or whatever. This way it is easy to put your WMS data in VE. This code has been sent as a patch to the TC list so hopefully in the next TC release you can serve quadkey-tiles as well.

Whilst I was at it, I wrote the last bit: a VE-client which retrieves the tiles from a VE server and serves them as TMS, WMS-C or any other of the supported services. However since this is legally not allowed I’ve chosen to not release the code.


GIS