| 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; |
|---|
| 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 | } |
|---|