2009-07-07 47 views
1

我正在加緊利用Bing Maps控件的Silverlight 2項目。我們的UX用戶想知道的一件事是,是否可以完全自定義地圖的外觀。例如,將國家繪製爲具有不同顏色內飾的簡單輪廓。或者把海洋畫成白色,把海洋畫成黑色的虛線形狀。Bing Silverlight控件中的自定義渲染

有誰知道是否有可能達到這個級別的定製?班級看起來很有希望,但它似乎並不能給我所需要的東西。

感謝, 肯特

回答

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工具進行準備。