Skip to content

Commit

Permalink
Implement logic to move the logo on button click
Browse files Browse the repository at this point in the history
  • Loading branch information
markerikson committed Mar 7, 2017
1 parent 81d8d50 commit 145e67e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
17 changes: 16 additions & 1 deletion src/App.js
Expand Up @@ -5,7 +5,16 @@ import CesiumGlobe from "./cesium/CesiumGlobe";


class App extends Component {
state = {logoCoords : null}

onMoveLogoClicked = () => {
const logoCoords = {lat : 39.097465, lon : -84.50703};
this.setState({logoCoords});
}

render() {
const {logoCoords} = this.state;

const containerStyle = {
width: '100%',
height: '100%',
Expand All @@ -18,11 +27,17 @@ class App extends Component {

return (
<div style={containerStyle}>
<CesiumGlobe/>
<CesiumGlobe logoCoords={logoCoords} />
<div style={{position : "fixed", top : 0}}>
<div style={{color : "white", fontSize: 40, }}>
Text Over the Globe
</div>
<button
onClick={this.onMoveLogoClicked}
style={{fontSize: 40}}
>
Move Logo
</button>
</div>

</div>
Expand Down
18 changes: 18 additions & 0 deletions src/cesium/CesiumBillboardExample.jsx
Expand Up @@ -42,6 +42,24 @@ export default class CesiumBillboardExample extends Component {
});
}

componentDidUpdate(prevProps) {
if(prevProps.logoCoords !== this.props.logoCoords && this.props.logoCoords) {
this.updateIcon();
}
}

updateIcon() {
const {logoCoords} = this.props;
const {lat, lon} = logoCoords;

if(this.billboard) {
const newPosition = Cartesian3.fromDegrees(lon, lat);

this.billboard.position = newPosition;
}
}


render() {
return null;
}
Expand Down
3 changes: 2 additions & 1 deletion src/cesium/CesiumGlobe.jsx
Expand Up @@ -58,10 +58,11 @@ export default class CesiumGlobe extends Component {

if(viewerLoaded) {
const {scene} = this.viewer;
const {logoCoords} = this.props;

contents = (
<span>
<CesiumBillboardExample scene={scene} />
<CesiumBillboardExample scene={scene} logoCoords={logoCoords} />
</span>
);
}
Expand Down

0 comments on commit 145e67e

Please sign in to comment.