F
F
fronter-up2017-10-18 14:29:24
JavaScript
fronter-up, 2017-10-18 14:29:24

setMap() function for React?

Hi everybody! Can you please tell me how to correctly apply the setMap () function of google maps in React?
At the moment, everything works, but I feel that it should not be like this in react.)
There should be a way to write to a state or pass a variable through props and already take data from there and output it.
Here is the polyline that is rendered on click.

directServ = () => {
    googleMapLoader(bootstrapURLKeys)
    .then((maps) => {
      const map = this.props.map.map_;
      let flightPathCoordinates = [
        {lat: 37.772, lng: -122.214},
        {lat: 21.291, lng: -157.821},
        {lat: -18.142, lng: 178.431},
        {lat: -27.467, lng: 153.027}
      ];

      let flightPath = new maps.Polyline({
        path: markersData,
        strokeColor: '#992a49',
        strokeOpacity: 0.9,
        strokeWeight: 2
      });
      flightPath.setMap(map);
    })
  };

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question