Changeset 6362
- Timestamp:
- 02/24/08 21:48:18 (11 months ago)
- Files:
-
- sandbox/achipa/openlayers/lib/OpenLayers.js (modified) (1 diff)
- sandbox/achipa/openlayers/lib/OpenLayers/BaseTypes/ExtDate.js (moved) (moved from sandbox/achipa/openlayers/lib/OpenLayers/BaseTypes/DateTime.js) (2 diffs)
- sandbox/achipa/openlayers/lib/OpenLayers/Control/PanTimeBar.js (modified) (2 diffs)
- sandbox/achipa/openlayers/lib/OpenLayers/Layer.js (modified) (4 diffs)
- sandbox/achipa/openlayers/lib/OpenLayers/Layer/TimedPointTrack.js (modified) (5 diffs)
- sandbox/achipa/openlayers/lib/OpenLayers/Map.js (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
sandbox/achipa/openlayers/lib/OpenLayers.js
r6310 r6362 79 79 "OpenLayers/BaseTypes/Pixel.js", 80 80 "OpenLayers/BaseTypes/Size.js", 81 "OpenLayers/BaseTypes/ DateTime.js",81 "OpenLayers/BaseTypes/ExtDate.js", 82 82 "OpenLayers/Console.js", 83 83 "Rico/Corner.js", sandbox/achipa/openlayers/lib/OpenLayers/BaseTypes/ExtDate.js
r6328 r6362 3 3 * Instances of this class represent moments or intervals of time. This allows us to 4 4 * give the spatial data a temporal dimension and act accordingly. The default timezone 5 * is UTC and the precision is in seconds. The minimum representable time is 6 * 1970-01-01T00:00:00Z, and the maximum representable time is 2038-01-19T03:14:07Z 5 * is UTC and the precision is in seconds. 6 */ 7 8 9 Date.prototype.duration = 0; 10 11 /** 12 * Method: contains 13 * Return whether the parameter date is fully contained within the interval of the Date method 14 * in whose context this function is called 7 15 * 16 * Parameters: 17 * {Date} targetdate 18 * 19 * Returns: 20 * {bool} 8 21 */ 9 OpenLayers.DateTime = OpenLayers.Class(Date, { 22 Date.prototype.contains = function(targetdate) { 23 if (targetdate >= this && targetdate.getTime() + targetdate.duration <= this.getTime() + this.duration) 24 return true; 10 25 11 /** 12 * Property: to 13 * {Number} 14 */ 15 to: null, 26 return false; 27 }; 16 28 17 /** 18 * Property: zone 19 * {Number} 20 */ 21 zone: 'UTC', 29 /** 30 * Method: getEndDate 31 * Returns a {Date} object with the value of the end of the interval represented in this object 32 * 33 * Returns: 34 * {Date} 35 */ 36 Date.prototype.getEndDate = function() { 37 return new Date(this.getTime() + this.duration); 38 }; 22 39 23 /** 24 * Constructor: OpenLayers.DateTime 25 * Construct a new time object. 26 * 27 * Parameters: 28 * begin - {Date} The start bounds. 29 * end - {Date} The end bounds. 30 * zone - {String} Time zone. 31 */ 32 initialize: function(begin, end, zone) { 33 if (begin != null) { 34 this.prototype.setTime(begin); 35 } 36 if (end != null) { 37 if (begin > end) { // we got them swapped 38 this.to = begin; 39 this.from = end; 40 } else { 41 this.to = end; 42 } 43 } 44 if (this.from == this.to) { 45 this.interval = false; 46 } 47 }, 40 /** 41 * Method: getPlaceInInterval 42 * Returns a float value between 0 and 1 depending on where the targetdate parameter is in the 43 * date objects' time interval. If targetdate starts earlier than the date object, 0 is returned, 44 * if it starts after the end of the date object, 1 is returned. 45 * 46 * The optional second {bool} parameter defines whether the center of the 47 * targetdate's interval should be used (default is false). 48 * 49 * Parameters: 50 * {Date} targetdate 51 * {bool} us e 52 * 53 * Returns: 54 * {float} 0.0 - 1.0 55 */ 56 Date.prototype.getPlaceInInterval = function(targetdate, center) { 57 var centerdate = targetdate; 58 if (center && targetdate.duration != 0) 59 centerdate = new Date(targetdate.getTime() + targetdate.duration/2); 48 60 49 /** 50 * Method: setTime 51 * Set time 52 * 53 */ 54 setTime:function(targetdate) { 55 this.prototype.setTime(targetdate.getTime()); 56 if (targetdate.isInterval()) 57 this.setEnd(targetdate.to); 58 else 59 this.to = null; 60 }, 61 if (centerdate.getTime() > this.getTime() + this.duration) 62 return 1; 63 else if (targetdate <= centerdate) // using <= to accomodate for non-interval datetimes 64 return 0; 65 else 66 return (centerdate - this) / this.duration ; 67 68 }; 61 69 62 /** 63 * Method: setEnd 64 * Set time 65 * 66 */ 67 setEnd:function(targetdate) { 68 if (targetdate.isInterval()) 69 this.to = new Date(targetdate.to); 70 else 71 this.to = new Date(targetdate); 70 /** 71 * Method: equals 72 * Returns whether the targetdate is equal by both start times and duration to the objects' 73 * 74 * Parameters: 75 * {Date} targetdate 76 * 77 * Returns: 78 * {bool} 79 */ 80 Date.prototype.equals = function(targetdate) { 81 if (this == targetdate && this.duration == targetduration.duration) return true; 82 return false; 83 }; 72 84 73 if (this > this.to) { // we got them swapped74 this.tmp = this.to.getTime();75 this.to.setTime(this.getTime());76 this.prototype.setTime(this.tmp);77 delete this.tmp;78 }79 },80 81 /**82 * Method: contains83 * Set time84 *85 */86 contains:function(targetdate) {87 if (targetdate >= this && targetdate <= this.to && // start date within range88 (!targetdate.isInterval()) || (targetdate.to >= this && targetdate.to <= this.to)) // and both dates in range if it's an interval89 return true;90 91 return false;92 },93 94 /**95 * Method: contains96 * Set time97 *98 */99 getPlaceInInterval:function(targetdate) {100 if (targetdate) {101 if (targetdate > this.to)102 return 1;103 else if (targetdate <= this) // using <= to accomodate for non-interval datetimes104 return 0;105 106 return (targetdate - this) / (this.to - this) ;107 }108 return -1;109 },110 111 equal: function(dateTime) {112 if (this.from == dateTime.from && this.to == dateTime.to) return true;113 return false;114 },115 116 isInterval: function() {117 if (to)118 return true;119 120 return false;121 },122 123 CLASS_NAME: "OpenLayers.DateTime"124 125 });126 85 127 86 /** … … 130 89 * 131 90 */ 132 OpenLayers.DateTime.fromRFC3339 = function(datestr) {91 Date.fromRFC3339 = function(datestr) { 133 92 var targetdate = new Date(); 134 93 if (datestr) { sandbox/achipa/openlayers/lib/OpenLayers/Control/PanTimeBar.js
r6310 r6362 383 383 has = false; 384 384 for (j=0; j < this.time.length; j++) { 385 if (this.time[j].equal (features[i].dateTime)) {385 if (this.time[j].equals(features[i].dateTime)) { 386 386 has = true 387 387 continue; … … 397 397 else if (this.now >= this.time.length) this.now = this.time.length-1; 398 398 for (var i=0; i < this.map.layers.length; i++) { 399 if (this.map.layers[i].isTemporalLayer()) this.map.layers[i].set DateTime(this.time[this.now].from);399 if (this.map.layers[i].isTemporalLayer()) this.map.layers[i].setTime(this.time[this.now]); 400 400 } 401 401 }, sandbox/achipa/openlayers/lib/OpenLayers/Layer.js
r6310 r6362 1044 1044 1045 1045 getDateTimeIntervals: function () { 1046 alert(this.datetimeIntervals);1047 1046 return this.datetimeIntervals; 1048 1047 }, … … 1050 1049 /** 1051 1050 * Method: setDateTime 1052 * {Date} or {<OpenLayers.DateTime>}Sets the current date/time in the layers1053 * 1054 */ 1055 set DateTime: function (dt) {1051 * {Date} Sets the current date/time in the layers 1052 * 1053 */ 1054 setTime: function (dt) { 1056 1055 if (!this.isTemporalLayer()) 1057 1056 return; 1058 1057 1059 if ( typeof dt == "OpenLayers.DateTime")1058 if (!this.currentDateTime.equals(dt)){ 1060 1059 this.currentDateTime = dt; 1061 else 1062 this.currentDateTime = new OpenLayers.DateTime(dt); 1063 1064 this.events.triggerEvent("datetimechanged"); 1065 }, 1066 1067 /** 1068 * Method: getStartDateTime 1060 this.events.triggerEvent("datetimechanged"); 1061 } 1062 }, 1063 1064 /** 1065 * Method: getStartTime 1069 1066 * {Date} Returns the first date/time the layer is available for, null 1070 1067 * if the layer has no temporal conotation 1071 1068 * 1072 1069 */ 1073 getStart DateTime: function () {1070 getStartTime: function () { 1074 1071 if (!this.isTemporalLayer()) 1075 1072 return null; … … 1078 1075 return null; 1079 1076 1080 return this.datetimeIntervals[0] .from;1081 }, 1082 1083 /** 1084 * Method: getStop DateTime1077 return this.datetimeIntervals[0]; 1078 }, 1079 1080 /** 1081 * Method: getStopTime 1085 1082 * {Date} Returns the last date/time the layer is available for, null 1086 1083 * if the layer has no temporal conotation 1087 1084 * 1088 1085 */ 1089 getStop DateTime: function () {1086 getStopTime: function () { 1090 1087 if (!this.isTemporalLayer()) 1091 1088 return null; … … 1094 1091 return null; 1095 1092 1096 return this.datetimeIntervals[this.datetimeIntervals.length -1].to;1093 return new Date(this.datetimeIntervals[this.datetimeIntervals.length -1].getTime() + this.datetimeIntervals[this.datetimeIntervals.length -1].duration); 1097 1094 }, 1098 1095 sandbox/achipa/openlayers/lib/OpenLayers/Layer/TimedPointTrack.js
r6311 r6362 91 91 updateHighlight: function(){ 92 92 this.renderer.eraseFeatures([this.highlight]); 93 if (!this.permanentHighlight && (this.getStart DateTime() > this.currentDateTime.to || this.getStopDateTime() < this.currentDateTime.from))93 if (!this.permanentHighlight && (this.getStartTime() > this.currentDateTime.getEndDate() || this.getStopTime() < this.currentDateTime)) 94 94 return; 95 95 96 96 var closestpoint; 97 97 var closesttime = 0; 98 98 var closestfeature = 0; 99 99 for (var i=0; i < this.features.length; i++){ 100 if (Math.abs( closesttime - this.currentDateTime .from) > // our best result so far is worse100 if (Math.abs( closesttime - this.currentDateTime ) > // our best result so far is worse 101 101 Math.min( // than the result to the closer point in time 102 Math.abs( this.features[i].dateTime .from - this.currentDateTime.from),103 Math.abs( this.features[i].dateTime. to - this.currentDateTime.from)102 Math.abs( this.features[i].dateTime - this.currentDateTime ), 103 Math.abs( this.features[i].dateTime.getEndDate() - this.currentDateTime ) 104 104 ) 105 && (this.features[i].dateTime.contains(this.currentDateTime.from) || !this.features[i].dateTime.interval) // allow Points to match as they might not have intervals106 107 105 ){ 108 closesttime = this.features[i].dateTime .from;106 closesttime = this.features[i].dateTime; 109 107 closestpoint = this.features[i].geometry.components[0]; 110 108 closestfeature = this.features[i]; … … 143 141 for(var i = 0; i < this.features.length; i++) { 144 142 if (this.features[i].attributes["pubdate"]) { 145 pubdate = OpenLayers.DateTime.fromRFC3339(this.features[i].attributes["pubdate"]);143 pubdate = Date.fromRFC3339(this.features[i].attributes["pubdate"]); 146 144 if (pubdate <= begin) 147 145 begin = pubdate; … … 150 148 } 151 149 } 152 this.datetimeIntervals = [new OpenLayers.DateTime(begin, end)]; 150 this.datetimeIntervals = [new Date(begin)]; 151 this.datetimeIntervals[0].duration = end - begin; 153 152 }, 154 153 … … 179 178 180 179 if (pointFeature.data) 181 pubDate = OpenLayers.DateTime.fromRFC3339(pointFeature.data["pubdate"]);180 pubDate = Date.fromRFC3339(pointFeature.data["pubdate"]); 182 181 else if (pointFeature.attributes) 183 pubDate = OpenLayers.DateTime.fromRFC3339(pointFeature.attributes["pubdate"]);182 pubDate = Date.fromRFC3339(pointFeature.attributes["pubdate"]); 184 183 185 184 if (!endPoint) { … … 202 201 lines[i-1] = new OpenLayers.Feature.Vector(line, attributes); 203 202 if (attributes["pubdate"]) { 204 lines[i-1].dateTime = new OpenLayers.DateTime(prevDate, pubDate); 203 lines[i-1].dateTime = new Date(prevDate); 204 lines[i-1].dateTime.duration = pubDate-prevDate; 205 205 } 206 206 } sandbox/achipa/openlayers/lib/OpenLayers/Map.js
r5982 r6362 1921 1921 }, 1922 1922 1923 /** 1924 * Method: setTime 1925 * 1926 * Parameters: 1927 * {Date} Sets the current date/time in all layers 1928 * 1929 */ 1930 setTime: function (dt) { 1931 for(var i=0; i < this.layers.length; i++) 1932 if (this.layers[i].isTemporalLayer()) 1933 this.layers[i].setTime(dt); 1934 }, 1935 1936 1923 1937 CLASS_NAME: "OpenLayers.Map" 1924 1938 });
