5

我正在尝试获取文档中所写的折线路径中边缘的索引。但是,每当我触发折线上的点击事件时,我都会得到未定义的值。

这是我的代码:边缘、路径和顶点都是未定义的

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]);
  }

} });

我在这里错过了什么吗?非常感谢

4

1 回答 1

10

我在测试用例上看到了相同的结果

进一步测试,看起来它们在“可编辑”折线上可用,如果单击白色方块,则顶点为真,如果编辑折线并单击“新”顶点之一,则路径为真。 测试带有可编辑折线的案例

仔细查看文档,很明显它只适用于可编辑的折线/多边形:

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.

更多信息。单击白色的小方块(“编辑手柄”)会给出顶点#或边缘编号,没有找到使路径未定义的任何方法,但这可能是因为到目前为止我只玩过折线.

于 2012-08-21T18:29:42.757 回答