I'm using react-google-maps to render map in website. I have a problem about strokeColor for each line when using waypoints for DirectionsService. How to change strokeColor between them and how to callback after using DirectionsService . This is my source same example:
https://tomchentw.github.io/react-google-maps/#directionsrenderer
let DirectionsService = new google.maps.DirectionsService;
var directionsDisplay = new google.maps.DirectionsRenderer;
DirectionsService.route(
{
origin: new google.maps.LatLng(10.8441402, 106.76757429999999),
destination: new google.maps.LatLng(10.8463797,106.7721405),
travelMode: google.maps.TravelMode.DRIVING,
optimizeWaypoints: true,
waypoints: [
{
location: new google.maps.LatLng(10.8454946,106.764759),
stopover : false
}
]
},
(result, status) => {
console.log(result);
if (status === google.maps.DirectionsStatus.OK) {
this.setState({directions: result})
return (typeof callback == 'function') && callback( result);
} else {
console.error(`error fetching directions`, result);
}
}
);
Thanks about help
In order access DirestionsRendererOptions right in component, you need to use options
prop, like that:
<DirectionsRenderer
directions={props.directions}
options={{
polylineOptions: {
strokeOpacity: 0.5,
strokeColor: '#FF0000',
},
}}
/>
Please see the documentation to find out more about the options you have access to: https://developers.google.com/maps/documentation/javascript/reference/3.exp/directions#DirectionsRendererOptions
来源:https://stackoverflow.com/questions/49953003/how-to-change-strokecolor-between-points-when-using-directionsrenderer