我正在尝试创建一个模式内的地图。但是地图只显示了一部分。我在invalidatingSize()
创建节点后尝试过,但它似乎不起作用。
import React from 'react';
import ReactDOM from 'react-dom'
import L from 'leaflet';
class Mapa extends React.Component {
constructor(props){
super(props);
this.state = {
};
}
createMap(element){
var map = L.map(element);
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
return map;
}
setupMap(){
this.map.setView([this.props.lat, this.props.lon], this.props.zoom);
this.map.invalidateSize();
}
componentDidMount(){
let self = this;
if (this.props.createMap) {
this.map = this.props.createMap(ReactDOM.findDOMNode(self));
} else {
this.map = this.createMap(ReactDOM.findDOMNode(self));
}
this.setupMap();
}
render(){
/*Returns div with id map*/
}
}