Clickable Map Pins

2 posts, 0 answers
  1. Chris Burtch
    Chris Burtch avatar
    6 posts
    Member since:
    Apr 2005

    Posted 07 Mar Link to this post

    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?
  2. Hristo
    Admin
    Hristo avatar
    1023 posts

    Posted 07 Mar Link to this post

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