block by mbostock 6406992

U.S. State Mesh

Full Screen

This example, from How To Infer Topology, shows the start point of every arc in a TopoJSON file of U.S. state boundaries.

index.html

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

.mesh {
  fill: none;
  stroke: #333;
  stroke-width: .5px;
  stroke-linejoin: round;
}

.start {
  fill: black;
  stroke: white;
}

</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 = 500;

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

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

d3.json("us.json", function(error, us) {
  if (error) throw error;

  svg.append("path")
      .datum(topojson.mesh(us))
      .attr("class", "mesh")
      .attr("d", path);

  svg.selectAll(".start")
      .data(us.arcs)
    .enter().append("circle")
      .attr("class", "start")
      .attr("transform", function(d) { return "translate(" + transform(d[0]) + ")"; })
      .attr("r", 2.5);

  function transform(point) {
    return [
      point[0] * us.transform.scale[0] + us.transform.translate[0],
      point[1] * us.transform.scale[1] + us.transform.translate[1]
    ];
  }
});

</script>