简体   繁体   中英

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.

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

I tried this myself with the new WP8 "Nokia HERE maps" map control but was unable to achieve this. I had to resort to falling back to the older "Bing" based map control in Microsoft.Phone.Controls.Maps (marked as obsolete).

Here's how to remove the other layers in the older Microsoft.Phone.Controls.Maps control:

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.

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 .

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):

<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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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