我正在开发一个利用 Bing 地图控件的 Silverlight 2 项目。我们的 UX 人员想知道的一件事是是否可以完全自定义地图的外观。例如,将国家绘制为具有不同颜色内饰的简单轮廓。或者把海洋画成白色,把国家画成黑色的虚线形状。
有谁知道是否可以实现这种级别的定制?这MapMode
门课看起来很有希望,但似乎并没有完全满足我的需求。
谢谢,肯特
我正在开发一个利用 Bing 地图控件的 Silverlight 2 项目。我们的 UX 人员想知道的一件事是是否可以完全自定义地图的外观。例如,将国家绘制为具有不同颜色内饰的简单轮廓。或者把海洋画成白色,把国家画成黑色的虚线形状。
有谁知道是否可以实现这种级别的定制?这MapMode
门课看起来很有希望,但似乎并没有完全满足我的需求。
谢谢,肯特
要回答我自己的问题,是的,这是可能的。
首先,使用自定义平铺源添加您自己的图层:
<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工具来准备它。