0

我正在使用 react-google-maps 在网站中呈现地图。在为 DirectionsService 使用航点时,我对每条线的 strokeColor 有疑问。如何在它们之间更改 strokeColor 以及使用 DirectionsService 后如何回调。这是我的来源相同的例子:

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);
        }
    }
);

感谢帮助

4

1 回答 1

0

为了在组件中访问 DirestionsRendererOptions,您需要使用optionsprop,如下所示:

<DirectionsRenderer
  directions={props.directions}
  options={{
      polylineOptions: {
          strokeOpacity: 0.5,
          strokeColor: '#FF0000',
      },

  }}
/>

请参阅文档以了解有关您可以访问的选项的更多信息:https ://developers.google.com/maps/documentation/javascript/reference/3.exp/directions#DirectionsRendererOptions

于 2018-05-08T07:26:03.153 回答