reactjs - 为什么我得到 'Map' 不是从 'react-leaflet' 导出的?

标签 reactjs react-leaflet

为什么我得到:

./src/components/mapComponent/MapView.jsx
Attempted import error: 'Map' is not exported from 'react-leaflet'.
我在组件中导入它:
import React, { Component } from "react";
import { Map, TileLayer } from "react-leaflet";
import "leaflet/dist/leaflet.css";
这让我感到困惑,因为代码中的所有内容看起来都是正确的....

最佳答案

尝试使用 MapContainer component

The MapContainer component is responsible for creating the Leaflet Map instance and providing it to its child components, using a React Context.

When creating a MapContainer element, its props are used as options to create the Map instance.


现在您必须导入 MapContainer。
import { MapContainer, TileLayer, Marker } from 'react-leaflet';

<MapContainer
  className="markercluster-map"
  center={[51.0, 19.0]}
  zoom={4}
  maxZoom={18}
>
  <TileLayer
    url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
    attribution='&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
  />
</MapContainer>

关于reactjs - 为什么我得到 'Map' 不是从 'react-leaflet' 导出的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64839175/

相关文章:

javascript - 可以在基于数组的循环中创建 useState 吗?

javascript - 关于如何在reactjs和react-leaflet中使用leaflet的折线的指针

reactjs - 如何在 React 16.4.1 中使用 leaflet-polylinedecorator

webpack - React-Leaflet 与 Gatsby

leaflet - React-Leaflet-Draw : accessing a polygon's array of coordinates on save

css - 如何在 create-react-app 中自定义 blueprintjs 外观

javascript - ReactJS PreventDefault 当已经传递参数时

reactjs - 过去可以正常工作的Azure应用程序服务zip部署失败(旧版react应用程序)

javascript - 是否有从对象渲染组件的方法? - react

reactjs - 为什么我的 map 上没有全屏图标?