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(story): set default view for globe #198

Merged
merged 6 commits into from
Nov 15, 2019
Merged
Show file tree
Hide file tree
Changes from 5 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
34 changes: 18 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 0 additions & 18 deletions src/scripts/actions/set-selected-layer-ids.ts

This file was deleted.

8 changes: 3 additions & 5 deletions src/scripts/components/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const TranslatedApp: FunctionComponent = () => {
<div className={styles.app}>
<div className={styles.layout}>
<Switch>
<Route path="/" exact>
<Route path="(/|/layers)/:mainLayerId?/:compareLayerId?">
<TimeSlider />
<StoriesButton />
<div className={styles.nav}>
Expand All @@ -54,6 +54,7 @@ const TranslatedApp: FunctionComponent = () => {
<ProjectionMenu />
<LayerSelector />
</div>
<LayerLoader />
</Route>

<Route path="/present">
Expand All @@ -70,13 +71,12 @@ const TranslatedApp: FunctionComponent = () => {

<Route
path="/stories/:storyId"
exact
render={props => (
<Redirect to={`${props.match.url}/0`} />
)}></Route>
<Redirect to="/" />
</Switch>
</div>

<div className={styles.story}>
<Globes />
<Route path="/stories/:storyId/:page">
Expand All @@ -85,9 +85,7 @@ const TranslatedApp: FunctionComponent = () => {
</div>
</div>
</IntlProvider>

<UrlSync />
<LayerLoader />
<Init />
</Router>
);
Expand Down
28 changes: 11 additions & 17 deletions src/scripts/components/data-set-info/data-set-info.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,24 @@
import React, {FunctionComponent} from 'react';
import {useSelector} from 'react-redux';

import {selectedLayersSelector} from '../../selectors/layers/selected';
import RemoveCompare from '../remove-compare/remove-compare';
import InfoButton from '../info-button/info-button';

import styles from './data-set-info.styl';
import {LayerListItem} from '../../types/layer-list';

interface Props {
isMain?: boolean;
layer: LayerListItem | null;
}

const DataSetInfo: FunctionComponent<Props> = ({isMain}) => {
const {main, compare} = useSelector(selectedLayersSelector);
const layer = isMain ? main : compare;

return (
<div className={styles.dataSetInfo}>
<h1 className={styles.title}>{layer && layer.name}</h1>
<h2 className={styles.description}>{layer && layer.description}</h2>
<div className={styles.buttons}>
<InfoButton layer={layer} />
{!isMain && <RemoveCompare />}
</div>
const DataSetInfo: FunctionComponent<Props> = ({layer, isMain}) => (
<div className={styles.dataSetInfo}>
<h1 className={styles.title}>{layer && layer.name}</h1>
<h2 className={styles.description}>{layer && layer.description}</h2>
<div className={styles.buttons}>
<InfoButton layer={layer} />
{!isMain && <RemoveCompare />}
</div>
);
};
</div>
);

export default DataSetInfo;
6 changes: 5 additions & 1 deletion src/scripts/components/globe/globe.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {GlobeProjection} from '../../types/globe-projection';
import 'cesium/Source/Widgets/widgets.css';
import 'cesium/Build/Cesium/Cesium';

import {LayerListItem} from '../../types/layer-list';

import styles from './globe.styl';

const Cesium = window.Cesium;
Expand Down Expand Up @@ -44,6 +46,7 @@ const cesiumOptions = {

interface Props {
active: boolean;
layer: LayerListItem | null;
isMain?: boolean;
view: GlobeView;
projection: GlobeProjection;
Expand All @@ -59,6 +62,7 @@ const Globe: FunctionComponent<Props> = ({
projection,
imageUrl,
active,
layer,
isMain,
flyTo,
onMouseEnter,
Expand Down Expand Up @@ -177,7 +181,7 @@ const Globe: FunctionComponent<Props> = ({

return (
<div className={styles.globe} onMouseEnter={() => onMouseEnter()} ref={ref}>
<DataSetInfo isMain={isMain} />
<DataSetInfo layer={layer} isMain={isMain} />
</div>
);
};
Expand Down
25 changes: 19 additions & 6 deletions src/scripts/components/globes/globes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import React, {
useCallback
} from 'react';
import {useSelector, useDispatch} from 'react-redux';
import {matchPath, useLocation} from 'react-router';

import {selectedLayerIdsSelector} from '../../selectors/layers/selected-ids';
import {activeLayersSelector} from '../../selectors/layers/active';
import {globeViewSelector} from '../../selectors/globe/view';
import {timeSelector} from '../../selectors/globe/time';
Expand All @@ -15,20 +15,31 @@ import setGlobeViewAction from '../../actions/set-globe-view';
import Globe from '../globe/globe';
import {getLayerTileUrl} from '../../libs/get-layer-tile-url';
import {flyToSelector} from '../../selectors/fly-to';
import {State} from '../../reducers';

import {GlobeView} from '../../types/globe-view';

import styles from './globes.styl';
import {selectedLayersSelector} from '../../selectors/layers/selected';

const Globes: FunctionComponent = () => {
const location = useLocation();
const match = matchPath(location.pathname, {
path: '(/|/layers)/:mainLayerId?/:compareLayerId?',
exact: true
});
const dispatch = useDispatch();
const projection = useSelector(projectionSelector);
const globalGlobeView = useSelector(globeViewSelector);
const activeLayers = useSelector(activeLayersSelector);
const {mainLayerDetails, compareLayerDetails} = useSelector((state: State) =>
activeLayersSelector(state, match && match.params)
);
const {main, compare} = useSelector((state: State) =>
selectedLayersSelector(state, match && match.params)
);
const time = useSelector(timeSelector);
const [currentView, setCurrentView] = useState(globalGlobeView);
const [isMainActive, setIsMainActive] = useState(true);
const selectedLayerIds = useSelector(selectedLayerIdsSelector);
const flyTo = useSelector(flyToSelector);
const onChangeHandler = useCallback(
(view: GlobeView) => setCurrentView(view),
Expand All @@ -39,8 +50,8 @@ const Globes: FunctionComponent = () => {
[dispatch]
);

const mainImageUrl = getLayerTileUrl(activeLayers.main, time);
const compareImageUrl = getLayerTileUrl(activeLayers.compare, time);
const mainImageUrl = getLayerTileUrl(mainLayerDetails, time);
const compareImageUrl = getLayerTileUrl(compareLayerDetails, time);

// apply changes in the app state view to our local view copy
// we don't use the app state view all the time to keep store updates low
Expand All @@ -51,6 +62,7 @@ const Globes: FunctionComponent = () => {
return (
<div className={styles.globes}>
<Globe
layer={main}
active={isMainActive}
isMain
view={currentView}
Expand All @@ -62,8 +74,9 @@ const Globes: FunctionComponent = () => {
onMoveEnd={onMoveEndHandler}
/>

{selectedLayerIds.compare && (
{compare && (
<Globe
layer={compare}
active={!isMainActive}
view={currentView}
projection={projection}
Expand Down
3 changes: 2 additions & 1 deletion src/scripts/components/info-button/info-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import {useIntl} from 'react-intl';

import {InfoIcon} from '../icons/info-icon';

import styles from './info-button.styl';
import {LayerListItem} from '../../types/layer-list';

import styles from './info-button.styl';

interface Props {
layer: LayerListItem | null;
}
Expand Down
Loading