I'm currently working on some map stuff and I'm planning to use the Bing Maps Tile server for retrieving tiles that would be "stitched" together, forming a bigger map of a given extent (I do not want to use the Bing Maps API for a reason).
I'm getting familiar with the tiles logic and the quadKeys that define them (thanks to this article) and everything goes fine except one problem: I'm having a hard time finding a smart way to figure out how can I get the level of detail that contains a given extent and the tiles retrieved on this LoD will fit in a required image size.
A little bit detailed explanation:
Let's say I need to show the map of Hungay on a 800x600 bitmap image.
The extent that defines the top-left and the bottom-right corner of a rectangle that contains Hungary, is (roughly): 48.593, 16.145 ; 45.923, 23.396.
Having the math from the above-mentioned article, I can find the tile that contains the whole Hungary. With a little bit of cropping, I can get the desired extent from one tile. But this will give me a bitmap with size less than 250x250, which will look bad on my 800x600 desired image size. Of course, I can recursively drill into the sub-tiles, checking if their combined size will fit in the 800x600 rectangle. But this approach seems very heuristic to me and I would like to find a way to calculate the desired level of details.
Basically I need something similar to the VEMap.SetMapView method, where you pass an array of locations and the map finds the best possible zoom that will fit all the locations in your viewport. (in my case the locations will be the top-left/bottom-right points of the bounding box).
I found a similar article but the approach described there seems to behave weirdly for bigger image sizes.
I hope I managed to explain my problem. Any help and suggestions are highly appreciated.