将GeoJSON文件导入React-Leaflet

问题描述 投票:1回答:1

我正在尝试导入GeoJSON文件以进行如下所示的react-leaflet:

import * as bar from "./data/bar.geojson";

...

function Foo() {
  return (
    <Map center={[...]} zoom={...}>
      <TileLayer
        ...
      />
      <GeoJSON data={bar} />
    </Map>
  );
}

export default Foo;

我收到“错误:无效的GeoJSON对象。”用于调用<GeoJSON data={bar} />。我将相同的GeoJSON数据硬编码到此javascript文件中,并且它可以正常工作,因此它必须是导入或处理引起问题的GeoJSON文件的方式。

有人知道我为什么出错吗?预先感谢!

json reactjs leaflet geojson react-leaflet
1个回答
0
投票

您可以这样导入geojson文件:

    import bar from "./data/bar.geojson";
© www.soinside.com 2019 - 2024. All rights reserved.