This is a migrated thread and some comments may be shown as answers.

Z Order of Map object and whole InformationLayer

1 Answer 182 Views
Map
This is a migrated thread and some comments may be shown as answers.
Johannes
Top achievements
Rank 1
Johannes asked on 17 May 2013, 09:54 AM
I have multiple InformationLayers inside my RadMap control, each of them showing different MapItems. The objects (MapItems) are bound via ItemsSource.

How can I bringt a MapItem to front?
It seems that there is no ZIndex Property. I managed it by moving an object to the end of the ItemsSource. Is there a better way?

How can I bring a whole InformationLayer to Front?
When moving an object to the end of ItemsSource like said above, it is still covered by MapItems which are part of a "higher" layer. Is there anything like good old "BringToFront()" for InformationLayer?

1 Answer, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 18 May 2013, 03:20 PM
Hi Johannes,

You can use the Canvas.ZIndex attachable property for map item to bring it to front. But when you use MVVM with a data template then you should apply this property to the container for the item.
You can also use the Canvas.ZIndex to bring a whole InformationLayer to front.
The sample code is below.
It uses the MouseLeftButtonDown event from a data template for a map item. I hope it helps.
private int maxElementZIndex = 1;
private int maxLayerZIndex = 1;
 
private void BringElementToFront(UIElement newTopElement)
{
    int zIndex = Canvas.GetZIndex(newTopElement);
    if (zIndex < maxElementZIndex)
    {
        Canvas.SetZIndex(newTopElement, ++maxElementZIndex);
    }
}
 
private void BringLayerToFront(UIElement newTopElement)
{
    int zIndex = Canvas.GetZIndex(newTopElement);
    if (zIndex < maxLayerZIndex)
    {
        Canvas.SetZIndex(newTopElement, ++maxLayerZIndex);
    }
}
 
private void ItemMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    FrameworkElement element = sender as FrameworkElement;
    if (element != null)
    {
        InformationLayer layer = element.GetVisualParent<InformationLayer>();
        if (layer != null)
        {
            this.BringLayerToFront(layer);
            if (!layer.Items.Contains(element) && element.DataContext != null)
            {
                // element is a part of the datatemplate for item
                // get the container for the item
                element = layer.ItemContainerGenerator.ContainerFromItem(element.DataContext) as FrameworkElement;
            }
 
            if (element != null)
            {
                this.BringElementToFront(element);
            }
        }
 
        e.Handled = true;
    }
}

Note that the sample code uses the GetVisualParent extension. So, you should also add the 'using Telerik.Windows.Controls' statement in your code.

All the best,
Andrey Murzov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
Map
Asked by
Johannes
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Share this question
or