Skip to content

Instantly share code, notes, and snippets.

@vlandham
Forked from mbostock/.block
Created November 29, 2012 03:01
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 vlandham/4166498 to your computer and use it in GitHub Desktop.
Save vlandham/4166498 to your computer and use it in GitHub Desktop.
Satellite Projection
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.graticule {
fill: none;
stroke: #777;
}
.boundary {
fill: #ccc;
fill-opacity: .8;
stroke: #000;
}
.background {
fill: none;
pointer-events: all;
}
</style>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="https://raw.github.com/d3/d3-plugins/master/geo/projection/projection.js"></script>
<script>
var width = 960,
height = 960;
var map, graticule;
var projection = d3.geo.satellite()
.distance(1.1)
.scale(5500)
.rotate([76.00, -34.50, 32.12])
.center([-2, 5])
.tilt(25)
.clipAngle(25);
var graticule = d3.geo.graticule()
.extent([[-93, 27], [-47 + 1e-6, 57 + 1e-6]])
.step([3, 3]);
var path = d3.geo.path()
.projection(projection);
function zoomer() {
projection.translate(d3.event.translate).scale(d3.event.scale);
map.attr("d", path);
graticule.attr("d", path);
}
var zoom = d3.behavior.zoom()
.translate(projection.translate())
.scale(projection.scale())
.on("zoom", zoomer);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height)
.call(zoom);
svg.append("rect")
.attr("class", "background")
.attr("width", width)
.attr("height", height)
.attr("pointer-events", "all")
graticule = svg.append("path")
.datum(graticule)
.attr("class", "graticule")
.attr("d", path);
d3.json("/d/3750900/us-boundary.json", function(error, collection) {
map = svg.append("path")
.datum(collection)
.attr("class", "boundary")
.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