0

I try to use the event .isOpen does not update its status when I click on my popup. Someone know why or know how to do ?

This is my code :

class Map extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      x: 0,
      y: 0,
      geojsonData: null,
      geojsonData6: null,
    }
  }    
  initMap() {
     //Declaration of the map
     var valMarker = L.marker([this.state.y, this.state.x]).addTo(this.state.map)
     .bindPopup('Hotel "Port de Calais"<br> 7 circuits à proximités.')
     var valPopup = valMarker.getPopup()
     if (valPopup.isOpen() === true) {
       var myData = [this.state.geojsonData, this.state.geojsonData6]
       L.geoJSON(myData).addTo(this.state.map)
     }
  }

componentDidMount() {
    this.initData(2985).then((data) => {
      this.setState({geojsonData: JSON.parse(data[0].geojson)})
    });
//and more
    this.initData(4661).then((data) => {
      this.setState({geojsonData6: JSON.parse(data[0].geojson)})
      this.initMap()
  });
}
  render() {
    <Map />
    return <div id="map" style={style} />;
  }
}

I think, I need to do something in render(), but I don't find actually the solution. Of course, when I do "marker.openPopup();" before the .isOpen(), the condition is true. But I want a action from the user?

Thanks !

3
  • You are not returning anything inside your Map component. I see a lot of issues in this piece of code. Is that all your code?
    – Spleen
    Commented Oct 5, 2018 at 14:42
  • No that's not all of my code. But the things that are missing are not necessarily useful for my problem. It's mostly initializations via API, and the declaration of my map.
    – Verdouze
    Commented Oct 5, 2018 at 14:45
  • I'vent got a lot of code ...
    – Verdouze
    Commented Oct 5, 2018 at 15:07

0

Browse other questions tagged or ask your own question.