Skip to content

Commit

Permalink
feat(cesium): add first cesium globe (#80)
Browse files Browse the repository at this point in the history
* feat(cesium): add first cesium steps

* feat(cesium): use pre-build cesium

* feat(cesium): copy assets

* feat(cesium): load in component
  • Loading branch information
pwambach authored Oct 1, 2019
1 parent 13a7199 commit 5f91047
Show file tree
Hide file tree
Showing 8 changed files with 270 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
indent_style = space
indent_size = 2
insert_final_newline = true
172 changes: 172 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"homepage": "https://github.com/ubilabs/esa-climate-from-space#readme",
"dependencies": {
"@types/redux-logger": "^3.0.7",
"cesium": "^1.61.0",
"react": "^16.9.0",
"react-dom": "^16.9.0",
"react-redux": "^7.1.1",
Expand All @@ -30,16 +31,19 @@
"redux-thunk": "^2.3.0"
},
"devDependencies": {
"@types/cesium": "^1.59.0",
"@types/react": "^16.9.2",
"@types/react-dom": "^16.9.0",
"@types/react-redux": "^7.1.2",
"@types/redux-thunk": "^2.1.0",
"@typescript-eslint/eslint-plugin": "^2.3.0",
"@typescript-eslint/parser": "^2.3.0",
"copy-webpack-plugin": "^5.0.4",
"css-loader": "^3.2.0",
"eslint": "^6.4.0",
"eslint-config-prettier": "^6.3.0",
"eslint-plugin-react": "^7.14.3",
"file-loader": "^4.2.0",
"git-state": "^4.1.0",
"html-webpack-plugin": "^3.2.0",
"mini-css-extract-plugin": "^0.8.0",
Expand Down
8 changes: 6 additions & 2 deletions src/scripts/components/app/app.styl
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
.app
border: 1px solid green
:global(html), :global(body), :global(#app)
margin: 0
height: 100%

.app
height: 100%
7 changes: 5 additions & 2 deletions src/scripts/components/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ import thunk from 'redux-thunk';
import logger from 'redux-logger';
import rootReducer from '../../reducers/index';
import LayerSelector from '../layer-selector/layer-selector';
import Globe from '../globe/globe';

import styles from './app.styl';

const store = createStore(rootReducer, applyMiddleware(thunk, logger));

const App: FunctionComponent<{}> = () => (
<Provider store={store}>
<h1 className={styles.app}>Hello</h1>
<LayerSelector />
<div className={styles.app}>
<Globe />
<LayerSelector />
</div>
</Provider>
);

Expand Down
2 changes: 2 additions & 0 deletions src/scripts/components/globe/globe.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.globe
height: 100%
43 changes: 43 additions & 0 deletions src/scripts/components/globe/globe.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React, {FunctionComponent, useRef, useEffect, useState} from 'react';

import 'cesium/Source/Widgets/widgets.css';
import 'cesium/Build/Cesium/Cesium';

import styles from './globe.styl';

// set global base url
const Cesium = window.Cesium;
Cesium.buildModuleUrl.setBaseUrl('./cesium/');

const viewerOptions = {
homeButton: false,
fullscreenButton: false,
sceneModePicker: false,
infoBox: false,
geocoder: false,
navigationHelpButton: false,
animation: false,
timeline: false,
baseLayerPicker: false
};

const Globe: FunctionComponent<{}> = () => {
const ref = useRef();
const [viewer, setViewer] = useState(null);

useEffect(() => {
if (!ref || !ref.current) {
return;
}

const viewer = new Cesium.Viewer(ref.current, viewerOptions);
return () => {
viewer.destroy();
setViewer(null);
};
}, [ref]);

return <div className={styles.globe} ref={ref} />;
};

export default Globe;
Loading

0 comments on commit 5f91047

Please sign in to comment.