VisualTreeHelper.FindElementsInHostCoordinates and MapShape

2 posts, 0 answers
  1. Clint Singer
    Clint Singer avatar
    133 posts
    Member since:
    Oct 2012

    Posted 26 Nov 2009 Link to this post


    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.

  2. Andrey
    Andrey avatar
    1681 posts

    Posted 01 Dec 2009 Link to this post

    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

    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.
Back to Top