Instantly share code, notes, and snippets.

@mbostock mbostock/.block forked from mbostock/.block
Last active Feb 9, 2016

What would you like to do?
Resampling Comparison
license: gpl-3.0

A comparison of the Larrivée projection, with and without D3’s adaptive resampling. Note the polygonal artifacts in Antarctica that are fixed with resampling.

<!DOCTYPE html>
<meta charset="utf-8">
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;
<script src="//"></script>
<script src="//"></script>
<script src="//"></script>
var width = 960,
height = 420;
var projection = d3.geo.larrivee()
.translate([0, 0])
var position = d3.scale.ordinal()
.domain([0, .1])
.rangePoints([0, width], 1.02);
var path = d3.geo.path()
var graticule = d3.geo.graticule();
var svg ="body").append("svg")
.attr("width", width)
.attr("height", height);
var g = svg.selectAll("g")
.attr("transform", function(d) { return "translate(" + position(d) + "," + height / 2 + ")"; });
.datum({type: "Sphere"})
.attr("id", "sphere")
.attr("d", path);
.attr("class", "stroke")
.attr("xlink:href", "#sphere");
.attr("class", "fill")
.attr("xlink:href", "#sphere");
.attr("class", "graticule")
.attr("d", path);
d3.json("/mbostock/raw/4090846/world-110m.json", function(error, world) {
if (error) throw error;
g.insert("path", ".graticule")
.attr("class", "land");
g.insert("path", ".graticule")
.datum(topojson.mesh(world, world.objects.countries, function(a, b) { return a !== b; }))
.attr("class", "boundary");
g.each(function(d) {
projection.precision(d);".land,.boundary").attr("d", path);
});"height", height + "px");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment