GMap-无法检测到点击多边形 [英] GMap - cannot detect clicking on polygon

查看:150
本文介绍了GMap-无法检测到点击多边形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

IsMouseOverMarker属性可以很好地检测到单击标记,但是当尝试使用GMap控件的IsMouseOverPolygon属性来检测用户是否单击了多边形线时,它似乎无法正常工作.

IsMouseOverMarker property detects clicking on marker just fine, but when trying to use IsMouseOverPolygon property of GMap Control to detect if user clicked on polygon line - it doesn't seem to be working.

注意:GMap控件的PolygonEnabled属性设置为True.

Note: PolygonEnabled property of GMap control is set to True.

OnPolygonClick事件甚至不会触发:

private void gMap_OnPolygonClick(GMapPolygon item, MouseEventArgs e) {
        double pLat = item.From.Value.Lat;
}

地图Click事件确实触发,但是'IsMouseOverPolygon'从未获得True值:

Map Click event does fire, but the 'IsMouseOverPolygon` never gets True value:

private void gMap_Click(object sender, EventArgs e) {
   if (gMap.IsMouseOverMarker) {
       MessageBox.Show("Clicked on marker and it works!");
   }

   if (gMap.IsMouseOverPolygon) {
       MessageBox.Show("clicked on line - never works");
   } 
}

我想知道添加多边形的方式是否有问题,或者是因为在我的情况下,这仅仅是线条:

I wonder if there is something wrong in a way I'm adding polygons or is it because in my case it's just lines:

GMapOverlay polyOverlay  = new GMapOverlay("polygons");
gMap.Overlays.Add(polyOverlay);
List<PointLatLng> points = new List<PointLatLng>();
points.Add(start);
points.Add(end);
polygon = new GMapPolygon(points, "mypolygon");
polygon.Stroke = new Pen(Color.Blue, 5);
polyOverlay.Polygons.Add(polygon);

所以,问题是:我应该如何检测这些行上的鼠标单击?

So, the question is: how should I go about detecting mouse click on those lines?

推荐答案

我可以在代码中看到两个问题.首先,您需要将多边形明确定义为HitTestVisible:

I can see two issues within the code. First you need to explicitely define the polygon as HitTestVisible:

polygon.IsHitTestVisible = true;

第二,要设置多边形,请添加至少三个未对齐的点,并实际生成一个区域.我发现点击只会在实际区域中引起注意,理论上该区域可以由两个点组成.

Second, to set up a polygon add at least three points that are not aligned and actually spawn an area. I've found that the click will only be noticed on an actual area, where in theory a polygon can consist of two points.

在上面的提示下,对gMap.IsMouseOverPolygon的检查应返回true.

With the hints above the check for gMap.IsMouseOverPolygon should return true then.

这篇关于GMap-无法检测到点击多边形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆