Skip to content

Instantly share code, notes, and snippets.

@piwodlaiwo
Created March 4, 2018 03:07
Show Gist options
  • Save piwodlaiwo/3734a1357696dcff203a94012646e932 to your computer and use it in GitHub Desktop.
Save piwodlaiwo/3734a1357696dcff203a94012646e932 to your computer and use it in GitHub Desktop.
World Map with D3 and TopoJSON
license: mit
<!DOCTYPE html>
<meta charset="utf-8">
<style>svg{width:100%;height:500px;margin:0px auto;}</style>
<body>
<script src="https://unpkg.com/d3@4"></script>
<script src="https://unpkg.com/topojson-client@3"></script>
<script>
var svg = d3.select("body").append("svg");
var path = d3.geoPath().projection(d3.geoMercator());
d3.json("https://unpkg.com/world-atlas@1/world/110m.json", function(error, world) {
if (error) throw error;
svg.selectAll("path")
.data(topojson.feature(world,world.objects.countries).features)
.enter().append("path")
.attr("d", path);
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment