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

Getting the Location Under the Cursor

3 Answers 399 Views
Map
This is a migrated thread and some comments may be shown as answers.
Ziad
Top achievements
Rank 1
Ziad asked on 07 Jul 2010, 01:50 PM
Hello,

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

Thank you.

3 Answers, 1 is accepted

Sort by
0
Accepted
Andrey
Telerik team
answered on 08 Jul 2010, 09:39 AM
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
0
Ziad
Top achievements
Rank 1
answered on 08 Jul 2010, 10:43 AM
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".


0
Accepted
Andrey
Telerik team
answered on 09 Jul 2010, 09:12 AM
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
Tags
Map
Asked by
Ziad
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Ziad
Top achievements
Rank 1
Share this question
or