Resium教程1:Resium is library of React components for Cesium

Resium
Resium is library of React components for 🌍Cesium
Resium 前端框架react封装cesium的库。
You can import all resium components as following.

import { Viewer } from “resium”;
The simplest resium application
The simplest resium application is as following.

Just as Cesium’s root object is Viewer, is also a root component in resium.

app.js:

import React from “react”;
import { Viewer } from “resium”;
const App = () => ;
export default App;
index.js:

import React from “react”;
import ReactDOM from “react-dom”;
import App from “./app”;
ReactDOM.render(, document.getElementById(“wrapper”));
This is almost equivalent to:

const viewer = new Cesium.Viewer(“wrapper”);
But the viewer is displayed small because it does not have its own size.

The easiest solution is using full prop. It makes the viewer displayed on the full screen.

This is equivalent to:

<Viewer
style={{
position: “absolute”,
top: 0,
left: 0,
right: 0,
bottom: 0,
}}
/>
If you want to customize the container styles, you can use style and className prop. They are applied to div element rendered by a Viewer component.

It means that CSS-in-JS libraries (styled-components, emotion…) are available on a Viewer component.

Hereafter, we omit the code such as HMR in example code.

Displaying an entity
Next, let’s display an entity on Cesium. Entity component is available in resium.

Entity has many way to visualize geograohical data. Here let’s try to use PointGraphics.

import React from “react”;
import { Viewer, Entity } from “resium”;
import { Cartesian3 } from “cesium”;
const position = Cartesian3.fromDegrees(-74.0707383, 40.7117244, 100);
const pointGraphics = { pixelSize: 10 };
const App = () => (



);
This is equivalent to:

const viewer = new Cesium.Viewer(“wrapper”);
const entity = new Cesium.Entity({
position: Cartesian3.fromDegrees(-74.0707383, 40.7117244, 100),
point: { pixelSize: 10 },
});
viewer.entities.add(entity);
If HMR is enabled, it fully works in resium, so entity is updated without reloading the page when the source code is changed!

The following is also the same. It uses PointGraphics component. This enables updating graphic properties with minimal cost.

import React from “react”;
import { Viewer, Entity, PointGraphics } from “resium”;
import { Cartesian3 } from “cesium”;
const position = Cartesian3.fromDegrees(-74.0707383, 40.7117244, 100);
const App = () => (





);
Displaying description of an entity
The following example is displaying a simple name and description of the entity.

import React from “react”;
import { Viewer, Entity, PointGraphics } from “resium”;
import { Cartesian3 } from “cesium”;
const position = Cartesian3.fromDegrees(-74.0707383, 40.7117244, 100);
const App = () => (





);
If you want to render rich description, EntityDescription component is the best. It enables using JSX in the description of entities!

import React from “react”;
import { Viewer, Entity, PointGraphics, EntityDescription } from “resium”;
import { Cartesian3 } from “cesium”;
const position = Cartesian3.fromDegrees(-74.0707383, 40.7117244, 100);
const App = () => (




Hello, world.


JSX is available here!





);
Adding Cesium world terrain
terrainProvider prop of Viewer is available.

import React from “react”;
import { Viewer, Entity, PointGraphics, EntityDescription } from “resium”;
import { Cartesian3, createWorldTerrain } from “cesium”;
const terrainProvider = createWorldTerrain();
const position = Cartesian3.fromDegrees(-74.0707383, 40.7117244, 100);
const App = () => (




Hello, world.


JSX is available here!





);
Loading your own data
Cesium and resium support KML, GeoJSON, TopoJSON, and CZML. Let’s load and display your own data!

import React from “react”;
import { Viewer, GeoJsonDataSource, KmlDataSource } 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 = () => (

<GeoJsonDataSource data={“your_geo_json.geojson”} />
<KmlDataSource data={“your_geo_json.kml”} />


);
3D tile is also available.

import React from “react”;
import { Viewer, Cesium3DTileset } from “resium”;
import { IonResource } from “cesium”;
const App = () => {
let viewer; // This will be raw Cesium’s Viewer object.
const handleReady = tileset => {
if (viewer) {
viewer.zoomTo(tileset);
}
};
return (
<Viewer
full
ref={e => {
viewer = e && e.cesiumElement;
}}>


);
};
What’s next?
Guide
Components: see menu
Examples
Cesium Documentation

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

李树林gis

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值