Reputation: 10059
In the Google Maps API v3, how can I get the waypoint markers from the DirectionsRenderer in order to add click events to them (such as a delete menu).
Upvotes: 5
Views: 6077
Reputation: 66
Instead of creating a click event on a waypoint, you can create it on a marker, and assign it a high z-index so it overlays the waypoint.
marker = new google.maps.Marker({
map:map,
position: new google.maps.LatLng(1.99, 2.99),
});
marker.setZIndex(999);
google.maps.event.addListener(marker, 'click', function(event){
alert(marker.title);
});
Upvotes: 0
Reputation: 31
Another way, which doesn't involve putting new markers on the map, would be to detect DOM click events on the map widget. The idea is simple. When a click is detected:
I coded a complete solution in java for gwt. It should be pretty straightforward to get it translated into javascript.
Upvotes: 1
Reputation: 2565
Until a better solution can be found here is the work around that I have employed. The basic idea is to put your own marker on top of the waypoints and bind a click event listener to your marker. I have made a jsfiddle demonstrating the idea.
It definitely isn't perfect, but with a custom icon instead of the default marker it could look sort of natural.
Upvotes: 5