Skip to content

Instantly share code, notes, and snippets.

@russbiggs
Created November 23, 2019 20:48
Show Gist options
  • Save russbiggs/340bc6781e3bf276201425c5e93e2b96 to your computer and use it in GitHub Desktop.
Save russbiggs/340bc6781e3bf276201425c5e93e2b96 to your computer and use it in GitHub Desktop.
World map
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>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script type="text/javascript" src="https://d3js.org/d3.v5.min.js"></script>
<title>Document</title>
<style>
body {
margin:0;
padding:0;
}
.country {
fill: #222;
stroke: #555;
stroke-width: 1px;
}
svg {
background-color: #555;
}
</style>
</head>
<body>
<div id="container" class="svg-container"></div>
<script type="text/javascript">
var w = window.innerWidth;
var h = window.innerHeight;
var svg = d3.select("div#container").append("svg").attr('width', w).attr('height', h)
var projection = d3.geoMercator().translate([w/2, h/2]).scale(220).center([0,25]);
var path = d3.geoPath().projection(projection);
var worldmap = d3.json("countries.json");
Promise.all([worldmap]).then(function(countries){
console.log(countries);
svg.selectAll("path")
.data(countries[0].features)
.enter()
.append("path")
.attr("class","country")
.attr("d", path);
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment