Skip to content

Instantly share code, notes, and snippets.

@kirkbackus
Last active August 29, 2015 14:11
Show Gist options
  • Save kirkbackus/b7ee4a896808a9420aac to your computer and use it in GitHub Desktop.
Save kirkbackus/b7ee4a896808a9420aac to your computer and use it in GitHub Desktop.
Orthographic Projection with Blip
<!DOCTYPE html>
<meta charset="utf-8">
<style>
body {
background: #fcfcfa;
}
.stroke {
fill: none;
stroke: #000;
stroke-width: 3px;
}
.fill {
fill: #fff;
}
.graticule {
fill: none;
stroke: #777;
stroke-width: .5px;
stroke-opacity: .5;
}
.land {
fill: #222;
}
.boundary {
fill: none;
stroke: #fff;
stroke-width: .5px;
}
</style>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script>
var width = 960,
height = 320;
var projection = d3.geo.orthographic()
.scale(320)
.translate([width / 2, height / 2])
.clipAngle(90)
.rotate([100, -35, 0])
.precision(.1);
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);
svg.append("defs").append("path")
.datum({type: "Sphere"})
.attr("id", "sphere")
.attr("d", path);
svg.append("use")
.attr("class", "stroke")
.attr("xlink:href", "#sphere");
svg.append("use")
.attr("class", "fill")
.attr("xlink:href", "#sphere");
svg.append("path")
.datum(graticule)
.attr("class", "graticule")
.attr("d", path);
d3.json("world-50m.json", function(error, world) {
svg.insert("path", ".graticule")
.datum(topojson.feature(world, world.objects.land))
.attr("class", "land")
.attr("d", path);
svg.insert("path", ".graticule")
.datum(topojson.mesh(world, world.objects.countries, function(a, b) { return a !== b; }))
.attr("class", "boundary")
.attr("d", path);
});
(function() {
var lng = -92.33 + (Math.random() - 0.5) * 25;
var lat = 38.95 + (Math.random() - 0.5) * 10;
var coord = projection([lng, lat]);
svg.append('svg:circle')
.attr('cx', coord[0]).attr('cy', coord[1])
.attr('r', 1)
.attr('stroke', '#FF0000')
.attr('stroke-width', 2)
.attr('stroke-opacity', 1)
.attr('fill-opacity', 0)
.transition().duration(2000).ease('in-out')
.attr('r', 5)
.attr('stroke-opacity', 0)
.remove();
setTimeout(arguments.callee, Math.floor((Math.random() * 500) + 1000));
})();
d3.select(self.frameElement).style("height", height + "px");
</script>
Display the source blob
Display the rendered blob
Raw
Loading
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