Posted 24 October 2022, 2:29 am EST
I created many polylines from bicycle tracks on a map and want to get the number of the corresponding item when I hover over the line. Is this reversal method possible?
Regards
Forums Home / ComponentOne / WinForms Edition
Posted by: cnoelle on 24 October 2022, 2:29 am EST
Posted 24 October 2022, 2:29 am EST
I created many polylines from bicycle tracks on a map and want to get the number of the corresponding item when I hover over the line. Is this reversal method possible?
Regards
Posted 27 October 2022, 3:13 am EST
Hi,
You can use the HitTest(Point p) method of the C1Map to check if and what vector is under at the point.
Documentation : https://www.grapecity.com/componentone/docs/win/online-maps/C1.Win.Map.4.5.2~C1.Win.Map.C1Map~HitTest.html
private void Map_Click(object sender, MouseEventArgs e)
{
var htInfo = c1Map.HitTest(e.Location);
if (htInfo != null && htInfo.Type == C1.Win.Map.HitTestType.VectorItem)
{
Console.WriteLine(htInfo.Vector);
}
}
Regards.
Posted 28 October 2022, 4:14 am EST
Thanks, but it only shows one of several overlying polylines.
Do I have to find the others by searching in the GeoLine.Points for the corresponding hit point or is there another more usual way?
Regards
Posted 28 October 2022, 4:52 pm EST
And btw (only one polyline), which GeoPoint in the Vector.Geometry is hit?
Would be great to have the index.
Regards
Posted 31 October 2022, 11:25 am EST
Hi,
The HitTest gets you the topmost element, in the case of multiple vector items, you will get the item that is on the Top. If you want to get the GeoPoint that was hit then you can use the ScreenToGeographic() method of the C1Map to convert the mouse coordinated into Geo coordinates.
C1Map.ScreenToGeographic(new C1.Win.Interop.Point(htInfo.Point.X, htInfo.Point.Y))
Regards
Avnish
Posted 6 November 2022, 5:45 pm EST
Seems there is no method to get the GeoPoint of the Polyline directly.
I have to loop through the points of the GeoLine and match with some epsilon…
Regards,
Chris
Posted 7 November 2022, 2:17 am EST
Hi Chris,
Yes, there is no direct way to get a GeoPoint of the Polyline directly.
To create a line, you will need a minimum of two points. Now if you click anywhere on the line the HitTest will give the VectorPolyline but the polyline will only have two GeoPoints. Even if you loop through them you will not get the point that was hit.
Instead, the Point property of the HitTestInfo gives you the point on the Map Viewport which you can then convert as we mentioned in the previous reply. If you are facing any issues, let us know.
Regards
Avnish