Skip to content

Instantly share code, notes, and snippets.

@jsl6906
Last active August 29, 2015 14:05
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 jsl6906/c4e61fa2ed5006b1a290 to your computer and use it in GitHub Desktop.
Save jsl6906/c4e61fa2ed5006b1a290 to your computer and use it in GitHub Desktop.
Orthographic 'arc' using d3.graticule()
<!DOCTYPE html>
<meta charset="utf-8">
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<style>
.land {
fill: #B6C598;
stroke: #818141;
}
.arc {
fill: red;
fill-opacity: 0.3;
stroke: black;
stroke-opacity: 0.5;
}
</style>
<script>
var width = 960,
height = 500,
bb = {W: -5.0, N: 50.0, E: 10.0, S: 40.0 };
var projection = d3.geo.orthographic()
.scale(250)
.translate([width / 2, height / 2])
.clipAngle(90);
var path = d3.geo.path()
.projection(projection);
var arc = d3.geo.graticule()
.majorExtent([[bb.W, bb.S], [bb.E, bb.N]])
var λ = d3.scale.linear()
.domain([0, width])
.range([-180, 180]);
var φ = d3.scale.linear()
.domain([0, height])
.range([90, -90]);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
svg.on("mousemove", function() {
var p = d3.mouse(this);
projection.rotate([λ(p[0]), φ(p[1])]);
svg.selectAll("path.land").attr("d", path);
svg.selectAll("path.arc").attr("d", path(arc.outline()));
});
d3.json("world-110m.json", function(error, world) {
svg.append("path")
.datum(topojson.feature(world, world.objects.land))
.attr("class", "land")
.attr("d", path);
svg.append("path")
.attr("class", "arc")
.attr("d", path(arc.outline()));
});
</script>
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment