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/a148825fe86bcc0ba242 to your computer and use it in GitHub Desktop.
Save darrenjaworski/a148825fe86bcc0ba242 to your computer and use it in GitHub Desktop.
Orthographic transition II
<!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],
tunisia = [9, 34],
//35.2200° N, 97.4400° W norman
//34.0000° N, 9.0000° E tunisia
delay = 2000,
duration = 10;
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"};
function rotate(array){
projection.rotate([-array[0], -array[1]]);
}
function draw(array){
rotate(array);
context.beginPath();
path(countries);
context.fillStyle = "#000";
context.fill();
context.strokeStyle = "#fff";
context.stroke();
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() {
draw(tunisia);
d3.transition()
.delay(delay)
.duration(duration)
.tween("rotate", function() {
context.clearRect(0, 0, width, height);
draw(norman);
});
}) ();
});
}) ();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment