Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Clicking wms point shows vector alert #2884

Benjamin King6378d9df9413
diff --git a/web/js/containers/alerts.js b/web/js/containers/alerts.js
index 4c07d9677..91ddc49a6 100644
--- a/web/js/containers/alerts.js
+++ b/web/js/containers/alerts.js
@@ -5,8 +5,11 @@ import PropTypes from 'prop-types';
import AlertUtil from '../components/util/alert';
import EventsAlertModalBody from '../components/events/alert-body';
import CompareAlertModalBody from '../components/compare/alert';
+import VectorAlertModalBody from '../components/layer/vector/alert';
import { openCustomContent } from '../modules/modal/actions';
import util from '../util/util';
+import { hasVectorLayers } from '../modules/layers/util';
+import { DISABLE_VECTOR_ALERT } from '../modules/alerts/constants';
const MODAL_PROPERTIES = {
eventModalProps: {
@@ -31,9 +34,19 @@ const MODAL_PROPERTIES = {
desktopOnly: true,
},
},
+ vectorModalProps: {
+ id: 'vector_layer_info',
+ props: {
+ headerText: 'Vector features may not be clickable at all times.',
+ backdrop: false,
+ size: 'lg',
+ clickableBehindModal: true,
+ bodyComponent: VectorAlertModalBody,
+ desktopOnly: true,
+ },
+ },
};
const HAS_LOCAL_STORAGE = util.browser.localStorage;
-
class DismissableAlerts extends React.Component {
constructor(props) {
super(props);
@@ -58,10 +71,10 @@ class DismissableAlerts extends React.Component {
render() {
const {
- isEventsActive, isCompareActive, openAlertModal, isSmall,
+ isEventsActive, isCompareActive, isVectorAlertPresent, dismissVectorAlert, openAlertModal, isSmall,
} = this.props;
const { hasDismissedEvents, hasDismissedCompare } = this.state;
- const { eventModalProps, compareModalProps } = MODAL_PROPERTIES;
+ const { eventModalProps, compareModalProps, vectorModalProps } = MODAL_PROPERTIES;
if (isSmall || !HAS_LOCAL_STORAGE) return null;
return (
<>
@@ -84,6 +97,15 @@ class DismissableAlerts extends React.Component {
message="You are now in comparison mode."
/>
) : null}
+ {isVectorAlertPresent ? (
+ <AlertUtil
+ isOpen
+ noPortal
+ onClick={() => openAlertModal(vectorModalProps)}
+ onDismiss={dismissVectorAlert}
+ message="Vector features may not be clickable at every zoom level."
+ />
+ ) : null}
</>
);
}
@@ -92,16 +114,20 @@ const mapDispatchToProps = (dispatch) => ({
openAlertModal: ({ id, props }) => {
dispatch(openCustomContent(id, props));
},
+ dismissVectorAlert: () => dispatch({ type: DISABLE_VECTOR_ALERT }),
});
const mapStateToProps = (state) => {
const {
- browser, events, sidebar, compare,
+ browser, events, sidebar, compare, layers, alerts,
} = state;
+ const { activeString } = compare;
+ const { isVectorAlertActive } = alerts;
return {
isSmall: browser.lessThan.small,
isEventsActive: !!(events.selected.id && sidebar.activeTab === 'events'),
isCompareActive: compare.active,
+ isVectorAlertPresent: hasVectorLayers(layers[activeString]) && isVectorAlertActive,
};
};
export default connect(
@@ -114,4 +140,6 @@ DismissableAlerts.propTypes = {
isCompareActive: PropTypes.bool,
openAlertModal: PropTypes.func,
isSmall: PropTypes.bool,
+ isVectorAlertPresent: PropTypes.bool,
+ dismissVectorAlert: PropTypes.func,
};
diff --git a/web/js/containers/map-interactions.js b/web/js/containers/map-interactions.js
index ca29fbf05..8d4402da0 100644
--- a/web/js/containers/map-interactions.js
+++ b/web/js/containers/map-interactions.js
@@ -9,62 +9,30 @@ import { openCustomContent, onClose } from '../modules/modal/actions';
import { selectVectorFeatures as selectVectorFeaturesActionCreator } from '../modules/vector-styles/actions';
import { changeCursor as changeCursorActionCreator } from '../modules/map/actions';
import { isFromActiveCompareRegion } from '../modules/compare/util';
-import { hasNonClickableVectorLayer, hasVectorLayers } from '../modules/layers/util';
-import util from '../util/util';
-import VectorAlertModalBody from '../components/layer/vector/alert';
-import AlertUtil from '../components/util/alert';
+import { hasNonClickableVectorLayer } from '../modules/layers/util';
+import { ACTIVATE_VECTOR_ALERT } from '../modules/alerts/constants';
-const VECTOR_MODAL_PROPS = {
- id: 'vector_layer_info',
- props: {
- headerText: 'Vector features may not be clickable at all times.',
- backdrop: false,
- size: 'lg',
- clickableBehindModal: true,
- bodyComponent: VectorAlertModalBody,
- desktopOnly: true,
- },
-};
export class MapInteractions extends React.Component {
constructor(props) {
super(props);
- this.state = {
- isVectorAlertActive: false,
- };
this.mouseMove = lodashDebounce(this.mouseMove.bind(this), 8);
this.singleClick = this.singleClick.bind(this);
- this.toggleVectorAlert = this.toggleVectorAlert.bind(this);
this.registerMouseListeners();
}
- static getDerivedStateFromProps(props, state) {
- if (
- !props.isVectorLayerPresent
- && state.isVectorAlertActive
- ) {
- return {
- isVectorAlertActive: false,
- };
- }
- return null;
- }
-
registerMouseListeners() {
const { mouseEvents } = this.props;
mouseEvents.on('mousemove', this.mouseMove);
mouseEvents.on('singleclick', this.singleClick);
}
- toggleVectorAlert() {
- const { isVectorAlertActive } = this.state;
- this.setState({ isVectorAlertActive: !isVectorAlertActive });
- }
singleClick(e, map) {
const {
lastSelected, openVectorDiaglog, onCloseModal, selectVectorFeatures,
modalState, getDialogObject, measureIsActive, isMobile, activeLayers,
+ activateVectorAlert,
} = this.props;
if (measureIsActive) return;
@@ -83,8 +51,8 @@ export class MapInteractions extends React.Component {
const mapRes = map.getView().getResolution();
const hasNonClickableVectorLayerType = hasNonClickableVectorLayer(activeLayers, mapRes);
- if (hasNonClickableVectorLayerType && util.browser.localStorage) {
- this.toggleVectorAlert();
+ if (hasNonClickableVectorLayerType) {
+ activateVectorAlert();
}
}
if (Object.entries(selected).length || (Object.entries(lastSelected).length && !isVectorModalOpen)) {
@@ -128,9 +96,7 @@ export class MapInteractions extends React.Component {
isDistractionFreeModeActive,
isShowingClick,
mouseEvents,
- openCustomAlertModal,
} = this.props;
- const { isVectorAlertActive } = this.state;
let mapClasses = isShowingClick
? 'wv-map cursor-pointer'
: 'wv-map';
@@ -146,14 +112,6 @@ export class MapInteractions extends React.Component {
<OlCoordinates
mouseEvents={mouseEvents}
/>
- {isVectorAlertActive && (
- <AlertUtil
- isOpen
- onClick={() => openCustomAlertModal(VECTOR_MODAL_PROPS)}
- onDismiss={this.toggleVectorAlert}
- message="Vector features may not be clickable at all times."
- />
- )}
</>
)}
@@ -176,6 +134,7 @@ const mapDispatchToProps = (dispatch) => ({
onCloseModal: () => {
dispatch(onClose());
},
+ activateVectorAlert: () => dispatch({ type: ACTIVATE_VECTOR_ALERT }),
openVectorDiaglog: (dialogId, metaArray, offsetLeft, offsetTop, isMobile) => {
const dialogKey = new Date().getUTCMilliseconds();
dispatch(openCustomContent(dialogId,
@@ -228,7 +187,6 @@ function mapStateToProps(state) {
swipeOffset,
proj,
activeLayers,
- isVectorLayerPresent: hasVectorLayers(activeLayers),
};
}
MapInteractions.propTypes = {
@@ -248,8 +206,7 @@ MapInteractions.propTypes = {
proj: PropTypes.object,
swipeOffset: PropTypes.number,
activeLayers: PropTypes.array,
- openCustomAlertModal: PropTypes.func,
- isVectorLayerPresent: PropTypes.bool,
+ activateVectorAlert: PropTypes.func,
};
export default connect(
mapStateToProps,
diff --git a/web/js/modules/alerts/constants.js b/web/js/modules/alerts/constants.js
new file mode 100644
index 000000000..c47e88bab
--- /dev/null
+++ b/web/js/modules/alerts/constants.js
@@ -0,0 +1,3 @@
+export const TOGGLE_VECTOR_ALERT = 'ALERTS/TOGGLE_VECTOR_ALERT';
+export const DISABLE_VECTOR_ALERT = 'ALERTS/DISABLE_VECTOR_ALERT';
+export const ACTIVATE_VECTOR_ALERT = 'ALERTS/ACTIVATE_VECTOR_ALERT';
diff --git a/web/js/modules/alerts/reducer.js b/web/js/modules/alerts/reducer.js
new file mode 100644
index 000000000..d56afc635
--- /dev/null
+++ b/web/js/modules/alerts/reducer.js
@@ -0,0 +1,25 @@
+import { assign as lodashAssign } from 'lodash';
+import { TOGGLE_VECTOR_ALERT, DISABLE_VECTOR_ALERT, ACTIVATE_VECTOR_ALERT } from './constants';
+
+export const defaultAlertState = {
+ isVectorAlertActive: false,
+};
+
+export function alertReducer(state = defaultAlertState, action) {
+ switch (action.type) {
+ case TOGGLE_VECTOR_ALERT:
+ return lodashAssign({}, state, {
+ isVectorAlertActive: !state.isVectorAlertActive,
+ });
+ case DISABLE_VECTOR_ALERT:
+ return lodashAssign({}, state, {
+ isVectorAlertActive: false,
+ });
+ case ACTIVATE_VECTOR_ALERT:
+ return lodashAssign({}, state, {
+ isVectorAlertActive: true,
+ });
+ default:
+ return state;
+ }
+}
diff --git a/web/js/modules/combine-reducers.js b/web/js/modules/combine-reducers.js
index 191db82ac..9f2c3ec69 100644
--- a/web/js/modules/combine-reducers.js
+++ b/web/js/modules/combine-reducers.js
@@ -45,6 +45,7 @@ import {
import { LOCATION_POP_ACTION } from '../redux-location-state-customs';
import uiReducers from './ui/reducers';
+import { alertReducer } from './alerts/reducer';
function lastAction(state = null, action) {
return action;
@@ -99,6 +100,7 @@ const locationReducer = (state = { key: '' }, action) => {
};
const defaultReducer = (state = {}) => state;
const reducers = {
+ alerts: alertReducer,
proj: projectionReducer,
modal: modalReducer,
date: dateReducer,
diff --git a/web/js/modules/layers/actions.js b/web/js/modules/layers/actions.js
index bba91beb8..a3bfa5a13 100644
--- a/web/js/modules/layers/actions.js
+++ b/web/js/modules/layers/actions.js
@@ -1,5 +1,6 @@
import { findIndex as lodashFindIndex } from 'lodash';
import googleTagManager from 'googleTagManager';
+import update from 'immutability-helper';
import {
addLayer as addLayerSelector,
resetLayers as resetLayersSelector,
@@ -131,7 +132,9 @@ export function toggleVisibility(id, visible) {
}
export function removeLayer(id) {
return (dispatch, getState) => {
- const { layers, compare, data } = getState();
+ const {
+ layers, compare, data, alerts,
+ } = getState();
const { activeString } = compare;
const index = lodashFindIndex(layers[activeString], {
id,
@@ -144,12 +147,16 @@ export function removeLayer(id) {
if (def.product && def.product === data.selectedProduct) {
dispatch(selectProduct('')); // Clear selected Data product
}
+ if (alerts.isVectorAlertActive) {
+ // dispatch({ type: DISABLE_VECTOR_ALERT });
+ }
dispatch({
type: REMOVE_LAYER,
id,
index,
activeString,
def,
+ layers: update(layers[activeString], { $splice: [[index, 1]] }),
});
};
}
diff --git a/web/js/modules/layers/reducers.js b/web/js/modules/layers/reducers.js
index 4b342e672..5b51a20a4 100644
--- a/web/js/modules/layers/reducers.js
+++ b/web/js/modules/layers/reducers.js
@@ -51,6 +51,7 @@ export function layerReducer(state = initialState, action) {
case ADD_LAYER:
case REORDER_LAYER_GROUP:
case ADD_LAYERS_FOR_EVENT:
+ case REMOVE_LAYER:
return lodashAssign({}, state, {
[layerGroupStr]: action.layers,
});
@@ -151,10 +152,6 @@ export function layerReducer(state = initialState, action) {
},
});
}
- case REMOVE_LAYER:
- return update(state, {
- [layerGroupStr]: { $splice: [[action.index, 1]] },
- });
case UPDATE_OPACITY:
return update(state, {
[layerGroupStr]: {
diff --git a/web/js/modules/layers/util.js b/web/js/modules/layers/util.js
index 73d0edc0d..4fbf2f22a 100644
--- a/web/js/modules/layers/util.js
+++ b/web/js/modules/layers/util.js
@@ -1227,7 +1227,7 @@ export function mapLocationToLayerState(
}
/**
* Determine if active layers have a vector layer
- * @param {Object} layersState
+ * @param {Array} activeLayers
* @param {Object} compareState
*
* @return {Boolean}
@@ -1278,7 +1278,7 @@ export const hasNonClickableVectorLayer = (activeLayers, mapRes) => {
const def = activeLayers[i];
if (def.type === 'vector' && def.visible) {
isNonClickableVectorLayer = !isVectorLayerClickable(def, mapRes);
- break;
+ if (isNonClickableVectorLayer) break;
}
}
return isNonClickableVectorLayer;