Mapping and ID-ing Philadelphia 2010 Census Tracts with D3 and TopoJSON
Last active
October 3, 2016 17:47
2010 Census Geography with D3 and TopoJSON
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<style> | |
path { | |
fill: #aaa; | |
stroke: #fff; | |
stroke-width: .75px; | |
pointer-events: all; | |
} | |
text { | |
font-family: sans-serif; | |
font-size: 75px; | |
color: #aaa; | |
} | |
</style> | |
<body> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<script src="http://d3js.org/topojson.v0.min.js"></script> | |
<script> | |
var width = 960, | |
height = 500; | |
var projection = d3.geo.mercator() | |
.center([-75.12, 40]) | |
.scale(80000); | |
var path = d3.geo.path() | |
.projection(projection); | |
var svg = d3.select("body").append("svg") | |
.attr("width", width) | |
.attr("height", height); | |
var text = svg.append("text") | |
.attr("y", height/8) | |
.attr("text-anchor", "left"); | |
d3.json("tracts.json", function(error, topology) { | |
svg.selectAll("path") | |
.data(topojson.object(topology, topology.objects.tracts).geometries) | |
.enter().append("path") | |
.attr("class", "tracts") | |
.attr("id", function(d){return d.id;}) | |
.attr("d", path) | |
.on("mouseover", function(){d3.select(this).style("fill", "#ff0"); | |
text.text("tract: " + this.id);}) | |
.on("mouseout", function(){d3.select(this).style("fill", "#aaa"); | |
text.text("");}); | |
}); | |
</script> |
Loading
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