This is a repository for Resium workshop at FOSS4G-NA 2019.
In this workshop, I’ll tell you how to use Resium, and we’ll work on building a Japanese archaic map archive. Resium is a new library, abstracting Cesium functions as React components, and helping to build a rich web 3D GIS web-application faster.
Anyone who have been interested in web front-end, React, or Cesium
To create a Japanese archaic map archive with Resium, Cesium and React.
- Install Git, Node.js (LTS) and your favorite text editor.
- Clone this repository
- Install modules:
npm install
In this step, we try to display an entity in Cesium's viewer.
npm start
import { Cartesian3 } from "cesium";
import { Viewer, Entity } from "resium";
<Viewer full>
<Entity
position={Cartesian3.fromDegrees(61, 130, 100)}
point={{ pixelSize: 10 }} />
</Viewer>
<Viewer full>
<Entity
name="NAME"
description="DESC"
position={Cartesian3.fromDegrees(61, 130, 100)}
point={{ pixelSize: 10 }} />
</Viewer>
import { Cartesian3 } from "cesium";
import { Viewer, Entity, EntityDescription } from "resium";
<Viewer full>
<Entity
name="NAME"
position={Cartesian3.fromDegrees(61, 130, 100)}
point={{ pixelSize: 10 }}>
<EntityDescription>
<h1>Hello world</h1>
<p>test</p>
</EntityDescription>
</Entity>
</Viewer>
You will see how HMR (hot module replacement) works.
import { Color, Cartesian3 } from "cesium";
import { Viewer, Entity, EntityDescription, PointGraphics } from "resium";
<Viewer full>
<Entity
name="NAME"
position={Cartesian3.fromDegrees(61, 130, 100)}>
<PointGraphics pixelSize={100} color={Color.RED} />
<EntityDescription>
<h1>Hello world</h1>
<p>test</p>
</EntityDescription>
</Entity>
</Viewer>
import { BoundingSphere, HeadingPitchRange } from "cesium";
import { Viewer, CameraFlyToBoundingSphere } from "resium";
<Viewer full>
<CameraFlyToBoundingSphere
boundingSphere={new BoundingSphere(Cartesian3.fromDegrees(140, 35.7, 0), 0)}
offset={new HeadingPitchRange(0, CesiumMath.toRadians(-30), 80000)}
duration={3} />
</Viewer>
<Viewer
full
animation={false}
homeButton={false}
timeline={false}
baseLayerPicker={false} />
The first step is done!
import { createOpenStreetMapImageryProvider, createWorldImagery } from "cesium";
import { Viwer, ImageryLayer } from "resium";
const defaultImageryProvider = createWorldImagery();
const imageryProvider = createOpenStreetMapImageryProvider({
url: '//www.finds.jp/ws/tmc/1.0.0/Kanto_Rapid-900913-L/',
ext: "jpg",
zmin: 0,
zmax: 18,
credit: 'CC BY 国立研究開発法人農業環境技術研究所 歴史的農業環境閲覧システム',
});
<Viewer full>
<ImageryLayer imageryProvider={defaultImageryProvider} />
<ImageryLayer imageryProvider={imageryProvider} />
</Viewer>
import { Viewer, KmlDataSource } from "resium";
<Viewer full>
<KmlDataSource
data={process.env.PUBLIC_URL + "/doc.kml"}
onLoad={dataSource => {
// you can modify data source here
dataSource.entities.values.forEach(e => {
e.label = undefined;
});
}} />
</Viewer>
React's ref is used to access a raw object of Cesium.
class App extends React.PureComponent {
viewerRef = React.createRef();
handleSelectedEntityChanged = () => {
if (!this.viewerRef.current || !this.viewerRef.current.cesiumElement) {
return;
}
const viewer = this.viewerRef.current.cesiumElement;
const selectedEntity = viewer.selectedEntity;
if (selectedEntity) {
viewer.camera.flyToBoundingSphere(
new BoundingSphere(selectedEntity.position.getValue(viewer.clock.currentTime), 1000),
{ duration: 1 }
);
}
};
render() {
return (
<Viewer
full
ref={this.viewerRef}
onSelectedEntityChange={this.handleSelectedEntityChanged}>
{/* ... */}
</Viewer>
);
}
};
class App extends React.PureComponent {
state = {
tileAlpha: 100
}
handleTileAlphaChange = e => {
this.setState({ tileAlpha: parseInt(e.currentTarget.value, 10) });
}
render() {
return (
<Viewer full>
<ImageryLayer
imageryProvider={imageryProvider}
alpha={this.state.tileAlpha / 100} />
<input
type="range"
min="0"
max="0"
value={this.state.tileAlpha}
onChange={this.handleTileAlphaChange} />
</Viewer>
)
}
}
Please refer to completed
branch.
Please feel free to open a new issue in GitHub issue.
- Install create-react-app:
npm install -g create-react-app
- Initialize a new project:
create-react-app PROJECT_NAME
- Set up craco-cesium to use Cesium: please follow this guide
- Set up craco-plugin-react-hot-reload to enable HMR: please follow this guide
- Modify
App.js
:
import React from 'react';
import { hot } from 'react-hot-loader';
import { Viewer } from 'resium';
class App extends React.PureComponent {
render() {
return <Viewer full />
}
}
export default hot(module)(App);