Skip to content

Instantly share code, notes, and snippets.

@unamandita
Created November 10, 2015 22:05
Show Gist options
  • Save unamandita/2653a559e1f796ab1d4f to your computer and use it in GitHub Desktop.
Save unamandita/2653a559e1f796ab1d4f to your computer and use it in GitHub Desktop.
New York State: Module #3 exercise
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>New York State</title>
<script type="text/javascript" src="http://d3js.org/d3.v3.js"></script>
<style type="text/css">
body {
background-color: #e5e4e2;
}
svg {
background-color: white;
}
h1 {
font-family: Helvetica, Arial, sans-serif;
font-size: 24px;
font-weight: lighter;
margin-left: 200px;
}
</style>
</head>
<body>
<h1>New York State</h1>
<script type="text/javascript">
//Width and height
var w = 600;
var h = 450;
//Define map projection
var projection = d3.geo.mercator()
.center([ -76, 42.8 ])
.translate([ w/2, h/2 ])
.scale([ w*6 ]);
//Define path generator
var path = d3.geo.path()
.projection(projection);
//Create SVG
var svg = d3.select("body")
.append("svg")
.attr("width", w)
.attr("height", h);
//Load in GeoJSON data
d3.json("state_ny.json", function(json) {
//Bind data and create one path per GeoJSON feature
svg.selectAll("path")
.data(json.features)
.enter()
.append("path")
.attr("d", path)
.attr("fill", "#e56e94")
.attr("stroke", "black");
});
</script>
</body>
</html>
Display the source blob
Display the rendered blob
Raw
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