Created
November 17, 2015 21:14
-
-
Save lee00678/9666580dce617b2b46e3 to your computer and use it in GitHub Desktop.
US State Geo Map
This file contains 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> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>US State projection</title> | |
<script type="text/javascript" src="http://d3js.org/d3.v3.js"></script> | |
<style type="text/css"> | |
body { | |
background-color: white; | |
} | |
h1 { | |
font-family: sans-serif; | |
font-size: 20px; | |
padding-left: 30px; | |
padding-top: 0px; | |
} | |
h2 { | |
font-family: sans-serif; | |
font-size: 12px; | |
padding-left: 30px; | |
font-weight: normal; | |
padding-top: 10px; | |
} | |
svg { | |
background-color: white; | |
} | |
#container { | |
width: 800px; | |
margin-left: auto; | |
margin-right: auto; | |
margin-top: 60px; | |
padding: 50px; | |
background-color: white; | |
border: 1px solid #ccc; | |
/*box-shadow: 3px 3px 5px 6px #ccc;*/ | |
} | |
</style> | |
</head> | |
<body> | |
<div id="container"> | |
<h1>Unite States Geo Map</h1> | |
</div> | |
<script type="text/javascript"> | |
//Width and height | |
var w = 500; | |
var h = 300; | |
//Define map projection | |
var projection = d3.geo.albersUsa() | |
.translate([ w/2, h/2 ]) | |
.scale([ 600 ]); | |
//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("usstate.json", function(json) { | |
//Bind data and create one path per GeoJSON feature | |
svg.selectAll("path") | |
.data(json.features) | |
.enter() | |
.append("path") | |
.attr("d", path) | |
.style({fill: "steelblue", stroke: "#eee"}); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment