modified from http://bl.ocks.org/mbostock/3795040 response to this stack overflow question
Last active
August 29, 2015 14:05
-
-
Save jsl6906/c4e61fa2ed5006b1a290 to your computer and use it in GitHub Desktop.
Orthographic 'arc' using d3.graticule()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment