Silverlight中Bing地图的交通层 [英] Traffic Layer for Bing Maps in Silverlight

查看:95
本文介绍了Silverlight中Bing地图的交通层的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Bing Maps Silverlight应用程序,想在地图上显示路况信息. 它似乎在AJAX版本中实现,但在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.

那我该如何为Silverlight实施一个有效的流量层呢?

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

推荐答案

对于对此解决方案感兴趣的所有人:

For everyone who is interested in the solution:

经过数小时的搜索和尝试,我在这里找到了解决方案: Bing Silverlight控件中的自定义渲染

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>

我希望这对希望向其Silverlight应用程序添加流量层的所有人有所帮助.

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

问候.

这篇关于Silverlight中Bing地图的交通层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆