Simple Rotating World
Last active
February 17, 2017 05:33
-
-
Save grahamjenson/8192485 to your computer and use it in GitHub Desktop.
Simple Rotating World
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> | |
<div id='js-rotation-example'></div> | |
<script src='http://code.jquery.com/jquery-2.0.3.js'></script> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<script src="http://d3js.org/topojson.v0.min.js"></script> | |
<script src="/grahamjenson/raw/8168412/worldtopo.js"></script> | |
<style> | |
.background { | |
fill: #a4bac7; | |
} | |
.foreground { | |
fill: none; | |
stroke: #333; | |
stroke-width: 1.5px; | |
} | |
.graticule { | |
fill: none; | |
stroke: #fff; | |
stroke-width: .5px; | |
} | |
.graticule :nth-child(2n) { | |
stroke-dasharray: 2,2; | |
} | |
.land { | |
fill: #d7c7ad; | |
stroke: #766951; | |
} | |
.geojson { | |
fill: none; | |
stroke: red; | |
stroke-width: 5; | |
} | |
.boundary { | |
fill: none; | |
stroke: #a5967e; | |
} | |
</style> | |
<script> | |
var width = $(window).width(), | |
height = $(window).height(); | |
var sc = Math.min(width,height) * 0.5 | |
var lat = -180 | |
var projection = d3.geo.orthographic() | |
.scale(sc) | |
.translate([width/2,height/2]) | |
.rotate([lat,0]) | |
.clipAngle(90); | |
var path = d3.geo.path() | |
.projection(projection); | |
var graticule = d3.geo.graticule(); | |
var svg = d3.select("#js-rotation-example").append("svg") | |
.attr("width", width) | |
.attr("height", height); | |
svg.selectAll(".land") | |
.data([topojson.object(worldtopo, worldtopo.objects.land)]) | |
.enter().append('path') | |
.attr('class','land') | |
.attr("d", path); | |
setInterval(function(){ | |
lat = lat +.5 | |
projection.rotate([lat,0]); | |
svg.selectAll(".land") | |
.attr("d", path); | |
},100); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment