私はreact + google maps APIに問題があります。このGoogleマップイベントにthis.mapを渡すにはどうすればよいですか?
私は私のコンストラクタでthis.map
の値を設定しています:
constructor(props) {
super(props);
this.map = null;
}
私はGoogle MapsのAPIをロードし、componentWillReceiveProps
方法で私のマップを設定しています:
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);
});
方法はあります私は別の変数const map = this.map
か何かを作成して渡す以外にthis.map
を渡すことができますか?
I午前心配私は矢印の機能を使用すると、内部のthis
にアクセスできるようにすることを考えてthis.map
値:(