Traffic Layer for Bing Maps in Silverlight

I have a Bing Maps Silverlight Application and want to display Traffic Information on the Map. It seems to be implemented in the AJAX Version, but not in the Silverlight Version.

So how can I implement a working traffic layer for Silverlight?

Answers


For everyone who is interested in the solution:

After hours of searching and trying I found the solution here: Custom Rendering in Bing Silverlight Control

public class TrafficTileSource : TileSource
{
    public TrafficTileSource()
        : base(GetAbsoluteUrl("http://t0.tiles.virtualearth.net/tiles/t{0}.png"))
    {

    }

    public override Uri GetUri(int x, int y, int zoomLevel)
    {
        var quadKey = new QuadKey(x, y, zoomLevel);
        return new Uri(String.Format(this.UriFormat, quadKey.Key));
    }

    public static string GetAbsoluteUrl(string strRelativePath)
    {
        if (string.IsNullOrEmpty(strRelativePath))
            return strRelativePath;

        string strFullUrl;
        if (strRelativePath.StartsWith("http:", StringComparison.OrdinalIgnoreCase)
          || strRelativePath.StartsWith("https:", StringComparison.OrdinalIgnoreCase)
          || strRelativePath.StartsWith("file:", StringComparison.OrdinalIgnoreCase)
          )
        {
            //already absolute
            strFullUrl = strRelativePath;
        }
        else
        {
            //relative, need to convert to absolute
            strFullUrl = System.Windows.Application.Current.Host.Source.AbsoluteUri;
            if (strFullUrl.IndexOf("/ClientBin") > 0)
                strFullUrl = strFullUrl.Substring(0, strFullUrl.IndexOf("/ClientBin")) + strRelativePath;
        }
        return strFullUrl;
    }
}

And then add the Layer to the Map:

<m:MapTileLayer Visibility="{Binding Path=TrafficVisibility,Converter={StaticResource BoolToVisibilityConverter},Mode=OneWay,UpdateSourceTrigger=PropertyChanged}">
                <m:MapTileLayer.TileSources>
                    <utils:TrafficTileSource />
                </m:MapTileLayer.TileSources>
            </m:MapTileLayer>

I hope that helps everybody who wants to add a traffic layer to their Silverlight application.

Greetings.


Just to clean things up a bit: this does absolutly the same as Johannes answer:

public class TrafficTileSource : TileSource
{
    public TrafficTileSource() : base("http://t0.tiles.virtualearth.net/tiles/t{0}.png") { }

    public override Uri GetUri(int x, int y, int zoomLevel)
    {
        QuadKey quadKey = new QuadKey(x, y, zoomLevel);
        return new Uri(String.Format(UriFormat, quadKey.Key));
    }
}

And the map layer:

<maps:MapTileLayer>
    <maps:MapTileLayer.TileSources>
        <utils:TrafficTileSource />
    </maps:MapTileLayer.TileSources>
</maps:MapTileLayer>

Need Your Help

CSS Drop down will will not become visible on hover, but will become hidden on hover

html css drop-down-menu

I'm trying to create a hover dropdown menu. I can't get it to work. Currently, I have the menu to show and become hidden on hover. I tired just switching the visible and invisible, but that didn't ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.