Give curved line a deeper arc in turf.js and mapbox

Viewed 547

There's no simple curved-line tool in turf.js, nor is there an easy way to do it in mapbox (so far as I can see), so I've created a workaround based on this answer in this thread.

However, the curve it creates isn't very smooth or satisfying or has an inconsistent hump based on angle/length.

Ideally, I'd like an arc that is always in a nice, rounded form. and drawing a line between them. I then offset the midpoint by distance / 5 and apply a bearing. I then connect up the three points with a turf.bezierSpline.

const start = [parseFloat(originAirport.longitude), parseFloat(originAirport.latitude)];
const end = [
  parseFloat(destinationAirport.longitude),
  parseFloat(destinationAirport.latitude),
];

const distance = turf.distance(start, end, { units: 'miles' });
const midpoint = turf.midpoint(start, end);
const destination = turf.destination(midpoint, distance / 5, 20, { units: 'miles' });

// curvedLine gets rendered to the page
const curvedLine = turf.bezierSpline(
  turf.lineString([start, destination.geometry.coordinates, end]),
);

Okay-ish curve, but a bit sharp Curve is unbalanced Should be straight up-down

Desired curvature: Desired curvature

0 Answers
Related