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

VisualTreeHelper.FindElementsInHostCoordinates and MapShape

1 Answer 92 Views
Map
This is a migrated thread and some comments may be shown as answers.
Clint Singer
Top achievements
Rank 1
Clint Singer asked on 26 Nov 2009, 07:01 PM
Hi,

I am doing some hit testing on some MapPolygons that are on my map.  I didn't want to roll my own click event on the MapPolygon by using MouseDown MouseUp, MouseMoves, Timers, etc to determine the users intentions on the map.  I then thought I would use the MapMouseClick event from the map itself then use VisualTreeHelper.FindElementsInHostCoordinates to determine what was clicked.  Of course it is a polygon wrapped in a content presenter that makes up the shape and not the MapShape that is returned.

My goal was to then query my Tag property on my MapShape.  So I have a few requests:

1) Attach the shapes Tag property to the MapShape.Tag property like the Stroke, Fill etc. for direct Tag access.
2) Attach the shapes Parent property to the MapShape itself so one could at least get back to the original  MapShape.
3) Add map compatible Click and DoubleClick routed events to the MapShape so one doesn't have to create their own compatible logic.

Cheers,
Clint

1 Answer, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 01 Dec 2009, 11:38 AM
Hello Clint,

The 2010.Q1 official release will contain an additional method in the InformationLayer class to get its objects by location.
You can use the following code to getting the MapShape object in the MapMouseClick event handler:

private void radMap_MapMouseClick(object sender, MapMouseRoutedEventArgs eventArgs)
{
    IEnumerable<UIElement> elements = VisualTreeHelper.FindElementsInHostCoordinates(eventArgs.Location.GetPoint(this.radMap), this.informationLayer);
  
    foreach (UIElement element in elements)
    {
        ContentPresenter presenter = element as ContentPresenter;
  
        if (presenter != null)
        {
            MapShape shape = this.informationLayer.ItemContainerGenerator.ItemFromContainer(presenter) as MapShape;
            if (shape != null)
            {
                // available MapShape object here
            }
        }
    }
}

Regards,
Andrey Murzov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Map
Asked by
Clint Singer
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Share this question
or