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 8 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
13 changes: 13 additions & 0 deletions src/scripts/actions/show-markers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export const SHOW_MARKERS = 'SHOW_MARKERS';

export interface ShowMarkersAction {
type: typeof SHOW_MARKERS;
showMarkers: boolean;
}

const showMarkersAction = (showMarkers: boolean): ShowMarkersAction => ({
type: SHOW_MARKERS,
showMarkers
});

export default showMarkersAction;
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
19 changes: 18 additions & 1 deletion src/scripts/components/app/app.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {FunctionComponent} from 'react';
import {Provider as StoreProvider, useSelector} from 'react-redux';
import {Provider as StoreProvider, useSelector, useDispatch} from 'react-redux';
import {IntlProvider} from 'react-intl';
import {HashRouter as Router, Switch, Route, Redirect} from 'react-router-dom';

Expand All @@ -24,6 +24,9 @@ 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';
import showMarkersAction from '../../actions/show-markers';

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

const TranslatedApp: FunctionComponent = () => {
const language = useSelector(languageSelector);
const dispatch = useDispatch();

const selectedStory = useSelector(StoriesStateSelector);
const selectedLayers = useSelector(selectedLayerIdsSelector);
console.log(selectedLayers);
KatvonRivia marked this conversation as resolved.
Show resolved Hide resolved

if (
(!selectedLayers.mainId && !selectedLayers.compareId) ||
KatvonRivia marked this conversation as resolved.
Show resolved Hide resolved
!selectedStory.selected
) {
dispatch(showMarkersAction(true));
} else {
dispatch(showMarkersAction(false));
}

return (
<Router>
Expand Down
6 changes: 6 additions & 0 deletions src/scripts/components/globe/globe.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, {FunctionComponent, useRef, useEffect, useState} from 'react';
import {useSelector} from 'react-redux';
import 'cesium/Build/Cesium/Widgets/widgets.css';
import {
Viewer,
Expand All @@ -21,6 +22,8 @@ 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 {storyListSelector} from '../../selectors/story/list';

import {GlobeProjectionState} from '../../types/globe-projection-state';
import {BasemapId} from '../../types/basemap';
Expand Down Expand Up @@ -86,6 +89,7 @@ const Globe: FunctionComponent<Props> = ({
}) => {
const [viewer, setViewer] = useState<Viewer | null>(null);
const ref = useRef<HTMLDivElement>(null);
const stories = useSelector(storyListSelector);

// make latest "active" value always accessible in camera change handler
const isActiveRef = useRef<boolean>(active);
Expand Down Expand Up @@ -295,6 +299,8 @@ const Globe: FunctionComponent<Props> = ({
flyToGlobeView(viewer, flyTo);
}, [viewer, flyTo]);

useMarkers(viewer, stories);
KatvonRivia marked this conversation as resolved.
Show resolved Hide resolved

return (
<div
className={styles.globe}
Expand Down
2 changes: 2 additions & 0 deletions src/scripts/components/layer-selector/layer-selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {State} from '../../reducers';
import setFlyToAction from '../../actions/set-fly-to';

import styles from './layer-selector.styl';
import showMarkersAction from '../../actions/show-markers';

const LayerSelector: FunctionComponent = () => {
const dispatch = useDispatch();
Expand Down Expand Up @@ -73,6 +74,7 @@ const LayerSelector: FunctionComponent = () => {
icon={CloseIcon}
onClick={() => {
dispatch(showLayerSelectorAction(false));
dispatch(showMarkersAction(true));
}}
/>
</div>
Expand Down
8 changes: 6 additions & 2 deletions src/scripts/components/navigation/navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import {StoryIcon} from '../icons/story-icon';
import showLayerSelectorAction from '../../actions/show-layer-selector';
import Share from '../share/share';
import {MenuIcon} from '../icons/menu-icon';
import showMarkersAction from '../../actions/show-markers';

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 All @@ -27,7 +28,10 @@ const Navigation: FunctionComponent = () => {
<Button
className={styles.button}
label="layers"
onClick={() => dispatch(showLayerSelectorAction(true))}
onClick={() => {
dispatch(showLayerSelectorAction(true));
dispatch(showMarkersAction(false));
}}
icon={LayersIcon}
/>
<Share />
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;
}
59 changes: 59 additions & 0 deletions src/scripts/hooks/use-markers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import {useEffect} from 'react';
import {useSelector, useDispatch} from 'react-redux';
import {useHistory} from 'react-router-dom';
import {
Viewer,
ScreenSpaceEventHandler,
defined,
ScreenSpaceEventType
} from 'cesium';

import {createMarker} from '../libs/create-markers';
import {showMarkersSelector} from '../selectors/show-markers';
import showMarkersAction from '../actions/show-markers';

import {StoryList} from '../types/story-list';

export const useMarkers = (viewer: Viewer | null, stories: StoryList) => {
const showMarkers = useSelector(showMarkersSelector);
const history = useHistory();
const dispatch = useDispatch();

// create marker for each story
useEffect(() => {
if (!viewer) {
return;
}

viewer.entities.removeAll();

const scene = viewer.scene;
const handler = new ScreenSpaceEventHandler(
scene.canvas as HTMLCanvasElement
);

handler.setInputAction(movement => {
const pickedObject = scene.pick(movement.position);
if (defined(pickedObject)) {
dispatch(showMarkersAction(false));
history.push(`/stories/${pickedObject.id._id}/0`);
}
}, ScreenSpaceEventType.LEFT_CLICK);

const markers = showMarkers
? stories.map(story => createMarker(story))
: [];

Promise.all(markers)
KatvonRivia marked this conversation as resolved.
Show resolved Hide resolved
// eslint-disable-next-line @typescript-eslint/no-explicit-any
.then((entities: Array<any>) => {
entities.forEach(entity => viewer.entities.add(entity));
})
.catch(error => console.error(error));

// eslint-disable-next-line consistent-return
return () => handler.destroy();
}, [showMarkers, dispatch, history, stories, viewer]);

return;
};
Loading