2009-07-07 16 views
1

Bing Mapsコントロールを利用しているSilverlight 2プロジェクトでランプアップしています。私たちUXの人たちが疑問に思っていることは、マップの外観を完全にカスタマイズすることが可能かどうかということです。たとえば、異なる色のインテリアを持つ単純なアウトラインとして国を描​​画します。あるいは海を白く、黒い点線の形をとる。Bing Silverlightコントロールでのカスタムレンダリング

このレベルのカスタマイズを達成できるかどうかは誰にも分かりますか? MapModeクラスは有望そうに見えましたが、私に必要なものを与えてくれていないようです。

おかげで、 ケント

答えて

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ツールを使用してマップを準備できます。

関連する問題