Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Fix outerzoom renderinf of dams issue #2581

Benjamin King0aa84503e937
diff --git a/web/js/map/layerbuilder.js b/web/js/map/layerbuilder.js
index b24175106..fb9d734f6 100644
--- a/web/js/map/layerbuilder.js
+++ b/web/js/map/layerbuilder.js
@@ -420,9 +420,9 @@ export function mapLayerBuilder(models, config, cache, ui, store) {
url: source.url + urlParameters,
layer: layerName,
day: day,
- format: new MVT(),
+ format: new MVT({}),
matrixSet: tms,
- wrapX: true,
+ wrapX: !!(day === 1 || day === -1),
tileGrid: new OlTileGridTileGrid({
extent: gridExtent,
resolutions: matrixSet.resolutions,
@@ -433,8 +433,8 @@ export function mapLayerBuilder(models, config, cache, ui, store) {
var layer = new LayerVectorTile({
extent: layerExtent,
- source: sourceOptions
-
+ source: sourceOptions,
+ renderMode: 'image'
});
if (config.vectorStyles && def.vectorStyle && def.vectorStyle.id) {
@@ -452,7 +452,7 @@ export function mapLayerBuilder(models, config, cache, ui, store) {
}
setStyleFunction(def, vectorStyleId, vectorStyles, layer, state);
}
-
+ layer.wrap = day;
return layer;
};
diff --git a/web/js/modules/vector-styles/selectors.js b/web/js/modules/vector-styles/selectors.js
index bf9aa7d57..5869c32fb 100644
--- a/web/js/modules/vector-styles/selectors.js
+++ b/web/js/modules/vector-styles/selectors.js
@@ -4,6 +4,7 @@ import {
each as lodashEach,
find as lodashFind
} from 'lodash';
+
import {
getLayers
} from '../layers/selectors';
@@ -11,6 +12,7 @@ import { getMinValue, getMaxValue, selectedStyleFunction } from './util';
import update from 'immutability-helper';
import { containsCoordinate } from 'ol/extent';
import stylefunction from 'ol-mapbox-style/stylefunction';
+
/**
* Gets a single colormap (entries / legend combo)
*
@@ -75,6 +77,7 @@ export function setRange(layerId, props, index, palettes, state) {
}
export function setStyleFunction(def, vectorStyleId, vectorStyles, layer, state) {
+ const { compare } = state;
var styleFunction;
var layerId = def.id;
var glStyle = vectorStyles[layerId];
@@ -89,9 +92,10 @@ export function setStyleFunction(def, vectorStyleId, vectorStyles, layer, state)
).reverse();
var layerGroups;
var layerGroup;
+
if (olMap) {
layerGroups = olMap.getLayers().getArray();
- if (state.compare && state.compare.active) {
+ if (compare && compare.active) {
if (layerGroups.length === 2) {
layerGroup =
layerGroups[0].get('group') === activeLayerStr
@@ -102,7 +106,7 @@ export function setStyleFunction(def, vectorStyleId, vectorStyles, layer, state)
}
}
lodashEach(activeLayers, function(def) {
- if (state.compare && state.compare.active) {
+ if (compare && compare.active) {
if (layerGroup && layerGroup.getLayers().getArray().length) {
lodashEach(layerGroup.getLayers().getArray(), subLayer => {
if (subLayer.wv && (subLayer.wv.id === layerId)) {
@@ -127,21 +131,28 @@ export function setStyleFunction(def, vectorStyleId, vectorStyles, layer, state)
styleFunction = stylefunction(layerInLayerGroup, glStyle, vectorStyleId);
// Filter Orbit Tracks
- if (glStyle.name === 'Orbit Tracks') {
- // Filter time by 5 mins
+ if (glStyle.name === 'Orbit Tracks' &&
+ (selected[layerId] && selected[layerId].length)) {
+ const selectedFeatures = selected[layerId];
layerInLayerGroup.setStyle(function(feature, resolution) {
- var minute;
- var minutes = feature.get('label');
- if (minutes) {
- minute = minutes.split(':');
- }
- if (((minute && minute[1] % 5 === 0) || feature.getType() === 'LineString') &&
- shouldRenderFeature(feature, acceptableExtent)) {
+ const data = state.config.vectorData[def.vectorData.id];
+ const properties = data.mvt_properties;
+ const features = feature.getProperties();
+ const idKey = lodashFind(properties, { Function: 'Identify' }).Identifier;
+ const minutes = feature.get('label');
+ const uniqueIdentifier = features[idKey];
+ if (shouldRenderFeature(feature, acceptableExtent)) {
+ if (minutes && uniqueIdentifier && selectedFeatures && selectedFeatures.includes(uniqueIdentifier)) {
+ return selectedStyleFunction(feature, styleFunction(feature, resolution), 1.5);
+ } else {
+ return styleFunction(feature, resolution);
+ }
+ } else {
return styleFunction(feature, resolution);
}
});
- } else if (glStyle.name === 'SEDAC' &&
- ((selected[layerId] && selected[layerId].length))) {
+ } else if ((glStyle.name === 'SEDAC') &&
+ (selected[layerId] && selected[layerId].length)) {
const selectedFeatures = selected[layerId];
layerInLayerGroup.setStyle(function(feature, resolution) {
@@ -158,19 +169,13 @@ export function setStyleFunction(def, vectorStyleId, vectorStyles, layer, state)
}
}
});
- } else if (acceptableExtent) {
- layerInLayerGroup.setStyle(function(feature, resolution) {
- if (shouldRenderFeature(feature, acceptableExtent)) {
- return styleFunction(feature, resolution);
- }
- });
}
});
return vectorStyleId;
}
const shouldRenderFeature = (feature, acceptableExtent) => {
if (!acceptableExtent) return true;
- const midpoint = feature.getFlatCoordinates();
+ const midpoint = feature.getFlatCoordinates ? feature.getFlatCoordinates() : feature.getGeometry().getFlatCoordinates();
if (containsCoordinate(acceptableExtent, midpoint)) return true;
return false;
};
diff --git a/web/js/modules/vector-styles/util.js b/web/js/modules/vector-styles/util.js
index 977ba260c..da89f9303 100644
--- a/web/js/modules/vector-styles/util.js
+++ b/web/js/modules/vector-styles/util.js
@@ -3,6 +3,7 @@ import {
find as lodashFind,
get as lodashGet
} from 'lodash';
+
import { Stroke, Style, Fill, Circle } from 'ol/style';
import { setStyleFunction } from './selectors';
import { isFromActiveCompareRegion } from '../compare/util';
@@ -46,11 +47,33 @@ export function getMaxValue(v) {
export function isConditional(item) {
return Array.isArray(item) && item[0] === 'case';
}
-
-export function selectedCircleStyle(style) {
+export function adjustCircleRadius(style) {
+ const styleImage = style.getImage();
+ const fill = styleImage.getFill();
+ const radius = styleImage.getRadius() * 0.6;
+ return new Style({
+ image: new Circle({
+ radius: radius,
+ fill: fill
+ })
+ });
+}
+export function getOrbitPointStyles(feature, styleArray) {
+ return styleArray.map((style) => {
+ const type = feature.getType();
+ switch (type) {
+ case 'Point':
+ return adjustCircleRadius(style);
+ default:
+ return style;
+ }
+ });
+};
+export function selectedCircleStyle(style, size) {
+ size = size || 2;
const styleImage = style.getImage();
const fill = styleImage.getFill();
- const radius = styleImage.getRadius() * 2;
+ const radius = styleImage.getRadius() * size;
return new Style({
image: new Circle({
radius: radius,
@@ -64,6 +87,7 @@ export function selectedCircleStyle(style) {
})
});
}
+
export function selectedPolygonStyle(style) {
const fill = style.getFill();
const color = fill.getColor().replace(/[^,]+(?=\))/, '0.5');
@@ -73,13 +97,22 @@ export function selectedPolygonStyle(style) {
fill.setColor(color);
return style;
}
-export function selectedStyleFunction(feature, styleArray) {
+export function offsetLineStringStyle(feature, styleArray) {
+ return styleArray.map(style => {
+ const text = style.getText();
+ if (text) {
+ text.setOffsetX(25);
+ }
+ return style;
+ });
+}
+export function selectedStyleFunction(feature, styleArray, size) {
if (styleArray.length !== 1) return styleArray;
return styleArray.map((style) => {
const type = feature.getType();
switch (type) {
case 'Point':
- return selectedCircleStyle(style);
+ return selectedCircleStyle(style, size);
case 'Polygon':
return selectedPolygonStyle(style);
default:
@@ -138,6 +171,12 @@ export function getPaletteForStyle(layer, layerstyleLayerObject) {
id: layer.id + '0_legend'
}];
}
+export function isFeatureInRenderableArea(lon, wrap, acceptableExtent) {
+ if (acceptableExtent) {
+ return (lon > acceptableExtent[0] && lon < acceptableExtent[2]);
+ }
+ return wrap === -1 ? (lon < 250 && lon > 180) : wrap === 1 ? (lon > -250 && lon < -180) : false;
+}
export function onMapClickGetVectorFeatures(pixels, map, state, swipeOffset) {
const metaArray = [];
const selected = {};