Calculating the plane's positions

How do we get to the wayPoints array? Conceptually, we've said it all already. We now express it in code. First, you need to create an array for all planes, depending on the route data the respective button press has loaded in:

var routeFromTo = [];  routes.forEach(function(el) {    var arr = [el.source_airport, el.destination_airport];    routeFromTo.push(arr);  });

This is a simple array of elements representing the three-letter origin and the destination IATA airport codes.

Next, you iterate through this array of start and end points to calculate the wayPoints. You will create an object called planes holding the data as well as two helper functions to calculate the data. But before this, have a look at the simple ...

Get Learning D3.js 5 Mapping - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.