Created
August 25, 2017 21:06
-
-
Save mmmaaatttttt/e8b4a03237494270cfaa63ede746e341 to your computer and use it in GitHub Desktop.
Basic SF 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
d3.json("./sf_zips.json", function(err, data) { | |
// data - TOPOJSON | |
// mapData - GEOJSON | |
var width = 600; | |
var height = 600; | |
var svg = d3.select('svg') | |
.attr('width', width) | |
.attr('height', height); | |
var mapData = topojson.feature(data, data.objects.zip_codes_for_the_usa).features; | |
var projection = d3.geoMercator() | |
.scale(2500) | |
.translate([0, height]); | |
var path = d3.geoPath().projection(projection); | |
svg | |
.selectAll("path") | |
.data(mapData) | |
.enter() | |
.append("path") | |
.attr("d", path) | |
.attr("fill", "red") | |
.attr("stroke", "black"); | |
}); |
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>D3 Maps</title> | |
<style> | |
svg { | |
margin: 0 auto; | |
display: block; | |
} | |
</style> | |
</head> | |
<body> | |
<svg></svg> | |
<script src="https://d3js.org/d3.v4.js"></script> | |
<script src="https://unpkg.com/topojson@3"></script> | |
<script src="app.js"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment