Created
May 7, 2016 22:31
-
-
Save Libbum/e8cda20eea9d401f642357c4f46281e4 to your computer and use it in GitHub Desktop.
1:110m Globe with visible tiny countries.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment