Skip to content

Instantly share code, notes, and snippets.

@uafrazier
Last active November 12, 2015 17:21
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 uafrazier/98b7d1bdddfb7b2c6175 to your computer and use it in GitHub Desktop.
Save uafrazier/98b7d1bdddfb7b2c6175 to your computer and use it in GitHub Desktop.
D3: Map of Texas
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>D3: Map of Texas</title>
<script type="text/javascript" src="http://d3js.org/d3.v3.min.js"></script>
<style type="text/css">
@import url(http://fonts.googleapis.com/css?family=Oswald:700,400);
body {
font-family: oswald, arial, sans-serif;
color: #d3d3d3;
}
#container {
width: 900px;
margin-left: auto;
margin-right: auto;
margin-top: 50px;
margin-bottom: 50px;
padding: 20px 50px;
background: #333;
box-shadow: 0 0 5px #999999;
}
#container h1 {
text-align: center;
}
svg {
background: #333;
}
</style>
</head>
<body>
<div id="container">
<h1>The State of Texas</h1>
</div>
<script type="text/javascript">
//Width and height
var w = 900,
h = 500;
//Define projection
var projection = d3.geo.mercator()
.center([ -99.43,31.47 ])
.translate([ w/2, h/2 ])
.scale([ 2000 ]);
//Define path generator
var path = d3.geo.path()
.projection(projection);
//Create SVG
var svg = d3.select("#container")
.append("svg")
.attr("width", w)
.attr("height", h);
//Load in GeoJSON data
d3.json("texas.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","#d3d3d3");
});
</script>
</body>
</html>
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