map = {
const svg = d3
.create("svg")
.attr("viewBox", [0, 0, width, maxHeight]);
const path = d3.geoPath(projection);
svg
.append("g")
.append("path")
.datum(sphere)
.attr("fill", "#28879B")
.attr("d", path);
const g0 = svg.append("g").attr("id", "all");
const g1 = svg.append("g").attr("id", "africa");
d3.selectAll(".tooltip").remove();
const tooltip = d3
.select("body")
.append("div")
.attr("class", "svg-tooltip")
.style("position", "absolute")
.style("visibility", "hidden");
g0.append("path")
.attr("id", "land")
.attr("fill", "#DFDDD8")
.attr("stroke", "none")
.datum(topojson.feature(world, world.objects.land));
g0.append("path")
.attr("id", "borders-all")
.attr("fill", "none")
.attr("stroke", "#959591")
.style("stroke-opacity", 0.8)
.datum(topojson.mesh(world, world.objects.countries, (a, b) => a !== b));
g0.append("path")
.attr("id", "shore-all")
.attr("fill", "none")
.attr("stroke", "#959591")
.datum(topojson.feature(world, world.objects.land));
// g1.append("g")
// .attr("id", "countries-africa")
// .selectAll()
// .data(AfricanCountries)
// .join("path")
// .attr("fill", "#fefefe")
// .attr("stroke", "none");
g1.append("path")
.attr("id", "borders-africa")
.attr("fill", "none")
.attr("stroke", "#959591")
.style("stroke-opacity", 0.1)
.datum(
topojson.mesh(Africa0, Africa0.objects.countries, (a, b) => a !== b)
);
// g1.append("path")
// .attr("id", "shore-africa")
// .attr("fill", "none")
// .attr("stroke", "orange")
// .datum(Africa);
// Add points!
svg
.selectAll("circle")
.data(data)
.join("circle")
.attr("r", 6)
.attr("transform", function (d) {
// Project our stations to the same projeciton as our map!
return `translate(${projection([d.lon, d.lat])})`;
})
.attr("opacity", 0.85)
.attr("fill", function (d) {
return d.colour !== null
? d.colour === "green"
? "#E5AE46"
: "#C46328"
: "#4B494A";
})
.attr("stroke", "#aaa")
.on("mouseover", function (event, d) {
// console.log("here", d.Name);
d3.select(this).attr("stroke-opacity", 1).attr("r", 8);
let iso = countries.find((c) => c.iso3 === d.ISO_3);
tooltip.html(
htmltooltip({
name: d.Name,
var: iso.name
})
);
return tooltip.style("visibility", "visible");
})
.on("mousemove", function (event) {
return tooltip
.style("top", event.pageY - 10 + "px")
.style("left", event.pageX + 10 + "px");
})
.on("mouseout", function (event) {
d3.select(this).attr("stroke-opacity", 1).attr("r", 6);
return tooltip.style("visibility", "hidden");
});
svg.selectAll("path").attr("d", path);
return svg.node();
}