I have created multiple routes using Google map api.
I need to change the color and highlight the route while click any of the routes in Google map.
// Added code for multiple Routes.
let directionsService = new google.maps.DirectionsService;
let directionsDisplay;
directionsService.route({
origin: {
lat: sourceLat,
lng: sourceLon
},
destination: {
lat: destLat,
lng: destLon
},
provideRouteAlternatives: true,
travelMode: google.maps.TravelMode['DRIVING']
}, (res, status) => {
if (status == google.maps.DirectionsStatus.OK) {
for (var i = 0, len = res.routes.length; i < len; i++) {
directionsDisplay = new google.maps.DirectionsRenderer({
map: this.map,
directions: res,
routeIndex: i,
suppressMarkers: true,
polylineOptions: {
strokeColor: "darkgrey",
strokeOpacity: 1.0,
strokeWeight: 7
}
});
}
}
});
// Added event Listener to change the route color. But this is not working and also am not getting any error.
google.maps.event.addListener(directionsDisplay, 'click', function(event) {
directionsDisplay.setOptions({
map: this.map,
directions: res,
routeIndex: 0,
polylineOptions: {
strokeColor: 'green',
strokeOpacity: 1.0,
strokeWeight: 7
}
});
directionsDisplay.setMap(this.map);
});
Thanks in Advance.