Skip to content

Instantly share code, notes, and snippets.

Created October 17, 2017 12:08
Show Gist options
  • Save anonymous/49799e7c0a03b5dccbe3c3e762b654b1 to your computer and use it in GitHub Desktop.
Save anonymous/49799e7c0a03b5dccbe3c3e762b654b1 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<meta charset="utf-8">
<style>
h1 {
position: absolute;
top: 500px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 18px;
text-align: center;
width: 960px;
}
</style>
<h1></h1>
<script src="//d3js.org/d3.v3.min.js"></script>
<script src="//d3js.org/queue.v1.min.js"></script>
<script src="//d3js.org/topojson.v1.min.js"></script>
<script>
var width = 960,
height = 960;
var projection = d3.geo.orthographic()
.translate([width / 2, height / 2])
.scale(width / 2 - 20)
.clipAngle(90)
.precision(0.6);
var canvas = d3.select("body").append("canvas")
.attr("width", width)
.attr("height", height);
var c = canvas.node().getContext("2d");
var path = d3.geo.path()
.projection(projection)
.context(c);
var title = d3.select("h1");
queue()
.defer(d3.json, "/mbostock/raw/4090846/world-110m.json")
.defer(d3.tsv, "/mbostock/raw/4090846/world-country-names.tsv")
.await(ready);
function ready(error, world, names) {
if (error) throw error;
var globe = {type: "Sphere"},
land = topojson.feature(world, world.objects.land),
countries = topojson.feature(world, world.objects.countries).features,
borders = topojson.mesh(world, world.objects.countries, function(a, b) { return a !== b; }),
c.fillStyle = "#ccc", c.beginPath(), path(land), c.fill();
c.strokeStyle = "#fff", c.lineWidth = .5, c.beginPath(), path(borders), c.stroke();
c.strokeStyle = "#000", c.lineWidth = 2, c.beginPath(), path(globe), c.stroke();
title = "Country Name";
}
d3.select(self.frameElement).style("height", height + "px");
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment