Namespaces
Variants
Actions

Showing/Hiding map content with Windows Phone maps API

Jump to: navigation, search
WP Metro Icon WP8.png
SignpostIcon MapAndLocation 52.png
Article Metadata

Article
Created: symbianyucca (08 Nov 2012)
Last edited: jasfox (25 Apr 2013)

Contents

Introduction

This article shows how to display/hide map content with Windows Phone maps API. The WP7 codes discussed here are implemented in examples made for WP7, and can be found from Maps Examples for Windows phone wiki page.

Implementation on WP7

With WP7 Bing maps API you could simply use the Visibility variable of the map object class for setting it visible or hidden as shown with following code snipped:

if (poly.Visibility == System.Windows.Visibility.Visible){
poly.Visibility = System.Windows.Visibility.Collapsed;
}
else
{
poly.Visibility = System.Windows.Visibility.Visible;
}

Implementation on WP8

With WP8 Maps API the above mentioned approach generally cannot be taken, only exception being the markers which with WP8 are actually just MapOverlay objects inside MapLayer. With them you could use the Visibility variable, provided that it is available for the actual object set as content for the MapOverlay.

Following example, the snippet below shows how this could be done with Ellipse objects used as content for MapOverlay.

if (markerLayer != null)
{
for (var i = 0; i < markerLayer.Count(); i++)
{
Ellipse markker = (markerLayer[i].Content as Ellipse);
if (markker != null)
{
if (markker.Visibility == System.Windows.Visibility.Visible)
{
markker.Visibility = System.Windows.Visibility.Collapsed;
}
else
{
markker.Visibility = System.Windows.Visibility.Visible;
}
}
}
}

With polygon and polyline you would still have one option, and this would be to use the alpha channel defining the transparency factor for the color used with the map object. Note that with polygon, you do need to set the transparency for both line and the filling as shown in here:

if (poly.StrokeColor == Color.FromArgb(0xFF, 0x00, 0x00, 0xFF))
{
poly.FillColor = Color.FromArgb(0x00, 0x00, 0xFF, 0x00);
poly.StrokeColor = Color.FromArgb(0x00, 0x00, 0x00, 0xFF);
}
else
{
poly.FillColor = Color.FromArgb(0x55, 0x00, 0xFF, 0x00);
poly.StrokeColor = Color.FromArgb(0xFF, 0x00, 0x00, 0xFF);
}

Example code

The full example for this code can be found from Windows Phone 8 Maps examples project, the code used here is implemented for example in SimpleContent example inside that project.

This page was last modified on 25 April 2013, at 10:11.
216 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved