Skip to content

Instantly share code, notes, and snippets.

@ststeiger
Forked from jstcki/README.md
Last active February 23, 2021 15:28
Show Gist options
  • Save ststeiger/da217526868ffe80c610 to your computer and use it in GitHub Desktop.
Save ststeiger/da217526868ffe80c610 to your computer and use it in GitHub Desktop.
Swiss Cantons and Municipalities

Map of Switzerland with TopoJSON and map data from Swiss Maps. Cantons and municipalities are combined in a single TopoJSON file.

Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.country {
fill: #222;
}
.canton-boundaries {
fill: none;
stroke: #fff;
stroke-width: 1;
}
.municipality-boundaries {
fill: none;
stroke: #fff;
stroke-width: .3;
}
</style>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script>
var width = 960,
height = 500;
var path = d3.geo.path()
.projection(null);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
d3.json("ch.json", function(error, ch) {
svg.append("path")
.datum(topojson.feature(ch, ch.objects.country))
.attr("class", "country")
.attr("d", path);
svg.append("path")
.datum(topojson.mesh(ch, ch.objects.municipalities, function(a, b) { return a !== b; }))
.attr("class", "municipality-boundaries")
.attr("d", path);
svg.append("path")
.datum(topojson.mesh(ch, ch.objects.cantons, function(a, b) { return a !== b; }))
.attr("class", "canton-boundaries")
.attr("d", path);
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment