【问题标题】:Custom Rendering in Bing Silverlight ControlBing Silverlight Control 中的自定义渲染
【发布时间】:2009-07-07 14:15:42
【问题描述】:

我正在开发一个利用 Bing 地图控件的 Silverlight 2 项目。我们的 UX 人员想知道的一件事是是否可以完全自定义地图的外观。例如,将国家绘制为具有不同颜色内饰的简单轮廓。或者把海洋画成白色,把国家画成黑色的虚线形状。

有谁知道是否可以实现这种级别的定制? MapMode 类看起来很有希望,但它似乎并不能满足我的需求。

谢谢, 肯特

【问题讨论】:

    标签: rendering silverlight-2.0 bing


    【解决方案1】:

    回答我自己的问题,是的,这是可能的。

    首先,使用自定义平铺源添加您自己的图层:

    <m:Map>
        <m:Map.Mode>
            <mCore:MercatorMode/>
        </m:Map.Mode>
        <m:Map.Children>
            <m:MapTileLayer>
                <m:MapTileLayer.TileSources>
                    <local:CustomTileSource/>
                </m:MapTileLayer.TileSources>
            </m:MapTileLayer>
        </m:Map.Children>
    </m:Map>
    

    接下来,定义CustomTileSource。这是一个例子:

    public class CustomTileSource : TileSource
    {
        public CustomTileSource()
            : base(GetAbsoluteUrl("/ClientBin/Resources/{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;
        }
    }
    

    请注意磁贴源必须如何返回 URL。如果您有想要用作地图的图像,可以使用MapCruncher 工具来准备它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-09
      • 2022-01-10
      • 2013-07-27
      • 1970-01-01
      • 1970-01-01
      • 2012-08-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多