C#/ Bing Maps Win8.1 - 将当前的四键(s)作为字符串

时间:2014-10-04 11:53:58

标签: c# windows-8 windows-8.1 bing-maps bing

我有一张地图,我正在尝试添加图层,图层服务器支持XYZoomLevel标准,从而产生问题。

为了开始将四元组转换为XYZ的过程,我需要获取当前的四元组,这些四元组将用于渲染输出到字符串的映射,并在每次密钥更改时更改。如何将四键作为字符串值?

1 个答案:

答案 0 :(得分:2)

以下是允许您添加图层的示例代码,请参阅

http://msdn.microsoft.com/en-us/library/hh846495.aspx

MapTileLayer tileLayer = new MapTileLayer();
tileLayer.TileSource = "http://www.microsoft.com/maps/isdk/ajax/layers/lidar/{quadkey}.png";
map.TileLayers.Add(tileLayer);
map.SetView(new Location(48.03, -122.42), 11, MapAnimationDuration.None);

如果您想使用其他uri方案,可以使用GetTileUri()类的MapTileLayer方法使用另一种方法,您将使用自己的代码设置组合uri。然后,您可以将quadkey转换为xyz或相反。

以下是使用该方法的示例代码:

        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            Bing.Maps.MapTileLayer layer = new Bing.Maps.MapTileLayer();
            layer.GetTileUri += layer_GetTileUri;
            this.map.TileLayers.Add(layer);
        }

        private async void layer_GetTileUri(object sender, Bing.Maps.GetTileUriEventArgs e)
        {
            e.Uri = this.ComposeMyCustomUri(e);
        }

此处,eGetTileUriEventArgs类型的特定参数对象,请参阅:

http://msdn.microsoft.com/en-us/library/jj672952.aspx

如果您想从XYZ转到quadkey,可以使用此C#代码执行此操作:

    /// <summary>
    /// Converts tile XY coordinates into a QuadKey at a specified level of detail.
    /// </summary>
    /// <param name="tileX">Tile X coordinate.</param>
    /// <param name="tileY">Tile Y coordinate.</param>
    /// <param name="levelOfDetail">Level of detail, from 1 (lowest detail)
    /// to 23 (highest detail).</param>
    /// <returns>A string containing the QuadKey.</returns>
    public static string TileXYToQuadKey(int tileX, int tileY, int levelOfDetail)
    {
        StringBuilder quadKey = new StringBuilder();
        for (int i = levelOfDetail; i > 0; i--)
        {
            char digit = '0';
            int mask = 1 << (i - 1);
            if ((tileX & mask) != 0)
            {
                digit++;
            }
            if ((tileY & mask) != 0)
            {
                digit++;
                digit++;
            }
            quadKey.Append(digit);
        }
        return quadKey.ToString();
    }

以下是提取代码的更完整链接,MSDN:http://msdn.microsoft.com/en-us/library/bb259689.aspx