[OpenLayers-Commits] r12342 - in sandbox/mpriour/temporal_map/openlayers: examples lib lib/OpenLayers lib/OpenLayers/Control lib/OpenLayers/TimeHandler

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Thu Sep 8 00:33:17 EDT 2011


Author: mpriour
Date: 2011-09-07 21:33:16 -0700 (Wed, 07 Sep 2011)
New Revision: 12342

Added:
   sandbox/mpriour/temporal_map/openlayers/lib/OpenLayers/TimeHandler/
   sandbox/mpriour/temporal_map/openlayers/lib/OpenLayers/TimeHandler/WMS.js
Modified:
   sandbox/mpriour/temporal_map/openlayers/examples/time-control.html
   sandbox/mpriour/temporal_map/openlayers/examples/wmst.html
   sandbox/mpriour/temporal_map/openlayers/lib/OpenLayers.js
   sandbox/mpriour/temporal_map/openlayers/lib/OpenLayers/Control/TimeManager.js
Log:
Update examples and fix bugs to use automatic initialization of the TimeManager control.
TODO: Still need to auto-configure the control's units & step properties from controlled layers at some reasonable point with some reasonable values.

Modified: sandbox/mpriour/temporal_map/openlayers/examples/time-control.html
===================================================================
--- sandbox/mpriour/temporal_map/openlayers/examples/time-control.html	2011-09-08 04:30:05 UTC (rev 12341)
+++ sandbox/mpriour/temporal_map/openlayers/examples/time-control.html	2011-09-08 04:33:16 UTC (rev 12342)
@@ -30,9 +30,10 @@
 				time:OpenLayers.Date.toISOString(OpenLayers.Date.parse('2011-08-17T12:00:00Z')),
 				srs:'EPSG:900913'
 			},{
-				timeInterval:[OpenLayers.Date.parse('2011-08-17T12:00:00Z'),OpenLayers.Date.parse('2011-08-29T00:00:00Z')],
-				timeStep:6,
-				timeUnit:OpenLayers.TimeUnit.HOURS,
+				metadata: {
+                    timeInterval: 
+                        [OpenLayers.Date.parse('2011-08-17T12:00:00Z'), OpenLayers.Date.parse('2011-08-29T00:00:00Z')]
+                },
                 singleTile:true,
                 ratio:1,
                 transitionEffect:'resize',
@@ -59,11 +60,9 @@
 		});
 			
 			timeCtl = new OpenLayers.Control.TimeManager({
-				range:pts_wms.timeInterval,
-				units:pts_wms.timeUnit,
-				step:pts_wms.timeStep,
-				frameRate:1.3,
-				layers:[pts_wms]
+				units:OpenLayers.TimeUnit.HOURS,
+				step:6,
+				frameRate:1.3
 			});
 			timeCtl.events.on({
 				'tick': update_date,
@@ -72,8 +71,8 @@
 				scope: timeCtl
 			});
 
+            map.addControls([timeCtl,new OpenLayers.Control.LayerSwitcher()]);
             map.addLayers([osm,line_wms, pts_wms]);
-            map.addControl(new OpenLayers.Control.LayerSwitcher());
             map.zoomToExtent(new OpenLayers.Bounds(-8627260.535278,1425478.519205,-3729202.941056,5496444.989113));
 			update_date({
 				object: timeCtl,

Modified: sandbox/mpriour/temporal_map/openlayers/examples/wmst.html
===================================================================
--- sandbox/mpriour/temporal_map/openlayers/examples/wmst.html	2011-09-08 04:30:05 UTC (rev 12341)
+++ sandbox/mpriour/temporal_map/openlayers/examples/wmst.html	2011-09-08 04:33:16 UTC (rev 12342)
@@ -11,14 +11,15 @@
     <script type="text/javascript">
         var map, ia_wms;
         function init(){
+            
+            timeCtl = new OpenLayers.Control.TimeManager({
+                step: 5,
+                units: OpenLayers.TimeUnit.MINUTES
+            });
             map = new OpenLayers.Map('map');
-
+            map.addControl(timeCtl);
             var ol_wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",
-                "http://vmap0.tiles.osgeo.org/wms/vmap0?", {layers: 'basic'} );
-
-            var jpl_wms = new OpenLayers.Layer.WMS( "NASA Global Mosaic",
-                "http://t1.hypercube.telascience.org/cgi-bin/landsat7", 
-                {layers: "landsat7"});
+                "http://vmap0.tiles.osgeo.org/wms/vmap0?", {layers: 'vmap0'} );
 			
 			var last5min = new Date(Math.floor(Date.now()/3e5)*3e5);
 			var last65min = new Date(Math.floor(Date.now()/3e5)*3e5-36e5)
@@ -29,29 +30,26 @@
 				format: 'image/png',
 				time:OpenLayers.Date.toISOString(last65min)
 			},{
-				timeInterval:[last65min,last5min],
-				timeStep:5,
-				timeUnit:OpenLayers.TimeUnit.MINUTES,
-				singleTile:true,
-				ratio:1
+				metadata: {
+                    timeInterval: [last65min, last5min],
+                    timeStep: 5,
+                    timeUnit: OpenLayers.TimeUnit.MINUTES
+                },
+                singleTile:true,
+                ratio:1,
+                transitionEffect:'resize'
+                //buffer:0,
+                //smoothRedraw:true
 			});
-
-            jpl_wms.setVisibility(false);
 			
-			timeCtl = new OpenLayers.Control.TimeManager({
-				range:ia_wms.timeInterval,
-				units:ia_wms.timeUnit,
-				step:ia_wms.timeStep,
-				layers:[ia_wms]
-			});
-			timeCtl.events.on({
+            timeCtl.events.on({
 				'tick': update_date,
 				'reset': update_date,
 				'stop':function(evt){if(evt.rangeExceeded)alert('End of time range')},
 				scope: timeCtl
 			});
 
-            map.addLayers([ol_wms, jpl_wms, ia_wms]);
+            map.addLayers([ol_wms, ia_wms]);
             map.addControl(new OpenLayers.Control.LayerSwitcher());
             map.zoomToExtent(new OpenLayers.Bounds(-100.898437,22.148438,-78.398437,39.726563));
 			update_date({
@@ -62,7 +60,7 @@
         function update_date(evt) {
             var time = this.currentTime||evt.currentTime;
 			OpenLayers.Util.getElement('year').value = time.getFullYear();
-			OpenLayers.Util.getElement('month').value = time.getMonth();
+			OpenLayers.Util.getElement('month').value = time.getMonth()+1;
             OpenLayers.Util.getElement('day').value = time.getDate();
             OpenLayers.Util.getElement('hour').value = time.getHours();
             OpenLayers.Util.getElement('minute').value = time.getMinutes();

Modified: sandbox/mpriour/temporal_map/openlayers/lib/OpenLayers/Control/TimeManager.js
===================================================================
--- sandbox/mpriour/temporal_map/openlayers/lib/OpenLayers/Control/TimeManager.js	2011-09-08 04:30:05 UTC (rev 12341)
+++ sandbox/mpriour/temporal_map/openlayers/lib/OpenLayers/Control/TimeManager.js	2011-09-08 04:33:16 UTC (rev 12342)
@@ -144,7 +144,7 @@
 			if(!(this.range[1] instanceof Date))this.range[1]=OpenLayers.Date.parse(this.range[1]);
             this.fixedRange = true;
 		}
-		if (this.range[0]) {
+		if (this.range && this.range.length) {
             this.currentTime = new Date(this.range[0].getTime());
         }
 		if (options.layers) {
@@ -174,11 +174,11 @@
         OpenLayers.Control.prototype.setMap.call(this,map);
         //if the control was not directly intialized with specific layers, then
         //get layers from map and build appropiate time handlers
-        if(!this.timeHandlers){
-            for(var i=0,len=map.layers.length;i<len;i++){
-                var lyr=map.layers[i];
-                if(lyr.metadata.timeInterval && lyr.metadata.timeInterval.length){
-                    if(!this.layers)layers=[];
+        if (!this.timeHandlers) {
+            for (var i = 0, len = map.layers.length; i < len; i++) {
+                var lyr = map.layers[i];
+                if (lyr.metadata.timeInterval && lyr.metadata.timeInterval.length) {
+                    if (!this.layers) this.layers = [];
                     this.layers.push(lyr);
                 }
             }
@@ -191,6 +191,7 @@
         //if no range was specified then get from timeHandlers
         if(!this.range){
             this.range = this.buildRange(this.timeHandlers);
+            if(this.range)this.currentTime = new Date(this.range[(this.step>0)?0:1].getTime())
         }
         
         //set map handlers for layer additions and removal
@@ -227,12 +228,17 @@
                     this.intervals || (this.intervals = []);
                     this.intervals = this.getUniqueDates(this.intervals.concat(lyrIntervals));
                     //adjust range as needed
-                    if(this.intervals[0]<this.range[0]){this.range[0]=new Date(this.intervals[0].getTime())}
-                    if(this.intervals[1]>this.range[1]){this.range[1]=new Date(this.intervals[1].getTime())}
+                    if(this.intervals[0]<this.range[0]||this.intervals[1]>this.range[1]){
+                        this.setRange([Math.min(this.intervals[0],this.range[0]),Math.max(this.intervals[1],this.range[1])])
+                    }
                 }
                 else if(!this.fixedRange){
-                    if(lyrIntervals[0]<this.range[0]){this.range[0]=new Date(lyrIntervals[0].getTime())}
-                    if(lyrIntervals[1]>this.range[1]){this.range[1]=new Date(lyrIntervals[1].getTime())}
+                    if(!this.range){
+                        this.setRange(lyrIntervals);
+                    }
+                    else if(lyrIntervals[0]<this.range[0]||lyrIntervals[1]>this.range[1]){
+                        this.setRange([Math.min(lyrIntervals[0],this.range[0]),Math.max(lyrIntervals[1],this.range[1])])
+                    }
                 }
             }
         }
@@ -256,12 +262,13 @@
             }
             if(lyrIntervals.length>2 && !this.fixedIntervals){
                 this.intervals = this.buildIntervals(this.timeHandlers);
-                if(this.intervals[0]>this.range[0]){this.range[0]=new Date(this.intervals[0].getTime())}
-                if(this.intervals[1]<this.range[1]){this.range[1]=new Date(this.intervals[1].getTime())}
+                if(this.intervals[0]<this.range[0]||this.intervals[1]>this.range[1]){
+                    this.setRange([Math.min(this.intervals[0],this.range[0]),Math.max(this.intervals[1],this.range[1])])
+                }
             }
             else if(!this.fixedRange){
                 if (lyrIntervals[0].getTime() == this.range[0].getTime() || lyrIntervals[1].getTime() == this.range[1].getTime()) {
-                    this.range = this.buildRange(this.timeHandlers);
+                    this.setRange(this.buildRange(this.timeHandlers));
                 }
             }
         }
@@ -309,7 +316,7 @@
                 }
                 return canTick;
             }
-            if (canTickCheck()) {
+            if (canTickCheck.call(this)) {
                 this.events.triggerEvent('tick', {currentTime: this.currentTime});
             }else{
                 //TODO: Handle not yet ready timeHandlers & don't tick until we're ready
@@ -351,7 +358,7 @@
 		if(!(range[1] instanceof Date))range[1]=OpenLayers.Date.parse(range[1]);
 		this.range=range;
 		//set current time to correct location if the timer isn't running yet.
-		if(!this.timer){this.currentTime = this.range[(this.step>0)?0:1]}
+		if(!this.timer){this.currentTime = new Date(this.range[(this.step>0)?0:1].getTime())}
 	},
 	/**
 	 * Method:setStart
@@ -367,7 +374,7 @@
 		if(!(time instanceof Date))time=OpenLayers.Date.parse(time);
 		this.range[(this.step>0)?0:1]=time;
 		//set current time to this start time if we haven't already started
-		!this.timer && (this.currentTime=time);
+		!this.timer && (this.currentTime=new Date(time.getTime()));
 	},
 	/**
 	 * Method:setEnd
@@ -394,6 +401,7 @@
 	setTime:function(time){
 		if(!(time instanceof Date))time=OpenLayers.Date.parse(time);
 		this.currentTime = time;
+        this.events.triggerEvent('tick',{'currentTime':this.currentTime});
 	},
 	/**
 	 * Method:reset
@@ -404,8 +412,9 @@
 	 */
 	reset:function(){
 		this.timer && clearInterval(this.timer);
-		this.currentTime = (this.step>0)?new Date(this.range[0].getTime()):new Date(this.range[1].getTime());
-		this.events.triggerEvent('reset',{'looped':false,'currentTime':this.currentTime});
+		this.currentTime = new Date(this.range[(this.step>0)?0:1].getTime());
+		this.events.triggerEvent('reset',{'looped':false});
+        this.events.triggerEvent('tick',{'currentTime':this.currentTime});
 		return this.currentTime;
 	},
 	/**
@@ -432,7 +441,7 @@
 	 * {Array(<OpenLayers.Control.TimeControl>)}
 	 */
 	buildTimeHandlers:function(layers){
-		layers = layers || this.layers;
+		layers = layers || this.layers || [];
 		var layerTypes = {}, handlers = [];
 		//categorize layers and separate into arrays for use in subclasses
 		for(var i=0,len=layers.length;i<len;i++){
@@ -477,7 +486,7 @@
 			})
 			handlers.push(handler)
 		}
-		return handlers;
+		return (handlers.length)?handlers:null;
 	},
 	/**
 	 * Method: buildIntervals
@@ -490,7 +499,7 @@
 	 * Returns: {Array(Date)}
 	 */
     buildIntervals:function(handlers){
-        handlers = handlers || this.timeHandlers;
+        handlers = handlers || this.timeHandlers || [];
         var intervals = [];
         for(var i=0,len=handlers.length;i<len;i++){
             var handler = handlers[i];
@@ -512,14 +521,14 @@
 	 * Returns: {Array(Date)}
 	 */
     buildRange:function(handlers){
-        handlers = handlers || this.timeHandlers;
+        handlers = handlers || this.timeHandlers || [];
         var range = [];
         for(var i=0,len=handlers.length;i<len;i++){
             var subrange = handlers[i].range;
-            if(!subrange[0] || subrange[0]<range[0]){range[0]=new Date(subrange[0].getTime())}
-            if(!subrange[1] || subrange[1]>range[1]){range[1]=new Date(subrange[1].getTime())}
+            if(!range[0] || subrange[0]<range[0]){range[0]=new Date(subrange[0].getTime())}
+            if(!range[1] || subrange[1]>range[1]){range[1]=new Date(subrange[1].getTime())}
         }
-        return range;
+        return (range.length)?range:null;
     },
     getUniqueDates:function(dates){
         //sort the times

Added: sandbox/mpriour/temporal_map/openlayers/lib/OpenLayers/TimeHandler/WMS.js
===================================================================
--- sandbox/mpriour/temporal_map/openlayers/lib/OpenLayers/TimeHandler/WMS.js	                        (rev 0)
+++ sandbox/mpriour/temporal_map/openlayers/lib/OpenLayers/TimeHandler/WMS.js	2011-09-08 04:33:16 UTC (rev 12342)
@@ -0,0 +1,71 @@
+/* Copyright (c) 2006-2011 by OpenLayers Contributors (see authors.txt for 
+ * full list of contributors). Published under the Clear BSD license.  
+ * See http://svn.openlayers.org/trunk/openlayers/license.txt for the
+ * full text of the license. */
+
+
+/**
+ * @requires OpenLayers/TimeHandler.js
+ */
+
+/**
+ * Class: OpenLayers.TimeHandler.WMS
+ * Class to display and animate WMS layers across time.
+ * This class is created by {OpenLayers.Control.TimeManager} instances
+ *
+ * Inherits From:
+ *  - <OpenLayers.TimeHandler>
+ */
+OpenLayers.TimeHandler.WMS = OpenLayers.Class(OpenLayers.TimeHandler,{
+    /**
+	 * Property: intervalMode
+	 * {String} If a wms layer has distinct valid time intervals,
+	 *     then this property will control if and how the animation time is
+	 *     translated into a valid time instance for the layer
+	 *     Must be one of:
+	 *     "lastValid" - continue to display it using the last valid time within
+	 *         the overall control time range
+     *     "nearest" - (Default) use the nearest valid time within the overall
+     *         control time range.
+     *     "exact" - only display the layer when there's an exact match (to the 
+     *         grainularity of the step unit) in the control time and an interval
+	 */
+	intervalMode:'nearest',
+	
+	/**
+     * Constructor: OpenLayers.Control.TimeManager.WMS
+     * Create a new time manager control for temporal WMS layers.
+     *
+     * Parameters:
+     * options - {Object} Optional object whose properties will be set on the
+     *     control.
+     */
+	initialize:function(options){
+		OpenLayers.TimeHandler.prototype.initialize.call(this,options);
+	},
+	
+	onTick:function(evt){
+		this.currentTime = evt.currentTime || this.timeManager.currentTime;
+		if(this.currentTime<=this.range[1] && this.currentTime>=this.range[0]){
+			for(var i=0,len=this.layers.length;i<len;i++){
+				this.applyTime(this.layers[i],this.currentTime);
+			}
+		}else{
+			for(var i=0,len=this.layers.length;i<len;i++){
+				layers[i].setVisibility(false);
+			}
+		}
+	},
+	
+	applyTime:function(layer,time){
+		if(layer.metadata.timeInterval.length>2 && this.intervalMode != "exact"){
+			//TODO implement special case handling
+		}else{
+			//format time in ISO:8601 format
+			var isotime = OpenLayers.Date.toISOString(time);
+			layer.mergeNewParams({time:isotime});
+		}
+	},
+	
+	CLASS_NAME:'OpenLayers.TimeHandler.WMS'
+});
\ No newline at end of file

Modified: sandbox/mpriour/temporal_map/openlayers/lib/OpenLayers.js
===================================================================
--- sandbox/mpriour/temporal_map/openlayers/lib/OpenLayers.js	2011-09-08 04:30:05 UTC (rev 12341)
+++ sandbox/mpriour/temporal_map/openlayers/lib/OpenLayers.js	2011-09-08 04:33:16 UTC (rev 12342)
@@ -213,7 +213,8 @@
                 "OpenLayers/Control/TransformFeature.js",
                 "OpenLayers/Control/SLDSelect.js",
 				"OpenLayers/Control/TimeManager.js",
-				"OpenLayers/Control/TimeManager/WMS.js",
+				"OpenLayers/TimeHandler.js",
+                "OpenLayers/TimeHandler/WMS.js",
                 "OpenLayers/Geometry.js",
                 "OpenLayers/Geometry/Rectangle.js",
                 "OpenLayers/Geometry/Collection.js",



More information about the Commits mailing list