我正在尝试在传单地图上实现绘图功能。我创建了一个仅安装了 react-leaflet 的新应用程序,使用 npx create-react-app 并安装了以下软件包:
- npm install react react-dom 传单
- npm 安装反应传单
至此,我已经启动了应用程序,一切正常:地图已正确显示,中间有一个标记。
然后我添加了 react-leaflet-draw 包,使用 npm install react-leaflet-draw,并在页面中导入它,我收到以下错误:
./node_modules/react-leaflet-draw/dist/esm/EditControl.js
Attempted import error: 'MapControl' is not exported from 'react-leaflet'
这是完整的代码:
import './App.css';
import 'leaflet/dist/leaflet.css';
import { MapContainer, TileLayer, Marker, Popup, MapControl } from 'react-leaflet'
import L from 'leaflet';
import icon from 'leaflet/dist/images/marker-icon.png';
import iconShadow from 'leaflet/dist/images/marker-shadow.png';
import iconRetina from 'leaflet/dist/images/marker-icon-2x.png';
import 'leaflet-draw/dist/leaflet.draw.css';
import { EditControl } from "react-leaflet-draw";
delete L.Icon.Default.prototype._getIconUrl;
L.Icon.Default.mergeOptions({
iconRetinaUrl: iconRetina,
iconUrl: icon,
shadowUrl: iconShadow
})
function App() {
return (
<MapContainer center={[51.505, -0.09]} zoom={10} scrollWheelZoom={true}>
<TileLayer
attribution='© <a href="http://osm.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>
);
}
export default App;
这个包有什么问题?它对反应有效吗?