Skip to content

Instantly share code, notes, and snippets.

@mmmaaatttttt
Created August 25, 2017 21:06
Show Gist options
  • Save mmmaaatttttt/e8b4a03237494270cfaa63ede746e341 to your computer and use it in GitHub Desktop.
Save mmmaaatttttt/e8b4a03237494270cfaa63ede746e341 to your computer and use it in GitHub Desktop.
Basic SF Map
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");
});
<!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>
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