Ich habe Probleme mit react + Google Maps API.Wie kann ich diese.map in diese Google Map Events eintragen?
ich den Wert von this.map
in meinem Konstruktor Einstellung:
constructor(props) {
super(props);
this.map = null;
}
ich die Google Maps API bin Laden und meine Karte in der componentWillReceiveProps
Methode einrichten:
componentWillReceiveProps({ isScriptLoaded, isScriptLoadSucceed }) {
if (isScriptLoaded && !this.props.isScriptLoaded) { // load finished
console.log('yes - isScriptLoaded && !this.props.isScriptLoaded');
if (isScriptLoadSucceed) {
this.map = new google.maps.Map(this.refs.map, mapOptions);
/* not sure how to do this part */
google.maps.event.addDomListener(window, 'resize', function() {
const center = this.map.getCenter(); //this.map undefined, unless above I add const map = this.map, and then use map.
google.maps.event.trigger(this.map, 'resize');
this.map.setCenter(center);
});
Gibt es eine Möglichkeit Ich kann this.map
übergeben neben einer anderen Variablen const map = this.map
oder etwas und das weitergeben?
Ich bin besorgt, dass const map = this.map
durch die Verwendung und dann weiter modifiziert auf nur map
wird zu Problemen führen, wenn ich this.map
Wert zu aktualisieren vergessen :(