Commit 7153518aeef3e682f4f0f2f38fc013b45c2edc6f

Fixed task #16: Route hovering does not work at high zoom levels.
  
21332133 return null;
21342134 var smallestDistance = null;
21352135 var smallestDistancePoint = null;
2136 var index = 0;
2136 var index = 0; // Index is used to find out the position of the point in the ordered list of points
21372137 var maxDistance = this.HOVER_MAX_DISTANCE * this.map.getResolution();
21382138 for(var j=0; j<this.features.length; j++)
21392139 {
21412141 continue;
21422142
21432143 var points = this.features[j].geometry.components;
2144 for(var i=0; i<points.length; i++,index++)
2144 var p1,p2,d,u,px;
2145 for(var i=0; i<points.length-1; i++,index++)
21452146 {
2146 var distanceX = Math.abs(points[i].x-lonlat.lon);
2147 var distanceY = Math.abs(points[i].y-lonlat.lat);
2147 p1 = points[i];
2148 p2 = points[i+1];
2149 d = { x : p2.x-p1.x, y : p2.y-p1.y };
2150 u = ((lonlat.lon-p1.x)*d.x + (lonlat.lat-p1.y)*d.y) / (d.x*d.x + d.y*d.y); // See http://local.wasp.uwa.edu.au/~pbourke/geometry/pointline/
2151
2152 if(u < 0 || u > 1)
2153 continue;
2154
2155 px = { x : p1.x+u*d.x, y : p1.y+u*d.y };
2156
2157 var distanceX = Math.abs(px.x-lonlat.lon);
2158 var distanceY = Math.abs(px.y-lonlat.lat);
21482159 if(distanceX > maxDistance || distanceY > maxDistance)
21492160 continue;
21502161 var distance = Math.sqrt(Math.pow(distanceX, 2) + Math.pow(distanceY, 2));
21632163 continue;
21642164 if(smallestDistance == null || distance < smallestDistance)
21652165 {
2166 smallestDistancePoint = [ index, points[i] ];
2166 smallestDistancePoint = [ index+u, px ];
21672167 smallestDistance = distance;
21682168 }
21692169 }