OpenLayers OpenLayers

Changeset 6269

Show
Ignore:
Timestamp:
02/14/08 11:15:13 (1 year ago)
Author:
achipa
Message:

proper point interpolation for timed pointtracks

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/achipa/openlayers/lib/OpenLayers/BaseTypes/DateTime.js

    r6180 r6269  
    115115     */ 
    116116    contains:function(targetdate) { 
    117         if (typeof targetdate == "Date") { 
    118             if (targetdate >= this.from && targetdate <= this.to){ 
     117        if (targetdate >= this.from && targetdate <= this.to) 
    119118                return true; 
    120             } 
    121         } 
     119 
    122120        return false; 
    123121    }, 
     
    129127     */ 
    130128    getPlaceInInterval:function(targetdate) { 
    131         if (typeof targetdate == "Date") { 
     129        if (targetdate) { 
    132130            if (targetdate > this.to) 
    133131        return 1; 
  • sandbox/achipa/openlayers/lib/OpenLayers/Layer/TimedPointTrack.js

    r6264 r6269  
    105105        var closestfeature = 0; 
    106106        for (var i=0; i < this.features.length; i++){ 
    107             var atime = 0; 
    108             if (this.features[i].attributes["pubdate"]){ 
    109                 atime = OpenLayers.DateTime.fromRFC3339(this.features[i].attributes["pubdate"]); 
    110             } 
    111             if (Math.abs( closesttime - this.currentDateTime.from ) > Math.abs( atime - this.currentDateTime.from )){ 
    112                 closesttime = atime; 
     107            if (Math.abs( closesttime - this.currentDateTime.from ) >  // our best result so far is worse 
     108               Math.min(                                           // than the result to the closer point in time 
     109                   Math.abs( this.features[i].dateTime.from - this.currentDateTime.from ), 
     110                   Math.abs( this.features[i].dateTime.to - this.currentDateTime.from ) 
     111                   ) 
     112           && (this.features[i].dateTime.contains(this.currentDateTime.from)  || !this.features[i].dateTime.interval)    // allow Points to match as they might not have intervals 
     113 
     114        ){ 
     115                closesttime = this.features[i].dateTime.from; 
    113116                closestpoint = this.features[i].geometry.components[0]; 
    114                 closestfeature = i; 
    115             } 
    116         } 
    117  
    118         var closestgeom = this.features[closestfeature].geometry; 
    119         if (this.interpolatePoints && closestgeom.components && closestgeom.components.length) { 
    120             closestpoint = new OpenLayers.Geometry.Point(0,0); 
    121             for (var i=0; i < closestgeom.components.length; i++) 
    122                  closestpoint.move(closestgeom.components[i].x, closestgeom.components[i].y); 
    123              
    124             closestpoint.x /= closestgeom.components.length; 
    125             closestpoint.y /= closestgeom.components.length; 
    126  
    127         } 
    128  
    129         this.highlight.geometry = closestpoint.clone(); 
    130         this.drawFeature(this.highlight); 
     117                closestfeature = this.features[i]; 
     118            } 
     119        } 
     120 
     121        var closestgeom = closestfeature.geometry; 
     122        if (this.interpolatePoints && closestgeom && closestfeature.dateTime && closestgeom.CLASS_NAME == "OpenLayers.Geometry.LineString" && closestgeom.components.length == 2) {  
     123        // this is good for a two point {OpenLayers.LineString} only, but that's what our superclass uses 
     124        // if PointTrack was to work with something else, this would have to be adapted, too 
     125        alert(" " + this.currentDateTime.from + " " + closestfeature.dateTime.from + " " + closestfeature.dateTime.to + " " + closestfeature.dateTime.getPlaceInInterval(this.currentDateTime.from)); 
     126            closestpoint = new OpenLayers.Geometry.Point( 
     127                 closestgeom.components[0].x + (closestgeom.components[1].x - closestgeom.components[0].x) * closestfeature.dateTime.getPlaceInInterval(this.currentDateTime.from), 
     128                 closestgeom.components[0].y + (closestgeom.components[1].y - closestgeom.components[0].y) * closestfeature.dateTime.getPlaceInInterval(this.currentDateTime.from) 
     129        ); 
     130        } 
     131 
     132    if (closestpoint) { 
     133            this.highlight.geometry = closestpoint.clone(); 
     134            this.drawFeature(this.highlight); 
     135    } 
    131136    }, 
    132137         
     
    166171     *  
    167172     */ 
    168 /*    addNodes: function(pointFeatures) { 
     173    addNodes: function(pointFeatures) { 
    169174        if (pointFeatures.length < 2) { 
    170175            OpenLayers.Console.error( 
     
    176181        var lines = new Array(pointFeatures.length-1); 
    177182         
    178         var pointFeature, startPoint, endPoint
     183        var pointFeature, startPoint, endPoint, pubDate, prevDate
    179184        for(var i = 0; i < pointFeatures.length; i++) { 
    180185            pointFeature = pointFeatures[i]; 
    181186            endPoint = pointFeature.geometry; 
     187 
     188        if (pointFeature.data) 
     189            pubDate = OpenLayers.DateTime.fromRFC3339(pointFeature.data["pubdate"]); 
     190        else if (pointFeature.attributes) 
     191            pubDate = OpenLayers.DateTime.fromRFC3339(pointFeature.attributes["pubdate"]); 
    182192             
    183193            if (!endPoint) { 
     
    199209                         
    200210                lines[i-1] = new OpenLayers.Feature.Vector(line, attributes); 
     211        if (attributes["pubdate"]) { 
     212                lines[i-1].dateTime = new OpenLayers.DateTime(prevDate, pubDate); 
     213        } 
    201214            } 
    202215             
    203216            startPoint = endPoint; 
     217        prevDate = pubDate; 
    204218        } 
    205219 
    206220        this.addFeatures(lines); 
    207     },*/ 
     221    }, 
    208222     
    209223    CLASS_NAME: "OpenLayers.Layer.TimedPointTrack"