Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Fix event layer rendering in sidebar #1565

Benjamin Kingd35b57b93532
diff --git a/web/js/map/animate.js b/web/js/map/animate.js
index 284576299..2c11164ef 100644
--- a/web/js/map/animate.js
+++ b/web/js/map/animate.js
@@ -1,6 +1,6 @@
import * as olExtent from 'ol/extent';
import OlGeomLineString from 'ol/geom/LineString';
-
+import Promise from 'bluebird';
export function mapAnimate(models, config, ui) {
var self = {};
@@ -11,7 +11,7 @@ export function mapAnimate(models, config, ui) {
* @param {integer} endZoom Ending Zoom Level
* @return {Promise} Promise that is fulfilled when animation completes
*/
- self.fly = function (endPoint, endZoom) {
+ self.fly = function(endPoint, endZoom) {
var view = ui.map.selected.getView();
var polarProjectionCheck = models.proj.selected.id !== 'geographic'; // boolean if current projection is polar
view.cancelAnimations();
@@ -24,16 +24,16 @@ export function mapAnimate(models, config, ui) {
var line = new OlGeomLineString([startPoint, endPoint]);
var distance = line.getLength(); // In map units, which is usually degrees
var distanceDuration = polarProjectionCheck ? distance / 50000 : distance; // limit large polar projection distances from coordinate transforms
- var duration = Math.floor((distanceDuration * 20) + 1000); // approx 6 seconds to go 360 degrees
- var animationPromise = function () {
+ var duration = Math.floor(distanceDuration * 20 + 1000); // approx 6 seconds to go 360 degrees
+ var animationPromise = function() {
var args = Array.prototype.slice.call(arguments);
- return new Promise(function (resolve, reject) {
- args.push(function (complete) {
+ return new Promise(function(resolve, reject) {
+ args.push(function(complete) {
if (complete) resolve();
if (!complete) reject(new Error('Animation interrupted!'));
});
view.animate.apply(view, args);
- }).catch(function () {});
+ }).catch(function() {});
};
if (hasEndInView) {
// allow faster fly with nearby events
@@ -48,7 +48,10 @@ export function mapAnimate(models, config, ui) {
return Promise.all([
animationPromise({ center: endPoint, duration: duration }),
animationPromise(
- { zoom: getBestZoom(distance, startZoom, endZoom, view), duration: duration / 2 },
+ {
+ zoom: getBestZoom(distance, startZoom, endZoom, view),
+ duration: duration / 2
+ },
{ zoom: endZoom, duration: duration / 2 }
)
]);
@@ -63,18 +66,20 @@ export function mapAnimate(models, config, ui) {
* @param {object} view map view
* @return {integer} best zoom level for flight animation
*/
- var getBestZoom = function (distance, start, end, view) {
+ var getBestZoom = function(distance, start, end, view) {
var idealLength = 1500;
- var lines = [2, 3, 4, 5, 6, 7, 8].map(function (zoom) {
+ var lines = [2, 3, 4, 5, 6, 7, 8].map(function(zoom) {
return {
zoom: zoom,
pixels: distance / view.getResolutionForZoom(zoom)
};
});
- var bestFit = lines.sort(function (a, b) {
- return Math.abs(idealLength - a.pixels) - Math.abs(idealLength - b.pixels);
+ var bestFit = lines.sort(function(a, b) {
+ return (
+ Math.abs(idealLength - a.pixels) - Math.abs(idealLength - b.pixels)
+ );
})[0];
return Math.max(2, Math.min(bestFit.zoom, start - 1, end - 1));
};
return self;
-};
+}
diff --git a/web/js/natural-events/ui.js b/web/js/natural-events/ui.js
index 2e8fe2147..e1f325ad0 100644
--- a/web/js/natural-events/ui.js
+++ b/web/js/natural-events/ui.js
@@ -184,6 +184,11 @@ export default function naturalEventsUI(models, ui, config, request) {
};
self.selectEvent = function(id, date, isInitialLoad) {
var isIdChange = !self.selected || self.selected.id !== id;
+ var prevId = self.selected.id ? self.selected.id : false;
+ var prevEvent = prevId
+ ? naturalEventsUtilGetEventById(model.data.events, prevId)
+ : false;
+ var prevCategory = prevEvent ? prevEvent.categories[0].title : false;
// Store selected id and date in model
self.selected = { id: id };
@@ -194,6 +199,9 @@ export default function naturalEventsUI(models, ui, config, request) {
return;
}
+ var category = event.categories[0].title;
+ var isSameCategory = category === prevCategory;
+
date = date || self.getDefaultEventDate(event);
const zoomPromise = getZoomPromise(event, date, !isIdChange, isInitialLoad);
self.selected.date = date;
@@ -205,7 +213,7 @@ export default function naturalEventsUI(models, ui, config, request) {
self.markers = naturalEventMarkers.draw();
zoomPromise.then(function() {
self.selecting = true;
- if (!isInitialLoad && isIdChange) {
+ if (isIdChange && !isSameCategory && !isInitialLoad) {
activateLayersForCategory(event.categories[0].title);
}
if (!isInitialLoad) models.date.select(util.parseDateUTC(date));
@@ -249,6 +257,7 @@ export default function naturalEventsUI(models, ui, config, request) {
}
naturalEventsTrack.update(event, ui.map.selected, date, self.selectEvent);
self.selecting = false;
+ model.events.trigger('selection-done', self.selected);
});
model.events.trigger('selected-event', self.selected);
diff --git a/web/js/sidebar/ui.js b/web/js/sidebar/ui.js
index ee26c4695..094c51fef 100644
--- a/web/js/sidebar/ui.js
+++ b/web/js/sidebar/ui.js
@@ -77,9 +77,9 @@ export function sidebarUi(models, config, ui) {
models.naturalEvents.events
.on('activate', () => self.selectTab('events'))
.on('list-change', debounceUpdateEventsList)
+ .on('selection-done', updateLayers)
.on('selected-event', selected => {
self.reactComponent.setState({ selectedEvent: selected });
- updateLayers();
});
}
if (models.compare) {