block by larskotthoff 10587926

10587926

Full Screen

index.html

<!DOCTYPE html>
<meta charset="utf-8">
<style>

.land {
  fill: #ddd;
}

.boundary {
  fill: none;
  stroke: #999;
}

</style>
<body>
<script src="//d3js.org/d3.v3.min.js"></script>
<script src="//d3js.org/topojson.v1.min.js"></script>
<script>

var width = 960,
    height = 800;

var path = d3.geo.path()
    .projection(null);

var svg = d3.select("body").append("svg")
    .attr("width", width)
    .attr("height", height);

var svg2 = d3.select("body").append("svg")
    .attr("width", width)
    .attr("height", height);

d3.json("ca.json", function(error, ca) {
  svg.append("path")
      .datum(topojson.feature(ca, ca.objects.counties))
      .attr("class", "land")
      .attr("d", path)
      .on("click", function(d) { svg2.selectAll(".foo").data([d]).enter().append("path").attr("d", path); });

  svg.append("path")
      .datum(topojson.mesh(ca, ca.objects.counties, function(a, b) { return a !== b; }))
      .attr("class", "boundary")
      .attr("d", path);
});

d3.select(self.frameElement).style("height", height + "px");

</script>