Interactive interface for browsing global, full-resolution satellite imagery
Move map animation to its own method
Taylor Gunnoe67e841a3de41
diff --git a/web/index.html b/web/index.htmlindex 3c49149ab..28a03da35 100644--- a/web/index.html+++ b/web/index.html@@ -249,6 +249,7 @@<!-- link.dev --> <script type="text/javascript" src="js/map/wv.map.rotate.js"></script><!-- link.dev --> <script type="text/javascript" src="js/map/wv.map.runningdata.js"></script><!-- link.dev --> <script type="text/javascript" src="js/map/wv.map.ui.js"></script>+ <!-- link.dev --> <script type="text/javascript" src="js/map/wv.map.animate.js"></script><!-- link.dev --> <script type="text/javascript" src="js/link/wv.link.model.js"></script><!-- link.dev --> <script type="text/javascript" src="js/link/wv.link.ui.js"></script>diff --git a/web/js/map/wv.map.animate.js b/web/js/map/wv.map.animate.jsnew file mode 100644index 000000000..06889b2a5--- /dev/null+++ b/web/js/map/wv.map.animate.js@@ -0,0 +1,106 @@+/*+ * 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 - 2014 United States Government as represented by the+ * Administrator of the National Aeronautics and Space Administration.+ * All Rights Reserved.+ */+var wv = wv || {};+wv.map = wv.map || {};++/*+ * @Class+ */+wv.map.animate = wv.map.animate || function(models, config, ui) {++ var model = models.map;+ var self = {};++ var map = ui.map.selected;++ var init = function(){++ };+ /*+ * Pan and zooms the map to a new location+ *+ * @function move+ * @static+ *+ * @param {String} method - "fly" "pan" or "zoom"+ * @param {Array} location - Geographical coordinates+ * @param {Number} zoom - desired zoom level, if any+ *+ * @returns {void}+ */+ self.move = function(method, location, zoomLevel, callback) {++ var currentZoom = map.getView().getZoom();+ var newZoom = zoomLevel || 5;++ 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 = (currentZoom >= 8) ? 4 : currentZoom - 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[currentZoom],+ start: start+ });+ //If the zoom level is far out enough then it should start with a 'zoom'+ if(currentZoom < 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);++ map.getView().setZoom(zoomLevel);++ } else {+ map.getView().fit(location, map.getSize());+ if(map.getView().getZoom() > 8)+ map.getView().setZoom(8);+ }+ callback();+ }, wait);+ };+++ init();+ return self;++}diff --git a/web/js/naturalEvents/wv.naturalEvents.map.js b/web/js/naturalEvents/wv.naturalEvents.map.jsindex b754db999..eb4026bf9 100644--- a/web/js/naturalEvents/wv.naturalEvents.map.js+++ b/web/js/naturalEvents/wv.naturalEvents.map.js@@ -12,7 +12,7 @@var wv = wv || {};wv.naturalEvents = wv.naturalEvents || {};-wv.naturalEvents.map = wv.naturalEvents.map || function(location, map, config) {+wv.naturalEvents.map = wv.naturalEvents.map || function(location, map) {var self = {};diff --git a/web/js/naturalEvents/wv.naturalEvents.ui.js b/web/js/naturalEvents/wv.naturalEvents.ui.jsindex c991180d5..f3c652dee 100644--- a/web/js/naturalEvents/wv.naturalEvents.ui.js+++ b/web/js/naturalEvents/wv.naturalEvents.ui.js@@ -20,6 +20,7 @@ wv.naturalEvents.ui = wv.naturalEvents.ui || function(models, ui, config) {var data;self.selector = "#wv-events";self.id = "wv-events";+ var map = ui.map.selected;//Local storage may not be a good idea because they'll never see it again//wv.util.localStorage('notified') || false;@@ -30,7 +31,7 @@ wv.naturalEvents.ui = wv.naturalEvents.ui || function(models, ui, config) {var $notification;var init = function() {- //model.events.on("select", onSelect);+ model.events.on("select", onSelect);model.events.on( "queryResults", onQueryResults );ui.sidebar.events.on("select", function(tab) {if ( tab === "events" ) {@@ -43,6 +44,9 @@ wv.naturalEvents.ui = wv.naturalEvents.ui || function(models, ui, config) {$(window).resize(resize);render();+ };+ var onSelect = function(){+};var onQueryResults = function(){//FIXME: this if check needs to be reworked@@ -81,31 +85,11 @@ wv.naturalEvents.ui = wv.naturalEvents.ui || function(models, ui, config) {var $messageWrapper = $('<div></div>').click( function(e){showNotificationHelp();- //showLargeNotification();});- var $altMessage = $('<span></span>')- .text("Why can’t I see an event?")- .addClass('notify-message-alt').hide();-- var $longmessage = 'There are a variety of factors as to why you may not be seeing an event in Worldview at the moment.' +- '<ul>' +- '<li>Satellite overpass may have occurred before the event. Check out subsequent days or try a different satellite/sensor which has a different overpass time.</li>' +- '<li>Cloud cover may obscure the event.</li>' +- '<li>Some events don’t appear on the day that they are reported, you may have to wait a day or two for an event to become visible. Try and scroll through the days to see an event’s progression and/or change the satellite/sensor. NOTE: Wildfire events are currently set to automatically display the next day, as fire events often do not appear in the satellite imagery on the day they are reported.</li>' +- '<li>The resolution of the imagery may be too coarse to see an event.</li>' +- '<li>There are normal swath data gaps in some of the imagery layers due to way the satellite orbits the Earth, and an event may have occurred in the data gap.</li>' +- '</ul>' +- 'This is currently an experimental feature and we are working closely with the provider of these events, the <a href="http://eonet.sci.gsfc.nasa.gov/" target="_blank">Earth Observatory Natural Event Tracker</a>, to refine this listing to only show events that are visible with our satellite imagery.';-- var $longWrapper = $('<div></div>')- .addClass('notify-message-body')- .hide();-$messageWrapper.append($icon)- .append($message)- .append($altMessage);+ .append($message);var $close = $('<i></i>').addClass('fa fa-times fa-1x')@@ -116,7 +100,6 @@ wv.naturalEvents.ui = wv.naturalEvents.ui || function(models, ui, config) {$notification = $('<div></div>').append( $close ).append( $messageWrapper )- .append( $longWrapper ).dialog({autoOpen: false,resizable: false,@@ -140,12 +123,6 @@ wv.naturalEvents.ui = wv.naturalEvents.ui || function(models, ui, config) {//**************************************};- var showLargeNotification = function(){- $('.notify-message').hide();- $('.notify-message-alt').show();-- $('.notify-message-long').show();- };var showNotificationHelp = function(){var headerMsg = "<h3 class='wv-data-unavailable-header'>Why can’t I see an event?</h3>";var bodyMsg = 'There are a variety of factors as to why you may not be seeing an event in Worldview at the moment.' +@@ -275,82 +252,23 @@ wv.naturalEvents.ui = wv.naturalEvents.ui || function(models, ui, config) {else {models.date.select(eventDate);}++ // If an event is a Wildfire or Volcano, zoom in more+ if ((eventCategoryName !== null) && (eventCategoryName == "Wildfires")) {+ zoomLevel = 8;+ } else if (eventCategoryName == "Volcanoes") {+ zoomLevel = 6;+ }+ var callback = function(){+ wv.naturalEvents.map(eventItem.coordinates, map);+ };if ( eventItem.type === "Point" ) {- goTo(method, eventItem.coordinates);+ ui.map.animate.move(method, eventItem.coordinates, zoomLevel, callback);} 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';+ ui.map.animate.move(method, extent, zoomLevel, callback);}-- 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) {diff --git a/web/js/wv.main.js b/web/js/wv.main.jsindex 11a1ffa4b..721555757 100644--- a/web/js/wv.main.js+++ b/web/js/wv.main.js@@ -135,6 +135,7 @@ $(function() {}// HACK: Map needs to be created before the data download modelui.map = wv.map.ui(models, config, wv.map.rotate, wv.map.runningdata);+ ui.map.animate = wv.map.animate(models, config, ui);if ( config.features.animation ) {models.anim = wv.anim.model(models, config);models.link.register(models.anim);