Skip to content

Instantly share code, notes, and snippets.

@thayashi
Created June 26, 2016 23:46
Show Gist options
  • Save thayashi/85206f581fd4cf4047903dcef68847d6 to your computer and use it in GitHub Desktop.
Save thayashi/85206f581fd4cf4047903dcef68847d6 to your computer and use it in GitHub Desktop.
Orthographic Clipping 2
license: gpl-3.0

The above grid demonstrates an orthographic azimuthal projection. The lines are at uniform 10º increments of latitude and longitude.

Part 2 of 3.

  1. Orthographic Grid
  2. Orthographic Clipping
  3. Orthographic Shading

To see this technique applied to real geographic features, see the Spinny Globe example.

forked from mbostock's block: Orthographic Clipping

forked from thayashi's block: Orthographic Clipping

forked from thayashi's block: Orthographic Clipping 2

forked from thayashi's block: Orthographic Clipping 2

<!DOCTYPE html>
<meta charset="utf-8">
<style>
circle,
path {
fill: none;
stroke: #666;
}
circle {
stroke-width: 2px;
}
.land {
fill: #f33;
opacity: 0.8;
}
</style>
<body>
<script src="//d3js.org/d3.v3.min.js"></script>
<script>
var width = 960,
height = 500;
var rotate = [-71.03, 702.37],
velocity = [.018, .006];
var projection = d3.geo.orthographic()
.scale(240)
.clipAngle(90);
var path = d3.geo.path()
.projection(projection);
var graticule = d3.geo.graticule();
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
var feature = svg.append("path")
.datum(graticule);
svg.append("circle")
.attr("cx", width / 2)
.attr("cy", height / 2)
.attr("r", 240);
var url = "http://enjalot.github.io/wwsd/data/world/world-110m.geojson";
d3.json(url, function(err, geojson) {
var _geojson = geojson;
var _map = svg.append("path")
.attr("d", path(geojson));
d3.timer(function(elapsed) {
projection.rotate([rotate[0] + elapsed * velocity[0], rotate[1] + elapsed * velocity[1]]);
feature.attr("d", path);
_map.attr("d", path(_geojson))
.attr("class", "land");
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment