Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

target map coordinates with joyride

Jason Kentec08a444f88c
diff --git a/web/js/components/tour/joyride-wrapper.js b/web/js/components/tour/joyride-wrapper.js
new file mode 100644
index 000000000..a84962938
--- /dev/null
+++ b/web/js/components/tour/joyride-wrapper.js
@@ -0,0 +1,105 @@
+import React, { useState, useEffect } from 'react';
+// import { connect } from 'react-redux';
+import PropTypes from 'prop-types';
+import Joyride from 'react-joyride';
+
+function JoyrideWrapper ({ tourSteps, currentTourStep, map }) {
+ const currentStepObj = tourSteps[currentTourStep - 1];
+ const joyrideProps = (currentStepObj || {}).joyride;
+ if (!joyrideProps) {
+ return null;
+ }
+
+ const {
+ continuous,
+ disableOverlayClose,
+ spotlightClicks,
+ steps,
+ } = joyrideProps;
+
+ const styleOptions = {
+ arrowColor: '#ccc',
+ backgroundColor: '#ccc',
+ beaconSize: 44,
+ overlayColor: 'rgba(0, 0, 0, 0.5)',
+ primaryColor: '#d54e21',
+ spotlightShadow: '0 0 25px rgba(0, 0, 0, 0.75)',
+ textColor: '#333',
+ width: undefined,
+ zIndex: 1050,
+ };
+
+ const [joyrideState, setJoyrideState] = useState({});
+ // const [overlayTarget, setOverlayTarget] = useState(false);
+
+ // useEffect(() => {
+ // if (overlayTarget) {
+ // overlayTarget.remove();
+ // setOverlayTarget(false);
+ // }
+ // }, [currentTourStep]);
+
+ useEffect(
+ () => {
+ const { step } = joyrideState;
+ if (map && step && step.targetCoordinates) {
+ const id = step.target.substr(1, step.target.length);
+ const placeholderEl = document.querySelector(id) || document.createElement('span');
+ const { topLeft, bottomRight } = step.targetCoordinates;
+ let [x1, y1] = map.getPixelFromCoordinate(topLeft) || [0, 0];
+ let [x2, y2] = map.getPixelFromCoordinate(bottomRight) || [0, 0];
+ x1 = x1.toFixed(0);
+ y1 = y1.toFixed(0);
+ x2 = x2.toFixed(0);
+ y2 = y2.toFixed(0);
+ placeholderEl.id = id;
+ placeholderEl.style.position = 'absolute';
+ placeholderEl.style.top = `${y1}px`;
+ placeholderEl.style.left = `${x1}px`;
+ placeholderEl.style.height = `${x2 - x1}px`;
+ placeholderEl.style.width = `${y2 - y1}px`;
+ placeholderEl.style.backgroundColor = 'rgba(255, 0, 0, 0.25)';
+ placeholderEl.style.zIndex = '0';
+ placeholderEl.style.pointerEvents = 'none';
+
+ if (!document.querySelector(step.target)) {
+ document.querySelector('body').appendChild(placeholderEl);
+ // setOverlayTarget(placeholderEl);
+ }
+ }
+ },
+ );
+
+ const joyrideStateCallback = (jState) => {
+ console.log(jState);
+ setJoyrideState(jState);
+ };
+
+ return !steps ? null : (
+ <Joyride
+ steps={steps}
+ continuous={continuous}
+ spotlightClicks={spotlightClicks}
+ disableOverlayClose={disableOverlayClose}
+ styles={{ options: styleOptions }}
+ callback={joyrideStateCallback}
+ disableScrolling
+ />
+ );
+}
+
+// const mapStateToProps = (state) => {
+// const { map } = state;
+// return {
+// map: map.ui.selected,
+// };
+// };
+
+// export default connect(mapStateToProps)(JoyrideWrapper);
+export default JoyrideWrapper;
+
+JoyrideWrapper.propTypes = {
+ currentTourStep: PropTypes.number,
+ map: PropTypes.object,
+ tourSteps: PropTypes.array,
+};
diff --git a/web/js/containers/tour.js b/web/js/containers/tour.js
index 344c10a40..d783efe87 100644
--- a/web/js/containers/tour.js
+++ b/web/js/containers/tour.js
@@ -5,8 +5,8 @@ import { connect } from 'react-redux';
import googleTagManager from 'googleTagManager';
import { findIndex as lodashFindIndex, get as lodashGet, uniqBy } from 'lodash';
import update from 'immutability-helper';
-import Joyride from 'react-joyride';
+import JoyrideWrapper from '../components/tour/joyride-wrapper';
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';
@@ -382,6 +382,7 @@ class Tour extends React.Component {
render() {
const {
+ map,
stories,
screenHeight,
screenWidth,
@@ -412,34 +413,14 @@ class Tour extends React.Component {
if (!modalStart && !modalInProgress && !modalComplete) {
this.setState({ modalStart: true });
}
-
-
- const joyride = (currentStep && currentStory.steps[currentStep - 1].joyride) || {};
- const {
- continuous, spotlightClicks, steps, disableOverlayClose,
- } = joyride;
- const styleOptions = {
- arrowColor: '#ccc',
- backgroundColor: '#ccc',
- beaconSize: 44,
- overlayColor: 'rgba(0, 0, 0, 0.5)',
- primaryColor: '#d54e21',
- spotlightShadow: '0 0 25px rgba(0, 0, 0, 0.75)',
- textColor: '#333',
- width: undefined,
- zIndex: 1050,
- };
-
return (
<ErrorBoundary>
<div>
- {joyride && (
- <Joyride
- steps={steps}
- continuous={continuous}
- spotlightClicks={spotlightClicks}
- disableOverlayClose={disableOverlayClose || false}
- styles={{ options: styleOptions }}
+ {currentStory && currentStory.steps && (
+ <JoyrideWrapper
+ currentTourStep={currentStep}
+ tourSteps={currentStory.steps}
+ map={map.ui.selected}
/>
)}
{modalStart
@@ -509,15 +490,16 @@ const mapDispatchToProps = (dispatch) => ({
});
function mapStateToProps(state) {
const {
- browser, config, tour, palettes,
+ browser, config, tour, palettes, models, compare, map,
} = state;
const { screenWidth, screenHeight } = browser;
return {
config,
isActive: tour.active,
- models: state.models,
- compareState: state.compare,
+ map,
+ models,
+ compareState: compare,
stories: config.stories,
storyOrder: config.storyOrder,
currentStoryId: tour.selected,
@@ -565,6 +547,7 @@ export default connect(
Tour.propTypes = {
config: PropTypes.object.isRequired,
hideTour: PropTypes.func.isRequired,
+ map: PropTypes.object,
selectTour: PropTypes.func.isRequired,
showTour: PropTypes.func.isRequired,
showTourAlert: PropTypes.func.isRequired,