Skip to content

Instantly share code, notes, and snippets.

@FrieseWoudloper
Last active May 17, 2019 12:22
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 FrieseWoudloper/fa86853aecde846e3c8d945e61869f20 to your computer and use it in GitHub Desktop.
Save FrieseWoudloper/fa86853aecde846e3c8d945e61869f20 to your computer and use it in GitHub Desktop.
Groninger gemeenten

This is a TopoJSON file of municipalities in the north of The Netherlands visualized with D3.js. The TopoJSON file was created using Mapshaper.org.

<!DOCTYPE html>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="https://unpkg.com/topojson@3"></script>
<div class="graph"></div>
<script>
var width = 700, height = 400;
var svg = d3.select(".graph").append("svg")
.attr("viewBox", "0 0 " + (width) + " " + (height))
.style("max-width", "700px");
var tooltip = d3.select("body")
.append("div")
.attr("class", "tooltip")
.style("opacity", 0);
d3.json("mapshaper.json", function(error, topology) {
var mapdata = topojson.feature(topology, topology.objects.test);
var projection = d3.geoMercator();
var path = d3.geoPath().projection(projection);
projection.fitSize([width, height], {"type": "FeatureCollection", "features": mapdata.features});
svg.append("g")
.attr("class", "gemeente")
.selectAll("path")
.data(mapdata.features)
.enter()
.append("path")
.attr("d", path)
.on("mouseover", function(d) {
tooltip.transition()
.duration(200)
.style("opacity", .9);
tooltip.html(d.properties.gemeentenaam)
.style("left", (d3.event.pageX) + "px")
.style("top", (d3.event.pageY - 28) + "px");
})
.on("mouseout", function(d) {
tooltip.transition()
.duration(500)
.style("opacity", 0);
});
});
</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