Skip to content

Commit

Permalink
feat(welcomeScreen): add custom story markers to globe (#448)
Browse files Browse the repository at this point in the history
* feat(welcomeScreen): add story markers to globe

* feat(welcomeScreen): add custom billboard entities

* feat(welcomeScreen): remove comment

* fix(layer-selector): change animation type back to lower case

* feat(fonts): add NotesEsa font to markers

* feat(markers): hide markers in layer selection

* refactor(welcomeScreen): remove showMarker from store and pass markers to globe directly

* refactor(welcomeScreen): add custom hook for story markers

* refactor(welcomeScreen): change return
  • Loading branch information
KatvonRivia authored Aug 13, 2020
1 parent af06cd3 commit ea297f4
Show file tree
Hide file tree
Showing 13 changed files with 329 additions and 7 deletions.
5 changes: 5 additions & 0 deletions src/scripts/components/app/app.styl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
font-family: NotesEsa
src: url('../../../../assets/fonts/NotesEsaReg.otf')

@font-face
font-style: normal
font-family: NotesEsaBold
src: url('../../../../assets/fonts/NotesEsaBol.otf')

:global(html), :global(body), :global(#app)
overflow: hidden
margin: 0
Expand Down
4 changes: 3 additions & 1 deletion src/scripts/components/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import Globes from '../globes/globes';
import translations from '../../i18n';

import styles from './app.styl';
import {useStoryMarkers} from '../../hooks/use-story-markers';

// create redux store
const store = createReduxStore();
Expand All @@ -36,6 +37,7 @@ const App: FunctionComponent = () => (

const TranslatedApp: FunctionComponent = () => {
const language = useSelector(languageSelector);
const markers = useStoryMarkers();

return (
<Router>
Expand All @@ -58,7 +60,7 @@ const TranslatedApp: FunctionComponent = () => {
<div className={styles.logo}>
<EsaLogo />
</div>
<Globes />
<Globes markers={markers} />
<Navigation />
<GlobeNavigation />
<TimeSlider />
Expand Down
6 changes: 6 additions & 0 deletions src/scripts/components/globe/globe.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ import {isElectron} from '../../libs/electron/index';
import {GlobeView} from '../../types/globe-view';
import {GlobeProjection} from '../../types/globe-projection';
import config from '../../config/main';
import {useMarkers} from '../../hooks/use-markers';

import {GlobeProjectionState} from '../../types/globe-projection-state';
import {BasemapId} from '../../types/basemap';
import {Marker} from '../../types/marker-type';

import styles from './globe.styl';

Expand Down Expand Up @@ -52,6 +54,7 @@ interface Props {
basemap: BasemapId | null;
zoomLevels: number;
flyTo: GlobeView | null;
markers?: Marker[];
onMouseEnter: () => void;
onTouchStart: () => void;
onChange: (view: GlobeView) => void;
Expand Down Expand Up @@ -79,6 +82,7 @@ const Globe: FunctionComponent<Props> = ({
zoomLevels,
active,
flyTo,
markers = [],
onMouseEnter,
onTouchStart,
onChange,
Expand Down Expand Up @@ -295,6 +299,8 @@ const Globe: FunctionComponent<Props> = ({
flyToGlobeView(viewer, flyTo);
}, [viewer, flyTo]);

useMarkers(viewer, markers);

return (
<div
className={styles.globe}
Expand Down
8 changes: 7 additions & 1 deletion src/scripts/components/globes/globes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@ import {selectedLayerIdsSelector} from '../../selectors/layers/selected-ids';
import {GlobeView} from '../../types/globe-view';

import styles from './globes.styl';
import {Marker} from '../../types/marker-type';

const Globes: FunctionComponent = () => {
interface Props {
markers?: Marker[];
}

const Globes: FunctionComponent<Props> = ({markers = []}) => {
const dispatch = useDispatch();
const selectedLayerIds = useSelector(selectedLayerIdsSelector);
const projectionState = useSelector(projectionSelector);
Expand Down Expand Up @@ -84,6 +89,7 @@ const Globes: FunctionComponent = () => {
/>
)}
<Globe
markers={markers}
active={isMainActive}
view={currentView}
projectionState={projectionState}
Expand Down
4 changes: 1 addition & 3 deletions src/scripts/components/layer-selector/layer-selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ const LayerSelector: FunctionComponent = () => {
<Button
className={styles.button}
icon={CloseIcon}
onClick={() => {
dispatch(showLayerSelectorAction(false));
}}
onClick={() => dispatch(showLayerSelectorAction(false))}
/>
</div>
{selectedMainLayer && (
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/components/navigation/navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import {MenuIcon} from '../icons/menu-icon';
import styles from './navigation.styl';

const Navigation: FunctionComponent = () => {
const [showMenu, setShowMenu] = useState(false);
const dispatch = useDispatch();
const [showMenu, setShowMenu] = useState(false);

return (
<div className={styles.navigation}>
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/components/splash-screen/splash-screen.styl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
text-transform: uppercase
font-weight: bold
font-size: emCalc(36px)
font-family: NotesEsa
font-family: NotesEsaBold
line-height: emCalc(16px)

p
Expand Down
10 changes: 10 additions & 0 deletions src/scripts/custom.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,13 @@ declare module '*.styl' {
const content: any;
export default content;
}

declare module '*.svg' {
const content: string;
export default content;
}

declare module '*.otf' {
const content: string;
export default content;
}
47 changes: 47 additions & 0 deletions src/scripts/hooks/use-markers.ts
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;
};
24 changes: 24 additions & 0 deletions src/scripts/hooks/use-story-markers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {useSelector} from 'react-redux';

import {selectedLayerIdsSelector} from '../selectors/layers/selected-ids';
import {StoriesStateSelector} from '../selectors/story/story-state';

export const useStoryMarkers = () => {
const selectedLayers = useSelector(selectedLayerIdsSelector);
const stories = useSelector(StoriesStateSelector).list;
const hideMarkers = Boolean(
selectedLayers.mainId || selectedLayers.compareId
);

if (hideMarkers) {
return [];
}

const storyMarkers = stories.map(story => ({
id: story.id,
title: story.title,
position: story.position
}));

return storyMarkers;
};
Loading

0 comments on commit ea297f4

Please sign in to comment.