Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Maps Polyline click does not fire PolyMouseEvent

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

like image 207
artsince Avatar asked Aug 21 '12 17:08

artsince


People also ask

How do you delete a polygon in Google Maps?

To remove a polygon from the map, call the setMap() method passing null as the argument. In the following example, bermudaTriangle is a polygon object: bermudaTriangle. setMap(null);


1 Answers

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.

like image 53
geocodezip Avatar answered Nov 14 '22 23:11

geocodezip