How to change strokeColor between points when using DirectionsRenderer

蓝咒 提交于 2020-01-01 19:56:11

问题


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


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!