Skip to content
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

Merged
merged 14 commits into from
Aug 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah I see 👍

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