I'm trying to get an D3.js interactive map that, on hovering on a certain municipality (divided into svg paths), will return the name and the number of escape room themes in said municipality. However, I can't get selectAll("path") or any variation to work on it.
Here's my code:
d3.json("data/seoul_municipalities_topo_simple.json", function(error, data) {
var features = topojson.feature(data, data.objects.seoul_municipalities_geo).features;
seoulmap.selectAll("path")
.data(features)
.enter().append("path")
.attr("class", function(d) {
console.log();
return "municipality c" + d.properties.SIG_CD
})
.attr("id", function(d) {
return d.properties.SIG_KOR_NM
})
.attr("d", path); /* the path variable holds the geoPath from my topojson file*/
});
//tooltip displays
var mouselocation;
var tooltip = d3.select(".tooltip");
var mappath = d3.selectAll("path"); /* this doesn't work */
mappath.on('mouseenter', function() {
tooltip.style('display', 'block');
let textID = this.id;
tooltip.select(".tooltip-city")
.html("<strong>" + textID + "</strong></br>");
tooltip.select(".tooltip-num")
.html("# of Themes: ");
}).on('mousemove', function() {
mouselocation = d3.mouse(d3.select('body').node());
tooltip.style("left", mouselocation[0] + 160 + "px")
.style("top", mouselocation[1] + 10 + "px");
}).on('mouseleave', function() {
tooltip.style('display', 'none');
});
when I run my site on console, each element in the svg is divided into paths that hold the class .municipality. Selecting through that doesn't work either. But if I replace the selector to something else, say "svg", works like a charm. I'm not sure what I'm doing wrong here??
(I'm using D3.js v4!)