Last active
December 22, 2015 06:49
-
-
Save x2764tech/6433962 to your computer and use it in GitHub Desktop.
an example of r2d3 and d3 projections
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
<html> | |
<head> | |
</head> | |
<body> | |
<h1></h1> | |
<!--[if lte IE 8]><script src="https://raw.github.com/mhemesath/r2d3/master/r2d3.js" charset="utf-8"></script><![endif]--> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<script src="http://d3js.org/queue.v1.min.js"></script> | |
<script src="http://d3js.org/topojson.v1.min.js"></script> | |
<script> | |
var width = 960, | |
height = 500; | |
var projection = d3.geo.orthographic() | |
.scale(250) | |
.translate([width / 2, height / 2]) | |
.clipAngle(90); | |
var path = d3.geo.path() | |
.projection(projection); | |
var λ = d3.scale.linear() | |
.domain([0, width]) | |
.range([-180, 180]); | |
var φ = d3.scale.linear() | |
.domain([0, height]) | |
.range([90, -90]); | |
var svg = d3.select("body").append("svg") | |
.attr("width", width) | |
.attr("height", height); | |
/*svg.on("mousemove", function() { | |
var p = d3.mouse(this); | |
projection.rotate([λ(p[0]), φ(p[1])]); | |
svg.selectAll("path").attr("d", path); | |
});*/ | |
var x = 1; | |
setInterval( function() { | |
projection.rotate([λ(x), φ(0)]); | |
x+=1; | |
svg.selectAll("path").attr("d", path); | |
}, 1000); | |
d3.json("/d/4090846/world-110m.json", function(error, world) { | |
svg.append("path") | |
.datum(topojson.feature(world, world.objects.land)) | |
.attr("class", "land") | |
.attr("d", path); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment