Skip to content

Instantly share code, notes, and snippets.

@mbostock
Last active February 9, 2016 02:06
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Ohio State Plane (N)
license: gpl-3.0
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.county {
fill: #eee;
}
.county:hover {
fill: orange;
}
.county-border {
fill: none;
stroke: #777;
pointer-events: none;
}
</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 = 1200;
var projection = d3.geo.conicConformal()
.parallels([40 + 26 / 60, 41 + 42 / 60])
.rotate([82 + 30 / 60, -39 - 40 / 60])
.translate([width / 2, height / 2]);
var path = d3.geo.path()
.projection(projection);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
d3.json("oh-counties.json", function(error, oh) {
if (error) throw error;
var counties = topojson.feature(oh, oh.objects.counties);
projection
.scale(1)
.translate([0, 0]);
var b = path.bounds(counties),
s = .95 / Math.max((b[1][0] - b[0][0]) / width, (b[1][1] - b[0][1]) / height),
t = [(width - s * (b[1][0] + b[0][0])) / 2, (height - s * (b[1][1] + b[0][1])) / 2];
projection
.scale(s)
.translate(t);
svg.selectAll("path")
.data(counties.features.filter(function(d) { return d.id % 1000; }))
.enter().append("path")
.attr("class", "county")
.attr("d", path)
.append("title")
.text(function(d) { return d.properties.name; });
svg.append("path")
.datum(topojson.mesh(oh, oh.objects.counties, function(a, b) { return a !== b; }))
.attr("class", "county-border")
.attr("d", path);
});
d3.select(self.frameElement).style("height", height + "px");
</script>
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment