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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.