Recommended

Skip Navigation LinksHome / Articles / View Article

Virtual earth deep zooming.

+ Add to SilverlightShow Favorites
20 comments   /   posted by Alexey Zakharov on Sep 25, 2008
(31 votes)
Categories: 18 Aug 08 - 28 Sep 08

Note: This article is submitted by Alexey Zakharov for Silverlight: Write and Win contest.Thanks a lot, Alexey! Hello All, Please drop a comment if you like it.

It is time to vote now! Please, choose your favorite articles and enter your vote by going to contest page. Thank you!

Introduction

In this article I'd like to tell you how you can easily create your own Virtual Earth viewer based on Silverlight Deep Zoom technology.

Concept

As you may be already know Silverlight MultiScaleImage control have a property called Source, which type is MultiScaleTileSource. And if you have created simple deep zoom composer project your MultiScaleImage source would be somethig like this:

new DeepZoomImageTileSource(new Uri("GeneratedImages/dzc_output.xml", UriKind.Relative));

In silverlight project generated by deep zoom composer project we already have all functionality to move and zoom our MultiScaleImage.

So all we need to do is to create our own implementation of base MultiScaleTileSource class, which will provide virtual earth image tiles.

Step 1: Virtual earth tile system

All virtual earth image tiles can be get via http using special url format : http://h{0}.ortho.tiles.virtualearth.net/tiles/h{1}.jpeg?g=203 (for arial map) and http://r{0}.ortho.tiles.virtualearth.net/tiles/r{1}.png?g=203 (for road map)

First paramter is number of virtual earth (there are 4 tile servers) tile server and the second is tile quad key.

To transform X Y coordinate into quad key you can ues this function (more information about virtual earth tile system you can find here http://msdn.microsoft.com/en-us/library/bb259689.aspx):

   1: /// <summary>
   2: /// Converts tile XY coordinates into a QuadKey at a specified level of detail.
   3: /// </summary>
   4: /// <param name="tileX">Tile X coordinate.</param>
   5: /// <param name="tileY">Tile Y coordinate.</param>
   6: /// <param name="levelOfDetail">Level of detail, from 1 (lowest detail)
   7: /// to 23 (highest detail).</param>
   8: /// <returns>A string containing the QuadKey.</returns>
   9: private static string TileXYToQuadKey(int tileX, int tileY, int levelOfDetail)
  10: {
  11:     var quadKey = new StringBuilder();
  12:     for (int i = levelOfDetail; i > 0; i--)
  13:     {
  14:         char digit = '0';
  15:         int mask = 1 << (i - 1);
  16:         if ((tileX & mask) != 0)
  17:         {
  18:             digit++;
  19:         }
  20:         if ((tileY & mask) != 0)
  21:         {
  22:             digit++;
  23:             digit++;
  24:         }
  25:         quadKey.Append(digit);
  26:     }
  27:     return quadKey.ToString();
  28: }

 

Step 2: Creating of custom MultiScaleTileSource for Virtual earth.

Let's create base tile source for arial and road virtual earth tiles.

To implement your own MultiScaleTileSource you should override GetTileLayers method and use base constructor.

In constructor we will set max image size and size of image tiles. In hex numerical notation max virtual earth image width and height are 0x8000000 and tile width and height are 0x100.

   1: /// <summary>
   2: /// Setting of tile size and max image size.
   3: /// </summary>
   4: protected BaseVETileSource()
   5:     : base(0x8000000, 0x8000000, 0x100, 0x100, 0)
   6: {
   7: }

Next step is to override GetTileLayers method. It adds image uris for specified zoom level, x and y tile positions. Zoom level of MultiScaleImage is not equal to virtual earth zoom level so we should subtract 8 from the value which was received as an input parameter.

   1: /// <summary>
   2: /// Get tiles for <see cref="MultiScaleImage"   />.
   3: /// </summary>
   4: /// <param name="tileLevel">Tile Level</param>
   5: /// <param name="tilePositionX">Tile X position</param>
   6: /// <param name="tilePositionY">Tile Y position</param>
   7: /// <param name="tileImageLayerSources">Tile images repository</param>
   8: protected override void GetTileLayers(int tileLevel, int tilePositionX, int tilePositionY,
   9:                                       IList<object> tileImageLayerSources)
  10: {
  11:     int zoom = tileLevel - 8;
  12:     if (zoom > 0)
  13:     {
  14:         string QuadKey = TileXYToQuadKey(tilePositionX, tilePositionY, zoom);
  15:         string veLink = string.Format(UriFormat,
  16:                                       new object[] {QuadKey[QuadKey.Length - 1], QuadKey});
  17:         var veUri = new Uri(veLink);
  18:         tileImageLayerSources.Add(veUri);
  19:     }
  20: }

Now we should add abstract string property for UrlFormat. We will implement it differently for road and arial tile sources.

   1: /// <summary>
   2: /// Format for map tile uri.
   3: /// </summary>
   4: public abstract string UriFormat { get; }

The last thing we should do is to create two clases for road tile images (VERoadTileSource) and arial tile images (VEArialTileSource). They are inherited from the base tile source class created above and implement uri format property.

VERoadTileSource:

   1: public class VERoadTileSource : BaseVETileSource
   2: {
   3:     public override string UriFormat
   4:     {
   5:         get { return "http://r{0}.ortho.tiles.virtualearth.net/tiles/r{1}.png?g=203"; }
   6:     }
   7: }

VEArialTileSource:

   1: public class VEArialTileSource : BaseVETileSource
   2: {
   3:     public override string UriFormat
   4:     {
   5:         get { return "http://h{0}.ortho.tiles.virtualearth.net/tiles/h{1}.jpeg?g=203"; }
   6:     }
   7: }

 

Step 3: Add virtual earth tile source to you deep zoom application.

Replace MultiScaleImage source property initialization in deep zoom composer genereated project and start browse Virtual Earth with deep zoom!

   1: msi.Source = new VERoadTileSource(); 
   2: // or try arial tile source: 
   3: // new VEArialTileSource();

 

Summary

Concept of using deep zoom technology for viewing virtual earth map which was showed in article can be used for Google Maps too. Also you should remember that direct usage of virtual earth tile system is not legal. And if you want to create your silverlight Api for Virtual earth you should first discuss it with microsoft.

Source code : http://weblogs.asp.net/blogs/alexeyzakharov/VESilverlightApplication.zip

 

Share


Comments

Comments RSS RSS
  • RE: Virtual earth deep zooming.  

    posted by Alexander Byndyu on Sep 25, 2008 09:32

    Thanks, for post!

    It is better that Google map. And I can use .NET for map now =)

  • RE: Virtual earth deep zooming.  

    posted by SoulSolutions on Sep 25, 2008 15:44

    There is a codeplex project: http://www.codeplex.com/deepearth/ that takes this to another level, always looking for people to contribute.

    Please do remember that accessing the VE tile system directly without approval is a violation of the terms of use from Microsoft.

    John.

  • RE: Virtual earth deep zooming.  

    posted by lexer on Sep 25, 2008 20:14

    Thanks John for your comment.

    >> Please do remember that accessing the VE tile system directly without approval is a violation of the terms of use from Microsoft.

    Yes. It's true. I write about this in the summary of my article.

    >>  There is a codeplex project: http://www.codeplex.com/deepearth/ that takes this to another level, always looking for people to contribute.

    Yes that's cool project. But my purpose in this article was to show main concept as simple as possible.

  • RE: Virtual earth deep zooming.  

    posted by lexer on Sep 25, 2008 20:18

    There was a bug in application, that's why many people don't see anything in demo. I have already updated source files of the project, but article corrections are still in moderation.

    Have fun!

  • RE: Virtual earth deep zooming.  

    posted by Arman on Sep 26, 2008 04:22

    That's nice... I like it.

    I will try to take this theme 4 my course project during this year. very Interesting technologies... Much opportunities...

    Alex Thanks!!

  • RE: Virtual earth deep zooming.  

    posted by Alexander Byndyu on Sep 28, 2008 08:07

    Hey!

    Didn't see this before! Very impressive =)

    Thanks for post!

  • RE: Virtual earth deep zooming.  

    posted by Mural on Sep 29, 2008 08:06

    Very nice!

    I don't even imagine that this task can be done so simple.

    If it possible, could u also share a google map example.

  • RE: Virtual earth deep zooming.  

    posted by James on Sep 30, 2008 16:55

    Great info!

    Simple and straightforward. Thanks!

    http://xpirtdesign.com

  • RE: Virtual earth deep zooming.  

    posted by Krist on Oct 02, 2008 01:46

    Simple and Clear!

    +1

  • RE: Virtual earth deep zooming.  

    posted by Chris Cavanagh on Oct 07, 2008 21:20

    Alexey - This is totally awesome! :)

  • RE: Virtual earth deep zooming.  

    posted by Marti on Oct 08, 2008 16:33

    It also works with Open Street Map if you create a tile server with the following

     

    string veLink = string.Format("http://tile.openstreetmap.org/{0}/{1}/{2}.png",zoom, tilePositionX, tilePositionY);

    See LiveSide article for more info.

  • RE: Virtual earth deep zooming.  

    posted by beautifulART on Oct 12, 2008 10:47

    Great map!

    I hope Google would imagine it to adopt.

     

  • RE: Virtual earth deep zooming.  

    posted by bluedream198096 on Jan 19, 2009 03:41

    I downloaded the app. I am not able to see the map. I just see the black background. Am i missing something?

  • RE: Virtual earth Silverlight, no deep zooming.  

    posted by Mark Alexander on Mar 02, 2009 10:17

    Our Silverlight map control supports Virtual Earth and DOES NOT USE Deep Zoom.  Check out our demos at:

    http://www.mapdotnet.com/Pages3.0/demos/default.aspx

     

     

  • RE: Virtual earth deep zooming.  

    posted by Haseeb Ali on Dec 22, 2009 01:56
    i wnt to live watching software.cn i get t?if  ys thn let me knw wht software is ths?thax.awaitng reply 
  • RE: Virtual earth deep zooming.  

    posted by anon on Dec 23, 2009 23:20

    +1 on bluedream:

    I downloaded the app. I am not able to see the map. I just see the black background. Am i missing something?

  • RE: Virtual earth deep zooming.  

    posted by anon on Dec 23, 2009 23:25

    to add to previous post:

    GetTileLayers is being hit. it gets correct Uri but fiddler not showing any requests.

  • RE: Virtual earth deep zooming.  

    posted by anon on Dec 29, 2009 01:02
    in case anyone cares, my friend told me the reason for not seeing any tiles - you have to run the project from a Website; don't run it as a .html page. Set the website included in the sln as startup project.
  • RE: Virtual earth deep zooming.  

    posted by Balu on Apr 23, 2010 09:55

    Hi

    i did a similar application.But how could i improve the details.The details we zoom in are too low compared to (http://www.bing.com/mapindia/?mkt=en-in).Is there any way i could get more details?

    Regards

    balu

  • RE: Virtual earth deep zooming.  

    posted by Micron on May 08, 2010 00:35
    Buy ambien
    This is an excellent article, thank you very much for it,

Add Comment

 
 

   
  
  
   
Please add 8 and 6 and type the answer here:

Help us make SilverlightShow even better and win a free t-shirt. Whether you'd like to suggest a change in the structure, content organization, section layout or any other aspect of SilverlightShow appearance - we'd love to hear from you! Need a material (article, tutorial, or other) on a specific topic? Let us know and SilverlightShow content authors will work to have that prepared for you. (hide this)