Skip to content

Instantly share code, notes, and snippets.

@jbwhit
Last active December 28, 2015 07:38
Show Gist options
  • Select an option

  • Save jbwhit/7465303 to your computer and use it in GitHub Desktop.

Select an option

Save jbwhit/7465303 to your computer and use it in GitHub Desktop.
<!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: #bbb;
}
.boundary {
fill: none;
stroke: #fff;
stroke-width: .5px;
}
.points circle {
fill: #fff;
stroke: red;
stroke-width: 2px;
}
.points text {
font: 11px sans-serif;
text-anchor: middle;
text-shadow: 0 1px 0 #fff, 0 -1px 0 #fff, 1px 0 0 #fff, -1px 0 0 #fff;
}
.route {
fill: none;
stroke: red;
stroke-width: 3px;
}
</style>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/d3.geo.projection.v0.min.js"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script>
var width = 960,
height = 570;
var places = {
MEL: [+144.8433, -37.6733],
LAX: [-118.4081, +33.9425],
DFW: [-97.0381, +32.8969],
IAD: [-77.4558, +38.9444],
DFW: [-97.0381, +32.8969],
SAN: [-117.1625, +32.7150],
LAX: [-118.4081, +33.9425],
MEL: [+144.8433, -37.6733]
};
var route = {
type: "LineString",
coordinates: [
places.MEL,
places.LAX,
places.DFW,
places.IAD,
places.DFW,
places.SAN,
places.LAX,
places.MEL
]
};
var projection = d3.geo.kavrayskiy7()
.scale(170)
.rotate([-40, 0])
.translate([width / 2, height / 2])
.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);
svg.append("path")
.datum(route)
.attr("class", "route")
.attr("d", path);
var point = svg.append("g")
.attr("class", "points")
.selectAll("g")
.data(d3.entries(places))
.enter().append("g")
.attr("transform", function(d) { return "translate(" + projection(d.value) + ")"; });
point.append("circle")
.attr("r", 4.5);
point.append("text")
.attr("y", 10)
.attr("dy", ".71em")
.text(function(d) { return d.key; });
d3.json("/mbostock/raw/4090846/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);
});
d3.select(self.frameElement).style("height", height + "px");
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment