OpenLayers OpenLayers

Changeset 6369

Show
Ignore:
Timestamp:
02/25/08 22:00:00 (11 months ago)
Author:
achipa
Message:

Followed general prototype extension deprecation rules
Added forgotten tests
Added forgotten TimePosition control

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/achipa/openlayers/examples/time-select-control.html

    r6365 r6369  
    2323            timeBar = new OpenLayers.Control.PanTimeBar(); 
    2424            map.addControl(timeBar); 
     25            map.addControl(new OpenLayers.Control.TimePosition()); 
     26            map.addControl(new OpenLayers.Control.MousePosition()); 
    2527        } 
    2628 
     
    7274 
    7375        function setTime() { 
    74             var targetdate = Date.fromRFC3339(OpenLayers.Util.getElement('date').value); 
     76            var targetdate = OpenLayers.Date.smartParse(OpenLayers.Util.getElement('date').value); 
    7577            map.setTime(targetdate); 
    7678        } 
  • sandbox/achipa/openlayers/examples/timed-point-track-markers.html

    r6364 r6369  
    6767 
    6868        function setTime() { 
    69             var targetdate = Date.fromRFC3339(OpenLayers.Util.getElement('date').value); 
     69            var targetdate = OpenLayers.Date.smartParse(OpenLayers.Util.getElement('date').value); 
    7070            lineLayer.permanentHighlight = OpenLayers.Util.getElement('phighlight').checked; 
    7171            lineLayer.interpolatePoints = OpenLayers.Util.getElement('ipoints').checked; 
  • sandbox/achipa/openlayers/lib/OpenLayers.js

    r6362 r6369  
    152152            "OpenLayers/Control/Permalink.js", 
    153153            "OpenLayers/Control/Scale.js", 
     154            "OpenLayers/Control/TimePosition.js", 
    154155            "OpenLayers/Control/LayerSwitcher.js", 
    155156            "OpenLayers/Control/DrawFeature.js", 
  • sandbox/achipa/openlayers/lib/OpenLayers/BaseTypes.js

    r6180 r6369  
    1010 * @requires OpenLayers/BaseTypes/Bounds.js 
    1111 * @requires OpenLayers/BaseTypes/Element.js 
    12  * @requires OpenLayers/BaseTypes/DateTime.js 
    1312 */ 
    1413 
    1514/** 
    1615 * Header: OpenLayers Base Types 
    17  * OpenLayers custom string, number and function functions are described here. 
     16 * OpenLayers custom string, number, function and date functions are described here. 
    1817 */ 
    1918 
     
    475474     
    476475}; 
     476 
     477/********************* 
     478 *                   * 
     479 *      DATE         *  
     480 *                   *  
     481 *********************/ 
     482 
     483OpenLayers.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 
     612Date.prototype.duration = 0; 
  • sandbox/achipa/openlayers/lib/OpenLayers/Control/PanTimeBar.js

    r6365 r6369  
    383383            has = false; 
    384384            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)) { 
    386386                    has = true 
    387387                    continue; 
  • sandbox/achipa/openlayers/lib/OpenLayers/Layer.js

    r6364 r6369  
    10431043    }, 
    10441044 
    1045     getDateTimeIntervals: function () { 
    1046         return this.datetimeIntervals; 
    1047     }, 
    1048  
    10491045    /** 
    10501046     * Method: setTime 
     
    10561052            return; 
    10571053 
    1058         if (!this.currentDateTime || !this.currentDateTime.equals(dt)){ 
     1054        if (!this.currentDateTime || !OpenLayers.Date.equals(this.currentDateTime,dt)){ 
    10591055            this.currentDateTime = dt; 
    10601056        } 
     
    10671063     */ 
    10681064    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); 
    10751066    }, 
    10761067 
  • sandbox/achipa/openlayers/lib/OpenLayers/Layer/TimedPointTrack.js

    r6364 r6369  
    9090    updateHighlight: function(){ 
    9191        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)) 
    9393            return; 
    9494       
     
    100100               Math.min(                                           // than the result to the closer point in time 
    101101                   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 ) 
    103103                   ) 
    104            && (this.features[i].dateTime.contains(this.currentDateTime)  || !this.features[i].dateTime.duration || this.permanentHighlight)    // allow Points to match as they might not have intervals 
     104           && (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 
    105105        ){ 
    106106                closesttime = this.features[i].dateTime; 
     
    115115        // if PointTrack was to work with something else, this would have to be adapted, too 
    116116            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) 
    119119        ); 
    120120        } 
     
    137137     */ 
    138138    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
    141141        for(var i = 0; i < this.features.length; i++) { 
    142142            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
    145145                    begin = pubdate; 
    146                 if (pubdate >= end
     146                if (pubdate >= end || !end
    147147                    end = pubdate; 
    148148            } 
     
    178178 
    179179        if (pointFeature.data) 
    180             pubDate = Date.fromRFC3339(pointFeature.data["pubdate"]); 
     180            pubDate = OpenLayers.Date.smartParse(pointFeature.data["pubdate"]); 
    181181        else if (pointFeature.attributes) 
    182             pubDate = Date.fromRFC3339(pointFeature.attributes["pubdate"]); 
     182            pubDate = OpenLayers.Date.smartParse(pointFeature.attributes["pubdate"]); 
    183183             
    184184            if (!endPoint) { 
  • sandbox/achipa/openlayers/lib/OpenLayers/Map.js

    r6364 r6369  
    19361936     */ 
    19371937    setTime: function (dt) { 
    1938         if (!this.currentDateTime || !this.currentDateTime.equals(dt)){ 
     1938        if (!this.currentDateTime || !OpenLayers.Date.equals(this.currentDateTime,dt)){ 
    19391939            this.currentDateTime = dt; 
    1940         } 
    1941  
    1942         this.events.triggerEvent("datechanged"); 
     1940            this.events.triggerEvent("datechanged"); 
     1941        } 
    19431942         
    19441943    }, 
  • sandbox/achipa/openlayers/tests/test_BaseTypes.html

    r5686 r6369  
    240240    } 
    241241 
    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    } 
    243316 
    244317  </script> 
  • sandbox/achipa/openlayers/tests/test_Layer.html

    r5982 r6369  
    349349    } 
    350350 
     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    } 
    351366 
    352367 
  • sandbox/achipa/openlayers/tests/test_Map.html

    r5982 r6369  
    976976    } 
    977977 
     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 
    978992    function test_99_Map_destroy (t) { 
    979993        t.plan( 3 );     
  • sandbox/achipa/openlayers/theme/default/style.css

    r6025 r6369  
    3636    bottom: 0em; 
    3737    right: 3px; 
     38    display: block; 
     39    position: absolute; 
     40    font-family: Arial; 
     41    font-size: smaller; 
     42} 
     43 
     44div.olControlTimePosition { 
     45    bottom: 0em; 
     46    left: 3px; 
    3847    display: block; 
    3948    position: absolute;