Skip to content

Instantly share code, notes, and snippets.

@Libbum
Created May 7, 2016 22:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Libbum/e8cda20eea9d401f642357c4f46281e4 to your computer and use it in GitHub Desktop.
Save Libbum/e8cda20eea9d401f642357c4f46281e4 to your computer and use it in GitHub Desktop.
1:110m Globe with visible tiny countries.
<!DOCTYPE html>
<meta charset="utf-8">
<style>
body {
background: #fcfcfa;
}
.fill {
fill: #fff;
}
.graticule {
fill: none;
stroke: #777;
stroke-width: .5px;
stroke-opacity: .5;
}
.land {
fill: #222;
}
</style>
<body>
<script src="//d3js.org/d3.v3.min.js"></script>
<script src="//d3js.org/topojson.v1.min.js"></script>
<script>
var width = 500,
height = 500;
var projection = d3.geo.orthographic()
.translate([width / 2, height / 2])
.scale(width / 2 - 20)
.clipAngle(90)
.precision(0.6)
.rotate([-40, -30]);
var path = d3.geo.path()
.projection(projection);
var graticule = d3.geo.graticule();
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
svg.append("defs").append("path")
.datum({type: "Sphere"})
.attr("id", "sphere")
.attr("d", path);
svg.append("use")
.attr("class", "stroke")
.attr("xlink:href", "#sphere");
svg.append("use")
.attr("class", "fill")
.attr("xlink:href", "#sphere");
svg.append("path")
.datum(graticule)
.attr("class", "graticule")
.attr("d", path);
d3.json("world.json", function(error, world) {
if (error) throw error;
var land = topojson.feature(world, world.objects.countries).features;
svg.insert("g", ".graticule").attr("id", "countries");
d3.selectAll("#countries").selectAll("path").data(land)
.enter().append("path").attr("class", "land").attr("id", function(d, i) { return d.id; }).attr("d", path);
});
</script>
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment