Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

prevent vector click on non-active compare modes #2465

Benjamin King88095861213d
diff --git a/web/js/containers/map-interactions.js b/web/js/containers/map-interactions.js
index 7e45cafb0..7a531b03b 100644
--- a/web/js/containers/map-interactions.js
+++ b/web/js/containers/map-interactions.js
@@ -8,6 +8,7 @@ import { openCustomContent, onClose } from '../modules/modal/actions';
import { selectVectorFeatures } from '../modules/vector-styles/actions';
import { groupBy as lodashGroupBy, debounce as lodashDebounce } from 'lodash';
import { changeCursor } from '../modules/map/actions';
+import { isFromActiveCompareRegion } from '../modules/compare/util';
export class MapInteractions extends React.Component {
constructor(props) {
@@ -48,14 +49,20 @@ export class MapInteractions extends React.Component {
mouseMove(event, map, crs) {
const pixels = map.getEventPixel(event);
const coord = map.getCoordinateFromPixel(pixels);
- const { isShowingClick, changeCursor, measureIsActive } = this.props;
+ const { isShowingClick, changeCursor, measureIsActive, compareState, swipeOffset } = this.props;
const [lon, lat] = coord;
if (lon < -180 || lon > 180 || lat < -90 || lat > 90) {
return;
}
const hasFeatures = map.hasFeatureAtPixel(pixels);
if (hasFeatures && !isShowingClick && !measureIsActive) {
- changeCursor(true);
+ let isActiveLayer = false;
+ map.forEachFeatureAtPixel(pixels, function(feature, layer) {
+ if (isFromActiveCompareRegion(map, pixels, layer.wv, compareState, swipeOffset)) {
+ isActiveLayer = true;
+ }
+ });
+ if (isActiveLayer) changeCursor(true);
} else if (!hasFeatures && isShowingClick) {
changeCursor(false);
}
@@ -114,14 +121,21 @@ const mapDispatchToProps = dispatch => ({
}
});
function mapStateToProps(state) {
- const { modal, map, measure, vectorStyles, browser } = state;
+ const { modal, map, measure, vectorStyles, browser, compare } = state;
+ let swipeOffset;
+ if (compare.active && compare.mode === 'swipe') {
+ const percentOffset = state.compare.value || 50;
+ swipeOffset = browser.screenWidth * (percentOffset / 100);
+ }
return {
modalState: modal,
isShowingClick: map.isClickable,
- getDialogObject: (pixels, map) => { return onMapClickGetVectorFeatures(pixels, map, state); },
+ getDialogObject: (pixels, map) => onMapClickGetVectorFeatures(pixels, map, state, swipeOffset),
lastSelected: vectorStyles.selected,
measureIsActive: measure.isActive,
- isMobile: browser.lessThan.medium
+ isMobile: browser.lessThan.medium,
+ compareState: compare,
+ swipeOffset
};
}
MapInteractions.propTypes = {
@@ -134,6 +148,7 @@ MapInteractions.propTypes = {
onCloseModal: PropTypes.func.isRequired,
openVectorDiaglog: PropTypes.func.isRequired,
selectVectorFeatures: PropTypes.func.isRequired,
+ compareState: PropTypes.object,
isMobile: PropTypes.bool,
lastSelected: PropTypes.object
};
diff --git a/web/js/map/runningdata.js b/web/js/map/runningdata.js
index ad8747efd..f42dc6abc 100644
--- a/web/js/map/runningdata.js
+++ b/web/js/map/runningdata.js
@@ -9,7 +9,9 @@ import {
runningData as runningDataAction,
clearRunningData as clearRunningDataAction
} from '../modules/map/actions';
-
+import {
+ isFromActiveCompareRegion
+} from '../modules/compare/util';
export function MapRunningData(models, compareUi, store) {
var self;
@@ -24,34 +26,6 @@ export function MapRunningData(models, compareUi, store) {
store.dispatch(clearRunningDataAction());
}
};
- /**
- * When in A|B only show Running-data from active side of Map while in swipe mode -
- * No other modes will allow for running-data
- * @param {Object} map | OL map object
- * @param {Array} coords | Coordinates of hover point
- * @param {Object} layerAttributes | Layer Properties
- */
- var isFromActiveCompareRegion = function(map, coords, layerAttributes) {
- var compareModel = store.getState().compare;
- if (compareModel && compareModel.active) {
- if (compareModel.mode !== 'swipe') {
- return false;
- } else {
- const swipeOffset = Math.floor(compareUi.getOffset());
-
- if (compareModel.isCompareA) {
- if (coords[0] > swipeOffset || layerAttributes.group !== 'active') {
- return false;
- }
- } else {
- if (coords[0] < swipeOffset || layerAttributes.group !== 'activeB') {
- return false;
- }
- }
- }
- }
- return true;
- };
/*
* Compare old and new arrays to determine which Layers need to be
* removed
@@ -69,9 +43,14 @@ export function MapRunningData(models, compareUi, store) {
const state = store.getState();
const activeLayerObj = {};
const [lon, lat] = map.getCoordinateFromPixel(pixels);
+ let swipeOffset;
+ if (compareUi && state.compare.active) {
+ swipeOffset = Math.floor(compareUi.getOffset());
+ }
+
if (!(lon < -180 || lon > 180 || lat < -90 || lat > 90)) {
map.forEachFeatureAtPixel(pixels, (feature, layer) => {
- if (!layer.wv || !layer.wv.def || !isFromActiveCompareRegion(map, pixels, layer.wv)) return;
+ if (!layer.wv || !layer.wv.def || !isFromActiveCompareRegion(map, pixels, layer.wv, state.compare, swipeOffset)) return;
let color;
const def = layer.wv.def;
const identifier = def.palette.styleProperty;
@@ -99,7 +78,7 @@ export function MapRunningData(models, compareUi, store) {
map.forEachLayerAtPixel(pixels, function(layer, data) {
if (!layer.wv) return;
const { def } = layer.wv;
- if (!isFromActiveCompareRegion(map, pixels, layer.wv)) return;
+ if (!isFromActiveCompareRegion(map, pixels, layer.wv, state.compare, swipeOffset)) return;
if (def.palette && !lodashGet(layer, 'wv.def.disableHoverValue')) {
activeLayerObj[def.id] = {
paletteLegends: getPalette(def.id, undefined, undefined, state),
diff --git a/web/js/modules/compare/util.js b/web/js/modules/compare/util.js
index 9b61834e9..1821a6510 100644
--- a/web/js/modules/compare/util.js
+++ b/web/js/modules/compare/util.js
@@ -21,3 +21,28 @@ export function mapLocationToCompareState(parameters, stateFromLocation) {
}
return stateFromLocation;
}
+/**
+ * Is layer on active side of Map while in swipe mode -
+ * No other modes will allow for running-data or vector interactions
+ * @param {Object} map | OL map object
+ * @param {Array} coords | Coordinates of hover point
+ * @param {Object} layerAttributes | Layer Properties
+ */
+export function isFromActiveCompareRegion(map, coords, layerAttributes, compareModel, swipeOffset) {
+ if (compareModel && compareModel.active) {
+ if (compareModel.mode !== 'swipe') {
+ return false;
+ } else {
+ if (compareModel.isCompareA) {
+ if (coords[0] > swipeOffset || layerAttributes.group !== 'active') {
+ return false;
+ }
+ } else {
+ if (coords[0] < swipeOffset || layerAttributes.group !== 'activeB') {
+ return false;
+ }
+ }
+ }
+ }
+ return true;
+};
diff --git a/web/js/modules/vector-styles/util.js b/web/js/modules/vector-styles/util.js
index df1d47552..977ba260c 100644
--- a/web/js/modules/vector-styles/util.js
+++ b/web/js/modules/vector-styles/util.js
@@ -5,7 +5,7 @@ import {
} from 'lodash';
import { Stroke, Style, Fill, Circle } from 'ol/style';
import { setStyleFunction } from './selectors';
-
+import { isFromActiveCompareRegion } from '../compare/util';
export function getVectorStyleAttributeArray(layer) {
var isCustomActive = false;
var isMinActive = false;
@@ -138,7 +138,7 @@ export function getPaletteForStyle(layer, layerstyleLayerObject) {
id: layer.id + '0_legend'
}];
}
-export function onMapClickGetVectorFeatures(pixels, map, state) {
+export function onMapClickGetVectorFeatures(pixels, map, state, swipeOffset) {
const metaArray = [];
const selected = {};
const config = state.config;
@@ -167,6 +167,7 @@ export function onMapClickGetVectorFeatures(pixels, map, state) {
map.forEachFeatureAtPixel(pixels, function(feature, layer) {
const def = lodashGet(layer, 'wv.def');
if (!def) return;
+ if (!isFromActiveCompareRegion(map, pixels, layer.wv, state.compare, swipeOffset)) return;
if (def.vectorData && def.vectorData.id && def.title) {
const layerId = def.id;
if (!selected[layerId]) selected[layerId] = [];