Skip to content

Instantly share code, notes, and snippets.

Last active January 10, 2024 01:25
Show Gist options
  • Star 24 You must be signed in to star a gist
  • Fork 33 You must be signed in to fork a gist
  • Save mbostock/4183330 to your computer and use it in GitHub Desktop.
Save mbostock/4183330 to your computer and use it in GitHub Desktop.
World Tour
license: gpl-3.0
<!DOCTYPE html>
<meta charset="utf-8">
h1 {
position: absolute;
top: 500px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 18px;
text-align: center;
width: 960px;
<script src="//"></script>
<script src="//"></script>
<script src="//"></script>
var width = 960,
height = 960;
var projection = d3.geo.orthographic()
.translate([width / 2, height / 2])
.scale(width / 2 - 20)
var canvas ="body").append("canvas")
.attr("width", width)
.attr("height", height);
var c = canvas.node().getContext("2d");
var path = d3.geo.path()
var title ="h1");
.defer(d3.json, "/mbostock/raw/4090846/world-110m.json")
.defer(d3.tsv, "/mbostock/raw/4090846/world-country-names.tsv")
function ready(error, world, names) {
if (error) throw error;
var globe = {type: "Sphere"},
land = topojson.feature(world,,
countries = topojson.feature(world, world.objects.countries).features,
borders = topojson.mesh(world, world.objects.countries, function(a, b) { return a !== b; }),
i = -1,
n = countries.length;
countries = countries.filter(function(d) {
return names.some(function(n) {
if ( == return =;
}).sort(function(a, b) {
(function transition() {
.each("start", function() {
title.text(countries[i = (i + 1) % n].name);
.tween("rotate", function() {
var p = d3.geo.centroid(countries[i]),
r = d3.interpolate(projection.rotate(), [-p[0], -p[1]]);
return function(t) {
c.clearRect(0, 0, width, height);
c.fillStyle = "#ccc", c.beginPath(), path(land), c.fill();
c.fillStyle = "#f00", c.beginPath(), path(countries[i]), 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();
.each("end", transition);
}"height", height + "px");
Copy link

Getting this error when trying to locate Singapore:
(index):75 Uncaught TypeError: Cannot read property 'name' of undefined(…)

Is it not in world-110m.json?

Copy link

Zerg00s commented Feb 4, 2017

I've slightly tweaked this project to add search:

Copy link

There is another small mistake:
land = topojson.feature(world,
should be:
land = topojson.feature(world,
This does not show up because all countries compose land, but when you filter countries, e.g. to highlight only the countries of the Pacific Rim, it becomes a problem that's hard to find...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment