Skip to content

Instantly share code, notes, and snippets.

@piwodlaiwo
Created October 13, 2018 16:28
Show Gist options
  • Save piwodlaiwo/9f23abd977381b77e9cb86b1888769fc to your computer and use it in GitHub Desktop.
Save piwodlaiwo/9f23abd977381b77e9cb86b1888769fc to your computer and use it in GitHub Desktop.
Quartic Authalic with D3v4
license: mit
<!DOCTYPE html>
<meta charset="utf-8">
<style>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
svg { width:100%; height: 100% }
.stroke {
fill: none;
stroke: #000;
stroke-width: 2px;
}
.graticule {
fill: none;
stroke: #777;
stroke-width: .5px;
stroke-opacity: .5;
}
.land {
fill: #222;
stroke: #fff;
stroke-width: 0.5px;
}
</style>
<body>
<script src="https://unpkg.com/d3@4"></script>
<script src="https://unpkg.com/d3-geo-projection@2"></script>
<script src="https://unpkg.com/topojson-client@3"></script>
<script>
var width = 900;
var height = 500;
var svg = d3.select("body").append("svg");
//Quartic Authalic: https://bl.ocks.org/mbostock/4463175
var projection = d3.geoHammer()
.coefficient(Infinity)
.scale(150)
.translate([width / 2, height / 2])
.precision(.1);
var path = d3.geoPath().projection(projection);
var graticule = d3.geoGraticule();
var defs = svg.append("defs");
defs.append("path")
.datum({type: "Sphere"})
.attr("id", "sphere")
.attr("d", path);
svg.append("use")
.attr("class", "stroke")
.attr("xlink:href", "#sphere");
/*
defs.append("clipPath")
.attr("id", "clip")
.append("use")
.attr("xlink:href", "#sphere");
svg.append("use")
.attr("class", "fill")
.attr("xlink:href", "#sphere");
svg.append("path")
.datum(graticule)
.attr("class", "graticule")
.attr("clip-path", "url(#clip)")
.attr("d", path);
*/
svg.append("path")
.datum(graticule)
.attr("class", "graticule")
.attr("d", path);
d3.json("https://unpkg.com/world-atlas@1/world/50m.json", function(error, world) {
if (error) throw error;
svg.selectAll("path")
.data(topojson.feature(world, world.objects.countries).features)
.enter().append("path")
.attr("class", "land")
.attr("d", path);
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment