Bing Silverlight控件中的自定义渲染 [英] Custom Rendering in Bing Silverlight Control

查看:76
本文介绍了Bing Silverlight控件中的自定义渲染的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm ramping up on a Silverlight 2 project that leverages the Bing Maps control. One thing our UX guys are wondering is whether it is possible to customize the look of the map completely. For example, draw countries as simple outlines with different color interiors. Or draw the ocean as white and countries as black dotted shapes.

有人知道是否可以实现这种级别的定制吗? MapMode类看起来很有前途,但似乎并不能完全满足我的需求.

Does anyone know whether it is possible to achieve this level of customization? The MapMode class looked promising, but it doesn't seem to quite give me what I need.

谢谢, 肯特

推荐答案

要回答我自己的问题,可以的.

To answer my own question, yes this is possible.

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

Firstly, add your own layer with a custom tile source:

<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.这是一个示例:

Next, define the CustomTileSource. Here is an example:

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 准备它的工具.

Note how the tile source must return a URL. If you have an image you want to use as the map, you can use the MapCruncher tool to prepare it.

这篇关于Bing Silverlight控件中的自定义渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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