我正在使用 React Leaflet 创建自定义地图。
当前正在渲染卡片(图像叠加),但它不会填充放置卡片的容器。
容器的大小是严格设置的,我希望地图尽可能填充容器。所有使用 CSS 调整大小的尝试都失败了。
实例: https: //codesandbox.io/s/dark-worker-8qbzfr
我的代码:
import "./styles.css";
import { MapContainer, ImageOverlay } from "react-leaflet";
import "leaflet/dist/leaflet.css";
const M = ({ width, height, zoom, center }) => {
const wh = [width, 500];
const origin = [0, 0];
const bounds = [origin, wh];
return (
<div style={{ width: "1100px", height: "600px" }}>
<MapContainer
style={{ height: "100%", minHeight: "100%" }}
bounds={zoom ? undefined : bounds}
boundsOptions={{
padding: [0, 0]
}}
maxBounds={bounds}
zoom={center ? zoom : …Run Code Online (Sandbox Code Playgroud)