Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Final js for alpha release

Tilak Joshia7e6d5a29973
diff --git a/js/accordionPicker.js b/js/accordionPicker.js
index d5ff9dc7f..235281ef9 100644
--- a/js/accordionPicker.js
+++ b/js/accordionPicker.js
@@ -89,11 +89,24 @@ SOTE.widget.AccordionPicker.prototype.init = function(){
SOTE.widget.AccordionPicker.prototype.render = function(){
if(this.items === undefined){return false;}
this.container.innerHTML = "";
+ var htmlExpanded;
+ var selected;
+ var defaultSelection = null;
var accordion = document.createElement("form");
accordion.setAttribute("class","accordion");
accordion.setAttribute("id",this.id+"accordion");
for(var category in this.items){
+ if(category === "expanded"){
+ if(this.items[category] !== undefined && this.items[category] !== ""){
+ htmlExpanded = this.items[category].replace(" ","");
+ }
+ continue;
+ }
+ if(category === "selected"){
+ selected = this.items[category];
+ continue;
+ }
var htmlCategory = category.replace(" ","");
var catHeader = document.createElement("a");
catHeader.setAttribute("href","#");
@@ -103,6 +116,9 @@ SOTE.widget.AccordionPicker.prototype.render = function(){
var catList = document.createElement("ul");
for(var i=0; i < this.items[category].length; i++){
var item = this.items[category][i];
+ if(defaultSelection === null){
+ defaultSelection = item.value;
+ }
var catListItem = document.createElement("li");
if(item.type !== "single" && item.type !== "multi"){
alert("Invalid list item!");
@@ -121,9 +137,19 @@ SOTE.widget.AccordionPicker.prototype.render = function(){
this.container.appendChild(accordion);
$('.accordion').accordion();
- $('.accordion').accordion("option","collapsible",true);
+ //$('.accordion').accordion("option","collapsible",true);
$('.accordionFormItem').bind('click',{self:this},SOTE.widget.AccordionPicker.handleSelection);
+ if(htmlExpanded !== undefined){
+ $('.accordion').accordion("activate","#"+this.id+htmlExpanded);
+ }
+ if(selected !== undefined && selected !== ""){
+ this.setValue(selected);
+ }
+ else {
+ this.setValue(defaultSelection);
+ }
+
@@ -132,6 +158,7 @@ SOTE.widget.AccordionPicker.prototype.render = function(){
SOTE.widget.AccordionPicker.handleSelection = function(e){
var self = e.data.self;
+ self.value = SOTE.util.extractFromQuery(self.id,self.getValue());
self.fire();
@@ -189,6 +216,9 @@ SOTE.widget.AccordionPicker.prototype.setValue = function(values){
}
}
+ this.value = values;
+ this.fire();
+
return this.validate();
};
@@ -212,7 +242,7 @@ SOTE.widget.AccordionPicker.prototype.getValue = function(){
}
}
- if(selected.length === 0){ selected.push("none"); };
+ if(selected.length === 0){ selected.push(""); };
var checkboxes = document.getElementsByName(this.id+"multi");
@@ -237,8 +267,8 @@ SOTE.widget.AccordionPicker.prototype.getValue = function(){
SOTE.widget.AccordionPicker.prototype.updateComponent = function(querystring){
var qs = (querystring === undefined)? "":querystring;
SOTE.util.getJSON(
- this.dataSourceUrl+querystring,
- {self:this},
+ this.dataSourceUrl+"?"+querystring,
+ {self:this,qs:querystring},
SOTE.widget.AccordionPicker.handleUpdateSuccess,
SOTE.widget.AccordionPicker.handleUpdateFailure
);
@@ -252,12 +282,13 @@ SOTE.widget.AccordionPicker.prototype.updateComponent = function(querystring){
*
*/
SOTE.widget.AccordionPicker.handleUpdateSuccess = function(data,status,xhr,args){
- var value = args.self.getValue();
+ var expanded = SOTE.util.extractFromQuery("hazard",args.qs);
+ data.expanded = (expanded !== undefined && expanded !== "" && expanded !== null)? expanded:data.expanded;
+ data.selected = (data.selected === undefined || data.selected === "")? SOTE.util.extractFromQuery(args.self.id,args.self.getValue()):data.selected;
args.self.items = data;
args.self.render();
- args.self.setValue(value);
};
-
+
/**
* Static function to handle a failed retrieval from the data accessor
*
diff --git a/js/dateSpan.js b/js/dateSpan.js
index f0d82162d..19563b876 100644
--- a/js/dateSpan.js
+++ b/js/dateSpan.js
@@ -85,7 +85,7 @@ SOTE.widget.DateSpan = function(containerId, config){
this.thumbSource = config.thumbSource;
this.extent = config.extent;
this.product = config.product;
- this.value = config.selected;
+ this.value = config.selected;
this.dataSourceUrl = config.dataSourceUrl;
this.statusStr = "";
this.init();
@@ -109,25 +109,33 @@ SOTE.widget.DateSpan.prototype.init = function(){
//bgStripe.setAttribute('class','horizontalContainer');
var spanContainer = document.createElement('div');
spanContainer.setAttribute('class','spanContainer');
+ spanContainer.setAttribute('id',this.id+'spanContainer');
//bgStripe.appendChild(spanContainer);
this.container.appendChild(spanContainer);
+ var labelForSpanContainer = document.createElement('label');
+ labelForSpanContainer.setAttribute('for',this.id+'spanContainer');
+ labelForSpanContainer.setAttribute('class','spanContainerLabel');
+ labelForSpanContainer.innerHTML = "<span class='.annotation'>* drag the slider to select a date</span><span id='"+this.id+
+ "spanContainerLabelDate'class='spanContainerLabelDate'></span><span id='"+this.id+
+ "spanContainerLabelTime' class='spanContainerLabelTime'></span>";
+ this.container.appendChild(labelForSpanContainer);
var numOfDays = this.range/24/60/60/1000;
-
+ var startDate = new Date(this.endDate.getTime() - this.range);
for(var i=0; i < numOfDays; ++i){
var mapDiv = document.createElement('div');
mapDiv.setAttribute('id','mapdiv'+i);
mapDiv.setAttribute('class','dateitem');
spanContainer.appendChild(mapDiv);
-
- var time = new Date(this.endDate.getTime() - i*24*60*60*1000);
+ var time = new Date(startDate.getTime() + i*24*60*60*1000);
+ //var time = new Date(this.endDate.getTime() - i*24*60*60*1000);
var timeString = time.getFullYear() + "-" + eval(time.getMonth()+1) + "-" + time.getDate();
this.maps.push(new SOTE.widget.Map('mapdiv'+i,{baseLayer:"Terra_MODIS",time:timeString,hasControls:false}));
}
var slider = document.createElement('div');
slider.setAttribute('id',this.id+'sliderDiv');
- slider.innerHTML = '<input type="range" name="slider" id="'+this.id+'slider" class="dateSpanSlider" value="0" min="0" max="100" step="1" />';
+ slider.innerHTML = '<input type="range" name="slider" id="'+this.id+'slider" class="dateSpanSlider" value="100" min="0" max="100" step="1" />';
spanContainer.appendChild(slider);
$('#'+this.id+'slider').slider();
@@ -140,6 +148,11 @@ SOTE.widget.DateSpan.prototype.init = function(){
alert("No REGISTRY found! Cannot register AccordionPicker!");
}
+ this.spanDate = document.getElementById(this.id+"spanContainerLabelDate");
+ this.spanTime = document.getElementById(this.id+"spanContainerLabelTime");
+
+ this.setVisualDate();
+
};
/**
@@ -164,9 +177,9 @@ SOTE.widget.DateSpan.handleSlide = function(e,ui){
var value = e.target.value;
var self = e.data.self;
- var x = self.range * (value)/100;
+ var x = self.range * (100-value)/100;
var time = new Date(self.endDate.getTime() - x);
-
+ self.setVisualDate();
self.setValue(time.toUTCString());
};
@@ -183,6 +196,13 @@ SOTE.widget.DateSpan.prototype.setValue = function(value){
this.fire();
};
+SOTE.widget.DateSpan.prototype.setVisualDate = function(){
+ this.spanDate.innerHTML = this.value.getFullYear() + "-" + SOTE.util.zeroPad(eval(this.value.getMonth()+1),2) + "-" +
+ SOTE.util.zeroPad(this.value.getDate(),2);
+ this.spanTime.innerHTML = SOTE.util.zeroPad(this.value.getHours(),2) + ":" +
+ SOTE.util.zeroPad(this.value.getMinutes(),2) + ":" + SOTE.util.zeroPad(this.value.getSeconds(),2);
+};
+
/**
* Gets the currently selected date in ISO8601 format
*
@@ -207,7 +227,15 @@ SOTE.widget.DateSpan.prototype.getValue = function(){
*/
SOTE.widget.DateSpan.prototype.updateComponent = function(qs){
var bbox = SOTE.util.extractFromQuery('map',qs);
- for(var i=0; i<this.maps.length; i++){
+ var products = SOTE.util.extractFromQuery('products',qs);
+ var activeLayers = products.split(".");
+ var numOfDays = this.range/24/60/60/1000;
+ var startDate = new Date(this.endDate.getTime() - this.range);
+ for(var i=0; i<numOfDays; i++){
+ var time = new Date(startDate.getTime() + i*24*60*60*1000);
+ var timeString = time.getFullYear() + "-" + SOTE.util.zeroPad(eval(time.getMonth()+1),2) + "-" +
+ SOTE.util.zeroPad(time.getDate(),2);
+ this.maps[i].activateLayersDisableTheRest(activeLayers,timeString);
this.maps[i].setValue(bbox);
}
};
diff --git a/js/map.js b/js/map.js
index 51c3f5096..251558785 100644
--- a/js/map.js
+++ b/js/map.js
@@ -174,7 +174,7 @@ SOTE.widget.Map.prototype.activateLayersDisableTheRest = function(activeLayerNam
{
allLayers[i].setVisibility(true);
allLayers[i].setOpacity(1.0);
- if (j>0)
+ if (i>1)
allLayers[i].setZIndex(1);
isLayerFound = true;
}
diff --git a/js/mapSote.js b/js/mapSote.js
index 755541f1c..c85c28a9a 100644
--- a/js/mapSote.js
+++ b/js/mapSote.js
@@ -56,7 +56,7 @@ SOTE.widget.MapSote.prototype.getNumTimeStepsAvailable = function()
// TODO: compute based on date values in soteMapData, not the length
return this.soteMapData.length;
-}
+};
SOTE.widget.MapSote.prototype.setLayerCaching = function(enable)
{
diff --git a/js/menuPicker.js b/js/menuPicker.js
index 6017ca5c3..0a3aabad3 100644
--- a/js/menuPicker.js
+++ b/js/menuPicker.js
@@ -151,6 +151,7 @@ SOTE.widget.MenuPicker.prototype.setValue = function(value){
else {
this.selectedValue = oldSelectedValue;
}
+ this.fire();
return validation;
};
@@ -162,7 +163,7 @@ SOTE.widget.MenuPicker.prototype.setValue = function(value){
*
*/
SOTE.widget.MenuPicker.prototype.getValue = function(){
- return this.selectedValue;
+ return this.id+"="+this.selectedValue;
};
/**
diff --git a/js/sote.js b/js/sote.js
index 1f1455420..68e78e9fa 100644
--- a/js/sote.js
+++ b/js/sote.js
@@ -1,9 +1,18 @@
window.onload = function(){// Initialize "static" vars
// Create map
- var m = new SOTE.widget.MapSote("map",{baseLayer:"Terra_MODIS",time:"2011-11-30"});
+ var m = new SOTE.widget.MapSote("map",{baseLayer:"Aqua_MODIS",time:"2011-11-26"});
var a = new SOTE.widget.AccordionPicker("products",{dataSourceUrl:"data/ap.json"});
var h = new SOTE.widget.MenuPicker("hazard",{dataSourceUrl:"data/mp_hazard.json"});
- var tr = new SOTE.widget.MenuPicker("transition",{dataSourceUrl:"data/mp_transition.json",selected:"sta"});
+ //var tr = new SOTE.widget.MenuPicker("transition",{dataSourceUrl:"data/mp_transition.json",selected:"sta"});
var map = new SOTE.widget.DateSpan("time");
-}
\ No newline at end of file
+}
+
+function showOverlay(){
+ var overlay = new YAHOO.widget.Panel("panel1", { fixedcenter:true,
+ visible:false,
+ width:"300px"} );
+ overlay.setBody("<p>Hello World</p>");
+ overlay.render(document.body);
+ overlay.show();
+}