简体   繁体   English

带有自定义图块的WP8地图控件

[英]WP8 Map control with custom tiles

I'm trying to display a map control in my app targeting Windows Phone 8 but I want to use custom tiles from open street map. 我正在尝试在面向Windows Phone 8的应用程序中显示地图控件,但我想使用开放街道地图中的自定义图块。

I'm using this line : 我正在使用此行:

mapControl.TileSources.Add(new TileSource("http://a.tile.openstreetmap.org/{zoomLevel}/{x}/{y}.png"));

When I launch the app the custom tiles are properly displayed, but there's still the default map tiles underneath them. 当我启动该应用程序时,自定义图块会正确显示,但是在它们下面仍然有默认的地图图块。

I tried to hide them, but I counld'nt even find where they exist in the map control and what is displaying them exactly. 我试图隐藏它们,但我什至无法找到它们在地图控件中的位置以及确切显示它们的内容。

I would like to know how I can remove those default tiles when loading custom tiles. 我想知道在加载自定义图块时如何删除这些默认图块。

I tried to hide them, but I counld'nt even find where they exist in the map control and what is displaying them exactly. 我试图隐藏它们,但我什至无法找到它们在地图控件中的位置以及确切显示它们的内容。

PS : Here's the link to the "old" bing map control if you cannot find it in the latest WP Tools : http://www.microsoft.com/en-us/download/confirmation.aspx?id=2949 PS:如果您在最新的WP Tools中找不到“旧” bing地图控件,则这里是链接: http : //www.microsoft.com/zh-cn/download/confirmation.aspx?id=2949

I tried this myself with the new WP8 "Nokia HERE maps" map control but was unable to achieve this. 我自己使用新的WP8“诺基亚此处地图”地图控件进行了尝试,但无法实现。 I had to resort to falling back to the older "Bing" based map control in Microsoft.Phone.Controls.Maps (marked as obsolete). 我不得不求助于Microsoft.Phone.Controls.Maps(标记为过时)中较旧的基于“ Bing”的地图控件。

Here's how to remove the other layers in the older Microsoft.Phone.Controls.Maps control: 这是在旧的Microsoft.Phone.Controls.Maps控件中删除其他层的方法:

for (var i = Map.Children.Count - 1; i >= 0; i--)
{
    MapTileLayer tileLayer = Map.Children[i] as MapTileLayer;
    if (tileLayer != null)
    {
        Map.Children.RemoveAt(i);
    }
}

Even though this older map control has been superseded in WP8 the newer control doesn't seem to support the same flexibility with layers and the "obsolete" control still works happily under WP8.1 if used in your app. 即使此较旧的地图控件已在WP8中取代,较新的控件似乎也不支持图层的相同灵活性,并且如果在您的应用程序中使用,则“过时”控件在WP8.1下仍然可以令人满意地工作。

Here's my app which still uses the older control which is probably achieving what you're trying to do - NZ Topo Map app for Windows Phone . 这是我的应用程序,它仍然使用较旧的控件,这可能正在实现您要尝试的操作-Windows Phone的NZ Topo Map应用程序

Cut down Xaml for using the older map control in your app (you'll probably want to ignore my data bindings and replace them with your own): 减少Xaml,以便在您的应用中使用较旧的地图控件(您可能希望忽略我的数据绑定,并用自己的数据绑定替换):

<UserControl x:Class="TopoMap.Controls.Map"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:m="clr-namespace:Microsoft.Phone.Controls.Maps;assembly=Microsoft.Phone.Controls.Maps"
    mc:Ignorable="d"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    d:DesignHeight="480" d:DesignWidth="480"
    DataContext="{Binding Main, Source={StaticResource Locator}}">

    <Grid x:Name="LayoutRoot" Background="Transparent">
        <m:Map x:Name="MapBase" LogoVisibility="Collapsed" ScaleVisibility="Visible"
               Loaded="Map_Loaded"
               LayoutUpdated="Map_LayoutUpdated"
               ZoomLevel="{Binding ZoomLevel, Mode=TwoWay}"
               Center="{Binding Center, Mode=TwoWay}">
        </m:Map>
    </Grid>

</UserControl>

The important reference that you need it: 您需要的重要参考:

xmlns:m="clr-namespace:Microsoft.Phone.Controls.Maps;assembly=Microsoft.Phone.Controls.Maps"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM