最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Google Maps Polyline click does not fire PolyMouseEvent - Stack Overflow

programmeradmin2浏览0评论

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 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

Share Improve this question edited Jun 20, 2020 at 9:12 CommunityBot 11 silver badge asked Aug 21, 2012 at 17:51 artsinceartsince 1,0421 gold badge21 silver badges37 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 10

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.

发布评论

评论列表(0)

  1. 暂无评论