OpenLayers OpenLayers

Changeset 6560

Show
Ignore:
Timestamp:
03/19/08 20:43:44 (10 months ago)
Author:
achipa
Message:

minor code cleanups, changed a few comments

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/achipa/openlayers/lib/OpenLayers/Layer/TimedPointTrack.js

    r6369 r6560  
    1717    /** 
    1818     * APIProperty: 
    19      * dataFrom  - {<OpenLayers.Layer.PointTrack.dataFrom>} optional. If the 
    20      *             lines should get the data/attributes from one of the two 
    21      *             points, creating it, which one should it be? 
    22      */ 
    23     highlight: null, 
    24  
    25     /** 
    26      * APIProperty: 
    2719     * interpolatePoints - {Boolean} If the flag is no, the layer  
    2820     *             will place the highlight over the data point nearest in  
     
    5749     */ 
    5850    highlightStyle: {}, 
     51 
     52    /** 
     53     * APIProperty: 
     54     * highlight  - {<OpenLayers.Feature.Vector>} internal, used for drawing the 
     55     *             highlight feature 
     56     */ 
     57    highlight: null, 
    5958 
    6059    /** 
     
    7675            this.highlightStyle 
    7776        ); 
    78         defaultStyle = this.sty 
    7977        this.events.register("datetimechanged", this, this.updateHighlight); 
    8078    }, 
     
    9795        var closestfeature = 0; 
    9896        for (var i=0; i < this.features.length; i++){ 
    99             if (Math.abs( closesttime - this.currentDateTime ) >  // our best result so far is worse 
    100                Math.min(                                           // than the result to the closer point in time 
    101                    Math.abs( this.features[i].dateTime - this.currentDateTime ), 
    102                    Math.abs( OpenLayers.Date.getEndDate(this.features[i].dateTime) - this.currentDateTime ) 
     97            if (Math.abs( closesttime - this.currentDateTime ) >                     // our best result so far is worse 
     98               Math.min(                                                         // than the result to the closer point in time 
     99                   Math.abs( this.features[i].dateTime - this.currentDateTime ), // of either the beginning 
     100                   Math.abs( OpenLayers.Date.getEndDate(this.features[i].dateTime) - this.currentDateTime ) // or the end of the interval of this feature 
    103101                   ) 
    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 
     102        && (OpenLayers.Date.contains(this.features[i].dateTime, this.currentDateTime)  // make sure we are picking the right feature  
     103                   || !this.features[i].dateTime.duration                            // allow Points to match as they might not have intervals 
     104                   || this.permanentHighlight)                                       // if permanent, we always draw it, regardless of previous criteria  
    105105        ){ 
    106106                closesttime = this.features[i].dateTime; 
     
    110110        } 
    111111 
    112         var closestgeom = closestfeature.geometry; 
    113         if (this.interpolatePoints && closestgeom && closestfeature.dateTime && closestgeom.CLASS_NAME == "OpenLayers.Geometry.LineString" && closestgeom.components.length == 2) {  
    114         // this is good for a two point {OpenLayers.LineString} only, but that's what our superclass uses 
    115         // if PointTrack was to work with something else, this would have to be adapted, too 
    116             closestpoint = new OpenLayers.Geometry.Point( 
    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         ); 
     112        var closestgeom = closestfeature.geometry;   // set the closest point as default 
     113        if (this.interpolatePoints && closestgeom && closestfeature.dateTime) {      // sanity check to see if we have all the required parameters for interpolation 
     114            if (closestgeom.CLASS_NAME == "OpenLayers.Geometry.LineString" && closestgeom.components.length == 2) {  
     115            // this is ATM good for a two point {OpenLayers.LineString} only, but that's what our superclass uses 
     116            // if PointTrack was to work with something else, additional cases will have to be written to accomodate 
     117            // interpolation for other geometries 
     118                closestpoint = new OpenLayers.Geometry.Point( 
     119                     closestgeom.components[0].x + (closestgeom.components[1].x - closestgeom.components[0].x) * OpenLayers.Date.getPlaceInInterval(closestfeature.dateTime,this.currentDateTime), 
     120                     closestgeom.components[0].y + (closestgeom.components[1].y - closestgeom.components[0].y) * OpenLayers.Date.getPlaceInInterval(closestfeature.dateTime,this.currentDateTime) 
     121            ); 
     122            } 
    120123        } 
    121124 
     
    127130         
    128131    /** 
    129      * APIMethod: setDateTime 
    130      * Adds point features that will be used to create lines from, using point 
    131      * pairs. The first point of a pair will be the source node, the second 
    132      * will be the target node. 
     132     * APIMethod: dateTimeFromFeatures 
     133     * Generates the datetimeIntervals property of the Layer object from a  
     134     * property of each feature so that the new datetimeIntervals 
     135     * begins with the date found on the earliest feature, and ends with the 
     136     * date found on the latest feature. The property name to use for the dates 
     137     * is specified in the attrname parameter and is "pubdate" by default 
    133138     *  
    134139     * Parameters: 
    135      * pointFeatures - {Array(<OpenLayers.Feature>)
    136      *  
    137      */ 
    138     dateTimeFromFeatures: function() { 
     140     * attrname - {String
     141     *  
     142     */ 
     143    dateTimeFromFeatures: function(attrname) { 
    139144        var begin = null; 
    140145        var end = null; 
     146        var attr = attrname; 
     147        if (!attr) attr = "pubdate"; 
    141148        for(var i = 0; i < this.features.length; i++) { 
    142149            if (this.features[i].attributes["pubdate"]) { 
    143                 pubdate = OpenLayers.Date.smartParse(this.features[i].attributes["pubdate"]); 
     150                pubdate = OpenLayers.Date.smartParse(this.features[i].attributes[attr]); 
    144151                if (pubdate <= begin || !begin) 
    145152                    begin = pubdate;