chart = function(routes) {
const context = DOM.context2d(width, height);
const path = d3.geoPath(projection, context);
let colour_scale = d3
.scaleSequential(d3.interpolateOrRd)
.domain(d3.extent(routes, d => d["distance"]));
function render() {
context.clearRect(0, 0, width, height);
context.beginPath(),
path(sphere),
(context.fillStyle = "#fff"),
context.fill();
context.beginPath(),
path(land),
(context.fillStyle = "#000"),
context.fill();
context.beginPath(), path(sphere), context.stroke();
routes.forEach(function(d) {
let coordinates = [
[d["lng_from"], d["lat_from"]],
[d["lng_to"], d["lat_to"]]
];
let resampled = resample(coordinates);
let mid_point_with_drift = [
resampled["after"][1][0] + (d["lat_from"] + d["lng_to"]) / 100,
resampled["after"][1][1] + (d["lat_from"] + d["lng_to"]) / 100
];
resampled["after"][1] = mid_point_with_drift;
let route = {
type: "LineString",
coordinates: resampled["after"]
};
context.lineWidth = 1.5;
context.lineO;
context.beginPath(),
path(route),
(context.strokeStyle = colour_scale(d["distance"])),
context.stroke();
});
context.lineWidth = 1;
context.strokeStyle = "#000000";
}
return d3
.select(context.canvas)
.call(drag(projection).on("drag.render", render))
.call(render)
.node();
}