Skip to content

Instantly share code, notes, and snippets.

@idibidiart
Last active December 18, 2015 23:29
Show Gist options
  • Save idibidiart/5861692 to your computer and use it in GitHub Desktop.
Save idibidiart/5861692 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.graticule {
fill: none;
stroke: #777;
}
.boundary {
fill: #ccc;
fill-opacity: .8;
stroke: #000;
}
</style>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/d3.geo.projection.v0.min.js"></script>
<script>
var width = 960,
height = 960;
var projection = d3.geo.satellite()
.distance(1.1)
.scale(2000)
.rotate([76.00, -34.50, 32.12])
.center([-2, 5])
.tilt(25);
var circle = function() {
return d3.geo.circle()
.angle(20)
.origin([-projection.rotate()[0], -projection.rotate()[1]]);
};
var graticule = d3.geo.graticule()
.extent([[-93, 27], [-47 + 1e-6, 57 + 1e-6]])
.step([3, 3]);
var path = function() {
return d3.geo.path()
.projection(projection);
};
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
svg.append("path")
.datum(graticule)
.attr("class", "graticule")
.attr("d", path());
d3.json("/d/3750900/us-boundary.json", function(collection) {
svg.append("path")
.datum(circle().clip(collection))
.attr("class", "boundary")
.attr("d", path());
// begin animation
d3.timer(function(t) {
// scale passes through 0 in 6 seconds and becomes negative
projection = projection.scale(6000-t);
svg.select("path.graticule")
.datum(graticule)
.attr("d", path());
svg.select("path.boundary")
.datum(circle().clip(collection))
.attr("d", path());
});
});
d3.select(self.frameElement).style("height", height + "px");
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment