Getting the Location Under the Cursor

4 posts, 2 answers
  1. Ziad
    Ziad avatar
    13 posts
    Member since:
    Apr 2009

    Posted 07 Jul 2010 Link to this post

    Hello,

    How can I get the location (latitude and longitude coordinates) for the point beneath the mouse cursor?

    Thank you.
  2. Answer
    Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 08 Jul 2010 Link to this post

    Hi Ziad,

    You can use following code for this purpose:

    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
      
            this.radMap.MouseMove += new MouseEventHandler(radMap_MouseMove);
        }
      
        private void radMap_MouseMove(object sender, MouseEventArgs e)
        {
            Location mouse = Location.GetCoordinates(this.radMap, e.GetPosition(this.radMap));
            this.coordinates.Text = mouse.ToString();
        }
    }


    Sincerely yours,
    Andrey Murzov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
  4. Ziad
    Ziad avatar
    13 posts
    Member since:
    Apr 2009

    Posted 08 Jul 2010 Link to this post

    Thank you for your answer, Andrey.

    I have another similar question. When adding items to the information layer (for example an ellipse) I noticed that the item is being added at the specified coordinates using it's top-left corner as the starting point. Is it possible to add items centered? In other words, I want the location chosen to designate the center of the ellipse.


    Edit:

    Thanks to this post http://www.telerik.com/community/forums/wpf/map/how-to-position-images-without-using-pinpoint.aspx , I was able to solve the above issue by using the VerticalAlignment and HorizontalAlignment properties and setting them to "Center".


  5. Answer
    Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 09 Jul 2010 Link to this post

    Hello Ziad,

    The RadMap supports two ways to align FrameworkElement around the location.

    The first one is using of VerticalAlignment and HorizontalAlignment properties.
    HorizontalAlignment.Right (default) - the element is located to the right of the location.
    HorizontalAlignment.Left - the element is shifted to the left of the location.
    HorizontalAlignment.Center - the element is centered over the location.

    VerticalAlignment.Bottom (default) - the element is located at the bottom of the location.
    VerticalAlignment.Top - the element is shifted to the top of the location.
    VerticalAlignment.Center - the element is centered over the location.

    The second approach is using of the HotSpot definition. The HotSpot can be defined for the whole element as well as for any children inside. Hot spot is a position inside or outside the element which is bound to the geographical location is specified for the framework element. You can see how it can be implemented in our RadMap demo:
    http://demos.telerik.com/silverlight/#Map/HotSpot
    For more information please see the Using of the Hot Spot documentation topic:
    http://www.telerik.com/help/wpf/map-item-hot-spot.html

    If you use the MapEllipse shape, then you can use the following sample method to get centered ellipse:

    private MapEllipse CreateMapEllipseByCenter(Location center, double width, double height)
    {
        MapEllipse ellipse = new MapEllipse();
        ellipse.Width = width;
        ellipse.Height = height;

        
    Size degreeSize = radMap.GetLatitudeLongitudeSize(center, width, height);
        Location location = new Location(center.Latitude + degreeSize.Height / 2d,
            center.Longitude - degreeSize.Width / 2d);

        
    MapLayer.SetLocation(ellipse, location);

        
    return ellipse;
    }

    Sincerely yours,
    Andrey Murzov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top