Concept of ShapeLayers

Oct 15, 2008 at 7:20 PM

Can somebody please give me a hint on the basic concept of shapelayers.
What I want to do, is to create some shapelayers and add some pushpins or other visuals to each of them.
Then I need to add/remove or switch the visibility of the shapelayers to control which layers are shown.
Unfortunately, either the IsVisible property of the shapelayer nor the add/remove methods of the map have any effect on the visibility of the layers.

Is it neccessary to always clear and set the list of shapes to do that?
If this is the case, why do we have more than one layer?
I read some of the posts regarding this topic, but could not find a clear answer.

By the way, this is a fantastic project.

thx, mikesnet
Oct 16, 2008 at 4:19 AM
Edited Oct 16, 2008 at 4:22 AM
I made a simple user control with 2 buttons

"Show ShapeLayer" & "Hide ShapeLayer"

really what it does is create a "ShapeLayer" object, this has a "List" property

to Show and Hide the layer, really what I am doing it Clearing the "List" property of it's pins to hide it,
or Adding the pins to the "List" property to show the layer...

drop the user control on to the page.xaml file, the same way the Dashboard control is
then in the page constructor you hook up the map, as the Dashboard control does.

Page.xaml snippet

<DeepEarthPrototype:AddRemoveLayers x:Name="addRemoveLayers" Grid.Row="1" HorizontalAlignment="Left" VerticalAlignment="Bottom" />

Page.cs snippet

        public Page(string token)



            map.GeocodeService = new Geocode(token);

            map.RouteService = new Route(token);

            map.BaseLayers.Add(new TileLayer(MapMode.Aerial, token));

            map.BaseLayers.Add(new TileLayer(MapMode.Hybrid, token));

            map.BaseLayers.Add(new TileLayer(MapMode.Road, token));


            map.EventBehavior.List.Insert(0, new PrototypeBehavior());

            map.EventBehavior.List.Insert(1, new MapModeBehavior());


            dashboard.MapControl = map;

            addRemoveLayers.MapControl = map;


the UserControl Xaml

<UserControl x:Class="DeepEarthPrototype.AddRemoveLayers"




    <Grid x:Name="LayoutRoot">


            <Button x:Name="ShowShapeLayer" Content="Show ShapeLayer" Margin="3,3,3,3"/>

            <Button x:Name="HideShapeLayer" Content="Hide ShapeLayer" Margin="3,3,3,3"/>





the UserControl code

using System.Windows;

using System.Windows.Controls;

using DeepEarth;


namespace DeepEarthPrototype


    public partial class AddRemoveLayers : UserControl


        private ShapeLayer shapeLayer;


        Map mapControl;

        public Map MapControl




                return this.mapControl;




                this.mapControl = value;




        public AddRemoveLayers()




            // Add button event handlers

            this.ShowShapeLayer.Click += new RoutedEventHandler(ShowShapeLayer_Click);

            this.HideShapeLayer.Click += new RoutedEventHandler(HideShapeLayer_Click);



        void HideShapeLayer_Click(object sender, RoutedEventArgs e)


            if (shapeLayer.IsVisible == true)


                // to Hide the layer, really we clear the list of PushPins


                shapeLayer.IsVisible = false;




        void ShowShapeLayer_Click(object sender, RoutedEventArgs e)


            if (shapeLayer == null)


                // Create the ShapeLayer and Add it to the MapControl

                shapeLayer = new ShapeLayer { ID = "CUSTOMLAYER" };




            if (shapeLayer.IsVisible == false)


                // to Show the Lapyer, really we add the PushPins into the list

                // Create a new PushPin and add it to the ShapeLayer

                var pushpin = new Pushpin { Point = new Point(153.453941, -28.088413) };


                shapeLayer.IsVisible = true;





Oct 16, 2008 at 7:52 AM
thx for your answer.
So the best way to switch between different layers would be to persist the lists of the different shapelayers somewhere else and to dynamically add/remove them on demand, right?
Oct 16, 2008 at 8:03 AM
yes i would think so
Oct 17, 2008 at 1:08 PM

Its not ideal is it? This is the only solution that works with the current control.
I think we need to add some logic into the control to do this for you, it seems a waste to have to maintain a 2nd list and then clear and add to list inside the control.
We should be able to do something in the base shape object or a pattern to follow in the pin/poly to respect a isvisible property pretty easily I would think.

I will add this to the Issue tracker as a feature request.