Last active
October 11, 2018 09:59
-
-
Save curran/307c61f2b30d449c3f5f08d6a67d324f to your computer and use it in GitHub Desktop.
[unlisted] map boxes
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
license: mit |
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
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> | |
<head> | |
<title>Let's make a map with D3.js!</title> | |
<link rel="stylesheet" href="styles.css"> | |
<script src="https://unpkg.com/d3@5.6.0/dist/d3.min.js"></script> | |
<script src="https://unpkg.com/topojson@3.0.2/dist/topojson.min.js"></script> | |
</head> | |
<body> | |
<svg width="960" height="600"></svg> | |
<script> | |
const svg = d3.select('svg'); | |
const width = +svg.attr('width'); | |
const height = +svg.attr('height'); | |
var projection = d3.geoAlbersUsa() | |
.scale(400) | |
.translate([width / 2, height / 2]); | |
var path = d3.geoPath() | |
.projection(projection); | |
d3.json('https://d3js.org/us-10m.v1.json') | |
.then(data => { | |
console.log(path); | |
const states = topojson.feature(data,data.objects.states); | |
svg.selectAll('path').data(states.features) | |
.enter().append('path') | |
.attr("class", "state") | |
.attr('d', path); | |
}); | |
</script> | |
</body> | |
</html> |
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
.state { | |
fill: #ccc; | |
stroke: black | |
} | |
.state-boundary { | |
fill: none; | |
stroke: #fff; | |
} | |
.state.selected { | |
fill: orange; | |
stroke: #000; | |
}1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment