Interrupted rotating Mollweide hemispheres.
Created
September 14, 2012 21:32
-
-
Save jasondavies/3724998 to your computer and use it in GitHub Desktop.
Interrupted Mollweide Hemispheres
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 { | |
padding: 37px 54px; | |
} | |
.background { | |
fill: #a4bac7; | |
} | |
.foreground { | |
fill: none; | |
stroke: #333; | |
stroke-width: 1.5px; | |
} | |
.graticule { | |
fill: none; | |
stroke: #fff; | |
stroke-width: .5px; | |
} | |
.graticule:nth-child(2n) { | |
stroke-dasharray: 2,2; | |
} | |
.land { | |
fill: #d7c7ad; | |
stroke: #766951; | |
} | |
.boundary { | |
fill: none; | |
stroke: #a5967e; | |
} | |
</style> | |
<body> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<script src="https://raw.github.com/d3/d3-plugins/master/geo/projection/projection.js"></script> | |
<script> | |
var width = 425, | |
height = 425; | |
var graticule = d3.geo.graticule(), | |
graticule90 = d3.geo.graticule() | |
.extent([[-90, -90], [90, 90]]); | |
var projection = d3.geo.mollweide() | |
.translate([width / 2 + .5, height / 2 + .5]) | |
.clipAngle(90), | |
path = d3.geo.path().projection(projection); | |
var svg = d3.select("body").selectAll("svg") | |
.data([{x: 0, y: 0, z: 0}, {x: 0, y: 0, z: 180}]) | |
.enter().append("svg") | |
.attr("width", width + 1) | |
.attr("height", height + 1); | |
svg.append("path") | |
.datum(graticule90.outline) | |
.attr("class", "background") | |
.attr("d", path); | |
svg.append("path") | |
.datum(graticule90.outline) | |
.attr("class", "foreground") | |
.attr("d", path); | |
d3.json("readme-boundaries.json", function(err, boundaries) { | |
d3.json("readme-world-countries.json", function(err, land) { | |
svg.insert("g", ".graticule") | |
.attr("class", "boundary") | |
.selectAll("path") | |
.data(boundaries.features) | |
.enter().append("path"); | |
svg.insert("g", ".graticule,.boundary") | |
.attr("class", "land") | |
.selectAll("path") | |
.data(land.features) | |
.enter().append("path"); | |
d3.timer(function() { | |
svg.call(hemisphere, boundaries, land); | |
}); | |
}); | |
}); | |
function hemisphere(svg, boundaries, land) { | |
svg.each(function(d, i) { | |
d.z++; | |
d.y += i ? -1 : 1; | |
projection.rotate([d.z, d.y, 0]); | |
var svg = d3.select(this); | |
svg.selectAll(".land, .boundary").selectAll("path") | |
.attr("d", path); | |
var g = svg.selectAll(".graticule") | |
.data(graticule.lines); | |
g.enter().append("path").attr("class", "graticule"); | |
g.attr("d", path); | |
g.exit().remove(); | |
}); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment