Interactive interface for browsing global, full-resolution satellite imagery
make tour work with redux changes #1623
Benjamin King7eda6fc085fe
diff --git a/web/js/app.js b/web/js/app.jsindex 8911c29a6..e1a1ee155 100644--- a/web/js/app.js+++ b/web/js/app.js@@ -21,6 +21,7 @@ import { updateLegacyInitComplete } from './modules/migration/actions';// actions// import { screenResize } from './modules/browser/actions';import { calculateResponsiveState } from 'redux-responsive';+import Tour from './containers/tour';// Dependency CSSimport '../../node_modules/bootstrap/dist/css/bootstrap.css';@@ -85,6 +86,7 @@ class App extends React.Component {<div className="wv-content" id="wv-content" data-role="content"><Toolbar /><Sidebar />+ <Tour /><div id="layer-modal" className="layer-modal" /><div id="layer-settings-modal" /><div id="wv-map" className="wv-map" />diff --git a/web/js/combine-ui.js b/web/js/combine-ui.jsindex 681797413..33a072fc3 100644--- a/web/js/combine-ui.js+++ b/web/js/combine-ui.js@@ -16,7 +16,7 @@ import { timelinePan } from './date/timeline-pan';import { timelineInput } from './date/timeline-input';import { timelineCompare } from './date/compare-picks';// Tour-import { tourUi } from './tour/ui';+// import { tourUi } from './tour/ui';import { layersActive } from './layers/active';import { mapui } from './map/ui';import { mapAnimate } from './map/animate';@@ -37,10 +37,10 @@ import naturalEventsUI from './map/natural-events/ui';export function combineUi(models, config, MapMouseEvents, store) {let ui = {};ui.map = mapui(models, config, store);- ui.map.animate = mapAnimate(models, config, ui);+ ui.map.animate = mapAnimate(config, ui, store);if (config.features.tour) {- ui.alert = alertUi(ui, config);- ui.tour = tourUi(models, ui, config);+ // ui.alert = alertUi(ui, config);+ // ui.tour = tourUi(models, ui, config);}ui.activeLayers = layersActive(models, ui, config);// ui.addModal = layersModal(models, ui, config);diff --git a/web/js/components/tour/modal-tour-in-progress.js b/web/js/components/tour/modal-tour-in-progress.jsindex 6e92f2f8d..4672e575d 100644--- a/web/js/components/tour/modal-tour-in-progress.js+++ b/web/js/components/tour/modal-tour-in-progress.js@@ -3,33 +3,11 @@ import PropTypes from 'prop-types';import { Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap';import Steps from './widget-steps';import util from '../../util/util';-import lodashEach from 'lodash/each';-import { getCompareObjects } from '../../compare/util';-import { parse as dateParser } from '../../date/date';-import {- parse as layerParser,- validate as layerValidate-} from '../../layers/layers';-import { mapParser } from '../../map/map';-import { parse as animationParser } from '../../animation/anim';-import palettes from '../../palettes/palettes';-import { dataParser } from '../../map/data/data';-import { parse as projectionParser } from '../../projection/projection';-import googleTagManager from 'googleTagManager';class ModalInProgress extends React.Component {constructor(props) {super(props);- this.state = {- metaLoaded: false,- isLoading: false,- error: null- };- this.fetchMetadata = this.fetchMetadata.bind(this);- this.processLink = this.processLink.bind(this);- this.loadLink = this.loadLink.bind(this);- this.setUI = this.setUI.bind(this);- this.processActions = this.processActions.bind(this);+this.escFunction = this.escFunction.bind(this);}@@ -41,47 +19,6 @@ class ModalInProgress extends React.Component {document.removeEventListener('keydown', this.escFunction, false);}- componentDidUpdate(prevProps) {- var currentStory = this.props.currentStory;- var currentStepIndex = this.props.currentStep - 1;- var modalStarted = this.props.modalInProgress;- var models = this.props.models;- var ui = this.props.ui;-- // When restarting tour, reset the MetaLoaded prop- if (this.props.restartTour) {- this.props.toggleRestartTour();- }-- // Scroll content div to the top when step updates- if (this.refs.stepContent) this.refs.stepContent.parentNode.scrollTop = 0;-- // Fetch meta and load link on first step if not already loaded- if (modalStarted && !this.props.metaLoaded) {- // If the comparison mode is open, close it before starting- if (models.compare.active === true) {- models.compare.toggle();- models.compare.load({});- ui.sidebar.reactComponent.setState({- isCompareMode: false- });- }-- this.props.toggleMetaLoaded();- this.fetchMetadata(currentStory, 0);- this.processLink(currentStory, currentStepIndex);- } else {- if (prevProps.currentStep !== this.props.currentStep) {- let prevStepIndex = prevProps.currentStep - 1;-- // Reset the prevStepIndex when a new tour is selected- if (currentStepIndex === 0 && prevStepIndex !== 1) prevStepIndex = null;- this.fetchMetadata(currentStory, currentStepIndex);- this.processLink(currentStory, currentStepIndex, prevStepIndex);- }- }- }-// Use custom escFunction since tabIndex prevents escape key use on loading WVescFunction(e) {if (e.keyCode === 27 && this.props.modalInProgress) {@@ -89,345 +26,41 @@ class ModalInProgress extends React.Component {}}- fetchMetadata(currentStory, stepIndex) {- var description = currentStory.steps[stepIndex]['description'];- var { origin, pathname } = window.location;- var currentStoryId = this.props.currentStory['id'];- var errorMessage = '<p>There was an error loading this description.</p>';- var uri = `${origin}${pathname}config/metadata/stories/${currentStoryId}/${description}`;-- this.setState({ isLoading: true });- fetch(uri)- .then(res => (res.ok ? res.text() : errorMessage))- .then(body => {- let isMetadataSnippet = !body.match(- /<(head|body|html|style|script)[^>]*>/i- );- let description = isMetadataSnippet ? body : errorMessage;- this.setState({ description: description, isLoading: false });- }- ).catch(error => this.setState({ error, isLoading: false }));- }-- processLink(currentStory, currentStepIndex, prevStepIndex) {- var currentStateParsers, prevStateParsers, requirements, currentState, currentStepLink, stepTransition, prevState, prevStepLink;- var errors = [];- var config = this.props.config;- var models = this.props.models;-- // When the link is loaded, save the tour to URL- models.tour.active = true;- models.tour.select(this.props.currentStoryId);-- // Record selected story's id, current steps, and total steps to analytics- googleTagManager.pushEvent({- 'event': 'tour_selected_story',- 'story': {- 'id': this.props.currentStoryId,- 'selectedStep': this.props.currentStep,- 'totalSteps': this.props.totalSteps- }- });-- // Get current step link + current tour parameter- currentStepLink = currentStory.steps[currentStepIndex]['stepLink'] +- '&tr=' + this.props.currentStoryId;-- // Remove base URL from step links string- currentStepLink = currentStepLink.split('/?').pop();-- // Get previous step link (if there is a previous step)- // Remove base URL from step links string- if (prevStepIndex !== null && !isNaN(prevStepIndex)) {- prevStepLink = currentStory.steps[prevStepIndex]['stepLink'];- prevStepLink = prevStepLink.split('/?').pop();- }-- // Create current and previous states from step links- currentState = util.fromQueryString(currentStepLink);- prevState = util.fromQueryString(prevStepLink);-- // Get current step transistion- stepTransition = currentStory.steps[currentStepIndex]['transition'];-- // Pass current step query string to the browser url- if (util.browser.history) {- window.history.pushState(- '',- '@OFFICIAL_NAME@',- '?' + currentStepLink- );- }-- // Start Parsing- layerValidate(errors, config);-- // Parse the current state- currentStateParsers = [- projectionParser,- layerParser,- dateParser,- mapParser,- palettes.parse- ];- if (config.features.dataDownload) {- currentStateParsers.push(dataParser);- }- if (config.features.animation) {- currentStateParsers.push(animationParser);- }- lodashEach(currentStateParsers, function(parser) {- parser(currentState, errors, config);- });-- // Parse the previous state- prevStateParsers = [- projectionParser,- layerParser,- dateParser,- mapParser,- palettes.parse- ];- if (config.features.dataDownload) {- prevStateParsers.push(dataParser);- }- if (config.features.animation) {- prevStateParsers.push(animationParser);- }- lodashEach(prevStateParsers, function(parser) {- parser(prevState, errors, config);- });-- // Reset the palette, min and max values if these are not present in the- // current step url but were present in previous step.- if (prevStepLink) {- Object.values(prevState.l).forEach(prevLayer => {- if (prevLayer.id) {- Object.values(currentState.l).forEach(currentLayer => {- if (prevLayer.id === currentLayer.id) {- if (!util.objectsHaveSameKeys(prevLayer.attributes, currentLayer.attributes)) {- let prevAttrArray = prevLayer.attributes;- let currentAttrArray = currentLayer.attributes;- if (prevAttrArray.find(prevAttrArray => (prevAttrArray.id === 'palette')) &&- !currentAttrArray.find(currentAttrArray => (currentAttrArray.id === 'palette'))) {- let array = currentLayer.attributes;- array.push({ id: 'palette', value: '' });- }- if (prevAttrArray.find(prevAttrArray => (prevAttrArray.id === 'min')) &&- !currentAttrArray.find(currentAttrArray => (currentAttrArray.id === 'min'))) {- let array = currentLayer.attributes;- array.push({ id: 'min', value: '' });- }- if (prevAttrArray.find(prevAttrArray => (prevAttrArray.id === 'max')) &&- !currentAttrArray.find(currentAttrArray => (currentAttrArray.id === 'max'))) {- let array = currentLayer.attributes;- array.push({ id: 'max', value: '' });- }- }- }- });- }- });- }-- requirements = palettes.requirements(currentState, config);-- // Load the step link after the palettes & defaults loaded- Promise.all([requirements])- .then(models.layers.loaded = false) // Layers have not yet loaded- .then(() => { // Ensure selectedB is set in the models before loading link- if (currentState.t1) {- let selectedB = util.toISOStringSeconds(currentState.t1);- selectedB = new Date(selectedB);- models.date.selectedB = selectedB;- }- })- .then(util.wrap(() => this.loadLink(currentState, stepTransition, prevState, currentStepIndex)));- }-- loadLink(currentState, stepTransition, prevState, currentStepIndex) {- var promises = [];- var errors = [];- var models = this.props.models;- var ui = this.props.ui;- var rotation = 0;-- // Close the comparison mode if there is no comparison mode in the step link- if ((!currentState.ca || !currentState.cm) && models.compare.active === true) {- models.compare.toggle();- models.compare.load({});- ui.sidebar.reactComponent.setState({- isCompareMode: false- });- models.compare.active = false;- }-- // Set rotation value if it exists- if (currentState.p === 'arctic' || currentState.p === 'antarctic') {- if (!isNaN(currentState.r)) {- rotation = currentState.r * (Math.PI / 180.0);- }- }-- // LOAD: Comparison- promises.push(models.compare.load(currentState, errors));-- // LOAD: Projection- promises.push(models.proj.load(currentState, errors));-- // LOAD: Layers- promises.push(models.layers.load(currentState, errors));-- // LOAD: Palettes- promises.push(models.palettes.load(currentState, errors));-- // LOAD: Date(s)- promises.push(models.date.load(currentState, errors));-- // LOAD: Animation- if (!currentState.ca || !currentState.cm) {- promises.push(models.anim.load(currentState, errors));- }-- // LOAD: Events- // Note: Can't simple load from model since these check for startup events- if (currentState.e && (!currentState.ca || !currentState.cm)) {- let values = currentState.e.split(',');- let id = values[0] || '';- let date = values[1] || '';- id = id.match(/^EONET_[0-9]+/i) ? values[0] : null;- date = date.match(/\d{4}-\d{2}-\d{2}/) ? values[1] : null;- models.naturalEvents.events.trigger('activate');- if (id) {- promises.push(ui.naturalEvents.selectEvent(id, date, rotation));- }- }-- // LOAD: Data Download- if (currentState.download && (!currentState.ca || !currentState.cm)) {- promises.push(models.anim.load(currentState, errors));- }-- Promise.all([promises])- .then(() => this.setUI(currentState, stepTransition, prevState, currentStepIndex));- }-- setUI(currentState, stepTransition, prevState, currentStepIndex) {- var models = this.props.models;- var ui = this.props.ui;- var rotation = 0;-- // SET UI: Select sidebar tab based on what has been loaded- if (currentState.e && (!currentState.ca || !currentState.cm)) {- ui.sidebar.selectTab('events');- } else if (currentState.download && (!currentState.ca || !currentState.cm)) {- ui.sidebar.selectTab('download');- } else {- ui.sidebar.selectTab('layers');- }-- // Set rotation value if it exists- if (currentState.p === 'arctic' || currentState.p === 'antarctic') {- if (!isNaN(currentState.r)) {- rotation = currentState.r * (Math.PI / 180.0);- }- }-- // SET UI: Comparison Mode- if (currentState.ca || currentState.cm) {- var compareObj = getCompareObjects(models);-- models.compare.events.trigger('toggle');- models.compare.events.trigger('toggle-state');- models.date.events.trigger('state-update');-- ui.sidebar.reactComponent.setState({- isCompareMode: true,- firstDateObject: compareObj.a,- secondDateObject: compareObj.b,- isCompareA: models.compare && models.compare.isCompareA,- comparisonType: currentState.cm- });- }-- // SET UI: Timeline Zoom Level- if (currentState.z) {- let zoomLevel = Number(currentState.z);- ui.timeline.config.zoom(zoomLevel);- }-- // SET UI: Animation- if (!currentState.ca || !currentState.cm) {- if (currentState.al === 'true') {- ui.anim.widget.reactComponent.setState({ looping: true });- models.anim.rangeState.loop = true;- } else {- ui.anim.widget.reactComponent.setState({ looping: false });- models.anim.rangeState.loop = false;- }- if (currentState.av) ui.anim.widget.reactComponent.setState({ value: Number(currentState.av) });- if (currentState.ab === 'on' && !document.getElementById('timeline-footer').classList.contains('wv-anim-active')) {- models.anim.deactivate();- ui.anim.widget.toggleAnimationWidget();- } else if ((currentState.ab === 'off' || !currentState.ab) && document.getElementById('timeline-footer').classList.contains('wv-anim-active')) {- models.anim.activate();- ui.anim.widget.toggleAnimationWidget();- }- }-- // SET UI: Map Zoom & View & Rotation (Animated)- if (currentState.v) {- let extent = currentState.v;- let coordinateX = extent[0] + (extent[2] - extent[0]) / 2;- let coordinateY = extent[1] + (extent[3] - extent[1]) / 2;- let coordinates = [coordinateX, coordinateY];- let resolution = ui.map.selected.getView().getResolutionForExtent(extent);- let zoom = ui.map.selected.getView().getZoomForResolution(resolution);-- // Animate to extent, zoom & rotate:- // Don't animate when an event is selected (Event selection already animates)- if (!currentState.e) {- ui.map.animate.fly(coordinates, zoom, rotation);- }-- // Jump to extent & zoom (instead of animate):- // ui.map.selected.getView().fit(currentState.v, ui.map.selected.getSize());- }-- this.processActions(currentState, stepTransition);- }-- processActions(currentState, stepTransition) {- var ui = this.props.ui;-- if (!stepTransition) return;-- // ACTION: Play & pause animation- if (currentState.ab === 'on') {- if (stepTransition.element === 'animation' && stepTransition.action === 'play') {- ui.anim.widget.onPressPlay();- ui.anim.widget.reactComponent.setState({ playing: true });- } else {- ui.anim.widget.onPressPause();- ui.anim.widget.reactComponent.setState({ playing: false });- }- }- }-render() {- var { description } = this.state;+ var { description } = this.props;return (<div>- <Modal isOpen={this.props.modalInProgress} toggle={this.props.toggleModalInProgress} onClosed={this.props.showTourAlert} wrapClassName='tour tour-in-progress' className={this.props.className + ' ' + this.props.currentStory['type']} backdrop={false} keyboard={false}>- <ModalHeader toggle={this.props.toggleModalInProgress} charCode="">{this.props.currentStory['title']}<i className="modal-icon" aria-hidden="true"></i></ModalHeader>+ <Modal+ isOpen={this.props.modalInProgress}+ toggle={this.props.toggleModalInProgress}+ onClosed={this.props.showTourAlert}+ wrapClassName="tour tour-in-progress"+ className={+ this.props.className + ' ' + this.props.currentStory['type']+ }+ backdrop={false}+ keyboard={false}+ >+ <ModalHeader toggle={this.props.toggleModalInProgress} charCode="">+ {this.props.currentStory['title']}+ <i className="modal-icon" aria-hidden="true" />+ </ModalHeader><ModalBody>{/* eslint-disable */}- <div ref="stepContent" dangerouslySetInnerHTML={{ __html: description }} />+ <div+ ref="stepContent"+ dangerouslySetInnerHTML={{ __html: description }}+ />{/* eslint-enable */}</ModalBody><ModalFooter>- <Steps currentStep={this.props.currentStep} totalSteps={this.props.totalSteps} decreaseStep={this.props.decreaseStep} incrementStep={this.props.incrementStep}></Steps>+ <Steps+ currentStep={this.props.currentStep}+ totalSteps={this.props.totalSteps}+ decreaseStep={this.props.decreaseStep}+ incrementStep={this.props.incrementStep}+ /></ModalFooter></Modal></div>@@ -436,24 +69,24 @@ class ModalInProgress extends React.Component {}ModalInProgress.propTypes = {- models: PropTypes.object.isRequired,- config: PropTypes.object.isRequired,- ui: PropTypes.object.isRequired,- modalInProgress: PropTypes.bool.isRequired,- toggleModalInProgress: PropTypes.func.isRequired,- currentStep: PropTypes.number.isRequired,- totalSteps: PropTypes.number.isRequired,- currentStoryIndex: PropTypes.number.isRequired,- currentStory: PropTypes.object.isRequired,- currentStoryId: PropTypes.string.isRequired,- decreaseStep: PropTypes.func.isRequired,- incrementStep: PropTypes.func.isRequired,- showTourAlert: PropTypes.func.isRequired,- restartTour: PropTypes.bool.isRequired,- toggleRestartTour: PropTypes.func.isRequired,- toggleMetaLoaded: PropTypes.func.isRequired,- metaLoaded: PropTypes.bool.isRequired,- className: PropTypes.string+ // models: PropTypes.object.isRequired,+ // config: PropTypes.object.isRequired,+ // ui: PropTypes.object.isRequired,+ // modalInProgress: PropTypes.bool.isRequired,+ // toggleModalInProgress: PropTypes.func.isRequired,+ // currentStep: PropTypes.number.isRequired,+ // totalSteps: PropTypes.number.isRequired,+ // currentStoryIndex: PropTypes.number.isRequired,+ // currentStory: PropTypes.object.isRequired,+ // currentStoryId: PropTypes.string.isRequired,+ // decreaseStep: PropTypes.func.isRequired,+ // incrementStep: PropTypes.func.isRequired,+ // showTourAlert: PropTypes.func.isRequired,+ // restartTour: PropTypes.bool.isRequired,+ // toggleRestartTour: PropTypes.func.isRequired,+ // toggleMetaLoaded: PropTypes.func.isRequired,+ // metaLoaded: PropTypes.bool.isRequired,+ // className: PropTypes.string};export default ModalInProgress;diff --git a/web/js/components/tour/tour.js b/web/js/components/tour/tour.jsdeleted file mode 100644index 9eac801f5..000000000--- a/web/js/components/tour/tour.js+++ /dev/null@@ -1,203 +0,0 @@-import React from 'react';-import PropTypes from 'prop-types';-import TourStart from './modal-tour-start';-import TourInProgress from './modal-tour-in-progress';-import TourComplete from './modal-tour-complete';-import googleTagManager from 'googleTagManager';--class Tour extends React.Component {- constructor(props) {- super(props);- this.state = {- models: props.models,- config: props.config,- ui: props.ui,- stories: props.stories,- storyOrder: props.storyOrder,- modalStart: props.modalStart,- modalInProgress: props.modalInProgress,- modalComplete: props.modalComplete,- currentStep: props.currentStep,- totalSteps: props.totalSteps,- tourParameter: props.tourParameter,- currentStoryIndex: props.currentStoryIndex,- currentStory: props.currentStory,- currentStoryId: props.currentStoryId,- showTourAlert: props.showTourAlert,- hideTour: props.hideTour,- restartTour: props.restartTour,- metaLoaded: props.metaLoaded- };-- this.toggleModalStart = this.toggleModalStart.bind(this);- this.toggleModalInProgress = this.toggleModalInProgress.bind(this);- this.toggleModalComplete = this.toggleModalComplete.bind(this);- this.toggleRestartTour = this.toggleRestartTour.bind(this);- this.toggleMetaLoaded = this.toggleMetaLoaded.bind(this);- this.incrementStep = this.incrementStep.bind(this);- this.decreaseStep = this.decreaseStep.bind(this);- }-- componentDidMount() {- window.addEventListener('resize', this.resize.bind(this));- this.resize();- }-- resize() {- if (window.innerWidth < 740) {- this.setState({ modalStart: false, modalInProgress: false, modalComplete: false });- }- if (window.innerHeight < 450) {- this.setState({ modalStart: false, modalInProgress: false, modalComplete: false });- }- }-- toggleModalStart(e) {- e.preventDefault();- this.setState({- modalStart: !this.state.modalStart- });- }-- toggleModalInProgress(e) {- e.preventDefault();- this.setState({- modalInProgress: !this.state.modalInProgress- });- // When tour is not in progress, remove from URL- this.props.models.tour.toggle();- this.props.models.tour.select(this.state.currentStoryId);- this.toggleMetaLoaded();- }-- toggleModalComplete(e) {- e.preventDefault();- this.setState({- modalComplete: !this.state.modalComplete- });- // The tour completed modal has been shown (all steps complete)- googleTagManager.pushEvent({- 'event': 'tour_completed',- 'story': {- 'id': this.state.currentStoryId- }- });- }-- toggleRestartTour() {- this.setState({- restartTour: !this.state.restartTour,- metaLoaded: false- });- }-- toggleMetaLoaded() {- this.setState({- metaLoaded: !this.state.metaLoaded- });- }-- incrementStep(e) {- if (this.state.currentStep + 1 <= this.state.totalSteps) this.setState({ currentStep: this.state.currentStep + 1 });- if (this.state.currentStep + 1 === this.state.totalSteps + 1) {- this.toggleModalInProgress(e);- this.toggleModalComplete(e);- }- }-- decreaseStep(e) {- if (this.state.currentStep - 1 >= 1) {- this.setState({ currentStep: this.state.currentStep - 1 });- } else {- this.setState({- currentStep: 1,- modalInProgress: false,- modalStart: true- });- }- }-- render() {- if (this.state.stories) {- return (- <div>- <TourStart- stories={this.state.stories}- storyOrder={this.state.storyOrder}- modalStart={this.state.modalStart}- toggleModalStart={this.toggleModalStart}- toggleModalInProgress={this.toggleModalInProgress}- toggleModalComplete={this.toggleModalComplete}- selectTour={this.props.selectTour}- showTourAlert={this.props.showTourAlert}- hideTour={this.props.hideTour}- showTour={this.props.showTour}- ></TourStart>-- <TourInProgress- models={this.state.models}- config={this.state.config}- ui={this.state.ui}- modalInProgress={this.state.modalInProgress}- toggleModalStart={this.toggleModalStart}- toggleModalInProgress={this.toggleModalInProgress}- toggleModalComplete={this.toggleModalComplete}- selectTour={this.props.selectTour}- currentStep={this.state.currentStep}- totalSteps={this.state.totalSteps}- incrementStep={this.incrementStep}- decreaseStep={this.decreaseStep}- currentStoryIndex={this.state.currentStoryIndex}- stories={this.state.stories}- currentStoryId={this.state.currentStoryId}- currentStory={this.state.currentStory}- showTourAlert={this.props.showTourAlert}- restartTour={this.state.restartTour}- metaLoaded={this.state.metaLoaded}- toggleRestartTour={this.toggleRestartTour}- toggleMetaLoaded={this.toggleMetaLoaded}- ></TourInProgress>-- <TourComplete- currentStory={this.state.currentStory}- modalComplete={this.state.modalComplete}- toggleModalStart={this.toggleModalStart}- toggleModalInProgress={this.toggleModalInProgress}- toggleModalComplete={this.toggleModalComplete}- startTour={this.props.startTour}- resetTour={this.props.resetTour}- ></TourComplete>- </div>- );- } else {- return null;- }- }-}--Tour.propTypes = {- models: PropTypes.object.isRequired,- config: PropTypes.object.isRequired,- ui: PropTypes.object.isRequired,- stories: PropTypes.object.isRequired,- storyOrder: PropTypes.array.isRequired,- modalStart: PropTypes.bool.isRequired,- modalInProgress: PropTypes.bool.isRequired,- modalComplete: PropTypes.bool.isRequired,- currentStep: PropTypes.number,- totalSteps: PropTypes.number,- tourParameter: PropTypes.string,- currentStoryIndex: PropTypes.number,- currentStory: PropTypes.object,- currentStoryId: PropTypes.string,- startTour: PropTypes.func.isRequired,- resetTour: PropTypes.func.isRequired,- selectTour: PropTypes.func.isRequired,- showTourAlert: PropTypes.func.isRequired,- hideTour: PropTypes.func.isRequired,- showTour: PropTypes.func.isRequired,- restartTour: PropTypes.bool.isRequired,- metaLoaded: PropTypes.bool.isRequired-};--export default Tour;diff --git a/web/js/containers/info.js b/web/js/containers/info.jsindex 071d72277..a71e17848 100644--- a/web/js/containers/info.js+++ b/web/js/containers/info.js@@ -1,6 +1,7 @@import React, { Component } from 'react';import PropTypes from 'prop-types';import { connect } from 'react-redux';+import googleTagManager from 'googleTagManager';import {requestTemplate,renderTemplate,@@ -12,6 +13,7 @@ import { onClickFeedback } from '../modules/feedback/util';import { addToLocalStorage } from '../modules/notifications/util';import { initFeedback } from '../modules/feedback/actions';+import { startTour } from '../modules/tour/actions';import { notificationsSeen } from '../modules/notifications/actions';import util from '../util/util';import Notifications from '../containers/notifications';@@ -43,8 +45,7 @@ class InfoList extends Component {feedbackIsInitiated,aboutClick,notifications,- config,- models+ config} = this.props;let arr = [{@@ -88,7 +89,10 @@ class InfoList extends Component {iconClass: 'ui-icon fa fa-truck fa-fw',id: 'start_tour_info_item',onClick: () => {- models.tour.events.trigger('start-tour');+ startTour();+ googleTagManager.pushEvent({+ event: 'tour_start_button'+ });}};arr.splice(1, 0, exploreWorlviewObj);diff --git a/web/js/components/sidebar/footer-content.js b/web/js/containers/sidebar/footer-content.jssimilarity index 96%rename from web/js/components/sidebar/footer-content.jsrename to web/js/containers/sidebar/footer-content.jsindex fabd19a86..80a4232a3 100644--- a/web/js/components/sidebar/footer-content.js+++ b/web/js/containers/sidebar/footer-content.js@@ -1,7 +1,7 @@import React from 'react';import PropTypes from 'prop-types';-import Button from '../util/button';-import ModeSelection from './mode-selection';+import Button from '../../components/util/button';+import ModeSelection from '../../components/sidebar/mode-selection';import googleTagManager from 'googleTagManager';import { get as lodashGet } from 'lodash';import { toggleCompareOnOff, changeMode } from '../../modules/compare/actions';@@ -10,7 +10,7 @@ import {getSelectionCounts,getDataSelectionSize} from '../../modules/data/selectors';-import ProductPicker from '../layer/product-picker/product-picker';+import ProductPicker from '../../components/layer/product-picker/product-picker';import { openCustomContent } from '../../modules/modal/actions';import { DATA_GET_DATA_CLICK } from '../../modules/data/constants';diff --git a/web/js/containers/sidebar/sidebar.js b/web/js/containers/sidebar/sidebar.jsindex fca720ded..d308ebddf 100644--- a/web/js/containers/sidebar/sidebar.js+++ b/web/js/containers/sidebar/sidebar.js@@ -5,7 +5,7 @@ import Layers from './layers';import Events from './events';import Data from './data';import CompareCase from './compare';-import FooterContent from '../../components/sidebar/footer-content';+import FooterContent from './footer-content';import { TabContent, TabPane } from 'reactstrap';import CollapsedButton from '../../components/sidebar/collapsed-button';import NavCase from '../../components/sidebar/nav/nav-case';diff --git a/web/js/containers/tour.js b/web/js/containers/tour.jsnew file mode 100644index 000000000..ad877c7e3--- /dev/null+++ b/web/js/containers/tour.js@@ -0,0 +1,345 @@+import React from 'react';+import PropTypes from 'prop-types';+import TourStart from '../components/tour/modal-tour-start';+import TourInProgress from '../components/tour/modal-tour-in-progress';+import TourComplete from '../components/tour/modal-tour-complete';+import { connect } from 'react-redux';+import googleTagManager from 'googleTagManager';+import { endTour, selectStory } from '../modules/tour/actions';+import { findIndex as lodashFindIndex, get as lodashGet } from 'lodash';+import update from 'immutability-helper';+import { history } from '../main';+import util from '../util/util';++class Tour extends React.Component {+ constructor(props) {+ super(props);+ const storyOrder = props.storyOrder;+ const stories = props.stories;+ const currentStoryIndex =+ lodashFindIndex(storyOrder, { id: props.currentStoryId }) || null;+ const currentStory =+ currentStoryIndex >= 0 ? stories[props.currentStoryId] : {};+ const steps = lodashGet(currentStory, 'steps') || [];++ this.state = {+ modalStart: true,+ modalInProgress: false,+ modalComplete: false,+ currentStep: currentStoryIndex !== -1 ? 1 : 0,+ totalSteps: steps.length,+ metaLoaded: false,+ isLoadingMeta: false,+ restartTour: true,+ currentStory,+ currentStoryId: props.currentStoryId,+ currentStoryIndex: currentStoryIndex+ };++ this.toggleModalStart = this.toggleModalStart.bind(this);+ this.toggleModalInProgress = this.toggleModalInProgress.bind(this);+ this.toggleModalComplete = this.toggleModalComplete.bind(this);+ this.toggleRestartTour = this.toggleRestartTour.bind(this);+ this.incrementStep = this.incrementStep.bind(this);+ this.decreaseStep = this.decreaseStep.bind(this);+ }+ toggleModalStart(e) {+ e.preventDefault();+ this.setState({+ modalStart: !this.state.modalStart+ });+ }+ selectTour(e, currentStory, currentStoryIndex, currentStoryId) {+ if (e) e.preventDefault();+ this.setState({+ currentStep: 1,+ currentStoryIndex: currentStoryIndex,+ modalStart: false,+ modalInProgress: true,+ metaLoaded: false,+ modalComplete: false,+ currentStory: currentStory,+ currentStoryId: currentStoryId,+ totalSteps: currentStory.steps.length+ });+ this.props.selectTour(currentStoryId);+ this.fetchMetadata(currentStory, 0);+ this.props.processStepLink(+ currentStory.steps[0]['stepLink'] + '&tr=' + currentStoryId+ );+ }+ fetchMetadata(currentStory, stepIndex) {+ var description = currentStory.steps[stepIndex]['description'];+ var { origin, pathname } = window.location;+ var errorMessage = '<p>There was an error loading this description.</p>';+ var uri = `${origin}${pathname}config/metadata/stories/${+ currentStory.id+ }/${description}`;+ this.setState({ isLoadingMeta: true, metaLoaded: false });+ fetch(uri)+ .then(res => (res.ok ? res.text() : errorMessage))+ .then(body => {+ let isMetadataSnippet = !body.match(+ /<(head|body|html|style|script)[^>]*>/i+ );+ let description = isMetadataSnippet ? body : errorMessage;+ this.setState({+ description: description,+ isLoadingMeta: false,+ metaLoaded: true+ });+ })+ .catch(error =>+ this.setState({ description: error, isLoadingMeta: false })+ );+ }+ resetTour(e) {+ if (e) e.preventDefault();+ // Tour startup modal shown by clicking "More Stories" button at end of story+ selectStory('');+ googleTagManager.pushEvent({+ event: 'tour_more_stories_button'+ });+ this.setState({+ modalInProgress: false,+ modalComplete: false,+ restartTour: true+ });+ }+ toggleModalInProgress(e) {+ e.preventDefault();+ this.setState({+ modalInProgress: !this.state.modalInProgress+ });+ this.toggleMetaLoaded();+ }++ toggleModalComplete(e) {+ e.preventDefault();+ this.setState({+ modalComplete: !this.state.modalComplete+ });+ // The tour completed modal has been shown (all steps complete)+ googleTagManager.pushEvent({+ event: 'tour_completed',+ story: {+ id: this.state.currentStoryId+ }+ });+ }++ toggleRestartTour() {+ this.setState({+ restartTour: !this.state.restartTour,+ metaLoaded: false+ });+ }+ incrementStep(e) {+ const {+ currentStep,+ currentStory,+ totalSteps,+ currentStoryId+ } = this.state;++ if (currentStep + 1 <= totalSteps) {+ let newStep = currentStep + 1;+ this.fetchMetadata(currentStory, currentStep);+ this.setState({ currentStep: newStep });+ this.props.processStepLink(+ currentStory.steps[newStep - 1]['stepLink'] + '&tr=' + currentStoryId+ );+ }+ if (currentStep + 1 === totalSteps + 1) {+ this.toggleModalInProgress(e);+ this.toggleModalComplete(e);+ }+ }++ decreaseStep(e) {+ const { currentStep, currentStory, currentStoryId } = this.state;+ if (currentStep - 1 >= 1) {+ let newStep = currentStep - 1;+ this.fetchMetadata(currentStory, newStep - 1);+ this.setState({ currentStep: newStep });+ this.props.processStepLink(+ currentStory.steps[newStep - 1]['stepLink'] + '&tr=' + currentStoryId+ );+ } else {+ this.setState({+ currentStep: 1,+ modalInProgress: false,+ modalStart: true+ });+ }+ }++ render() {+ const {+ stories,+ storyOrder,+ showTourAlert,+ hideTour,+ showTour,+ config,+ restartTour,+ screenHeight,+ screenWidth,+ endTour,+ processStepLink,+ isActive+ } = this.props;+ const {+ modalInProgress,+ metaLoaded,+ currentStory,+ currentStoryId,+ currentStep,+ totalSteps,+ modalComplete,+ models,+ modalStart,+ currentStoryIndex,+ description,+ isLoadingMeta+ } = this.state;+ if (screenWidth < 740 || screenHeight < 450) {+ endTour();+ }+ if (stories && isActive) {+ return (+ <div>+ {modalStart ? (+ <TourStart+ stories={stories}+ storyOrder={storyOrder}+ modalStart={modalStart}+ toggleModalStart={this.toggleModalStart}+ toggleModalInProgress={this.toggleModalInProgress}+ toggleModalComplete={this.toggleModalComplete}+ selectTour={this.selectTour.bind(this)}+ showTourAlert={showTourAlert}+ hideTour={hideTour}+ showTour={showTour}+ />+ ) : modalInProgress ? (+ <TourInProgress+ config={config}+ models={models}+ endTour={endTour}+ modalInProgress={modalInProgress}+ toggleModalStart={this.toggleModalStart}+ toggleModalInProgress={this.toggleModalInProgress}+ toggleModalComplete={this.toggleModalComplete}+ currentStep={currentStep}+ totalSteps={totalSteps}+ currentStoryIndex={currentStoryIndex}+ incrementStep={this.incrementStep}+ decreaseStep={this.decreaseStep}+ stories={stories}+ currentStoryId={currentStoryId}+ currentStory={currentStory}+ showTourAlert={showTourAlert}+ restartTour={restartTour}+ metaLoaded={metaLoaded}+ isLoadingMeta={isLoadingMeta}+ description={description}+ toggleRestartTour={this.toggleRestartTour}+ toggleMetaLoaded={this.toggleMetaLoaded}+ processStepLink={processStepLink}+ />+ ) : (+ <TourComplete+ currentStory={currentStory}+ modalComplete={modalComplete}+ toggleModalStart={this.toggleModalStart}+ toggleModalInProgress={this.toggleModalInProgress}+ toggleModalComplete={this.toggleModalComplete}+ resetTour={this.resetTour.bind(this)}+ />+ )}+ </div>+ );+ } else {+ return null;+ }+ }+}++Tour.propTypes = {+ config: PropTypes.object.isRequired,+ stories: PropTypes.object.isRequired,+ storyOrder: PropTypes.array.isRequired,+ currentStep: PropTypes.number,+ totalSteps: PropTypes.number,+ currentStory: PropTypes.object,+ currentStoryId: PropTypes.string,+ selectTour: PropTypes.func.isRequired,+ showTourAlert: PropTypes.func.isRequired,+ hideTour: PropTypes.func.isRequired,+ showTour: PropTypes.func.isRequired+};+const mapDispatchToProps = dispatch => ({+ processStepLink: search => {+ const location = update(history.location, {+ search: { $set: search }+ });+ dispatch({ type: 'REDUX-LOCATION-POP-ACTION', payload: location });+ },+ showTourAlert: message => {+ // dispatch(showAlert(message));+ },+ selectTour: id => {+ dispatch(selectStory(id));+ },+ showTour: showTour,+ hideTour: hideTour+});+function mapStateToProps(state) {+ const { browser, config, tour } = state;+ const { screenWidth, screenHeight } = browser;++ return {+ config,+ isActive: tour.active,+ models: state.models,+ compareState: state.compare,+ stories: config.stories,+ storyOrder: config.storyOrder,+ currentStoryId: tour.selected,+ hideTour,+ screenWidth,+ screenHeight,+ showTour+ };+}+const hideTour = function(e) {+ var hideTour = localStorage.getItem('hideTour');++ // Checkbox to "hide tour modal until a new story has been added" has been checked+ googleTagManager.pushEvent({+ event: 'tour_hide_checked'+ });++ if (!util.browser.localStorage) return;+ if (hideTour) return;++ localStorage.setItem('hideTour', new Date());+};+const showTour = function(e) {+ var hideTour = localStorage.getItem('hideTour');++ // Checkbox to "hide tour modal until a new story has been added" has been checked+ googleTagManager.pushEvent({+ event: 'tour_hide_unchecked'+ });++ if (!util.browser.localStorage) return;+ if (!hideTour) return;++ localStorage.removeItem('hideTour');+};+export default connect(+ mapStateToProps,+ mapDispatchToProps+)(Tour);diff --git a/web/js/date/timeline-input.js b/web/js/date/timeline-input.jsindex 80b8b5d7d..818d5e237 100644--- a/web/js/date/timeline-input.js+++ b/web/js/date/timeline-input.js@@ -2,7 +2,10 @@ import util from '../util/util';import DateSelector from '../components/date-selector/date-selector';import React from 'react';import ReactDOM from 'react-dom';+import { get as lodashGet } from 'lodash';import { INIT_SECOND_LAYER_GROUP } from '../modules/layers/constants';+import { LOCATION_POP_ACTION } from '../redux-location-state-customs';+const dateSelectorStr = 'date-selector-main';/*** Implements the date input@@ -24,14 +27,29 @@ export function timelineInput(models, config, ui, store) {var $incrementBtn = $('#right-arrow-group');var $decrementBtn = $('#left-arrow-group');+/**- * Suscribe to redux store and listen for+ * Subscribe to redux store and listen for* specific action types*/const subscribeToStore = function() {- const action = store.getState().lastAction;+ const state = store.getState();+ const action = state.lastAction;if (action.type === INIT_SECOND_LAYER_GROUP) {model.initCompare();+ } else if (action.type === LOCATION_POP_ACTION) {+ const newState = util.fromQueryString(action.payload.search);+ const selected = lodashGet(action, 'payload.query.legacy.date.selected');+ const selectedB = lodashGet(+ action,+ 'payload.query.legacy.date.selectedB'+ );+ if (newState.t && selected) {+ model.select(selected, 'selected');+ }+ if (newState.t1 && selectedB) {+ model.select(selectedB, 'selectedB');+ }}};var init = function() {diff --git a/web/js/location.js b/web/js/location.jsindex 3d5e7e8aa..1cb73691b 100644--- a/web/js/location.js+++ b/web/js/location.js@@ -1,13 +1,12 @@-import { assign as lodashAssign, has, set, get } from 'lodash';+import { assign as lodashAssign, get } from 'lodash';import { encode } from './modules/link/util';-// legacy crutches// import { getLayersParameterSetup } from './modules/layers/util';import { getDateParameterSetup } from './modules/date/util';--import { defaultDataState } from './modules/data/constants';import { getAnimationParameterSetup } from './modules/animation/util';-import { getTourParameterSetup } from './modules/tour/util';+import { checkTourBuildTimestamp } from './modules/tour/util';++import { tourStartModalCustomProps } from './modules/tour/constants';import { getMapParameterSetup } from './modules/map/util';import { eventParse, serializeEvent } from './modules/natural-events/util';import {@@ -17,10 +16,13 @@ import {} from './modules/layers/util';import { resetLayers } from './modules/layers/selectors';import { eventsReducerState } from './modules/natural-events/reducers';+import util from './util/util';import update from 'immutability-helper';export function mapLocationToState(state, location) {+ const config = state.config;if (location.search) {+ let parameters = util.fromQueryString(location.search);let stateFromLocation = location.query;const projId = get(stateFromLocation, 'proj.id');if (projId) {@@ -29,17 +31,22 @@ export function mapLocationToState(state, location) {proj: { selected: { $set: selected } }});}- if (stateFromLocation.compare) {+ if (parameters.ca !== undefined) {stateFromLocation = update(stateFromLocation, {compare: { active: { $set: true } }});+ if (!parameters.l1) {+ stateFromLocation = update(stateFromLocation, {+ layers: { activeB: { $set: stateFromLocation.layers.active } }+ });+ }}// legacy layers permalinkif (state.parameters.product) {stateFromLocation = update(stateFromLocation, {layers: {active: {- $set: layersParse11(state.parameters.product, state.config)+ $set: layersParse11(state.parameters.product, config)}}});@@ -52,10 +59,23 @@ export function mapLocationToState(state, location) {});}return update(state, { $merge: stateFromLocation });- } else return state;+ } else {+ const startTour = checkTourBuildTimestamp(state.config);+ if (+ startTour &&+ config.features.tour &&+ config.stories &&+ config.storyOrder+ ) {+ return update(state, {+ tour: { active: { $set: true } }+ });+ }+ return state;+ }}-const getParameters = function(config) {+const getParameters = function(config, parameters) {return {p: {stateKey: 'proj.id',@@ -80,7 +100,12 @@ const getParameters = function(config) {},serializeNeedsGlobalState: true,serialize: (currentLayers, state) => {- return serializeLayers(currentLayers, state, 'active');+ const compareIsActive = get(state, 'compare.active');+ const isCompareA = get(state, 'compare.isCompareA');+ const activeLayersB = get(state, 'layers.activeB');+ return !isCompareA && !compareIsActive+ ? serializeLayers(activeLayersB, state, 'activeB')+ : serializeLayers(currentLayers, state, 'active');}}},@@ -90,11 +115,17 @@ const getParameters = function(config) {type: 'array',options: {parse: permalink => {- return layersParse12(permalink, config);+ if (parameters.ca !== undefined) {+ return layersParse12(permalink, config);+ }+ return [];},serializeNeedsGlobalState: true,serialize: (currentLayers, state) => {- return serializeLayers(currentLayers, state, 'activeB');+ const compareIsActive = get(state, 'compare.active');+ return compareIsActive+ ? serializeLayers(currentLayers, state, 'activeB')+ : undefined;}}},@@ -113,12 +144,32 @@ const getParameters = function(config) {},cm: {stateKey: 'compare.mode',- initialState: 'swipe'+ initialState: 'swipe',+ options: {+ parse: str => {+ if (parameters.ca !== undefined) {+ return str;+ }+ return 'swipe';+ }+ }},cv: {stateKey: 'compare.value',initialState: 50,- type: 'number'+ type: 'number',+ options: {+ parse: num => {+ if (parameters.ca !== undefined) {+ return num;+ }+ return 50;+ }+ }+ },+ tr: {+ stateKey: 'tour.selected',+ initialState: ''},download: {stateKey: 'data.selectedProduct',@@ -150,7 +201,6 @@ export function getParamObject(legacyState,errors) {- let tourParamObject = {};let animationParamObject = {};const mapParamObject = getMapParameterSetup(@@ -160,15 +210,6 @@ export function getParamObject(legacyState,errors);- if (config.features.tour) {- tourParamObject = getTourParameterSetup(- parameters,- config,- models,- legacyState,- errors- );- }if (config.features.animation) {animationParamObject = getAnimationParameterSetup(parameters,@@ -185,22 +226,12 @@ export function getParamObject(legacyState,errors);- // const dataParamObject = getDataDownloadParameterSetup(- // parameters,- // config,- // models,- // legacyState,- // errors- // );-const obj = lodashAssign({},dateParamObject,animationParamObject,- // dataParamObject,- tourParamObject,mapParamObject,- getParameters(config)+ getParameters(config, parameters));return {global: objdiff --git a/web/js/main.js b/web/js/main.jsindex 9aac9e53e..184f6f522 100644--- a/web/js/main.js+++ b/web/js/main.js@@ -28,7 +28,6 @@ import { updateLegacyModule } from './modules/migration/actions';import { validate as layerValidate } from './layers/layers';import { polyfill } from './polyfill';import { debugConfig } from './debug';-import { changeProjection } from './modules/projection/actions';export let history = createBrowserHistory();const isDebugMode = typeof DEBUG !== 'undefined';diff --git a/web/js/map/animate.js b/web/js/map/animate.jsindex d212a7f9d..29dfb4caa 100644--- a/web/js/map/animate.js+++ b/web/js/map/animate.js@@ -1,7 +1,7 @@import * as olExtent from 'ol/extent';import OlGeomLineString from 'ol/geom/LineString';import Promise from 'bluebird';-export function mapAnimate(models, config, ui) {+export function mapAnimate(config, ui, store) {var self = {};/**@@ -11,9 +11,10 @@ export function mapAnimate(models, config, ui) {* @param {integer} endZoom Ending Zoom Level* @return {Promise} Promise that is fulfilled when animation completes*/- self.fly = function (endPoint, endZoom, rotation) {+ self.fly = function(endPoint, endZoom, rotation) {+ const state = store.getState();var view = ui.map.selected.getView();- var polarProjectionCheck = models.proj.selected.id !== 'geographic'; // boolean if current projection is polar+ var polarProjectionCheck = state.proj.selected.id !== 'geographic'; // boolean if current projection is polarview.cancelAnimations();var startPoint = view.getCenter();var startZoom = Math.floor(view.getZoom());@@ -24,9 +25,9 @@ export function mapAnimate(models, config, ui) {var line = new OlGeomLineString([startPoint, endPoint]);var distance = line.getLength(); // In map units, which is usually degreesvar distanceDuration = polarProjectionCheck ? distance / 50000 : distance; // limit large polar projection distances from coordinate transforms- var duration = Math.floor((distanceDuration * 20) + 1000); // approx 6 seconds to go 360 degrees+ var duration = Math.floor(distanceDuration * 20 + 1000); // approx 6 seconds to go 360 degreesif (!rotation) rotation = 0;- var animationPromise = function () {+ var animationPromise = function() {var args = Array.prototype.slice.call(arguments);return new Promise(function(resolve, reject) {args.push(function(complete) {@@ -41,15 +42,31 @@ export function mapAnimate(models, config, ui) {duration = duration < 1200 ? duration / 2 : duration;// If the event is already visible, don't zoom outreturn Promise.all([- animationPromise({ center: endPoint, duration: duration, rotation: rotation }),- animationPromise({ zoom: endZoom, duration: duration, rotation: rotation })+ animationPromise({+ center: endPoint,+ duration: duration,+ rotation: rotation+ }),+ animationPromise({+ zoom: endZoom,+ duration: duration,+ rotation: rotation+ })]);}// Default animation zooms out to arcreturn Promise.all([- animationPromise({ center: endPoint, duration: duration, rotation: rotation }),+ animationPromise({+ center: endPoint,+ duration: duration,+ rotation: rotation+ }),animationPromise(- { zoom: getBestZoom(distance, startZoom, endZoom, view), duration: duration / 2, rotation: rotation },+ {+ zoom: getBestZoom(distance, startZoom, endZoom, view),+ duration: duration / 2,+ rotation: rotation+ },{ zoom: endZoom, duration: duration / 2, rotation: rotation })]);diff --git a/web/js/map/compare/compare.js b/web/js/map/compare/compare.jsindex 91ff8ebf3..715d9c137 100644--- a/web/js/map/compare/compare.js+++ b/web/js/map/compare/compare.js@@ -66,7 +66,6 @@ export function mapCompare(config, store) {state.compare.value || null); // e.g. new self.swipe()} else {- console.log(compareMode);mode = compareMode;comparison = new self[compareMode](map,diff --git a/web/js/map/layerbuilder.js b/web/js/map/layerbuilder.jsindex 4faa83112..48e61407f 100644--- a/web/js/map/layerbuilder.js+++ b/web/js/map/layerbuilder.js@@ -61,7 +61,7 @@ export function mapLayerBuilder(models, config, cache, mapUi, store) {def = lodashCloneDeep(def);lodashMerge(def, def.projections[proj.id]);if (def.type === 'wmts') {- layer = createLayerWMTS(def, options, undefined, state);+ layer = createLayerWMTS(def, options, null, state);if (proj.id === 'geographic' &&(def.wrapadjacentdays === true || def.wrapX)@@ -95,7 +95,7 @@ export function mapLayerBuilder(models, config, cache, mapUi, store) {});}} else if (def.type === 'wms') {- layer = createLayerWMS(def, options, state);+ layer = createLayerWMS(def, options, null, state);if (proj.id === 'geographic' &&(def.wrapadjacentdays === true || def.wrapX)@@ -179,7 +179,7 @@ export function mapLayerBuilder(models, config, cache, mapUi, store) {* @returns {object} layer key Object*/self.layerKey = function(def, options, state) {- const { palettes, compare } = state;+ const { compare } = state;var date;var layerId = def.id;var projId = state.proj.id;@@ -385,7 +385,7 @@ export function mapLayerBuilder(models, config, cache, mapUi, store) {* @returns {object} OpenLayers WMS layer*/var createLayerWMS = function(def, options, day, state) {- const { palettes, proj } = state;+ const { proj } = state;const selectedProj = proj.selected;var source,urlParameters,diff --git a/web/js/map/ui.js b/web/js/map/ui.jsindex fe0ad124c..a5c999305 100644--- a/web/js/map/ui.js+++ b/web/js/map/ui.js@@ -5,6 +5,7 @@ import lodashForOwn from 'lodash/forOwn';import lodashThrottle from 'lodash/throttle';import lodashCloneDeep from 'lodash/cloneDeep';import lodashFind from 'lodash/find';+import { get as lodashGet } from 'lodash';import util from '../util/util';import OlMap from 'ol/Map';import OlView from 'ol/View';@@ -30,6 +31,7 @@ import { mapPrecacheTile } from './precachetile';import { mapUtilZoomAction, getActiveLayerGroup } from './util';import { mapCompare } from './compare/compare';import { CALCULATE_RESPONSIVE_STATE } from 'redux-responsive';+import { LOCATION_POP_ACTION } from '../redux-location-state-customs';import { CHANGE_PROJECTION } from '../modules/projection/constants';import * as layerConstants from '../modules/layers/constants';import * as compareConstants from '../modules/compare/constants';@@ -83,6 +85,15 @@ export function mapui(models, config, store) {case layerConstants.ADD_LAYER:let def = lodashFind(action.layers, { id: action.id });return addLayer(def);+ case LOCATION_POP_ACTION:+ const newState = util.fromQueryString(action.payload.search);+ const extent = lodashGet(action, 'payload.query.legacy.map.extent');+ const rotation = lodashGet(action, 'payload.query.legacy.map.rotation') || 0;+ updateProjection();+ if (newState.v && !newState.e && extent) {+ flyToNewExtent(extent, rotation);+ }+ return;case layerConstants.REMOVE_LAYER:return removeLayer(action);case layerConstants.TOGGLE_LAYER_VISIBILITY:@@ -130,6 +141,17 @@ export function mapui(models, config, store) {models.date.events.on('select', updateDate);updateProjection(true);};+ const flyToNewExtent = function(extent, rotation) {+ let coordinateX = extent[0] + (extent[2] - extent[0]) / 2;+ let coordinateY = extent[1] + (extent[3] - extent[1]) / 2;+ let coordinates = [coordinateX, coordinateY];+ let resolution = self.selected.getView().getResolutionForExtent(extent);+ let zoom = self.selected.getView().getZoomForResolution(resolution);+ // Animate to extent, zoom & rotate:+ // Don't animate when an event is selected (Event selection already animates)+ return self.animate.fly(coordinates, zoom, rotation);+ };+/** Changes visual projection*@@ -141,6 +163,7 @@ export function mapui(models, config, store) {* @returns {void}*/var updateProjection = function(start) {+ console.log('update proj')const state = store.getState();const { proj } = state;if (self.selected) {@@ -277,7 +300,7 @@ export function mapui(models, config, store) {var layerGroupStr = compareState.isCompareA ? 'active' : 'activeB';var activeLayers = layers[layerGroupStr];if (!config.features.compare || !compareState.active) {- if (!compareState.active) {+ if (!compareState.active && compareMapUi.active) {compareMapUi.destroy();}clearLayers(map);diff --git a/web/js/modules/combine-reducers.js b/web/js/modules/combine-reducers.jsindex 5dc2b743d..c9a30f773 100644--- a/web/js/modules/combine-reducers.js+++ b/web/js/modules/combine-reducers.js@@ -12,6 +12,7 @@ import {eventsReducer,eventRequestResponse} from './natural-events/reducers';+import tourReducer from './tour/reducers';import {notificationsRequest,notificationsReducer@@ -80,6 +81,7 @@ const reducers = {events: eventsReducer,data: dataDownloadReducer,palettes: paletteReducer,+ tour: tourReducer,requestedEvents,requestedEventSources,requestedEventCategories,diff --git a/web/js/modules/date/util.js b/web/js/modules/date/util.jsindex e1bfab553..2529563fc 100644--- a/web/js/modules/date/util.js+++ b/web/js/modules/date/util.js@@ -32,15 +32,14 @@ export function getDateParameterSetup(? undefined: serializeDate(currentItemState);},- parse: () => {- return modelLoaded.selected;+ parse: str => {+ return tryCatchDate(str, initialState);}}},t1: {stateKey: 'legacy.date.selectedB',initialState: bInit,- type: 'date',options: {serializeNeedsGlobalState: true,serialize: (currentItemState, state) => {@@ -49,17 +48,18 @@ export function getDateParameterSetup(if (!currentItemState) currentItemState = bInit;return serializeDate(currentItemState || bInit);},- parse: () => {- return modelLoaded.selectedB || bInit;+ parse: str => {+ return tryCatchDate(str, bInit);}}},z: {stateKey: 'legacy.date.selectedZoom',initialState: 3,- type: 'number',options: {- parse: () => modelLoaded.selectedZoom,+ parse: str => {+ return str ? Number(str) : 3;+ },serialize: () => {return models.date.selectedZoom.toString();}@@ -84,3 +84,11 @@ export function getActiveTime(state) {const activeStr = compare.isCompareA ? 'selected' : 'selectedB';return legacy.date[activeStr];}+var tryCatchDate = function(str, initialState) {+ try {+ return util.parseDateUTC(str);+ } catch (error) {+ console.warn('Invalid date: ' + str);+ return initialState;+ }+};diff --git a/web/js/modules/map/util.js b/web/js/modules/map/util.jsindex be8fa2c29..aa9bc8f6f 100644--- a/web/js/modules/map/util.js+++ b/web/js/modules/map/util.js@@ -1,5 +1,10 @@import util from '../../util/util';import { encode } from '../link/util';+import {+ each as lodashEach,+ isUndefined as lodashIsUndefined,+ map as lodashMap+} from 'lodash';export function getMapParameterSetup(parameters,@@ -8,7 +13,7 @@ export function getMapParameterSetup(legacyState,errors) {- const loadedModel = models.map.load(legacyState, errors);+ models.map.load(legacyState, errors);const leadingExtent = getLeadingExtent();return {v: {@@ -17,11 +22,25 @@ export function getMapParameterSetup(type: 'array',options: {delimiter: ',',- parse: () => {- return loadedModel.extent || leadingExtent;+ parse: state => {+ var extent = lodashMap(state.split(','), function(str) {+ return parseFloat(str);+ });+ var valid = mapIsExtentValid(extent);+ if (!valid) {+ errors.push({+ message: 'Invalid extent: ' + state+ });+ return leadingExtent;+ } else {+ return extent;+ }},serialize: (currentItemState, currentState) => {- return encode(models.map.extent || leadingExtent);+ const extent = mapIsExtentValid(currentItemState)+ ? currentItemState+ : leadingExtent;+ return encode(extent);}}},@@ -29,8 +48,8 @@ export function getMapParameterSetup(stateKey: 'legacy.map.rotation',initialState: 0,options: {- parse: () => {- return loadedModel.rotation || 0;+ parse: state => {+ return !isNaN(state) ? state * (Math.PI / 180.0) : 0;},serialize: (currentItemState, currentState) => {return models.map.rotation@@ -41,7 +60,33 @@ export function getMapParameterSetup(}};}-+/**+ * Determines if an exent object contains valid values.+ *+ * @method isExtentValid+ * @static+ *+ * @param extent {OpenLayers.Bound} The extent to check.+ *+ * @return {boolean} False if any of the values is NaN, otherwise returns+ * true.+ */+export function mapIsExtentValid(extent) {+ if (lodashIsUndefined(extent)) {+ return false;+ }+ var valid = true;+ if (extent.toArray) {+ extent = extent.toArray();+ }+ lodashEach(extent, function(value) {+ if (isNaN(value)) {+ valid = false;+ return false;+ }+ });+ return valid;+}export function getLeadingExtent() {var curHour = util.now().getUTCHours();diff --git a/web/js/modules/modal/constants.js b/web/js/modules/modal/constants.jsindex bd3249d65..a5c95804b 100644--- a/web/js/modules/modal/constants.js+++ b/web/js/modules/modal/constants.js@@ -1,12 +1,14 @@-export const TOGGLE = 'TOGGLE_MODAL_OPEN';-export const OPEN_CUSTOM = 'OPEN_MODAL_WITH_CUSTOM_CONTENT';-export const OPEN_BASIC = 'OPEN_MODAL_WITH_BASIC_CONTENT';-export const RENDER_TEMPLATE = 'OPEN_MODAL_CONTAINING_LOADED_PAGE';--export const ABOUT_PAGE_REQUEST = 'MODAL_ABOUT_PAGE_REQUEST';-export const ABOUT_PAGE_REQUEST_START = 'MODAL_ABOUT_PAGE_REQUEST_START';-export const ABOUT_PAGE_REQUEST_FAILURE = 'MODAL_ABOUT_PAGE_REQUEST_FAILURE';-export const ABOUT_PAGE_REQUEST_SUCCESS = 'MODAL_ABOUT_PAGE_REQUEST_SUCCESS';+export const TOGGLE = 'MODAL/TOGGLE_MODAL_OPEN';+export const OPEN_CUSTOM = 'MODAL/OPEN_MODAL_WITH_CUSTOM_CONTENT';+export const OPEN_BASIC = 'MODAL/OPEN_MODAL_WITH_BASIC_CONTENT';+export const RENDER_TEMPLATE = 'MODAL/OPEN_MODAL_CONTAINING_LOADED_PAGE';+export const CLOSE = 'MODAL/CLOSE_MODAL';+export const ABOUT_PAGE_REQUEST = 'MODAL/MODAL_ABOUT_PAGE_REQUEST';+export const ABOUT_PAGE_REQUEST_START = 'MODAL/MODAL_ABOUT_PAGE_REQUEST_START';+export const ABOUT_PAGE_REQUEST_FAILURE =+ 'MODAL/MODAL_ABOUT_PAGE_REQUEST_FAILURE';+export const ABOUT_PAGE_REQUEST_SUCCESS =+ 'MODAL/MODAL_ABOUT_PAGE_REQUEST_SUCCESS';export const ABOUT_MOCK_RESPONSE = '<html>MOCK</html>';export const TEST_KEY = 'some-key-0000';diff --git a/web/js/modules/modal/reducers.js b/web/js/modules/modal/reducers.jsindex bc6a252c8..840da245e 100644--- a/web/js/modules/modal/reducers.js+++ b/web/js/modules/modal/reducers.js@@ -3,7 +3,8 @@ import {OPEN_CUSTOM,OPEN_BASIC,RENDER_TEMPLATE,- ABOUT_PAGE_REQUEST+ ABOUT_PAGE_REQUEST,+ CLOSE} from './constants';import { requestReducer } from '../core/reducers';import { assign as lodashAssign } from 'lodash';@@ -61,6 +62,10 @@ export function modalReducer(state = modalState, action) {template: action.template,customProps: {}});+ case CLOSE:+ return lodashAssign({}, state, {+ isOpen: false+ });default:return state;}diff --git a/web/js/modules/tour/actions.js b/web/js/modules/tour/actions.jsnew file mode 100644index 000000000..e4ca9f103--- /dev/null+++ b/web/js/modules/tour/actions.js@@ -0,0 +1,15 @@+import { START, UPDATE_SELECTED, END_TOUR } from './constants';+export function startTour() {+ return {+ type: START+ };+}+export function selectStory(id) {+ return {+ type: UPDATE_SELECTED,+ id+ };+}+export function endTour() {+ return { type: END_TOUR };+}diff --git a/web/js/modules/tour/constants.js b/web/js/modules/tour/constants.jsnew file mode 100644index 000000000..b3feac675--- /dev/null+++ b/web/js/modules/tour/constants.js@@ -0,0 +1,18 @@+import Tour from '../../containers/tour';+export const START = 'TOUR/START_TOUR';+export const UPDATE_SELECTED = 'TOUR/UPDATE_SELECTED_STORY';++const customModalProps = {+ backdrop: false,+ CompletelyCustomModal: Tour,+ clickableBehindModal: true+};++export const tourStartModalCustomProps = {+ isOpen: true,+ isCustom: true,+ customProps: customModalProps,+ id: 'TOUR__MODAL',+ headerText: '',+ bodyText: ''+};diff --git a/web/js/modules/tour/reducers.js b/web/js/modules/tour/reducers.jsnew file mode 100644index 000000000..db0556802--- /dev/null+++ b/web/js/modules/tour/reducers.js@@ -0,0 +1,29 @@+import { START, UPDATE_SELECTED, EXIT } from './constants';+import { assign as lodashAssign } from 'lodash';++const INITIAL_STATE = {+ selected: '',+ active: false+};++export default function tourReducer(state = INITIAL_STATE, action) {+ switch (action.type) {+ case EXIT:+ return lodashAssign({}, state, {+ selected: '',+ active: false+ });+ case START:+ return lodashAssign({}, state, {+ selected: '',+ active: true+ });+ case UPDATE_SELECTED:+ return lodashAssign({}, state, {+ selected: action.id,+ active: true+ });+ default:+ return state;+ }+}diff --git a/web/js/modules/tour/selectors.js b/web/js/modules/tour/selectors.jsnew file mode 100644index 000000000..e69de29bbdiff --git a/web/js/modules/tour/util.js b/web/js/modules/tour/util.jsindex 4471091ef..de2525ed3 100644--- a/web/js/modules/tour/util.js+++ b/web/js/modules/tour/util.js@@ -1,4 +1,6 @@import { cloneDeep as lodashCloneDeep, get } from 'lodash';+import googleTagManager from 'googleTagManager';+import util from '../../util/util';export function getTourParameterSetup(parameters,@@ -27,3 +29,37 @@ export function getTourParameterSetup(}};}+export function checkTourBuildTimestamp(config) {+ if (!util.browser.localStorage) return;+ var hideTour = localStorage.getItem('hideTour');++ // Don't start tour if coming in via a permalink+ if (window.location.search && !config.parameters.tour) {+ return false;+ }++ if (hideTour && config.buildDate) {+ let buildDate = new Date(config.buildDate);+ let tourDate = new Date(hideTour);+ // Tour hidden when visiting fresh URL+ googleTagManager.pushEvent({+ event: 'tour_start_hidden',+ buildDate: buildDate,+ tourDate: tourDate+ });+ if (buildDate > tourDate) {+ localStorage.removeItem('hideTour');+ return true;+ } else {+ return false;+ }+ } else if (hideTour) {+ return false;+ } else {+ // Tour shown when visiting fresh URL+ googleTagManager.pushEvent({+ event: 'tour_start'+ });+ return true;+ }+}diff --git a/web/js/redux-location-state-customs.js b/web/js/redux-location-state-customs.jsindex e20eb7944..fe492dfed 100644--- a/web/js/redux-location-state-customs.js+++ b/web/js/redux-location-state-customs.js@@ -7,7 +7,7 @@ import {import isEqualDate from 'date-fns/is_equal';import { typeHandles } from 'redux-location-state/lib/typeHandles';import { ENCODING_EXCEPTIONS } from './modules/link/constants';-+export const LOCATION_POP_ACTION = 'REDUX-LOCATION-POP-ACTION';function isNotDefined(value) {return typeof value === 'undefined' || value === null;}diff --git a/web/js/tour/ui.js b/web/js/tour/ui.jsindex 6ca3fddc7..078a817e7 100644--- a/web/js/tour/ui.js+++ b/web/js/tour/ui.js@@ -110,7 +110,7 @@ export function tourUi(models, ui, config) {event: 'tour_start_button'});self.reactComponent.setState({- modalStart: true,+ checkBuildTimestamp: true,modalInProgress: false,modalComplete: false,restartTour: true@@ -126,9 +126,6 @@ export function tourUi(models, ui, config) {let totalSteps = currentStory.steps;if (e) e.preventDefault();self.reactComponent.setState({- models: models,- config: config,- ui: ui,currentStep: 1,totalSteps: totalSteps.length,currentStoryIndex: currentStoryIndex,