如何将工具提示添加到Gmap.Net多边形?

时间:2015-07-07 11:29:36

标签: tooltip polygon gmap.net

我正在使用Gmap.net强大的工具在我的.net 4桌面应用程序中启用映射。 我在表单加载事件上添加多边形。但是我无法为多边形设置工具提示文本。

任何想法?

2 个答案:

答案 0 :(得分:2)

我找到的唯一方法就是在同一个叠加层上添加一个标记,并在输入多边形时触发其IsVisible属性:

var gm = new GMapControl();

GMapOverlay polyOverlay = new GMapOverlay("polygons");

List<PointLatLng> points = new List<PointLatLng>();
points.Add(new PointLatLng(53.0, 10.0));
points.Add(new PointLatLng(53.0, 11.0));
points.Add(new PointLatLng(54.0, 11.0));
points.Add(new PointLatLng(54.0, 10.0));

var polygon = new GMapPolygon(points, "mypolygon");

polygon.Fill = new SolidBrush(Color.FromArgb(50, Color.Red));
polygon.Stroke = new Pen(Color.Red, 1);
polygon.IsHitTestVisible = true;

Controls.Add(gm);
gm.Overlays.Add(polyOverlay);
polyOverlay.Polygons.Add(polygon);

polyOverlay.Markers.Add(new GMarkerCross(new PointLatLng(53.5, 10.5)) { ToolTipText = "Test me", IsVisible = false, ToolTipMode = MarkerTooltipMode.Always });

gm.OnPolygonEnter += (poly) => polyOverlay.Markers.First().IsVisible = true;
gm.OnPolygonLeave += (poly) => polyOverlay.Markers.First().IsVisible = false;

您可以使用空GMarkerCross的{​​{1}}代替GMarkerGoogle。注意:当鼠标进入多边形时,Bitmap会产生GMarkerGoogleType.none

答案 1 :(得分:0)

还有另一种方法可以将工具提示添加到多边形:向表单添加标签,并将其隐藏在Load事件中。使用常规方式使用名称定义Polygon,并确保设置IsHitTestVisible。为OnPolygonEnter和OnPolygonLeave添加处理程序。

Dim points As New List(Of PointLatLng)()
points.Add(New PointLatLng(48.866383, 2.323575))
points.Add(New PointLatLng(48.863868, 2.321554))
points.Add(New PointLatLng(48.861017, 2.33003))
points.Add(New PointLatLng(48.863727, 2.331918))
Dim polygon As New GMapPolygon(points, "Jardin des Tuileries")
polygon.Fill = New SolidBrush(Color.FromArgb(30, Color.Red))
polygon.Stroke = New Pen(Color.Red, 1)
polygon.IsHitTestVisible = True
ovlPolygons.Polygons.Add(polygon)

Private Sub myMap_OnPolygonEnter(item As GMapPolygon) Handles myMap.OnPolygonEnter
    Label1.BringToFront()
    Label1.Show()
    Label1.Text = item.Name
    Label1.Location = New Point(MousePosition.X - Me.Left, MousePosition.Y - Me.Top)
End Sub

Private Sub myMap_OnPolygonLeave(item As GMapPolygon) Handles myMap.OnPolygonLeave
    Label1.Hide()
End Sub