Skip to content

Instantly share code, notes, and snippets.

@tmcw
Forked from Digital-Banana/buurten.json
Last active March 15, 2018 22:18
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 tmcw/0b04a6d6627faa250ec40da83e07ed7f to your computer and use it in GitHub Desktop.
Save tmcw/0b04a6d6627faa250ec40da83e07ed7f to your computer and use it in GitHub Desktop.
Heerlen Choropleth
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.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Heerlen</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<svg id="map"></svg>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.13.0/d3.min.js" charset="utf-8"></script>
<script src="index.js"></script>
</body>
</html>
var margin = { top: 50, right: 50, bottom: -20, left: 50 },
width = 250 - margin.left - margin.right,
height = 350 - margin.top - margin.bottom;
var svg = d3.select("#map")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top +")");
var projection = d3.geoMercator()
.center([5.961, 50.865])
.scale(100000)
.translate([width / 2, height / 2]);
var path = d3.geoPath()
.projection(projection);
var color = d3.scaleLinear()
.domain([0, 250, 500, 1400, 2800, 3600, 4500])
.range(['#ffffcc','#c7e9b4','#7fcdbb','#41b6c4','#1d91c0','#225ea8','#0c2c84']);
d3.json("buurten.json", function(err, json) {
if (err) throw error;
function drawMap() {
var features = svg.append("g")
.attr("class", "heerlen")
.selectAll("#map")
.data(json.features);
featuresEnter = features
.enter().append("g")
.attr("class", function(d) { return "buurt " + d.properties.BU_NAAM})
.append("path")
.attr("d", path)
.style("fill", function(d) {
return color(d.properties.AANT_INW); });
console.log(featuresEnter);
featuresEnter.on("mousemove", function(d) {
console.log(d.properties.AANT_INW);
});
};
function loopThrough() {
for (var i=0;i<json.features.length;i++){
var buurtInw = json.features[i].properties.AANT_INW;
var buurtNaam = json.features[i].properties.BU_NAAM;
//console.log(buurtNaam + ": " + buurtInw);
}
}
drawMap();
loopThrough();
// console.log(json);
// console.log(json.features);
// console.log(json.features[4].properties);
// console.log(json.features[4].properties.AANT_INW);
// console.log(json.features[4].properties.BU_NAAM);
});
body {
background: whitesmoke;
}
.buurten, .heerlen {
stroke: #444;
stroke-width: 1px;
stroke-linejoin: round;
stroke-linecap: round;
pointer-events: none;
}
div.tooltip {
position: absolute;
text-align: center;
width: 60px;
height: 28px;
padding: 2px;
font: 12px sans-serif;
background: lightsteelblue;
border: 0px;
border-radius: 8px;
pointer-events: none;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment