Look at the code of the basic d3 mapping workshop of the #jpd15.
The slides and the explanation in this link (although in Spanish).
license: mit | |
height: 1060 |
<!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> |