Part 1 of the transition works fine!
Last active
August 29, 2015 14:06
-
-
Save darrenjaworski/309155a55841fbdf868f to your computer and use it in GitHub Desktop.
Orthographic Transition III
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="//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], //35.2200° N, 97.4400° W norman | |
tunisia = [9, 34], //34.0000° N, 9.0000° E tunisia | |
delay = 1000, | |
duration = 3000; | |
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("world.json", function(error, world) { | |
var countries = topojson.feature(world, world.objects.countries), | |
land = topojson.feature(world, world.objects.land), | |
grid = graticule(), | |
globe = {type:"Sphere"}; | |
function projrotate(array){ | |
projection.rotate([-array[0], -array[1]]); | |
} | |
function draw() { | |
context.beginPath(); | |
path(countries); | |
context.fillStyle = "#000"; | |
context.fill(); | |
context.strokeStyle = "#fff"; | |
context.stroke(); | |
context.beginPath(); | |
path(globe); | |
context.lineWidth = 2; | |
context.strokeStyle = "#000"; | |
context.stroke(); | |
context.beginPath(); | |
path(grid); | |
context.lineWidth = .5; | |
context.strokeStyle = "#bbb"; | |
context.stroke(); | |
}; | |
projrotate(tunisia) | |
draw(); | |
( function transition() { | |
d3.transition() | |
.delay(delay) | |
.duration(duration) | |
.tween("rotate", function() { | |
var r = d3.interpolate(projection.rotate(), [-norman[0], -norman[1]]); | |
return function(t) { | |
projection.rotate(r(t)); | |
context.clearRect(0, 0, width, height); | |
draw(); | |
} | |
}) | |
.transition() | |
}) (); | |
}); | |
}) (); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment