-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(welcomeScreen): add custom story markers to globe #448
Changes from 10 commits
374f137
124d711
d0afe95
b3571ba
203e3fe
db40ea0
52041a0
ecb0cd3
5b41f44
a6b1262
e3b0c37
7f02aee
a26eec7
dc16da2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,8 @@ import Globes from '../globes/globes'; | |
import translations from '../../i18n'; | ||
|
||
import styles from './app.styl'; | ||
import {StoriesStateSelector} from '../../selectors/story/story-state'; | ||
import {selectedLayerIdsSelector} from '../../selectors/layers/selected-ids'; | ||
|
||
// create redux store | ||
const store = createReduxStore(); | ||
|
@@ -36,6 +38,19 @@ const App: FunctionComponent = () => ( | |
|
||
const TranslatedApp: FunctionComponent = () => { | ||
const language = useSelector(languageSelector); | ||
const selectedLayers = useSelector(selectedLayerIdsSelector); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we could put this stuff in a custom hook 'const markers = useStoryMarkers()' so that we keep the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also only map over the stories if hideMarkers is false to save some work if we don't show the markers |
||
const stories = useSelector(StoriesStateSelector).list; | ||
const hideMarkers = Boolean( | ||
selectedLayers.mainId || selectedLayers.compareId | ||
); | ||
|
||
const storyMarkers = stories.map(story => ({ | ||
id: story.id, | ||
title: story.title, | ||
position: story.position | ||
})); | ||
|
||
const markers = hideMarkers ? [] : storyMarkers; | ||
|
||
return ( | ||
<Router> | ||
|
@@ -58,7 +73,7 @@ const TranslatedApp: FunctionComponent = () => { | |
<div className={styles.logo}> | ||
<EsaLogo /> | ||
</div> | ||
<Globes /> | ||
<Globes markers={markers} /> | ||
<Navigation /> | ||
<GlobeNavigation /> | ||
<TimeSlider /> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import {useEffect} from 'react'; | ||
import {useDispatch} from 'react-redux'; | ||
import {useHistory} from 'react-router-dom'; | ||
import { | ||
Viewer, | ||
ScreenSpaceEventHandler, | ||
defined, | ||
ScreenSpaceEventType | ||
} from 'cesium'; | ||
|
||
import {createMarker} from '../libs/create-marker'; | ||
|
||
import {Marker} from '../types/marker-type'; | ||
|
||
export const useMarkers = (viewer: Viewer | null, markers: Marker[]) => { | ||
const history = useHistory(); | ||
const dispatch = useDispatch(); | ||
|
||
// create marker for each story | ||
useEffect(() => { | ||
if (!viewer) { | ||
return; | ||
} | ||
|
||
const scene = viewer.scene; | ||
const handler = new ScreenSpaceEventHandler( | ||
scene.canvas as HTMLCanvasElement | ||
); | ||
|
||
handler.setInputAction(movement => { | ||
const pickedObject = scene.pick(movement.position); | ||
if (defined(pickedObject)) { | ||
history.push(`/stories/${pickedObject.id._id}/0`); | ||
} | ||
}, ScreenSpaceEventType.LEFT_CLICK); | ||
|
||
Promise.all(markers.map(marker => createMarker(marker))).then(entities => { | ||
viewer.entities.removeAll(); | ||
entities.forEach(entity => viewer.entities.add(entity)); | ||
}); | ||
|
||
// eslint-disable-next-line consistent-return | ||
return () => handler.destroy(); | ||
}, [dispatch, history, markers, viewer]); | ||
|
||
return; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we still need this here? we only use the bold font in the markers which load the font by themselves, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this the global font import for all components? We use both fonts in other components.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry i mean: you're right we don't use is yet 😄 But we need it at least for the splash screen title. I have used the regular one before, but that's not correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah I see 👍