Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Make wrapper syle function for click events #2144

Benjamin King53948404c1f9
diff --git a/web/js/map/ui.js b/web/js/map/ui.js
index 4e42303a8..223701ddf 100644
--- a/web/js/map/ui.js
+++ b/web/js/map/ui.js
@@ -1,4 +1,4 @@
-import { groupBy, chain as lodashChain, throttle as lodashThrottle, forOwn as lodashForOwn, each as lodashEach, findIndex as lodashFindIndex } from 'lodash';
+import { groupBy, orderBy as lodashOrderBy, 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';
@@ -998,19 +998,22 @@ export function mapui(models, config, store, ui) {
const state = store.getState();
const vectorStyles = config.vectorStyles;
map.forEachFeatureAtPixel(e.pixel, function (feature, layer) {
+ console.log(feature, layer)
const def = lodashGet(layer, 'wv.def');
if (!def) return;
if (def.vectorData && def.vectorData.id && def.title) {
- const features = feature.getProperties();
+ let features = feature.getProperties();
const vectorDataId = def.vectorData.id;
const data = config.vectorData[vectorDataId];
+ const sortArray = def['feature-sort-order'] || [];
const obj = {
legend: data,
- features: features,
+ features: features, //orderObjectToArray(features, sortArray),
id: vectorDataId,
title: def['feature-title'] ? features[def['feature-title']] : '',
- featureId: vectorDataId + features[def['feature-id']]
+ featureId: vectorDataId + features[def['feature-id']],
+ sortOrder: def['feature-sort-order']
};
metaArray.push(obj);
selectedIdArray.push(vectorDataId);
@@ -1037,7 +1040,7 @@ export function mapui(models, config, store, ui) {
customProps: { vectorMetaObject: dialogObject },
onClose: () => {
defs.forEach((def) => {
- setStyleFunction(def, def.vectorStyle.id, vectorStyles, null, state, { id: selectedIdArray, features: selectedFeatures, reset: true })
+ setStyleFunction(def, def.vectorStyle.id, vectorStyles, null, state)
})
}
}
@@ -1212,3 +1215,18 @@ export function mapui(models, config, store, ui) {
init();
return self;
}
+function orderObjectToArray(obj, sortValues) {
+ let newArray = [];
+ for (let i = 0, len = sortValues.length; i < len; i++) {
+ const sortKey = sortValues[i];
+ const property = obj[sortKey];
+ if (property) {
+ newArray.push(obj[sortKey]);
+ delete obj[sortKey];
+ }
+ }
+ for (k in obj) {
+ newArray.push(newArray);
+ }
+ return newArray;
+}
\ No newline at end of file
diff --git a/web/js/modules/vector-styles/selectors.js b/web/js/modules/vector-styles/selectors.js
index 3b57e1ca9..a65f5ca8e 100644
--- a/web/js/modules/vector-styles/selectors.js
+++ b/web/js/modules/vector-styles/selectors.js
@@ -6,10 +6,9 @@ import {
import {
getLayers
} from '../layers/selectors';
-import { getMinValue, getMaxValue } from './util';
+import { getMinValue, getMaxValue, selectedStyleFunction } 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)
@@ -135,7 +134,7 @@ export function setStyleFunction(def, vectorStyleId, vectorStyles, layer, state,
if (minutes) {
minute = minutes.split(':');
}
- if ((minute && minute[1] % 5 === 0) || feature.type_ === 'LineString') {
+ if ((minute && minute[1] % 5 === 0) || feature.getType() === 'LineString') {
return styleFunction(feature, resolution);
}
});
@@ -145,9 +144,7 @@ export function setStyleFunction(def, vectorStyleId, vectorStyles, layer, state,
layer.setStyle(function (feature, resolution) {
const selectedFeature = selectedFeatures.includes(feature.get(featureIdentifier));
if (selectedFeature && !selected.reset) {
- return styleFunction(feature, resolution, { selected: 'true' });
- } else if (selectedFeature && selected.reset) {
- return styleFunction(feature, resolution, { selected: 'false' });
+ return selectedStyleFunction(feature, styleFunction(feature, resolution));
} else {
return styleFunction(feature, resolution);
}
@@ -204,10 +201,11 @@ export function clearStyleFunction(def, vectorStyleId, vectorStyles, layer, stat
if (minutes) {
minute = minutes.split(':');
}
- if ((minute && minute[1] % 5 === 0) || feature.type_ === 'LineString') {
+ if ((minute && minute[1] % 5 === 0) || feature.getType() === 'LineString') {
return styleFunction(feature, resolution);
}
});
}
return update(vectorStyles, { layerId: { maps: { $unset: ['custom'] } } });
}
+
diff --git a/web/js/modules/vector-styles/util.js b/web/js/modules/vector-styles/util.js
index 3e4f3623c..c919f28b7 100644
--- a/web/js/modules/vector-styles/util.js
+++ b/web/js/modules/vector-styles/util.js
@@ -1,6 +1,7 @@
import {
assign as lodashAssign
} from 'lodash';
+import { Stroke, Style, Fill, Circle } from 'ol/style';
export function getVectorStyleAttributeArray(layer) {
var isCustomActive = false;
@@ -42,3 +43,44 @@ export function getMaxValue(v) {
export function isConditional(item) {
return Array.isArray(item) && item[0] === 'case';
}
+
+export function selectedCircleStyle(style) {
+ const styleImage = style.getImage();
+ const fill = styleImage.getFill();
+ const radius = styleImage.getRadius() * 1.25;
+ return new Style({
+ image: new Circle({
+ radius: radius,
+ stroke: new Stroke({
+ color: 'white',
+ width: 1
+ }),
+ fill: new Fill({
+ color: fill.getColor().replace(/[^,]+(?=\))/, '0.5')
+ })
+ })
+ });
+}
+export function selectedPolygonStyle(style) {
+ const fill = style.getFill();
+ const color = fill.getColor().replace(/[^,]+(?=\))/, '0.5')
+ const stroke = style.getStroke();
+ stroke.setColor('white');
+ stroke.setWidth(0.5);
+ fill.setColor(color);
+ return style;
+}
+export function selectedStyleFunction(feature, styleArray) {
+ if (styleArray.length !== 1) return styleArray;
+ return styleArray.map((style) => {
+ const type = feature.getType();
+ switch (type) {
+ case 'Point':
+ return selectedCircleStyle(style);
+ case 'Polygon':
+ return selectedPolygonStyle(style);
+ default:
+ return style;
+ }
+ });
+}
\ No newline at end of file