Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何更改路线颜色?_Javascript_Reactjs_Maps - Fatal编程技术网

Javascript 如何更改路线颜色?

Javascript 如何更改路线颜色?,javascript,reactjs,maps,Javascript,Reactjs,Maps,我在react Google Maps routes中遇到了更改颜色的问题,我附上下面的代码 { DirectionsService.route({ origin: new google.maps.LatLng(newProsps[0].lat, newProsps[0].lng), destination: new google.maps.LatLng(40.95604847, -73.84254456), t

我在react Google Maps routes中遇到了更改颜色的问题,我附上下面的代码

{
DirectionsService.route({
              origin: new google.maps.LatLng(newProsps[0].lat, newProsps[0].lng),
              destination: new google.maps.LatLng(40.95604847, -73.84254456),
              travelMode: google.maps.TravelMode.DRIVING,
              provideRouteAlternatives: true,
            }, (result, status) => {
              if (status === google.maps.DirectionsStatus.OK) {
                  if(state.bol){
                  state.directions = result
                  }
                  else{
                    return null
                  }
              } else {
                console.error(`error fetching directions ${result}`);
              }
}

我不知道如何在初始化期间更改路由的颜色

也许您可以在路由内部使用此代码

directionsDisplay = new google.maps.DirectionsRenderer({
    polylineOptions: {
      strokeColor: "red"
    }
  });
directionsDisplay.setOptions({
  polylineOptions: {
    strokeColor: 'red'
  }
});

也许你可以在路线内部使用这个代码

directionsDisplay = new google.maps.DirectionsRenderer({
    polylineOptions: {
      strokeColor: "red"
    }
  });
directionsDisplay.setOptions({
  polylineOptions: {
    strokeColor: 'red'
  }
});

有一个你可能感兴趣的老答案有一个你可能感兴趣的老答案