Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Revision as of 05:45, 1 November 2013 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Showing/Hiding map content with Windows Phone maps API

From Wiki
Jump to: navigation, search
SignpostIcon HereMaps 99.png
WP Metro Icon WP8.png
Article Metadata
Windows Phone 8
Created: symbianyucca (08 Nov 2012)
Last edited: hamishwillee (01 Nov 2013)



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;
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;
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);
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 1 November 2013, at 05:45.
46 page views in the last 30 days.