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

Clickable Map Pins

1 Answer 183 Views
Map
This is a migrated thread and some comments may be shown as answers.
Chris Burtch
Top achievements
Rank 1
Chris Burtch asked on 07 Mar 2017, 06:25 AM
I was wondering if there is any way to capture a click on MapPin and associate an event handler with that. As far as I could tell, the only element that has events is a RadMap. The MapPin class has a HitTest() method that takes parameters PointG, PointL, and IMapViewport, but even if I were to iterated through all the pins on a map click to see if any of them pass the HitTest(), it's not clear what parameters should be passed in. I feel like there is probably a better way to do it. Can anyone please provide guidance on this?

1 Answer, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 07 Mar 2017, 04:05 PM
Hello Chris,

Thank you for writing.

Clicks on pins can be detected by handling the MouseDown event of the RadMap control. Indeed, you need to work with the HitTest method and you can invoke it directly on your layer and it will return a  object if found. The tricky part is transforming the mouse coordinates to geographic ones. Please see my code snippet below: 
private void radMap1_MouseDown(object sender, MouseEventArgs e)
{
    RadMap map = (RadMap)sender;
    PointL point = new PointL(e.X - map.MapElement.PanOffset.Width, e.Y - map.MapElement.PanOffset.Height);
    PointG location = MapTileSystemHelper.PixelXYToLatLong(point.X, point.Y, map.MapElement.ZoomLevel);
 
    while (location.Longitude > 180)
    {
        location.Longitude -= 360;
    }
 
    MapPin pin = map.MapElement.Layers["PointG"].HitTest(location) as MapPin;
    if (pin != null)
    {
        Console.WriteLine("Clicked");
    }
}

I hope this helps. Should you have further questions please do not hesitate to write back.

Regards,
Hristo
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Map
Asked by
Chris Burtch
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Share this question
or