On a Leaflet map, I have several points. Between these points, traffic occurs. To visualize this, I want to draw flight paths between these points. The main concern is that these points look good, and like what would be the shortest route between 2 points. If I went to whole way and implemented this correctly, a flightpath between the US and Russia would look like this:
And a path between the US and Japan looks like this:
This is not ideal for my purposes. I want my flight paths to stay on the map, without leaving it. Having read this tutorial (sadly written in R, which I can't read), I was pointed to using Bezier curves for my flight paths. I'm using the Leaflet plugin fullcanvas, and have modified it. My code for drawing curves looks like this:
drawBezierCurve: function (startPoint, endPoint, style) {
var context = this.getCanvas().getContext("2d");
context.strokeStyle = (style && style.strokeStyle) ? style.strokeStyle : "rgba(0,0,0, 1)";
context.lineWidth = (style && style.lineWidth) ? style.lineWidth : 3;
var mapSize = map.getSize();
var controlPoint1X = startPoint.x + 50;
var controlPoint1Y = startPoint.y > (mapSize.y / 2) ? startPoint.y + 50 : startPoint.y - 50;
var controlPoint2X = endPoint.x - 50;
var controlPoint2Y = endPoint.y > (mapSize.y / 2) ? endPoint.y + 50 : endPoint.y - 50;
context.moveTo(startPoint.x, startPoint.y);
context.bezierCurveTo(controlPoint1X, controlPoint1Y, controlPoint2X, controlPoint2Y, endPoint.x, endPoint.y);
context.stroke();
}
The end result of this looks okay only when the points are some distance between each other:
The paths originating from the US are all well drawn, the way I want them. However, the paths from Japan to Australia (which are above each other) and the one in south-east Asia (which are very close next to each other) are messed up. Plus, if I zoom in or out I get this awesome effect:
Which, while being funny to my co-workers, is not what I'm looking for. My question:
How can I edit my JavaScript function to have more natural looking flight paths? The flight paths do not have to be correct, they only have to look normal. Ideally, I'd get a result that looks like this.