我正在尝试获取折线路径中边缘的索引,因为它写在documentation中。但是,每当我在折线上触发click事件时,我都会得到未定义的值。
这是我的代码: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]);
}
} });
我在这里遗漏了什么吗?非常感谢
答案 0 :(得分:10)
进一步测试,看起来它们在“可编辑”折线上可用,如果单击白色方块,则顶点为true,如果编辑折线并单击其中一个“新”顶点,则路径为true ”。 test case with editable polyline
仔细观察documentation,很明显它只适用于可编辑的折线/多边形:
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.
更多信息。单击小白色方块(“编辑句柄”)给出顶点#或边数,没有找到一种方法使路径任何东西但未定义,但这可能是因为到目前为止我只使用折线