Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

add hover events to vectors #2144

Benjamin Kingad0b8eed5fef
diff --git a/web/js/containers/modal.js b/web/js/containers/modal.js
index e23cccbe5..0437ba354 100644
--- a/web/js/containers/modal.js
+++ b/web/js/containers/modal.js
@@ -126,7 +126,7 @@ class ModalContainer extends Component {
fade={!isDraggable}
>
{CompletelyCustomModal
- ? (<CompletelyCustomModal {...customProps} />)
+ ? (<CompletelyCustomModal {...customProps} toggleWithClose={toggleWithClose} />)
: (
<DetectOuterClick
onClick={toggleWithClose}
diff --git a/web/js/map/ui.js b/web/js/map/ui.js
index b444e576a..4e42303a8 100644
--- a/web/js/map/ui.js
+++ b/web/js/map/ui.js
@@ -1,7 +1,4 @@
-import lodashFindIndex from 'lodash/findIndex';
-import lodashEach from 'lodash/each';
-import lodashForOwn from 'lodash/forOwn';
-import lodashThrottle from 'lodash/throttle';
+import { groupBy, chain as lodashChain, throttle as lodashThrottle, forOwn as lodashForOwn, each as lodashEach, findIndex as lodashFindIndex } from 'lodash';
import util from '../util/util';
import OlMap from 'ol/Map';
import OlView from 'ol/View';
@@ -33,7 +30,6 @@ import { CHANGE_PROJECTION } from '../modules/projection/constants';
import { SELECT_DATE } from '../modules/date/constants';
import { openCustomContent } from '../modules/modal/actions';
import { CHANGE_UNITS, USE_GREAT_CIRCLE } from '../modules/measure/constants';
-import VectorMetaTable from '../components/vector-metadata/table';
import Cache from 'cachai';
import * as layerConstants from '../modules/layers/constants';
import * as compareConstants from '../modules/compare/constants';
@@ -53,6 +49,8 @@ import {
} from 'lodash';
import { CLEAR_ROTATE, RENDERED, UPDATE_MAP_UI, FITTED_TO_LEADING_EXTENT } from '../modules/map/constants';
import { getLeadingExtent } from '../modules/map/util';
+import vectorDialog from '../containers/vector-dialog';
+import { setSelected } from '../modules/vector-styles/actions';
export function mapui(models, config, store, ui) {
var layerBuilder, createLayer;
@@ -993,51 +991,55 @@ export function mapui(models, config, store, ui) {
};
map.on('rendercomplete', onRenderComplete);
map.on('click', function (e) {
- var metaTitle;
- var def;
- var metaArray = [];
-
+ let metaArray = [];
+ let selectedIdArray = [];
+ let selectedFeatures = [];
+ let defs = [];
+ const state = store.getState();
+ const vectorStyles = config.vectorStyles;
map.forEachFeatureAtPixel(e.pixel, function (feature, layer) {
- def = lodashGet(layer, 'wv.def');
+ const def = lodashGet(layer, 'wv.def');
if (!def) return;
- metaTitle = def.title;
- if (def.vectorData && def.vectorData.id) {
+
+ if (def.vectorData && def.vectorData.id && def.title) {
const features = feature.getProperties();
const vectorDataId = def.vectorData.id;
const data = config.vectorData[vectorDataId];
const obj = {
legend: data,
- features: features
+ features: features,
+ id: vectorDataId,
+ title: def['feature-title'] ? features[def['feature-title']] : '',
+ featureId: vectorDataId + features[def['feature-id']]
};
metaArray.push(obj);
+ selectedIdArray.push(vectorDataId);
+ selectedFeatures.push(features[def['feature-id']]);
+ defs.push(def);
}
});
+ if (metaArray.length) {
+ //https://stackoverflow.com/a/23600960/4589331
+ const dialogObject = groupBy(metaArray, 'id');
+ defs.forEach((def) => {
+ setStyleFunction(def, def.vectorStyle.id, vectorStyles, null, state, { id: selectedIdArray, features: selectedFeatures });
+ })
- var uniqueMeta = metaArray
- .map(e => e.layer)
- .map((e, i, final) => final.indexOf(e) === i && i)
- .filter(e => metaArray[e]).map(e => metaArray[e]);
-
- if (uniqueMeta.length) {
- const vectorPointMeta = uniqueMeta[0];
- const vectorDataId = def.vectorData.id;
- const legend = vectorPointMeta.legend;
- const features = vectorPointMeta.features;
- store.dispatch(openCustomContent('Vector' + vectorDataId,
+ store.dispatch(openCustomContent('Vector-dialog' + e.pixel[0] + e.pixel[1],
{
- headerText: metaTitle,
backdrop: false,
clickableBehindModal: true,
desktopOnly: true,
+ isDraggable: true,
wrapClassName: 'vector-modal-wrap',
modalClassName: 'vector-modal light',
- bodyComponent: VectorMetaTable,
- bodyComponentProps: {
- metaTitle: metaTitle,
- metaFeatures: features,
- metaLegend: legend
- },
- isDraggable: true
+ CompletelyCustomModal: vectorDialog,
+ customProps: { vectorMetaObject: dialogObject },
+ onClose: () => {
+ defs.forEach((def) => {
+ setStyleFunction(def, def.vectorStyle.id, vectorStyles, null, state, { id: selectedIdArray, features: selectedFeatures, reset: true })
+ })
+ }
}
));
};
diff --git a/web/js/modules/vector-styles/selectors.js b/web/js/modules/vector-styles/selectors.js
index dd09aaaa8..5f3e48ec6 100644
--- a/web/js/modules/vector-styles/selectors.js
+++ b/web/js/modules/vector-styles/selectors.js
@@ -9,6 +9,7 @@ import {
import { getMinValue, getMaxValue } from './util';
import update from 'immutability-helper';
import stylefunction from 'ol-mapbox-style/stylefunction';
+import { Stroke, Style, Fill } from 'ol/style';
/**
* Gets a single colormap (entries / legend combo)
@@ -53,7 +54,7 @@ export function findIndex(layerId, type, value, index, groupStr, state) {
index = index || 0;
var values = getVectorStyle(layerId, index, groupStr, state).entries.values;
var result;
- lodashEach(values, function(check, index) {
+ lodashEach(values, function (check, index) {
var min = getMinValue(check);
var max = getMaxValue(check);
if (type === 'min' && value === min) {
@@ -73,7 +74,8 @@ export function setRange(layerId, props, index, palettes, state) {
return (layerId, props, index, palettes, state);
}
-export function setStyleFunction(def, vectorStyleId, vectorStyles, layer, state) {
+export function setStyleFunction(def, vectorStyleId, vectorStyles, layer, state, selected) {
+ selected = selected || {};
var styleFunction;
var layerId = def.id;
var glStyle = vectorStyles[layerId];
@@ -99,7 +101,7 @@ export function setStyleFunction(def, vectorStyleId, vectorStyles, layer, state)
: null;
}
}
- lodashEach(activeLayers, function(def) {
+ lodashEach(activeLayers, function (def) {
if (!['subdaily', 'daily', 'monthly', 'yearly'].includes(def.period)) {
return;
}
@@ -124,11 +126,10 @@ export function setStyleFunction(def, vectorStyleId, vectorStyles, layer, state)
// Apply mapbox-gl styles
styleFunction = stylefunction(layer, glStyle, vectorStyleId);
-
// Filter Orbit Tracks
if (glStyle.name === 'Orbit Tracks') {
// Filter time by 5 mins
- layer.setStyle(function(feature, resolution) {
+ layer.setStyle(function (feature, resolution) {
var minute;
var minutes = feature.get('label');
if (minutes) {
@@ -138,6 +139,21 @@ export function setStyleFunction(def, vectorStyleId, vectorStyles, layer, state)
return styleFunction(feature, resolution);
}
});
+ } else if (glStyle.name === 'SEDAC' && selected.id && selected.id.includes(def.vectorData.id)) {
+ const selectedFeatures = selected.features;
+ const featureIdentifier = def['feature-id'];
+ layer.setStyle(function (feature, resolution) {
+ const selectedFeature = selectedFeatures.includes(feature.get(featureIdentifier));
+ if (selectedFeature && !selected.reset) {
+ console.log(selectedFeature);
+ return styleFunction(feature, resolution, { selected: 'true' });
+ } else if (selectedFeature && selected.reset) {
+ return styleFunction(feature, resolution, { selected: 'false' });
+ } else {
+ return styleFunction(feature, resolution);
+ }
+
+ });
}
return vectorStyleId;
}
@@ -183,7 +199,7 @@ export function clearStyleFunction(def, vectorStyleId, vectorStyles, layer, stat
styleFunction = stylefunction(layer, glStyle, vectorStyleId);
if (glStyle.name === 'Orbit Tracks') {
// Filter time by 5 mins
- layer.setStyle(function(feature, resolution) {
+ layer.setStyle(function (feature, resolution) {
var minute;
var minutes = feature.get('label');
if (minutes) {