Skip to content

Instantly share code, notes, and snippets.

@martgnz
Last active October 28, 2017 16:23
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 martgnz/9602b285e51a6100521a to your computer and use it in GitHub Desktop.
Save martgnz/9602b285e51a6100521a to your computer and use it in GitHub Desktop.
Barcelona's census tracts
license: mit
height: 1060

Look at the code of the basic d3 mapping workshop of the #jpd15.

The slides and the explanation in this link (although in Spanish).

<!DOCTYPE html>
<html>
<style>
body {
font-family: "Helvetica Neue", "Helvetica", Arial, sans-serif;
color: #333;
-moz-osx-font-smoothing: greyscale;
}
path {
fill: none;
stroke: #333;
stroke-width: 0.7px;
}
</style>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="https://d3js.org/topojson.v3.min.js"></script>
<body>
<script>
var margin = { top: 260, right: 10, bottom: 20, left: 150 },
width = 960 - margin.left - margin.right,
height = 1060 - margin.top - margin.bottom;
var projection = d3
.geoMercator()
.center([2.1722, 41.395691])
.scale(300000);
var path = d3.geoPath().projection(projection);
var svg = d3
.select("body")
.append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
d3.json("seccion-censal.json", function(error, data) {
if (error) return console.error(error);
svg
.append("path")
.datum(topojson.mesh(data))
.attr("d", path);
});
</script>
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