我想获得当前地图的边界,以便我可以使用Overpass API搜索这些边界.
对于传单我知道方法只是map.getBounds(),但我不知道如何在react-leaflet中实现它.
class SimpleExample extends React.Component {
constructor() {
super();
this.state = {
lat: 51.505,
lng: -0.09,
zoom: 13,
};
}
componentDidMount() {
console.log(this.refs.map.getBounds())
}
render() {
const position = [this.state.lat, this.state.lng];
return (
<Map center={position} zoom={this.state.zoom} ref='map'>
<TileLayer
attribution='© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
url='http://{s}.tile.osm.org/{z}/{x}/{y}.png'
/>
</Map>
);
}
}
Run Code Online (Sandbox Code Playgroud)
这就是我尝试过的.错误说这this.refs.map.getBounds不是一个功能.