country_picker = function () {
const W = width;
const H = (W * height) / width;
const svg = d3
.select(DOM.svg(W, H));
const g = svg.append("g");
const g_countries = g.append("g");
let x = 0;
let z = 1;
const projection = d3
.geoConicConformal()
.parallels([40, 68])
.rotate([-10 + x / z / 15, 0])
.center([8 - 10, 53.823])
.scale(width * 1.36 * z)
.translate([W / 2, H / 2]);
const path = d3.geoPath().projection(projection);
const selection_text = svg.append("text")
.attr("x", 0)
.attr("y", 0)
.attr('dy', "1em")
.text("Select a country");
g_countries
.selectAll("path")
.data(areas)
.join("path")
.attr("fill", "#eee")
.attr("d", path)
.attr("stroke", "black")
.attr("stroke-linejoin", "round")
.append("title")
.text(d => d.properties.name);
return Object.assign(svg.node(), {
value: null,
onclick: event => {
if (event.target.tagName == 'path') {
g_countries.selectAll("path").attr("fill", "#eee");
d3.select(event.target).attr('fill', 'gray');
event.currentTarget.value = d3.select(event.target).datum().properties;
selection_text.text(event.currentTarget.value.name);
event.currentTarget.dispatchEvent(new CustomEvent("input"));
}
}
});
}