Last active
February 9, 2016 01:37
-
-
Save mbostock/3790085 to your computer and use it in GitHub Desktop.
Rotating Winkel Tripel
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
license: gpl-3.0 |
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"> | |
<body> | |
<script src="//d3js.org/d3.v3.min.js"></script> | |
<script src="//d3js.org/d3.geo.projection.v0.min.js"></script> | |
<script src="//d3js.org/topojson.v1.min.js"></script> | |
<script> | |
var width = 960, | |
height = 500; | |
var velocity = .02; | |
var projection = d3.geo.winkel3() | |
.translate([width / 2, height / 2]); | |
var graticule = d3.geo.graticule(); | |
var canvas = d3.select("body").append("canvas") | |
.attr("width", width) | |
.attr("height", height); | |
var context = canvas.node().getContext("2d"); | |
var path = d3.geo.path() | |
.projection(projection) | |
.context(context); | |
d3.json("/mbostock/raw/4090846/world-110m.json", function(error, world) { | |
if (error) throw error; | |
var land = topojson.feature(world, world.objects.land); | |
d3.timer(function(elapsed) { | |
context.clearRect(0, 0, width, height); | |
projection.rotate([velocity * elapsed, 0]); | |
context.beginPath(); | |
path(land); | |
context.fill(); | |
context.beginPath(); | |
path(graticule()); | |
context.lineWidth = .5; | |
context.stroke(); | |
context.beginPath(); | |
path(graticule.outline()); | |
context.lineWidth = 1.5; | |
context.stroke(); | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment