I am trying to build a map from the USA. Once the map is displayed with it's states boundaries I want to display the county boundaries on click This is how I display the map:
var width = 960,
height = 500,
centered;
var path = d3.geo.path();
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
svg.append("rect")
.attr("class", "background")
.attr("width", width)
.attr("height", height)
.on("click", loadcounties);
var g = svg.append("g")
.attr("id", "states");
d3.json("readme.json", function(json) {
g.selectAll("path")
.data(json.features)
.enter().append("path")
.attr("d", path)
.on("click", loadcounties);
});
And here is the function I use to load the regions (only alabama in here):
function loadcounties (d) {
var id = d3.select(this).attr("name");
var bbox = this.getBBox();
if (id == "Alabama") {
d3.json("alabamacounties.json", function(json) {
g.selectAll("path")
.data(json.features)
.enter()
.append("path")
.attr("d", path);
});
}
}
When I try to display Alabama on its own it works but as a function it doesn't. Any idea of what I am doing wrong?thanks