Map management: remove or hide the default map layer

In my Windows Phone 8 app, I am using a custom TileSource

to overlap the default map background with a custom tile like this:

FROM#:

public class CustomTileSource : TileSource
{
   public CustomTileSource()
   {
      UriFormat ="http://myurl/{0}/{1}/{2}.png";
   }

   public override Uri GetUri(int x, int y, int zoomLevel)
   {

      if (zoomLevel > 0 && zoomLevel <= 18)
      {
          var url = string.Format(UriFormat, zoomLevel, x, y);
          return new Uri(url);
       }
       //if zoom level is not supported, return null
        return null;
    }
}

      

XAML:

...
xmlns:maps="clr-namespace:Microsoft.Phone.Maps.Controls;assembly=Microsoft.Phone.Maps"
xmlns:tileSource="clr-namespace:Mappa"
...

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
   <maps:Map x:Name="Map" Center="45,9" ZoomLevel="14">
      <maps:Map.TileSources>
         <tileSource:CustomTileSource />
      </maps:Map.TileSources>
    </maps:Map>
</Grid>

      

My problem is that I need to remove the default map layer to hide the shortcuts (metro stations, neighborhood names, etc.).

I know this can be done quite easily with Windows Phone 8.1 using a property MapTileLayer.BackgroundReplacement

(as a state here ), but I cannot find information on Windows Phone 8.

+3


source to share


1 answer


I tried this myself with the new WP8 "Nokia HERE maps" map control but couldn't get it. I had to resort to falling back to the old Bing control system in Microsoft.Phone.Controls.Maps (marked as obsolete).

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

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 old map control was replaced in WP8, the newer control does not seem to support the same flexibility with layers, and the "legacy" control still works in WP8.1 if used in your application.

Here's my app, which still uses an old control that probably achieves what you are trying to do - NZ Topo Map Windows Phone App .

+1


source







All Articles