我正在尝试使用leaflet
做出反应..我参考了这个模块
https://github.com/PaulLeCam/react-leaflet
https://www.npmjs.com/package/react-leaflet
但它没有显示地图为什么?
这是我的代码 https://plnkr.co/edit/pTpPxhEFqouMrLTrKUFq?p=preview
//代码在这里
const { Map, TileLayer, Marker, Popup } = ReactLeaflet;
class A extends React.Component{
constructor() {
super();
this.state = {
lat: 51.505,
lng: -0.09,
zoom: 13,
};
}
render(){
return (
const position = [this.state.lat, this.state.lng];
return (
<Map center={position} zoom={this.state.zoom}>
<label>cccc</label>
<TileLayer
attribution='© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
url='http://{s}.tile.osm.org/{z}/{x}/{y}.png'
/>
<Marker position={position}>
<Popup>
<span>A pretty CSS3 popup. <br/> Easily customizable.</span>
</Popup>
</Marker>
</Map>
);
)
}
}
ReactDOM.render(<A/>,document.getElementById('example'));
答案 0 :(得分:1)
render
中有两个返回语句。
render
应该只返回一次组件。
render(){
const position = [this.state.lat, this.state.lng];
return (
<Map center={position} zoom={this.state.zoom}>
<label>cccc</label>
<TileLayer
attribution='© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
url='http://{s}.tile.osm.org/{z}/{x}/{y}.png'
/>
<Marker position={position}>
<Popup>
<span>A pretty CSS3 popup. <br/> Easily customizable.</span>
</Popup>
</Marker>
</Map>
);
}
多件物品:
{this.state.items.map(item => (
<Marker position={[item.lat, item.lng]}>
<Popup>
<span>A pretty CSS3 popup. <br/> Easily customizable.</span>
</Popup>
</Marker
)}