0

我正在尝试通过 react-leaflet 将 openstreet 地图添加到我的反应应用程序中。我成功地让地图显示并在应用程序上工作,但是由于以下错误,我无法在地图上找到标记:

TypeError: Cannot read property 'initialize' of undefined.

我在我的反应组件上使用我的地图,如下所示:

import { MapContainer, TileLayer } from 'react-leaflet';

const mapScreen = ({ match, props }) => {

const position = [38, -97];

return (

       <MapContainer
        className='map'
        center={position}
        zoom={3}
        style={{ height: 500, width: '100%' }}>
        <TileLayer attribution='&amp;copy url='https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'/>
          <Marker position={position}></Marker> // generates error when added.
        </MapContainer> 
)}

我在我的index.html文件中添加了 css 样式表和 js 脚本。

这就是我的 package.json 中与 react-leaflet 相关的包的方式:

 "@react-leaflet/core": ">=1.0.0 <1.1.0 || ^1.1.1",
 "react-leaflet": ">=3.1.0 <3.2.0 || ^3.2.1"
4

0 回答 0