Google地图多段线点击不会触发PolyMouseEvent [英] Google Maps Polyline click does not fire PolyMouseEvent

查看:186
本文介绍了Google地图多段线点击不会触发PolyMouseEvent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图获取折线路径中边缘的索引,因为它写在文档。然而,每当我在多段线上触发单击事件时,我都会得到未定义的值。

这里是我的代码:edge,path和vertex都是未定义的

  route = new google.maps.Polyline({
path:polyLineArray,
strokeColor:#FF0000,
strokeOpacity:1.0,
strokeWeight:5,
clickable:true,
editable:false
});

google.maps.event.addListener(route,'click',function(evt){
console.log(route click1:+ evt.edge);
console.log(route click2:+ evt.path);
console.log(route click2:+ evt.vertex);
console.log(route click3:+ evt) ;
for(var property in evt){
console.log(route click4:+ property + - + evt [property]);
}

}
});



这里?非常感谢

解决方案

我在我的测试用例



进一步测试,看起来它们在可编辑折线上可用,顶点是真您点击白色方块,如果您编辑多段线并点击其中一个新顶点,则路径为true。
带有可编辑多段线的测试用例



仔细观察 documentation ,它很清楚它只适用于可编辑的多段线/多边形:

  google.maps.PolyMouseEvent对象
此对象从多段线和多边形上的鼠标事件返回

此对象扩展MouseEvent。
属性
属性|类型|说明
edge |数字|
|时光标下方路径边缘的索引事件发生,如果事件发生在
|的中点上可编辑多边形。
路径|数字|事件
|时光标下方路径的索引发生,如果事件发生在顶点和多边形
|上是可编辑的。否则未定义。
顶点|数字|事件
|时游标下方顶点的索引发生,如果事件发生在顶点和折线或
|上多边形是可编辑的。如果事件不发生在顶点上,
|该值是未定义的。

更多信息。点击小的白色方块(编辑手柄)会给出一个顶点号或一个边数,还没有找到一种方法来使路径没有被定义,但这可能是因为到目前为止,我只玩过折线。


I am trying to get the index of the edge in the path of a polyline as it is written in the documentation. However, I get undefined values whenever I trigger the click event on the polyline.

Here is my code: edge, path and vertex are all undefined

route = new google.maps.Polyline({
path: polyLineArray,
strokeColor: "#FF0000",
strokeOpacity: 1.0,
strokeWeight: 5,
clickable: true,
editable: false
});

google.maps.event.addListener(route, 'click', function(evt) {           
  console.log("route click1: " + evt.edge);
  console.log("route click2: " + evt.path);
  console.log("route click2: " + evt.vertex);
  console.log("route click3: " + evt);
  for(var property in evt) {
   console.log("route click4: " + property + " - " + evt[property]);
  }

} });

Am I missing something here? Thanks a lot

解决方案

I see the same results on my test case

Testing further, looks like they are available on "editiable" polylines, the vertex is true if you click on on of the white squares, the path is true if you edit the polyline and click on one of the "new" vertices". test case with editable polyline

Looking closer at the documentation, it is pretty clear it just applies to editable polylines/polygons:

google.maps.PolyMouseEvent object
This object is returned from mouse events on polylines and polygons.

This object extends MouseEvent.
Properties
Properties | Type   | Description
edge       | number | The index of the edge within the path beneath the cursor when 
                    | the event occurred, if the event occurred on a mid-point on an 
                    | editable polygon.
path       | number | The index of the path beneath the cursor when the event 
                    | occurred, if the event occurred on a vertex and the polygon
                    | is editable. Otherwise undefined.
vertex     | number | The index of the vertex beneath the cursor when the event 
                    | occurred, if the event occurred on a vertex and the polyline or 
                    | polygon is editable. If the event does not occur on a vertex, 
                    | the value is undefined.

More information. Clicking on the little white squares (the "edit handles") gives either a vertex # or an edge number, haven't found a way to make the path anything but undefined, but that may be because so far I have only played with polylines.

这篇关于Google地图多段线点击不会触发PolyMouseEvent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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