Skip to content

Instantly share code, notes, and snippets.

@swingley
Created November 13, 2015 04:02
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 swingley/35ad076bbe1b5d6bdff5 to your computer and use it in GitHub Desktop.
Save swingley/35ad076bbe1b5d6bdff5 to your computer and use it in GitHub Desktop.
"Satellite" d3 projection focused on California
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.graticule {
fill: none;
stroke: #777;
}
.boundary {
fill: #ccc;
fill-opacity: .8;
stroke: #000;
}
</style>
<body>
<script src="//d3js.org/d3.v3.min.js"></script>
<script src="//d3js.org/d3.geo.projection.v0.min.js"></script>
<script>
var width = 960,
height = 500;
var projection = d3.geo.satellite()
.distance(1.1)
.scale(4200)
.rotate([115, -30.5, -20])
.center([0, 85])
.tilt(10)
.clipAngle(Math.acos(1 / 1.1) * 180 / Math.PI - 1e-6)
.precision(.1);
var graticule = d3.geo.graticule()
.extent([[-160, 27], [-47 + 1e-6, 57 + 1e-6]])
.step([3, 3]);
var path = 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("california_50m.geojson", function(error, json) {
if (error) throw error;
svg.append("g").selectAll("path")
.data(json.features)
.enter()
.append("path")
.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