Skip to content

Instantly share code, notes, and snippets.

@mbostock
Last active January 8, 2020 03:26
Show Gist options
  • Save mbostock/3734273 to your computer and use it in GitHub Desktop.
Save mbostock/3734273 to your computer and use it in GitHub Desktop.
Rotating Equirectangular
license: gpl-3.0
<!DOCTYPE html>
<meta charset="utf-8">
<body>
<script src="//d3js.org/d3.v3.min.js"></script>
<script src="//d3js.org/topojson.v1.min.js"></script>
<script>
var width = 960,
height = 500;
var velocity = .01,
t0 = Date.now();
var projection = d3.geo.equirectangular()
.scale(159);
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() {
var t = Date.now() - t0;
projection.rotate([0, velocity * t]);
context.clearRect(0, 0, width, height);
context.beginPath();
path(land);
context.fill();
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment