Search code examples
c#winrt-xamlbing-mapspushpin

How can I keep my pushpins from showing through my popup?


I'm generating map makers on a Bing Map. If I use the design-time Map Layer, which is added in XAML:

<bm:Map.Children>
    <!-- Data Layer-->
    <bm:MapLayer Name="DataLayer"/>

...it works great. However, I decided if I were plopping multiple different sets of markers on the map, I should put each set on its own map layer. So I added code like this:

private async void Gener8MapMarkers(List<PhotraxBaseData> _pbd, bool Cre8DynamicMapLayer)
{
    . . .
    if (Cre8DynamicMapLayer)
    {
        MapLayer newLayer = new MapLayer();
        photraxMap.Children.Add(newLayer);
        AddPushpin(loc, stuff, newLayer);
    }
    else
    {
        AddPushpin(loc, stuff, DataLayer);
    }
    . . .

But note how the pushpins show through the popup when I do this (only if I dynamically create MapLayer[s]):

enter image description here

Was adding subsequent sets to its own MapLayer a bad idea (should I just add everything to "DataLayer")?

If not, how can I use multiple MapLayers without having the pushpins show through the popup?

UPDATE

Yes, Marvin Smit's suggestion works, namely:

if (Cre8DynamicMapLayer)    
{
    MapLayer newLayer = new MapLayer();
    //photraxMap.Children.Add(newLayer);
    photraxMap.Children.Insert(0, newLayer);
    AddPushpin(loc, stuff, newLayer);
}

His brother Rik is probably the better hoopster, but I doubt Rik can program his way out of a layup.


Solution

  • You are stacking the layers you are using for the pins you create on top of the popup layer.

    By changing the order you add the layer into the stack you can have the behavior you desire.

    Instead of the

    photraxMap.Children.Add(newLayer);
    

    Use

    photraxMap.Children.Insert(0, newLayer);
    

    Which will cause the new layer to be inserted at the 'bottom' of the layers instead of the 'top' (if you consider the 'top' layer to be the closest to you)