Rotating Guyou hemispheres.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
| <!DOCTYPE html> | |
| <meta charset="utf-8"> | |
| <style> | |
| body { | |
| padding: 22px 33px; | |
| } | |
| .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 = 446, | |
| height = 446, | |
| ε = 1e-4; | |
| var graticule = d3.geo.graticule(), | |
| graticule90 = d3.geo.graticule() | |
| .extent([[-90 + ε, -90 + ε], [90 - ε, 90 - ε]]); | |
| var projection = d3.geo.guyou() | |
| .scale(120) | |
| .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.selectAll(".graticule") | |
| .data(graticule.lines) | |
| .enter().append("path") | |
| .attr("class", "graticule") | |
| .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]); | |
| d3.select(this).selectAll(".land path, .boundary path, .graticule") | |
| .attr("d", path); | |
| }); | |
| } | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment