Created
March 16, 2020 14:55
-
-
Save hamzamu/e59c2e8ebf50a81f37af0b08d62a780d to your computer and use it in GitHub Desktop.
Map D3 JSON
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://bl.ocks.org/herrstucki/4327678 | |
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("/swiss/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); | |
svg.append("text") | |
.data(topojson.feature(ch, ch.objects.cantons).features) | |
.attr("class", "labs") | |
.attr('x', 100) | |
.attr('y', 200) | |
.text(function(d,i) { return (d.properties.name).toString(); }); | |
svg.selectAll(".labs") | |
.data(topojson.feature(ch, ch.objects.cantons).features) | |
.enter().append("text") | |
.attr("class", "labs") | |
.attr('x', 10) | |
.attr('y', 5) | |
.attr("dy", ".35em") | |
.text(function(d,i) { return (d.properties.name).toString(); }); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment