OpenLayers OpenLayers

Changeset 6364

Show
Ignore:
Timestamp:
02/25/08 10:43:59 (11 months ago)
Author:
achipa
Message:

datechanged event moved to map class
extdate class cleaned/extended
fixed broken marker example
refresh done properly now

Files:

Legend:

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

    r6312 r6364  
    4444            //alert(dumpObj(map.getControlsByClass('OpenLayers.Control.PanTimeBar')[0], 'object', '-', 8)); 
    4545 
     46            lineLayer.dateTimeFromFeatures(); 
     47 
     48            // make sure the highlights stays turned on and current with the map zoom 
     49            map.events.register("zoomend", lineLayer, lineLayer.updateHighlight); 
     50 
     51            // update the date of the layer from the map property and redraw to keeep up with changes 
     52        map.events.register("datechanged", lineLayer, lineLayer.setTimeFromMap); 
     53            map.events.register("datechanged", lineLayer, lineLayer.updateHighlight) 
     54 
    4655            rss.setName(rss.name + " Comments"); 
    4756 
     
    5564            } 
    5665 
    57             lineLayer.updateDateTimeInterval(); 
    58  
    5966            // keep markers on top of tracks 
    6067            map.raiseLayer(rss, 1); 
     
    6370 
    6471        function setTime() { 
    65             var targetdate = OpenLayers.DateTime.fromRFC3339(OpenLayers.Util.getElement('date').value); 
    66             lineLayer.setDateTime(targetdate); 
     72            var targetdate = Date.fromRFC3339(OpenLayers.Util.getElement('date').value); 
     73            map.setTime(targetdate); 
    6774        } 
    6875    </script> 
  • sandbox/achipa/openlayers/examples/timed-point-track-markers.html

    r6264 r6364  
    3939            lineLayer.addNodes(rss.features); 
    4040            map.addLayer(lineLayer); 
     41 
     42            // VERY IMPORTANT - set the validity interval of the layer so it encompasses all the Dates of the features 
     43            lineLayer.dateTimeFromFeatures(); 
     44 
     45        // make sure the highlights stays turned on and current with the map zoom 
     46            map.events.register("zoomend", lineLayer, lineLayer.updateHighlight); 
     47 
     48        // update the date of the layer from the map property and redraw to keeep up with changes 
     49            map.events.register("datechanged", lineLayer, lineLayer.setTimeFromMap); 
     50            map.events.register("datechanged", lineLayer, lineLayer.updateHighlight); 
    4151             
     52 
    4253            rss.setName(rss.name + " Comments"); 
    4354             
     
    5162            } 
    5263 
    53             lineLayer.updateDateTimeInterval(); 
    54  
    5564            // keep markers on top of tracks 
    5665            map.raiseLayer(rss, 1); 
     
    5867 
    5968        function setTime() { 
    60             var targetdate = OpenLayers.DateTime.fromRFC3339(OpenLayers.Util.getElement('date').value); 
     69            var targetdate = Date.fromRFC3339(OpenLayers.Util.getElement('date').value); 
    6170            lineLayer.permanentHighlight = OpenLayers.Util.getElement('phighlight').checked; 
    6271            lineLayer.interpolatePoints = OpenLayers.Util.getElement('ipoints').checked; 
    63             lineLayer.setDateTime(targetdate); 
     72            map.setTime(targetdate); 
    6473        } 
    6574    </script> 
     
    6978    <p style="font-size:.9em;">This demo uses OpenLayers.Layer.GeoRSS and OpenLayers.Layer.TimedPointTrack. The track is created by connecting the points of the GeoRSS feed.</a></p> 
    7079    <form onsubmit="return false;"> 
    71    Load GeoRSS URL: <input type="text" id="url" size="50" /><input type="submit" onclick="addUrl(); return false;" value="Load Feed" onsubmit="addUrl(); return false;" /> 
     80   Load GeoRSS URL: <input type="text" id="url" size="50" value="xml/track1.xml" /><input type="submit" onclick="addUrl(); return false;" value="Load Feed" onsubmit="addUrl(); return false;" /> 
    7281    </form> <form onsubmit="return false;"> 
    7382    <input type="checkbox" id="phighlight"> permanentHighlight <BR> 
  • sandbox/achipa/openlayers/lib/OpenLayers/BaseTypes/ExtDate.js

    r6362 r6364  
    2121 */ 
    2222Date.prototype.contains = function(targetdate) { 
    23     if (targetdate >= this && targetdate.getTime() + targetdate.duration <= this.getTime() + this.duration)  
     23    if (targetdate >= this && targetdate.getEndDate() <= this.getEndDate())  
    2424            return true; 
    2525 
     
    3636Date.prototype.getEndDate = function() { 
    3737    return new Date(this.getTime() + this.duration); 
     38}; 
     39 
     40/** 
     41 * Method: merge 
     42 * Extends the start or duration of this Date object so it encompasses the interval targetdate object as well 
     43 * as the currect interval. 
     44 * 
     45 * Parameters: 
     46 * {Date} targetdate 
     47 */ 
     48Date.prototype.merge = function(targetdate) { 
     49    if (targetdate < this) { 
     50        this.duration += this - targetdate; 
     51    this.setTime(targetdate.getTime()); 
     52    } 
     53    if (targetdate.getEndDate() > this.getEndDate()){ 
     54        this.duration += targetdate.getEndDate() - this.getEndDate(); 
     55    } 
    3856}; 
    3957 
     
    5573 */ 
    5674Date.prototype.getPlaceInInterval = function(targetdate, center) { 
    57     var centerdate = targetdate; 
     75    if (!targetdate) return 0; 
     76    var centerdate = new Date(targetdate); 
    5877    if (center && targetdate.duration != 0) 
    59         centerdate = new Date(targetdate.getTime() + targetdate.duration/2); 
     78        centerdate.setTime(targetdate.getTime() + targetdate.duration/2); 
    6079 
    61     if (centerdate.getTime() > this.getTime() + this.duration
     80    if (centerdate > this.getEndDate()
    6281        return 1; 
    63     else if (targetdate <= centerdate) // using <= to accomodate for non-interval datetimes 
     82    else if (this >= centerdate) // using <= to accomodate for non-interval datetimes 
    6483        return 0; 
    6584    else 
  • sandbox/achipa/openlayers/lib/OpenLayers/Layer.js

    r6362 r6364  
    4242     * {Array(String)} Supported application event types 
    4343     */ 
    44     EVENT_TYPES: ["loadstart", "loadend", "loadcancel", "visibilitychanged", "datetimechanged"], 
     44    EVENT_TYPES: ["loadstart", "loadend", "loadcancel", "visibilitychanged"], 
    4545 
    4646    /** 
     
    10481048 
    10491049    /** 
    1050      * Method: setDateTime 
    1051      * {Date} Sets the current date/time in the layers 
     1050     * Method: setTime 
     1051     * {Date} Sets the current date/time in the layer 
    10521052     * 
    10531053     */ 
     
    10561056            return; 
    10571057 
    1058         if (!this.currentDateTime.equals(dt)){ 
     1058        if (!this.currentDateTime || !this.currentDateTime.equals(dt)){ 
    10591059            this.currentDateTime = dt; 
    1060             this.events.triggerEvent("datetimechanged"); 
     1060        } 
     1061    }, 
     1062 
     1063    /** 
     1064     * Method: setTimeFromMap 
     1065     * Sets the current date/time in the layer 
     1066     * 
     1067     */ 
     1068    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; 
    10611074        } 
    10621075    }, 
  • sandbox/achipa/openlayers/lib/OpenLayers/Layer/TimedPointTrack.js

    r6362 r6364  
    7878        defaultStyle = this.sty 
    7979        this.events.register("datetimechanged", this, this.updateHighlight); 
    80 //        this.map.events.register("zoomend", this, this.updateHighlight); 
    8180    }, 
    8281 
     
    103102                   Math.abs( this.features[i].dateTime.getEndDate() - this.currentDateTime ) 
    104103                   ) 
     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 
    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.from), 
    118                  closestgeom.components[0].y + (closestgeom.components[1].y - closestgeom.components[0].y) * closestfeature.dateTime.getPlaceInInterval(this.currentDateTime.from
     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
    119119        ); 
    120120        } 
     
    136136     *  
    137137     */ 
    138     updateDateTimeInterval: function() { 
     138    dateTimeFromFeatures: function() { 
    139139        var begin = Date.UTC(2038,0,0); 
    140140        var end = Date.UTC(1970,0,0); 
  • sandbox/achipa/openlayers/lib/OpenLayers/Map.js

    r6362 r6364  
    5959        "addmarker", "removemarker", "clearmarkers", "mouseover", 
    6060        "mouseout", "mousemove", "dragstart", "drag", "dragend", 
    61         "changebaselayer"], 
     61        "changebaselayer", 
     62    "datechanged"], 
    6263 
    6364    /** 
     
    161162     */ 
    162163    zoom: 0,     
     164 
     165    /** 
     166     * Property: currentDateTime 
     167     * {Date} The current date/time if the map has temporal layers 
     168     */ 
     169    currentDateTime: null,     
    163170 
    164171    /** 
     
    19251932     *  
    19261933     * Parameters: 
    1927      * {Date} Sets the current date/time in all layers 
     1934     * {Date} Sets the current date/time for the map and emits the datechanged signal 
    19281935     * 
    19291936     */ 
    19301937    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); 
     1938        if (!this.currentDateTime || !this.currentDateTime.equals(dt)){ 
     1939            this.currentDateTime = dt; 
     1940        } 
     1941 
     1942        this.events.triggerEvent("datechanged"); 
     1943         
    19341944    }, 
    19351945