如何解决未定义的 React Leaflet“初始化”
我正在尝试通过 react-leaflet 将 openstreet 地图添加到我的 React 应用程序中。我成功地让地图显示并在应用程序上工作,但是,由于错误,我无法在地图上找到标记:
TypeError: Cannot read property 'initialize' of undefined
。
我在我的 react 组件上使用我的地图,如下所示:
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='&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"
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。