Реагируйте на Google Maps: отображайте маркеры на MapWithADirectionRenderer и перекомпоновывайте компонент - PullRequest
0 голосов
/ 28 мая 2018

У меня есть компонент MapWithADirectionsRenderer , определенный как здесь

var markers = [];
const MapWithADirectionsRenderer = compose(

withProps({
    googleMapURL: "https://maps.googleapis.com/maps/api/js?...",
    loadingElement: <div style={{ height: `100%` }} />,
    containerElement: <div style={{ height: `100%` }} />,
    mapElement: <div style={{ height: `100%` }}/>
  }),
  withScriptjs,
  withGoogleMap,
  lifecycle({

  componentDidMount() {

  const DirectionsService = new google.maps.DirectionsService();

  DirectionsService.route({
    origin: this.props.origin,
    destination: this.props.destination,
    travelMode: google.maps.TravelMode.DRIVING,
  }, (result, status) => {

    if (status === google.maps.DirectionsStatus.OK) {

      // here I fill my marker array correctly

      this.setState({
          directions: result
      });

     } else {
      console.error(`error fetching directions ${result}`);
     }
   });
 }

 })
)(props=> 
  <GoogleMap
    defaultZoom={3}
    defaultCenter={// coordinates}
  >
    {props.directions && <DirectionsRenderer 
                            options={{draggable:true}}
                            directions={props.directions}
                            ref={(r) => directionsRef = r}
                            onDirectionsChanged={getDirections}
                             />
    }
    {markers.map( (marker,i) => (
                              <Marker
                                key={i}
                                position={{ lat: marker.lat, lng: marker.lng }}
                            >
                              </Marker>
                          ))}


  </GoogleMap>
);

, но после перемещения маршрута на карте, маршруты, выбранные из Google, обновляются правильно, но немаркеры, которые я хочу показать.Одинаковые маркеры всегда отображаются.

Есть ли способ обновить MapWithADirectionRenderer , чтобы он повторно отображал мои маркеры, а не только направления?Спасибо

...