简体   繁体   中英

How to load kml file on cesium resium react components

I need to load a kml file on react component using resium-cesium. I have followed the exact procedure as shown in the official resium page as follows.

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

I tried to load sample kml file from official github page of cesium. https://github.com/CesiumGS/cesium/tree/master/Apps/SampleData I have downloaded this sampleData folder and put under the src folder of react project. 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. In my code GeoJsonDataSource work perfectly. but KmlDataSource have problem. In my log console, I noticed this warnings.

在此处输入图像描述

My final output like this. please help me to load kml file perfectly. Thank you for all.

在此处输入图像描述

You should place your KML file under the public folder like this.

在此处输入图像描述

// 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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