Skip to content

Instantly share code, notes, and snippets.

@darrenjaworski
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darrenjaworski/3c10133e953d6274fc4b to your computer and use it in GitHub Desktop.
Save darrenjaworski/3c10133e953d6274fc4b to your computer and use it in GitHub Desktop.
Orthographic transition I

Let's get this thing moving... not DRY

<!DOCTYPE html>
<meta charset="utf-8">
<body>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script>
( function map() {
var width = $(window).width() - 16,
height = width,
graticule = d3.geo.graticule(),
norman = [97.44, -35.22, 0],
tunisia = [-9, -34, 0];
//35.2200° N, 97.4400° W norman
//34.0000° N, 9.0000° E tunisia
var projection = d3.geo.orthographic()
.scale(width / 2)
.clipAngle(90)
.translate([width / 2, height / 2]);
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("/d/4090846/world-110m.json", function(error, world) {
var countries = topojson.feature(world, world.objects.countries),
land = topojson.feature(world, world.objects.land),
grid = graticule(),
sphere = {type:"Sphere"};
projection.rotate(norman);
context.beginPath();
path(countries);
context.fillStyle = "#000";
context.fill();
context.beginPath();
path(sphere);
context.lineWidth = 2;
context.strokeStyle = "#000";
context.stroke();
context.beginPath();
path(grid);
context.lineWidth = .5;
context.strokeStyle = "#bbb";
context.stroke();
( function transition() {
d3.transition()
.delay(2000)
.duration(10)
.tween("rotate", function() {
context.clearRect(0, 0, width, height);
projection.rotate(tunisia);
context.beginPath();
path(countries);
context.fillStyle = "#000";
context.fill();
context.beginPath();
path(sphere);
context.lineWidth = 2;
context.strokeStyle = "#000";
context.stroke();
context.beginPath();
path(grid);
context.lineWidth = .5;
context.strokeStyle = "#bbb";
context.stroke();
});
}) ();
});
}) ();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment