work-around for mobile-specific geodesic line drawing issue - appears to be an odd rounding problem

not ideal, but better than the current situation
This commit is contained in:
Jon Atkins 2013-12-15 06:08:54 +00:00
parent 11cfa11406
commit 78e9983d90

View File

@ -58,19 +58,23 @@ Modified by qnstie 2013-07-17 to maintain compatibility with Leaflet.draw
// loop ends before 'segments' is reached - we don't add the very last point here but outside the loop // loop ends before 'segments' is reached - we don't add the very last point here but outside the loop
// (this was to fix a bug - https://github.com/jonatkins/ingress-intel-total-conversion/issues/471 // (this was to fix a bug - https://github.com/jonatkins/ingress-intel-total-conversion/issues/471
// rounding errors? maths bug? not sure - but it solves the issue! and is a slight optimisation) // rounding errors? maths bug? not sure - but it solves the issue! and is a slight optimisation)
for (i = 1; i < segments; i++) { // UPDATE: there still seem to be rounding errors on relatively short links - but only on mobile.
// http://williams.best.vwh.net/avform.htm#Intermediate // let's only add intermediate points if there's two or more
// modified to handle longitude above +-180 degrees if (segments >= 3) {
f = i / segments; for (i = 1; i < segments; i++) {
A = Math.sin((1-f)*d) / Math.sin(d); // http://williams.best.vwh.net/avform.htm#Intermediate
B = Math.sin(f*d) / Math.sin(d); // modified to handle longitude above +-180 degrees
x = A * Math.cos(lat1) * Math.cos(0) + B * Math.cos(lat2) * Math.cos(dLng); f = i / segments;
y = A * Math.cos(lat1) * Math.sin(0) + B * Math.cos(lat2) * Math.sin(dLng); A = Math.sin((1-f)*d) / Math.sin(d);
z = A * Math.sin(lat1) + B * Math.sin(lat2); B = Math.sin(f*d) / Math.sin(d);
fLat = r2d * Math.atan2(z, Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2))); x = A * Math.cos(lat1) * Math.cos(0) + B * Math.cos(lat2) * Math.cos(dLng);
fLng = r2d * (Math.atan2(y, x)+lng1); y = A * Math.cos(lat1) * Math.sin(0) + B * Math.cos(lat2) * Math.sin(dLng);
z = A * Math.sin(lat1) + B * Math.sin(lat2);
fLat = r2d * Math.atan2(z, Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)));
fLng = r2d * (Math.atan2(y, x)+lng1);
convertedPoints.push(L.latLng([fLat, fLng])); convertedPoints.push(L.latLng([fLat, fLng]));
}
} }
// push the final point unmodified // push the final point unmodified
convertedPoints.push(L.latLng(endLatlng)); convertedPoints.push(L.latLng(endLatlng));