为什么React说明书中不显示Map?
import { MapContainer, Marker, TileLayer, Popup } from "react-leaflet";
import "leaflet/dist/leaflet.css";
<div style={{ width: "100%", height: "100vh" }}>
<MapContainer center={[51.505, -0.09]} zoom={13} scrollWheelZoom={false}>
<TileLayer
attribution='© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
/>
<Marker position={[51.505, -0.09]}>
<Popup>
A pretty CSS3 popup. <br /> Easily customizable.
</Popup>
</Marker>
</MapContainer>
</div>
export default App;
1条答案
按热度按时间hi3rlvi21#
您错过了向
MapContainer
添加样式表,现在它的高度为0。您应该向MapContainer
添加样式style={{ width: "100%", height: "100vh" }}
,请看下面的代码:现场演示:https://codesandbox.io/s/throbbing-cherry-s5mb4p?file=/src/App.js:0-735