block by mbostock 4522565

Two Point Equidistant

Full Screen

This is still a work in progress; elliptical clipping is needed to avoid visible artifacts outside of 145° in this example.

index.html

<!DOCTYPE html>
<meta charset="utf-8">
<style>

.background {
  fill: #ff0;
  fill-opacity: .1;
}

.foreground {
  fill: none;
  stroke: #333;
  stroke-width: 1.5px;
}

.graticule {
  fill: none;
  stroke: #f00;
  stroke-width: .5px;
}

.land {
  fill: cyan;
  fill-opacity: .5;
}

</style>
<body>
<script src="//d3js.org/d3.v3.min.js"></script>
<script src="//d3js.org/d3.geo.projection.v0.min.js"></script>
<script src="//d3js.org/topojson.v1.min.js"></script>
<script>

var width = 960,
    height = 652;

var a = [-158, 21.5], // Honolulu, HI
    b = [-77, 39]; // Washington, DC

var projection = d3.geo.twoPointEquidistant()
    .points([a, b])
    .scale(132.5)
    .translate([width / 2, height / 2])
    .clipAngle(145) // TODO clip to ellipse
    .precision(.1);

var path = d3.geo.path()
    .projection(projection);

var graticule = d3.geo.graticule()
    .minorStep([15, 15])
    .minorExtent([[-180, -75], [180, 75 + 1e-4]]);

var svg = d3.select("body").append("svg")
    .attr("width", width)
    .attr("height", height);

svg.append("image")
    .attr("xlink:href", "two-point-equidistant.png")
    .attr("transform", "rotate(1.2 " + width / 2 + "," + height / 2 + ")")
    .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", "background")
    .attr("xlink:href", "#sphere");

svg.append("path")
    .datum(graticule)
    .attr("class", "graticule")
    .attr("d", path);

d3.json("/mbostock/raw/4090846/world-50m.json", function(error, world) {
  if (error) throw error;

  svg.insert("path", ".graticule")
      .datum(topojson.feature(world, world.objects.land))
      .attr("class", "land")
      .attr("d", path);
});

d3.select(self.frameElement).style("height", height + "px");

</script>