Skip to content

Instantly share code, notes, and snippets.

@dwtkns
Created February 21, 2013 12:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dwtkns/5004429 to your computer and use it in GitHub Desktop.
Save dwtkns/5004429 to your computer and use it in GitHub Desktop.
{
"libraries": [
"d3"
],
"mode": "javascript",
"layout": "fullscreen mode (vertical)",
"resolution": "reset"
}
body {
font: 11px sans-serif;
}
svg { border: solid 1px #CCC; }
.states {
fill: #DDD;
stroke: #CCC;
}
.boroughs {
fill: #AAA;
stroke: #666;
}
.borough:hover {
fill:#999;
}
var width = 1000;
var height = 900;
// Set the width and height of the SVG
var svg = d3.select('svg')
.style("width",width)
.style("height",height);
// Make a couple of groups in the SVG to hold our two different types of map data (state outlines and borough outlines).
var state_map = svg.append("g").attr("class","states");
var borough_map = svg.append("g").attr("class","boroughs");
var maptext = svg.append("g")
.attr("class","textGroup")
.append("text")
.attr("class","label").text("hey");
// Start our map projection
var nyc_projection = d3.geo.mercator();
// Set some variables to center it over NYC
nyc_projection.center([-74.25,40.925])
.scale(436077)
.translate([0,0]);
// Start a "path generator" using the map projection above
var nyc_path = d3.geo.path().projection(nyc_projection);
borough_map.selectAll("path")
.data(livecoding.json.features)
.enter().append("path")
.attr("d", nyc_path)
.attr("class", "borough")
borough_map.selectAll("path")
.on("click",function(d) {
d3.select(".label")
.attr("transform", "translate(" + nyc_path.centroid(d) + ")")
.style("text-anchor", "middle")
.text(d.properties.BoroName);
});
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