Skip to content

Instantly share code, notes, and snippets.

@jstcki
Created December 18, 2012 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jstcki/4327678 to your computer and use it in GitHub Desktop.
Save jstcki/4327678 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
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