Changeset 6369
- Timestamp:
- 02/25/08 22:00:00 (11 months ago)
- Files:
-
- sandbox/achipa/openlayers/examples/time-select-control.html (modified) (2 diffs)
- sandbox/achipa/openlayers/examples/timed-point-track-markers.html (modified) (1 diff)
- sandbox/achipa/openlayers/lib/OpenLayers.js (modified) (1 diff)
- sandbox/achipa/openlayers/lib/OpenLayers/BaseTypes.js (modified) (2 diffs)
- sandbox/achipa/openlayers/lib/OpenLayers/BaseTypes/ExtDate.js (deleted)
- sandbox/achipa/openlayers/lib/OpenLayers/Control/PanTimeBar.js (modified) (1 diff)
- sandbox/achipa/openlayers/lib/OpenLayers/Control/TimePosition.js (added)
- sandbox/achipa/openlayers/lib/OpenLayers/Layer.js (modified) (3 diffs)
- sandbox/achipa/openlayers/lib/OpenLayers/Layer/TimedPointTrack.js (modified) (5 diffs)
- sandbox/achipa/openlayers/lib/OpenLayers/Map.js (modified) (1 diff)
- sandbox/achipa/openlayers/tests/test_BaseTypes.html (modified) (1 diff)
- sandbox/achipa/openlayers/tests/test_Layer.html (modified) (1 diff)
- sandbox/achipa/openlayers/tests/test_Map.html (modified) (1 diff)
- sandbox/achipa/openlayers/theme/default/style.css (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
sandbox/achipa/openlayers/examples/time-select-control.html
r6365 r6369 23 23 timeBar = new OpenLayers.Control.PanTimeBar(); 24 24 map.addControl(timeBar); 25 map.addControl(new OpenLayers.Control.TimePosition()); 26 map.addControl(new OpenLayers.Control.MousePosition()); 25 27 } 26 28 … … 72 74 73 75 function setTime() { 74 var targetdate = Date.fromRFC3339(OpenLayers.Util.getElement('date').value);76 var targetdate = OpenLayers.Date.smartParse(OpenLayers.Util.getElement('date').value); 75 77 map.setTime(targetdate); 76 78 } sandbox/achipa/openlayers/examples/timed-point-track-markers.html
r6364 r6369 67 67 68 68 function setTime() { 69 var targetdate = Date.fromRFC3339(OpenLayers.Util.getElement('date').value);69 var targetdate = OpenLayers.Date.smartParse(OpenLayers.Util.getElement('date').value); 70 70 lineLayer.permanentHighlight = OpenLayers.Util.getElement('phighlight').checked; 71 71 lineLayer.interpolatePoints = OpenLayers.Util.getElement('ipoints').checked; sandbox/achipa/openlayers/lib/OpenLayers.js
r6362 r6369 152 152 "OpenLayers/Control/Permalink.js", 153 153 "OpenLayers/Control/Scale.js", 154 "OpenLayers/Control/TimePosition.js", 154 155 "OpenLayers/Control/LayerSwitcher.js", 155 156 "OpenLayers/Control/DrawFeature.js", sandbox/achipa/openlayers/lib/OpenLayers/BaseTypes.js
r6180 r6369 10 10 * @requires OpenLayers/BaseTypes/Bounds.js 11 11 * @requires OpenLayers/BaseTypes/Element.js 12 * @requires OpenLayers/BaseTypes/DateTime.js13 12 */ 14 13 15 14 /** 16 15 * Header: OpenLayers Base Types 17 * OpenLayers custom string, number and functionfunctions are described here.16 * OpenLayers custom string, number, function and date functions are described here. 18 17 */ 19 18 … … 475 474 476 475 }; 476 477 /********************* 478 * * 479 * DATE * 480 * * 481 *********************/ 482 483 OpenLayers.Date = { 484 485 /** 486 * APIMethod: contains 487 * Return whether the parameter date is fully contained within the interval of the Date method 488 * in whose context this function is called 489 * 490 * Parameters: 491 * {Date} source date context 492 * {Date} targetdate 493 * 494 * Returns: 495 * {bool} 496 */ 497 498 contains: function(source, targetdate) { 499 if (targetdate >= source && OpenLayers.Date.getEndDate(targetdate) <= OpenLayers.Date.getEndDate(source)) 500 return true; 501 return false; 502 }, 503 504 /** 505 * APIMethod: getEndDate 506 * Returns a {Date} object with the value of the end of the interval represented in this object 507 * 508 * Parameters: 509 * {Date} source date context 510 * 511 * Returns: 512 * {Date} 513 */ 514 getEndDate: function(source) { 515 return new Date(source.getTime() + source.duration); 516 }, 517 518 /** 519 * APIMethod: merge 520 * Extends the start or duration of this Date object so it encompasses the interval targetdate object as well 521 * as the currect interval. 522 * 523 * Parameters: 524 * {Date} source date context 525 * {Date} targetdate 526 */ 527 merge: function(source, targetdate) { 528 var range = new Date(source); 529 if (targetdate < source) { 530 range.duration += source - targetdate; 531 range.setTime(targetdate.getTime()); 532 } 533 var extend = OpenLayers.Date.getEndDate(targetdate) - OpenLayers.Date.getEndDate(source); 534 if ( extend > 0){ 535 range.duration += extend; 536 } 537 return range; 538 }, 539 540 /** 541 * APIMethod: getPlaceInInterval 542 * Returns a float value between 0 and 1 depending on where the targetdate parameter is in the 543 * date objects' time interval. If targetdate starts earlier than the date object, 0 is returned, 544 * if it starts after the end of the date object, 1 is returned. 545 * 546 * The optional second {bool} parameter defines whether the center of the 547 * targetdate's interval should be used (default is false). 548 * 549 * Parameters: 550 * {Date} source date context 551 * {Date} targetdate 552 * {bool} use center of targetdate if it's an interval 553 * 554 * Returns: 555 * {float} 0.0 - 1.0 556 */ 557 getPlaceInInterval: function(source, targetdate, center) { 558 if (!targetdate) return 0.0; 559 if (!source.duration) return 0.0; 560 var centerdate = new Date(targetdate); 561 if (center && targetdate.duration != 0) 562 centerdate.setTime(targetdate.getTime() + targetdate.duration/2); 563 564 if (centerdate > OpenLayers.Date.getEndDate(source)) 565 return 1.0; 566 else if (source >= centerdate) // using <= to accomodate for non-interval datetimes 567 return 0.0; 568 else 569 return (centerdate - source) / source.duration ; 570 }, 571 572 /** 573 * APIMethod: equals 574 * Returns whether the targetdate is equal by both start times and duration to the objects' 575 * 576 * Parameters: 577 * {Date} source date context 578 * {Date} targetdate 579 * 580 * Returns: 581 * {bool} 582 */ 583 equals: function(source, targetdate) { 584 if (source == null || targetdate == null) return false; 585 if (source.getTime() == targetdate.getTime() && source.duration == targetdate.duration) return true; 586 return false; 587 }, 588 589 590 /** 591 * APIMethod: smartParse 592 * Parse String date regardless is it's RFC3339 or RFC822 593 * 594 * Parameters: 595 * {String} source date string 596 * 597 * Returns: 598 * {Date} 599 */ 600 smartParse: function(datestr) { 601 var targetdate = new Date(); 602 targetdate.setTime(Date.parse(datestr)); 603 if (datestr && !targetdate.getTime()) { 604 var pattern = /\D+/; 605 var datearray = datestr.split(pattern); 606 targetdate.setTime(Date.UTC(datearray[0], datearray[1]-1, datearray[2], datearray[3], datearray[4], datearray[5])); 607 } 608 return targetdate; 609 } 610 }; 611 612 Date.prototype.duration = 0; sandbox/achipa/openlayers/lib/OpenLayers/Control/PanTimeBar.js
r6365 r6369 383 383 has = false; 384 384 for (j=0; j < this.time.length; j++) { 385 if ( this.time[j].equals(features[i].dateTime)) {385 if (OpenLayers.Date.equals(this.time[j],features[i].dateTime)) { 386 386 has = true 387 387 continue; sandbox/achipa/openlayers/lib/OpenLayers/Layer.js
r6364 r6369 1043 1043 }, 1044 1044 1045 getDateTimeIntervals: function () {1046 return this.datetimeIntervals;1047 },1048 1049 1045 /** 1050 1046 * Method: setTime … … 1056 1052 return; 1057 1053 1058 if (!this.currentDateTime || ! this.currentDateTime.equals(dt)){1054 if (!this.currentDateTime || !OpenLayers.Date.equals(this.currentDateTime,dt)){ 1059 1055 this.currentDateTime = dt; 1060 1056 } … … 1067 1063 */ 1068 1064 setTimeFromMap: function () { 1069 if (!this.isTemporalLayer()) 1070 return; 1071 1072 if (!this.currentDateTime || !this.currentDateTime.equals(this.map.currentDateTime)){ 1073 this.currentDateTime = this.map.currentDateTime; 1074 } 1065 this.setTime(this.map.currentDateTime); 1075 1066 }, 1076 1067 sandbox/achipa/openlayers/lib/OpenLayers/Layer/TimedPointTrack.js
r6364 r6369 90 90 updateHighlight: function(){ 91 91 this.renderer.eraseFeatures([this.highlight]); 92 if (!this.permanentHighlight && (this.getStartTime() > this.currentDateTime.getEndDate() || this.getStopTime() < this.currentDateTime))92 if (!this.permanentHighlight && (this.getStartTime() > OpenLayers.Date.getEndDate(this.currentDateTime) || this.getStopTime() < this.currentDateTime)) 93 93 return; 94 94 … … 100 100 Math.min( // than the result to the closer point in time 101 101 Math.abs( this.features[i].dateTime - this.currentDateTime ), 102 Math.abs( this.features[i].dateTime.getEndDate() - this.currentDateTime )102 Math.abs( OpenLayers.Date.getEndDate(this.features[i].dateTime) - this.currentDateTime ) 103 103 ) 104 && ( this.features[i].dateTime.contains(this.currentDateTime) || !this.features[i].dateTime.duration || this.permanentHighlight) // allow Points to match as they might not have intervals104 && (OpenLayers.Date.contains(this.features[i].dateTime, this.currentDateTime) || !this.features[i].dateTime.duration || this.permanentHighlight) // allow Points to match as they might not have intervals 105 105 ){ 106 106 closesttime = this.features[i].dateTime; … … 115 115 // if PointTrack was to work with something else, this would have to be adapted, too 116 116 closestpoint = new OpenLayers.Geometry.Point( 117 closestgeom.components[0].x + (closestgeom.components[1].x - closestgeom.components[0].x) * closestfeature.dateTime.getPlaceInInterval(this.currentDateTime),118 closestgeom.components[0].y + (closestgeom.components[1].y - closestgeom.components[0].y) * closestfeature.dateTime.getPlaceInInterval(this.currentDateTime)117 closestgeom.components[0].x + (closestgeom.components[1].x - closestgeom.components[0].x) * OpenLayers.Date.getPlaceInInterval(closestfeature.dateTime,this.currentDateTime), 118 closestgeom.components[0].y + (closestgeom.components[1].y - closestgeom.components[0].y) * OpenLayers.Date.getPlaceInInterval(closestfeature.dateTime,this.currentDateTime) 119 119 ); 120 120 } … … 137 137 */ 138 138 dateTimeFromFeatures: function() { 139 var begin = Date.UTC(2038,0,0);140 var end = Date.UTC(1970,0,0);139 var begin = null; 140 var end = null; 141 141 for(var i = 0; i < this.features.length; i++) { 142 142 if (this.features[i].attributes["pubdate"]) { 143 pubdate = Date.fromRFC3339(this.features[i].attributes["pubdate"]);144 if (pubdate <= begin )143 pubdate = OpenLayers.Date.smartParse(this.features[i].attributes["pubdate"]); 144 if (pubdate <= begin || !begin) 145 145 begin = pubdate; 146 if (pubdate >= end )146 if (pubdate >= end || !end) 147 147 end = pubdate; 148 148 } … … 178 178 179 179 if (pointFeature.data) 180 pubDate = Date.fromRFC3339(pointFeature.data["pubdate"]);180 pubDate = OpenLayers.Date.smartParse(pointFeature.data["pubdate"]); 181 181 else if (pointFeature.attributes) 182 pubDate = Date.fromRFC3339(pointFeature.attributes["pubdate"]);182 pubDate = OpenLayers.Date.smartParse(pointFeature.attributes["pubdate"]); 183 183 184 184 if (!endPoint) { sandbox/achipa/openlayers/lib/OpenLayers/Map.js
r6364 r6369 1936 1936 */ 1937 1937 setTime: function (dt) { 1938 if (!this.currentDateTime || ! this.currentDateTime.equals(dt)){1938 if (!this.currentDateTime || !OpenLayers.Date.equals(this.currentDateTime,dt)){ 1939 1939 this.currentDateTime = dt; 1940 } 1941 1942 this.events.triggerEvent("datechanged"); 1940 this.events.triggerEvent("datechanged"); 1941 } 1943 1942 1944 1943 }, sandbox/achipa/openlayers/tests/test_BaseTypes.html
r5686 r6369 240 240 } 241 241 242 242 function test_Date_contains(t) { 243 t.plan(5); 244 var base = new Date(Date.parse("Jul 8, 2005")); 245 var target = new Date(Date.parse("Jul 8, 2005")); 246 var contains = OpenLayers.Date.contains(base,target); 247 t.eq(contains, true, "equal dates are considered containing dates"); 248 249 target = new Date(Date.parse("Jul 9, 2005")); 250 contains = OpenLayers.Date.contains(base,target); 251 t.eq(contains, false, "non-equal dates are not considered containing dates"); 252 253 base.duration = 86400000; 254 contains = OpenLayers.Date.contains(base,target); 255 t.eq(contains, true, "A time interval contains it's endpoints"); 256 257 target = new Date(Date.parse("Jul 8, 2005")); 258 target.duration = 86400000; 259 contains = OpenLayers.Date.contains(base,target); 260 t.eq(contains, true, "Two equal intervals are contained"); 261 262 target.duration = 2*86400000; 263 contains = OpenLayers.Date.contains(base,target); 264 t.eq(contains, false, "Two partially overlapping intervals are not contained"); 265 } 266 267 function test_Date_equals(t) { 268 t.plan(3); 269 var base = new Date(Date.parse("Jul 8, 2005")); 270 var target = new Date(Date.parse("Jul 8, 2005")); 271 var equals = OpenLayers.Date.equals(base,target); 272 t.eq(equals, true, "Equal dates are... equal dates !"); 273 274 base.duration = 86400000; 275 equals = OpenLayers.Date.equals(base,target); 276 t.eq(equals, false, "Durations have to be taken into account"); 277 278 target.duration = 86400000; 279 equals = OpenLayers.Date.equals(base,target); 280 t.eq(equals, true, "Durations have to be taken into account"); 281 } 282 283 function test_Date_merge(t) { 284 t.plan(3); 285 var base = new Date(Date.parse("Jul 8, 2005")); 286 var target = new Date(Date.parse("Jul 8, 2005")); 287 var merge = OpenLayers.Date.merge(base,target); 288 t.eq(OpenLayers.Date.equals(merge, base), true, "Merging with oneself is no change"); 289 290 target.duration = 86400000; 291 merge = OpenLayers.Date.merge(base,target); 292 t.eq(OpenLayers.Date.equals(merge, target), true, "Duration has to be taken into account"); 293 294 var base = new Date(Date.parse("Jul 7, 2005")); 295 merge = OpenLayers.Date.merge(base,target); 296 base.duration = 2*86400000; 297 t.eq(OpenLayers.Date.equals(merge, base), true, "Extend interval to fit"); 298 } 299 300 function test_Date_interval(t) { 301 t.plan(3); 302 var base = new Date(Date.parse("Jul 8, 2005")); 303 base.duration = 86400000; 304 var target = new Date(Date.parse("Jul 7, 2005")); 305 var value = OpenLayers.Date.getPlaceInInterval(base,target); 306 t.eq(value, 0, "Too early is 0"); 307 308 target = new Date(Date.parse("Jul 10, 2005")); 309 value = OpenLayers.Date.getPlaceInInterval(base,target); 310 t.eq(value, 1, "Too late is 1"); 311 312 target = new Date(Date.parse("Jul 8, 2005 12:00")); 313 value = OpenLayers.Date.getPlaceInInterval(base,target); 314 t.eq(value, 0.5, "Halfway is 0.5"); 315 } 243 316 244 317 </script> sandbox/achipa/openlayers/tests/test_Layer.html
r5982 r6369 349 349 } 350 350 351 function test_layer_temporal(t) { 352 t.plan(3); 353 var map = new OpenLayers.Map('map'); 354 layer = new OpenLayers.Layer(); 355 var d1 = new Date(Date.parse("Jul 8, 2005")); 356 var d2 = new Date(Date.parse("Jul 9, 2005")); 357 var d3 = new Date(Date.parse("Jul 10, 2005")); 358 map.addLayer(layer); 359 layer.datetimeIntervals = [ d1, d2, d3 ]; 360 map.setTime(d2); 361 layer.setTimeFromMap(); 362 t.eq(OpenLayers.Date.equals(layer.getStartTime(), d1), true, "First date"); 363 t.eq(OpenLayers.Date.equals(layer.getStopTime(), d3), true, "Last date"); 364 t.eq(OpenLayers.Date.equals(layer.currentDateTime, d2), true, "Time on layer set"); 365 } 351 366 352 367 sandbox/achipa/openlayers/tests/test_Map.html
r5982 r6369 976 976 } 977 977 978 function test_Map_setTime (t) { 979 t.plan( 2 ); 980 map = new OpenLayers.Map('map'); 981 map.events.register("datechanged", {count: 0}, function() { 982 this.count++; 983 t.ok(true, "datechanged event was triggered"); 984 }); 985 986 var d= new Date(Date.parse("Jul 8, 2005")); 987 map.setTime(d); 988 t.eq(OpenLayers.Date.equals(map.currentDateTime, d), true, "Map date set"); 989 map.setTime(new Date(Date.parse("Jul 8, 2005"))); // just to check that we don't get excessive events 990 } 991 978 992 function test_99_Map_destroy (t) { 979 993 t.plan( 3 ); sandbox/achipa/openlayers/theme/default/style.css
r6025 r6369 36 36 bottom: 0em; 37 37 right: 3px; 38 display: block; 39 position: absolute; 40 font-family: Arial; 41 font-size: smaller; 42 } 43 44 div.olControlTimePosition { 45 bottom: 0em; 46 left: 3px; 38 47 display: block; 39 48 position: absolute;
