简体   繁体   English

如何在铯resium反应组件上加载kml文件

[英]How to load kml file on cesium resium react components

I need to load a kml file on react component using resium-cesium.我需要使用 resium-cesium 在反应组件上加载一个 kml 文件。 I have followed the exact procedure as shown in the official resium page as follows.我已按照官方 reium 页面中所示的确切程序进行操作,如下所示。

https://resium.darwineducation.com/getting_started#loading-your-own-data https://resium.darwineducation.com/getting_started#loading-your-own-data

I tried to load sample kml file from official github page of cesium.我试图从铯的官方 github 页面加载示例 kml 文件。 https://github.com/CesiumGS/cesium/tree/master/Apps/SampleData I have downloaded this sampleData folder and put under the src folder of react project. https://github.com/CesiumGS/cesium/tree/master/Apps/SampleData我已经下载了这个 sampleData 文件夹并放在 react 项目的 src 文件夹下。 Then tried to load as follows.然后尝试如下加载。

import React from "react";
import { Viewer, KmlDataSource, GeoJsonDataSource } from "resium";

const data = {
  type: 'Feature',
  properties: {
    name: 'Coors Field',
    amenity: 'Baseball Stadium',
    popupContent: 'This is where the Rockies play!'
  },
  geometry: {
    type: 'Point',
    coordinates: [-104.99404, 39.75621]
  }
};

const App = () => (

  <Viewer full>
    <KmlDataSource data={"src/SampleData/kml/facilities/facilities.kml"} />
    <GeoJsonDataSource data={data} />
  </Viewer>

);

export default hot(App);

I should receive a similar result of this.我应该收到类似的结果。 https://sandcastle.cesium.com/index.html?src=KML.html But I did not receive. https://sandcastle.cesium.com/index.html?src=KML.html但我没有收到。 In my code GeoJsonDataSource work perfectly.在我的代码中 GeoJsonDataSource 工作得很好。 but KmlDataSource have problem.但 KmlDataSource 有问题。 In my log console, I noticed this warnings.在我的日志控制台中,我注意到了这个警告。

在此处输入图像描述

My final output like this.我的最终 output 就是这样。 please help me to load kml file perfectly.请帮我完美加载kml文件。 Thank you for all.感谢你所做的一切。

在此处输入图像描述

You should place your KML file under the public folder like this.您应该像这样将 KML 文件放在公共文件夹下。

在此处输入图像描述

// App.js
import React from "react";
import { Viewer, KmlDataSource, GeoJsonDataSource } from "resium";

const data = {
    type: 'Feature',
    properties: {
        name: 'Coors Field',
        amenity: 'Baseball Stadium',
        popupContent: 'This is where the Rockies play!'
    },
    geometry: {
        type: 'Point',
        coordinates: [-104.99404, 39.75621]
    }
};

const App = () => (
    <Viewer full>
        <KmlDataSource data={"./kml/facilities/facilities.kml"} />
        <GeoJsonDataSource data={data} />
    </Viewer>
);

export default App;

Finally, I see this.最后,我看到了这一点。
在此处输入图像描述

Source code here源代码在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM