How can I add a mouseover event listener to the directionsRenderer when using the DirectionsService?
I know how to add a listener to a straight line but can’t seem to find the object in the directionsRenderer.
For example this works:
function getStraightLine(coordinates) {
if (progress.length == 0)
progress = coordinates;
else
progress.push(coordinates[1]);
updateDistance();
var line = new google.maps.Polyline({
path: coordinates,
strokeColor: "#FF0000",
strokeOpacity: .5,
strokeWeight: 2,
map: map
});
google.maps.event.addListener(line, 'mouseover', function(){
alert("moused over straight line!");
});
return line;
}
But this doesn’t:
function getDirectionsPath(coordinates) {
var directionsPath = new google.maps.DirectionsRenderer();
directionsPath.setMap(map);
var request = {
origin: coordinates[0],
destination: coordinates[1],
travelMode: google.maps.TravelMode.WALKING
};
directionsService.route(request, function (result, status) {
if (status == google.maps.DirectionsStatus.OK) {
var coordinates = result.routes[0].overview_path;
if (progress.length == 0)
progress = coordinates;
else
progress = progress.concat(coordinates);
directionsPath.setDirections(result);
google.maps.event.addListener(directionsPath, 'mouseover', function(){
alert("moused over straight line!");
});
}
});
return directionsPath;
}
Instead of directionsPath I’ve tried result, result.routes[0], and a few others.
So what object should I use?
Will you use the ‘drag’ event on the ‘polyline’ that generated from the
setDirections(directionsResult)method?If you don’t, I think you can create a ‘polyline’ by yourself like this:
if you have solved the problem use the method like
google.maps.DirectionsRenderer().setDirections(result)?