Skip to content

Instantly share code, notes, and snippets.

@enjalot
Forked from enjalot/index.html
Created January 29, 2014 04:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enjalot/8681737 to your computer and use it in GitHub Desktop.
Save enjalot/8681737 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.state {
fill: #ccc;
}
.county-border {
fill: none;
stroke: #fff;
stroke-width: 1.01px;
stroke-linejoin: round;
stroke-linecap: round;
}
</style>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/d3.geo.projection.v0.min.js"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script>
var width = 960,
height = 500;
var projection = d3.geo.conicConformal()
.parallels([38 + 02 / 60, 39 + 12 / 60])
.rotate([78 + 30 / 60, 0])
.scale(8000)
.translate([0, 0]);
var path = d3.geo.path()
.projection(projection);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
d3.json("va-counties.json", function(error, topo) {
var state = topojson.feature(topo, topo.objects.states),
bounds = path.bounds(state);
projection
.translate([width / 2 - (bounds[0][0] + bounds[1][0]) / 2, height / 2 - (bounds[0][1] + bounds[1][1]) / 2]);
svg.append("path")
.datum(state)
.attr("class", "state")
.attr("d", path);
svg.append("path")
.datum(topojson.mesh(topo, topo.objects.counties, function(a, b) { return a !== b; }))
.attr("class", "county-border")
.attr("d", path);
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment