Jun 11

Written by: Soul Solutions
Wednesday, 11 June 2008 

The feedback from Part 1 has been great! There is definitely interest in this. Shaun Becker sent through this gem that removes my proxy server completely! Yes we now have Silverlight Deep Zoom talking directly to Virtual Earth! And better still I can give you a live demo (need SL beta2 installed – click image to view):

VEDZ

So what has Shaun done to make this possible?

He has created a VETileSource class inheriting from MultiScaleTileSource. Perfect! Now this code is still rough, we only have the one tile source, its very hard coded but it is a great proof of concept.

using System;
using System.Text;
using System.Windows.Media;

namespace DeepZoomProject
{
    public class VETileSource : MultiScaleTileSource
    {
        const string Protocol = "http://";
        const string TilePath = ".ortho.tiles.virtualearth.net/tiles/";
        const string Prefix = "h";
        const string Suffix = ".jpeg?g=159";

        static string TileXYToQuadKey(int tileX, int tileY, int levelOfDetail) {
            StringBuilder quadKey = new StringBuilder();
            for (int i = levelOfDetail; i > 0; i--) {
                char digit = '0';
                int mask = 1 << (i - 1);
                if ((tileX & mask) != 0) {
                    digit++;
                }
                if ((tileY & mask) != 0) {
                    digit++;
                    digit++;
                }
                quadKey.Append(digit);
            }
            return quadKey.ToString();
        }

        protected override void GetTileLayers(int tileLevel, int tilePositionX, int tilePositionY, System.Collections.Generic.IList<object> tileImageLayerSources) {
            int zoom = tileLevel - 8;
            if (zoom > 0) {
                string QuadKey = TileXYToQuadKey(tilePositionX, tilePositionY, zoom);
                string VEUrl = Protocol + Prefix + QuadKey[QuadKey.Length - 1] + TilePath + Prefix + QuadKey + Suffix;
                tileImageLayerSources.Add(new Uri(VEUrl));
            } else {
                string localPath = string.Format("http://localhost:1393/VE_files/{0}/{1}_{2}.jpg", tileLevel, tilePositionX, tilePositionY);
                Uri localUri = new Uri(localPath);
                tileImageLayerSources.Add(localUri);
            }
        }

        public VETileSource()
            : base(134217728, 134217728, 256, 256, 0) {
        }
    }
}

In the constructor we have called the base class setting the enormous image size for VE, 256px tiles and no overlap. Awesome.

So the only change needed to our Page.xaml.cs is to change the tile source:

public Page()
{
    InitializeComponent();

    //
    // We are setting the source here because of an issue that exists in Blend 2.5 when the Source is set via XAML
    //
    //this.msi.Source = new DeepZoomImageTileSource(new Uri("GeneratedImages/dzc_output.xml", UriKind.Relative));
    this.msi.Source = new VETileSource();
Next step is to clean up the code a little and work with some subimages to support Road, Shaded, Aerial and Hybrid tiles. The plan is build a codeplex open source project so if your interested send me an email to John at soulsolutions.com.au. Feel free to leave any comments here and I’ll again put a full download in the comments.

Tags:

19 comment(s) so far...

Re: Silverlight Virtual Earth, Part 2 MultiScaleTileSource

The source code, work in progress and clearly not supported, can be download from here:
http://www.soulsolutions.com.au/silverlight/VEDeepZoomProjectPart2.zip

By John (SoulSolutions) on   Wednesday, 11 June 2008

Re: Silverlight Virtual Earth, Part 2 MultiScaleTileSource

What a surprise today... I work on your first sample last night... And today you manage to do what I tried.
I will have a look tonight and will mail you as soon as possible concerning my intereset in a SL control.

By Nicolas on   Wednesday, 11 June 2008

Re: Silverlight Virtual Earth, Part 2 MultiScaleTileSource

This is pure gold [or should i say oil !]!, for the past week i was thinking deepzoom with VE tiles and wow u guys have started already ! cool and keep it up. The demo also looks good.

1. Silverlight Pushpin support would be one killer feature, but to make it happen i guess we need to translate GEO Points to User screen's x,y co-ordinate. This is where i got stuck in the previous SL VE map.

Thanks,

Gopi

By Gopinath on   Thursday, 12 June 2008

Re: Silverlight Virtual Earth, Part 2 MultiScaleTileSource

Gopi, there are some good algrithims out there to do this already. I used it in my cluster code for example to calculate overlapping pins on the server side. Stay tuned, codeplex project will launch this week.

By John (SoulSolutions) on   Thursday, 12 June 2008

Re: Silverlight Virtual Earth, Part 2 MultiScaleTileSource

Cool, Thanks... waiting for the launch...

By Gopinath on   Thursday, 12 June 2008

Re: Silverlight Virtual Earth, Part 2 MultiScaleTileSource

VERY awesome! Keep up the good work.

By Jeff on   Thursday, 12 June 2008

Re: Silverlight Virtual Earth, Part 2 MultiScaleTileSource

This is very cool.

Can't wait for it to go up on codeplex.

This would be a good control to have especially if you can easily add SL pushpins etc.

John

By John M on   Thursday, 12 June 2008

Re: Silverlight Virtual Earth, Part 2 MultiScaleTileSource

HOLY CRAP GUYS....picking my jaw up from the floor after seeing http://deepzoom.soulclients.com/VE/

By steve clayton on   Friday, 13 June 2008

Re: Silverlight Virtual Earth, Part 2 MultiScaleTileSource

Codeplex project comming very soon....
http://www.codeplex.com/deepearth

By John (SoulSolutions) on   Friday, 13 June 2008

Re: Silverlight Virtual Earth, Part 2 MultiScaleTileSource

Very nice, John !

By vasudev on   Friday, 13 June 2008

Re: Silverlight Virtual Earth, Part 2 MultiScaleTileSource

Fantastic

By Geert on   Friday, 13 June 2008

Re: Silverlight Virtual Earth, Part 2 MultiScaleTileSource

*Update* project "Deep Earth" launched today, read more here:
http://www.soulsolutions.com.au/Blog/tabid/73/EntryID/473/Default.aspx

By John (SoulSolutions) on   Friday, 13 June 2008

MultiScaleTileSource - other "earths"

Took that sample ZIP from the first comment and added some more map sources.

http://conceptdev.blogspot.com/2008/06/silverlightdeepzoomearth-beta-2.html

Thanks for all your hard work.

By Craig Dunn on   Saturday, 14 June 2008

Re: Silverlight Virtual Earth, Part 2 MultiScaleTileSource

I was almost there: http://silverlight.net/forums/p/17601/58664.aspx
Thanks for posting your solution!

By Ricardo Stuven on   Tuesday, 17 June 2008

Re: Silverlight Virtual Earth, Part 2 MultiScaleTileSource

very nice !!!
I wanted do something like this in march but I didn't have map's images.

By Jacek Ciereszko on   Wednesday, 18 June 2008

Re: Silverlight Virtual Earth, Part 2 MultiScaleTileSource

Hello all

All the examples I've seen till now on Deep Zoom and Virtual earth are based on Virtual Earth ASP.Net control. We already have a gigantic VE application thats written using VE JavaScript API 6.0 and ASP.NET and SQL Server 2008. I'm trying to implement deep zoom for the exisiting application. The thing Im unable to figure out is how I dynamically generate the silver light tiles on fly by using the tiles I render directly from the Microsoft VE server instead of having silverlight tiles pre-stored on my server ?

Regards
Aditya
www.GeoSpatialNews.com

By aditya@geospatialnews.com on   Saturday, 6 September 2008

Re: Silverlight Virtual Earth, Part 2 MultiScaleTileSource

I should definitely bookmark this page. Thanks a lot John!

By matthew on   Sunday, 21 February 2010

Re: Silverlight Virtual Earth, Part 2 MultiScaleTileSource

good job

By oil painting on   Thursday, 3 March 2011

Re: Silverlight Virtual Earth, Part 2 MultiScaleTileSource

I'm trying to implement deep zoom for the exisiting application

By oil painting on   Thursday, 3 March 2011

Your name:
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Security Code
Enter the code shown above in the box below
Add Comment   Cancel 
Copyright © 2002-2013 Soul Solutions Pty Ltd. | Login