Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Clean up model and add map library for natural events tooltips

Taylor Gunnoee6c2a416eb39
diff --git a/web/images/event-icon2.png b/web/images/event-icon2.png
new file mode 100644
index 000000000..9d00f240b
Binary files /dev/null and b/web/images/event-icon2.png differ
diff --git a/web/index.html b/web/index.html
index 7cc911aa7..3c49149ab 100644
--- a/web/index.html
+++ b/web/index.html
@@ -242,6 +242,7 @@
<!-- link.dev --> <script type="text/javascript" src="js/naturalEvents/wv.naturalEvents.model.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/naturalEvents/wv.naturalEvents.ui.js"></script>
+ <!-- link.dev --> <script type="text/javascript" src="js/naturalEvents/wv.naturalEvents.map.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/map/wv.map.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/map/wv.map.model.js"></script>
diff --git a/web/js/naturalEvents/wv.naturalEvents.map.js b/web/js/naturalEvents/wv.naturalEvents.map.js
new file mode 100644
index 000000000..b754db999
--- /dev/null
+++ b/web/js/naturalEvents/wv.naturalEvents.map.js
@@ -0,0 +1,79 @@
+/*
+ * NASA Worldview
+ *
+ * This code was originally developed at NASA/Goddard Space Flight Center for
+ * the Earth Science Data and Information System (ESDIS) project.
+ *
+ * Copyright (C) 2013 - 2017 United States Government as represented by the
+ * Administrator of the National Aeronautics and Space Administration.
+ * All Rights Reserved.
+ */
+
+var wv = wv || {};
+wv.naturalEvents = wv.naturalEvents || {};
+
+wv.naturalEvents.map = wv.naturalEvents.map || function(location, map, config) {
+
+ var self = {};
+
+ vectorLayer = null;
+
+ var init = function() {
+ model.events
+ .on("select", onSelect);
+ };
+ var getButtonDimensions = function() {
+ var zoom = map.getView().getZoom();
+ // Minimum size of the button is 15 pixels
+ var base = 12;
+ // Double the size for each zoom level
+ var add = Math.pow(2, zoom);
+ // But 47 pixels is the maximum size
+ var size = Math.min(base + add, base + 32);
+ return {
+ scale: size / 48,
+ size: size
+ };
+ };
+ var buttonStyle = function(feature) {
+ var dim = getButtonDimensions();
+ var image = "images/event-icon2.png";
+ return [new ol.style.Style({
+ image: new ol.style.Icon({
+ src: image,
+ scale: dim.scale,
+ anchor: [0.5, 46],
+ anchorXUnits: 'fraction',
+ anchorYUnits: 'pixels'
+ })
+ })];
+ };
+ var onSelect = function(){
+
+ map.removeLayer(vectorLayer);
+
+ var iconFeature = new ol.Feature({
+ geometry: new ol.geom.Point(location),
+ name: 'NaturalEvent',
+ population: 4000,
+ rainfall: 500
+ });
+
+ iconFeature.setStyle(buttonStyle);
+
+ var vectorSource = new ol.source.Vector({
+ features: [iconFeature],
+ wrapX: false
+ });
+
+ var vectorLayer = new ol.layer.Vector({
+ source: vectorSource
+ });
+ map.addLayer(vectorLayer);
+
+ };
+
+ onSelect();
+ return self;
+
+};
diff --git a/web/js/naturalEvents/wv.naturalEvents.model.js b/web/js/naturalEvents/wv.naturalEvents.model.js
index ddfef2a60..31f7b7e65 100644
--- a/web/js/naturalEvents/wv.naturalEvents.model.js
+++ b/web/js/naturalEvents/wv.naturalEvents.model.js
@@ -29,12 +29,12 @@ wv.naturalEvents.model = wv.naturalEvents.model || function(models, config) {
epsg: null,
time: null
};
+
self.EVENT_QUERY_RESULTS = "queryResults";
self.EVENT_SELECT = "select";
+
self.apiURL = config.features.naturalEvents.host;
var querySuccessFlag = false;
- var lastIndex = -1;
- var lastDateIndex = -1;
/**
* Handler for events fired by this class.
*
@@ -44,7 +44,7 @@ wv.naturalEvents.model = wv.naturalEvents.model || function(models, config) {
*/
self.events = wv.util.events();
- var layerLists = config.naturalEvents.layers;
+ self.layers = config.naturalEvents.layers;
self.ignored = config.naturalEvents.skip || [];
self.data = {};
@@ -58,6 +58,7 @@ wv.naturalEvents.model = wv.naturalEvents.model || function(models, config) {
var onQueryResults = function(){
if ( self.data ) {
querySuccessFlag = true;
+
//models.link.register(self);
//models.link.load(self);
}
@@ -66,163 +67,6 @@ wv.naturalEvents.model = wv.naturalEvents.model || function(models, config) {
self.save();
};
- self.select = function(index, dateIndex) {
-
- if ( index === lastIndex && lastDateIndex === dateIndex ) {
- return;
- }
-
- var method = "fly";
- if ( index == lastIndex && dateIndex != lastDateIndex ) {
- method = "pan";
- }
- lastIndex = index;
- lastDateIndex = lastDateIndex;
-
- if(models.proj.selected.id !=='geographic') {
- models.proj.select('geographic');
- }
- self.selected = index;
- event = self.data[index];
-
- eventItem = null;
- if ( event.geometries.length > 1 ) {
- eventItem = event.geometries[dateIndex || 0];
- } else {
- eventItem = event.geometries[0];
- }
-
-
- category = "Default";
- categories = event.categories;
- if ( categories.constructor !== Array ) {
- categories = [categories];
- }
- _.each(categories, function(c) {
- if ( layerLists[c.title] ) {
- category = c.title;
- return;
- }
- });
-
- layers = layerLists[category];
- if ( !layers ) {
- layers = layerLists.Default;
- }
-
- // Turn off all layers in list first
- _.each(models.layers.active, function(layer){
- models.layers.setVisibility( layer.id, false );
- });
-
- // Turn on or add new layers
- _.each(layers, function(layer) {
- var id = layer[0];
- var visible = layer[1];
- if( models.layers.exists( id ) ) {
- models.layers.setVisibility( id, visible );
- }
- else{
- models.layers.add(id, { visible: visible });
- }
- });
-
- // If an event is a Wildfire and the event date isn't "today", select
- // the following day to greatly improve the chance of the satellite
- // seeing the event
- //
- // NOTE: there is a risk that if the fire happened "yesterday" and
- // the satellite imagery is not yet available for "today", this
- // functionality may do more harm than good
- eventDate = wv.util.parseTimestampUTC(eventItem.date);
- var eventDateISOString = wv.util.toISOStringDate(eventDate);
- var todayDateISOString = wv.util.toISOStringDate(wv.util.today());
- var eventCategoryName = getEventCategoryName();
- if ((eventDateISOString !== todayDateISOString) &&
- ((eventCategoryName !== null) && (eventCategoryName == "Wildfires"))) {
- var eventDatePlusOne =
- wv.util.dateAdd(wv.util.parseDateUTC(eventItem.date), "day", 1);
- models.date.select(eventDatePlusOne);
- }
- else {
- models.date.select(eventDate);
- }
- if ( eventItem.type === "Point" ) {
- goTo(method, eventItem.coordinates);
- } else if ( eventItem.type === "Polygon" && eventItem.coordinates[0].length == 5 ) {
- c = eventItem.coordinates[0];
- var extent = [c[0][0], c[0][1], c[2][0], c[2][1]];
- goTo(method, extent);
- }
- };
-
- var goTo = function(method, location) {
-
- var map = wvx.ui.map.selected;
- var zoom = map.getView().getZoom();//3;
- var duration = ( method == "fly" ) ? 5000 : 1000;
- var wait = ( method == "fly" ) ? 1000 : 1;
- var start = +new Date();
- var pan = ol.animation.pan({
- duration: duration,
- source: map.getView().getCenter(),
- start: start
- });
-
- // use this to set proper zoom/res
-
- // For bounce, if zoom is too high, it bounces "in" instead of "out";
- // force it to zoom out by starting at zoom 4
- var bounceZoom = (zoom >= 8) ? 4 : zoom-2;
- if (bounceZoom < 0) { bounceZoom = 0; }
-
- var bounce = ol.animation.bounce({
- duration: duration,
- resolution: models.proj.selected.resolutions[bounceZoom],
- start: start
- });
- var zoomTo = ol.animation.zoom({
- duration: duration,
- resolution: models.proj.selected.resolutions[zoom],
- start: start
- });
- //HAX
- if(zoom < 4){
- method = 'zoom';
- }
-
- setTimeout(function() {
- if ( method === "fly" ) {
- map.beforeRender(pan, bounce);
- } else if ( method === 'zoom' ) {
- map.beforeRender(pan, zoomTo);
- } else {
- map.beforeRender(pan);
- }
- if ( location.length == 2 ) {
- map.getView()
- .setCenter(location);
-
- // Retrieve event category name, if possible
- var eventCategoryName = getEventCategoryName();
-
- // If an event is a Wildfire or Volcano, zoom in more
- if ((eventCategoryName !== null) && (eventCategoryName == "Wildfires")) {
- map.getView().setZoom(8);
- } else if (eventCategoryName == "Volcanoes") {
- map.getView().setZoom(6);
- } else {
- map.getView().setZoom(5);
- }
-
- } else {
- map.getView().fit(location, map.getSize());
- if(map.getView().getZoom() > 8)
- map.getView().setZoom(8);
- }
- }, wait);
- };
-
self.save = function(state) {
if ( self.active ){
state.events = self.selected;
@@ -248,7 +92,7 @@ wv.naturalEvents.model = wv.naturalEvents.model || function(models, config) {
var queryEvents = function(callback) {
var url = self.apiURL + "/events";
$.getJSON(url, function(data) {
- self.data = data.events;
+ self.data.events = data.events;
self.events.trigger('queryResults');
});
};
@@ -256,7 +100,7 @@ wv.naturalEvents.model = wv.naturalEvents.model || function(models, config) {
var queryTypes = function(callback) {
var url = self.apiURL + "/categories";
$.getJSON(url, function(data) {
- self.types = data.categories;
+ self.data.types = data.categories;
self.events.trigger('queryResults');
});
};
@@ -264,7 +108,7 @@ wv.naturalEvents.model = wv.naturalEvents.model || function(models, config) {
var querySources = function(callback) {
var url = self.apiURL + "/sources";
$.getJSON(url, function(data) {
- self.sources = data.sources;
+ self.data.sources = data.sources;
self.events.trigger('queryResults');
});
};
diff --git a/web/js/naturalEvents/wv.naturalEvents.ui.js b/web/js/naturalEvents/wv.naturalEvents.ui.js
index fb73097b3..9e82caf6e 100644
--- a/web/js/naturalEvents/wv.naturalEvents.ui.js
+++ b/web/js/naturalEvents/wv.naturalEvents.ui.js
@@ -24,6 +24,9 @@ wv.naturalEvents.ui = wv.naturalEvents.ui || function(models, ui, config) {
//Local storage may not be a good idea because they'll never see it again
//wv.util.localStorage('notified') || false;
var notified = false;
+ var lastIndex = -1;
+ var lastDateIndex = -1;
+
var $notification;
var init = function() {
@@ -43,8 +46,9 @@ wv.naturalEvents.ui = wv.naturalEvents.ui || function(models, ui, config) {
};
var onQueryResults = function(){
//FIXME: this if check needs to be reworked
- if ( model.data && model.sources && model.types ) {
- data = model.data;
+ if ( model.data ) {
+ data = model.data.events;
+ console.log('refreshed');
self.refresh();
}
};
@@ -188,6 +192,165 @@ wv.naturalEvents.ui = wv.naturalEvents.ui || function(models, ui, config) {
resize();
};
+ self.select = function(index, dateIndex) {
+
+ if ( index === lastIndex && lastDateIndex === dateIndex ) {
+ return;
+ }
+
+ var method = "fly";
+ if ( index == lastIndex && dateIndex != lastDateIndex ) {
+ method = "pan";
+ }
+ lastIndex = index;
+ lastDateIndex = lastDateIndex;
+
+ if(models.proj.selected.id !=='geographic') {
+ models.proj.select('geographic');
+ }
+ self.selected = index;
+ event = model.data.events[index];
+
+ eventItem = null;
+ if ( event.geometries.length > 1 ) {
+ eventItem = event.geometries[dateIndex || 0];
+ } else {
+ eventItem = event.geometries[0];
+ }
+
+
+ category = "Default";
+ categories = event.categories;
+ if ( categories.constructor !== Array ) {
+ categories = [categories];
+ }
+ _.each(categories, function(c) {
+ if ( model.layers[c.title] ) {
+ category = c.title;
+ return;
+ }
+ });
+
+ layers = model.layers[category];
+ if ( !layers ) {
+ layers = model.layers.Default;
+ }
+
+ // Turn off all layers in list first
+ _.each(models.layers.active, function(layer){
+ models.layers.setVisibility( layer.id, false );
+ });
+
+ // Turn on or add new layers
+ _.each(layers, function(layer) {
+ var id = layer[0];
+ var visible = layer[1];
+ if( models.layers.exists( id ) ) {
+ models.layers.setVisibility( id, visible );
+ }
+ else{
+ models.layers.add(id, { visible: visible });
+ }
+ });
+
+ // If an event is a Wildfire and the event date isn't "today", select
+ // the following day to greatly improve the chance of the satellite
+ // seeing the event
+ //
+ // NOTE: there is a risk that if the fire happened "yesterday" and
+ // the satellite imagery is not yet available for "today", this
+ // functionality may do more harm than good
+ eventDate = wv.util.parseTimestampUTC(eventItem.date);
+ var eventDateISOString = wv.util.toISOStringDate(eventDate);
+ var todayDateISOString = wv.util.toISOStringDate(wv.util.today());
+ var eventCategoryName = model.getEventCategoryName(index, dateIndex);
+ if ((eventDateISOString !== todayDateISOString) &&
+ ((eventCategoryName !== null) && (eventCategoryName == "Wildfires"))) {
+ var eventDatePlusOne =
+ wv.util.dateAdd(wv.util.parseDateUTC(eventItem.date), "day", 1);
+ models.date.select(eventDatePlusOne);
+ }
+ else {
+ models.date.select(eventDate);
+ }
+ if ( eventItem.type === "Point" ) {
+ goTo(method, eventItem.coordinates);
+ } else if ( eventItem.type === "Polygon" && eventItem.coordinates[0].length == 5 ) {
+ c = eventItem.coordinates[0];
+ var extent = [c[0][0], c[0][1], c[2][0], c[2][1]];
+ goTo(method, extent);
+ }
+ };
+
+ var goTo = function(method, location) {
+
+ var map = ui.map.selected;
+ var zoom = map.getView().getZoom();//3;
+ var duration = ( method == "fly" ) ? 5000 : 1000;
+ var wait = ( method == "fly" ) ? 1000 : 1;
+ var start = +new Date();
+ wv.naturalEvents.map(location, map, config);
+ console.log(location);
+ var pan = ol.animation.pan({
+ duration: duration,
+ source: map.getView().getCenter(),
+ start: start
+ });
+
+ // use this to set proper zoom/res
+
+ // For bounce, if zoom is too high, it bounces "in" instead of "out";
+ // force it to zoom out by starting at zoom 4
+ var bounceZoom = (zoom >= 8) ? 4 : zoom-2;
+ if (bounceZoom < 0) { bounceZoom = 0; }
+
+ var bounce = ol.animation.bounce({
+ duration: duration,
+ resolution: models.proj.selected.resolutions[bounceZoom],
+ start: start
+ });
+ var zoomTo = ol.animation.zoom({
+ duration: duration,
+ resolution: models.proj.selected.resolutions[zoom],
+ start: start
+ });
+ //HAX
+ if(zoom < 4){
+ method = 'zoom';
+ }
+
+ setTimeout(function() {
+ if ( method === "fly" ) {
+ map.beforeRender(pan, bounce);
+ } else if ( method === 'zoom' ) {
+ map.beforeRender(pan, zoomTo);
+ } else {
+ map.beforeRender(pan);
+ }
+ if ( location.length == 2 ) {
+ map.getView()
+ .setCenter(location);
+
+ // Retrieve event category name, if possible
+ var eventCategoryName = getEventCategoryName();
+
+ // If an event is a Wildfire or Volcano, zoom in more
+ if ((eventCategoryName !== null) && (eventCategoryName == "Wildfires")) {
+ map.getView().setZoom(8);
+ } else if (eventCategoryName == "Volcanoes") {
+ map.getView().setZoom(6);
+ } else {
+ map.getView().setZoom(5);
+ }
+
+ } else {
+ map.getView().fit(location, map.getSize());
+ if(map.getView().getZoom() > 8)
+ map.getView().setZoom(8);
+ }
+ }, wait);
+ };
+
var refreshEvent = function($content, event, index) {
if ((event.categories[0].title === 'Floods') ||
(event.categories[0].title === 'Earthquakes') ||
@@ -206,7 +369,6 @@ wv.naturalEvents.ui = wv.naturalEvents.ui || function(models, ui, config) {
dateString += ", " + eventDate.getUTCFullYear();
}
-
var $item = $("<li></li>")
.addClass("selectorItem")
.addClass("item")
@@ -244,7 +406,7 @@ wv.naturalEvents.ui = wv.naturalEvents.ui || function(models, ui, config) {
if ( references.length > 0 ) {
items = [];
_.each(references, function(reference) {
- var source = _.find(model.sources, { id: reference.id });
+ var source = _.find(model.data.sources, { id: reference.id });
if ( reference.url ) {
items.push("<a target='event' href='" + reference.url + "'>" +
"<i class='fa fa-external-link fa-1'></i>" +
@@ -273,7 +435,7 @@ wv.naturalEvents.ui = wv.naturalEvents.ui || function(models, ui, config) {
$("#wv-eventscontent [data-index='" + index + "'] .dates").show();
resize();
- model.select(index, dateIndex);
+ self.select(index, dateIndex);
};
var notify = function( text ) {
diff --git a/web/js/ui/wv.ui.js b/web/js/ui/wv.ui.js
index 95729b285..1b3c856b6 100644
--- a/web/js/ui/wv.ui.js
+++ b/web/js/ui/wv.ui.js
@@ -63,22 +63,52 @@ wv.ui = (function(self) {
var $dialog = self.getDialog();
title = title || "Notice";
width = width || 300;
+ var $close = $('<i></i>')
+ .addClass('fa fa-times fa-1x')
+ .click(function(e){
+ $(this).dialog( 'close' );
+ });
+ message = $(message).append($close);
$dialog.html(message).dialog({
title: title,
- show: { effect: "fade" },
- hide: { effect: "fade" },
width: width,
minHeight: 1,
- height: "auto"
+ height: "auto",
+ resizable: false,
+ draggable: false,
+ show: {
+ effect: "fade",
+ duration: 400
+ },
+ hide: {
+ effect: "fade",
+ duration: 200
+ },
+ dialogClass: 'no-titlebar notify-alert'
}).on('dialogclose', function() {
$(this).off('dialogclose');
if(callback) {
callback();
}
});
+ };
+ /**
+ * Displays a non-obtrusive message to the end user in the top right.
+ *
+ * @method notify
+ * @static
+ *
+ * @param {string} message The message to display to the user.
+ *
+ * @param [title="Notice"] {string} Title for the dialog box.
+ */
+ self.notify.small = function(title, link, width, callback){
- };
+ var $dialog = self.getDialog();
+ title = title || "Notice";
+ width = width || 200;
+ };
/**
* Asks the end user a yes or no question in a dialog box.