gmaps 标记范围问题的 onPositionChanged 处理程序
onPositionChanged handler of gmaps marker scope issue
我尝试更新 react-google-maps 包装器的可拖动标记的当前位置,并将这些值传递回父级。
我的问题是,在 onMarkerPositionChange
this
中要么是 FindLocationMarker class 要么是标记本身,具体取决于调用函数的方式。
onPositionChanged={() => this.onMarkerPositionChange()}
是我的另一个选择。
我需要两者,位置标记和 props 中功能的 class。
在提供的示例中,this
是标记。
evt
未定义,我知道。
如何为函数同时提供 class 作用域和标记?
class FindLocationMarker extends Component {
onMarkerPositionChange = (evt) => {
console.log(evt);
let lat = this.position.lat();
let lng = this.position.lng();
this.props.handleMarkerPositionChange(lat, lng);
}
render() {
return (
<div>
<Marker
position={this.props.position}
draggable
onPositionChanged={this.onMarkerPositionChange}
/>
</div>
)
}
}
export default FindLocationMarker;
经过下面的长时间讨论,我决定更新我对 https://github.com/tomchentw/react-google-maps Marker.jsx 组件未来问题的回答。
如果你想在PositionChange上获取标记的位置,你需要:
- 将标记存储在您的参考文献中
- 监听 onPositionChange 事件,然后访问标记在您的 refs 中的位置。
示例:
onPositionChanged() {
const position = this.marker.getPosition();
// do something with position
}
render() {
return <Marker
onPositionChanged={ ::this.onPositionChanged }
ref={input => this.marker = input}
/>
}
我尝试更新 react-google-maps 包装器的可拖动标记的当前位置,并将这些值传递回父级。
我的问题是,在 onMarkerPositionChange
this
中要么是 FindLocationMarker class 要么是标记本身,具体取决于调用函数的方式。
onPositionChanged={() => this.onMarkerPositionChange()}
是我的另一个选择。
我需要两者,位置标记和 props 中功能的 class。
在提供的示例中,this
是标记。
evt
未定义,我知道。
如何为函数同时提供 class 作用域和标记?
class FindLocationMarker extends Component {
onMarkerPositionChange = (evt) => {
console.log(evt);
let lat = this.position.lat();
let lng = this.position.lng();
this.props.handleMarkerPositionChange(lat, lng);
}
render() {
return (
<div>
<Marker
position={this.props.position}
draggable
onPositionChanged={this.onMarkerPositionChange}
/>
</div>
)
}
}
export default FindLocationMarker;
经过下面的长时间讨论,我决定更新我对 https://github.com/tomchentw/react-google-maps Marker.jsx 组件未来问题的回答。
如果你想在PositionChange上获取标记的位置,你需要:
- 将标记存储在您的参考文献中
- 监听 onPositionChange 事件,然后访问标记在您的 refs 中的位置。
示例:
onPositionChanged() {
const position = this.marker.getPosition();
// do something with position
}
render() {
return <Marker
onPositionChanged={ ::this.onPositionChanged }
ref={input => this.marker = input}
/>
}