Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@fogonwater
Last active November 30, 2017 19:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fogonwater/686102511117b84cfbed to your computer and use it in GitHub Desktop.
Save fogonwater/686102511117b84cfbed to your computer and use it in GitHub Desktop.
glitch map

Glitchy D3.js map of the world. This combination of clipAngle with geo.mercator() sends things particularly crazy.

<!DOCTYPE html>
<meta charset="utf-8">
<style>
body {
background: #fcfcfa;
}
.graticule {
fill: none;
stroke: #777;
stroke-width: .5px;
stroke-opacity: .5;
}
.land {
fill: #222;
}
.boundary {
fill: none;
stroke: #fcfcfa;
stroke-width: .3px;
}
</style>
<div id="chart"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/topojson/1.6.19/topojson.min.js"></script>
<script>
var width = 960,
height = 500,
map_center = [0, 90];
var projection = d3.geo.mercator()
.clipAngle(180 - 1e-3)
.scale(150)
.translate([width / 2, height / 2])
.rotate(map_center)
.precision(.1);
var path = d3.geo.path()
.projection(projection);
var graticule = d3.geo.graticule()
.step([0, 10]);;
var svg = d3.select("#chart").append("svg")
.attr("width", width)
.attr("height", height);
d3.json("world-50m.json", function(error, world) {
svg.append("path", ".graticule")
.datum(topojson.feature(world, world.objects.land))
.attr("class", "land")
.attr("d", path);
svg.append("path", ".graticule")
.datum(topojson.mesh(
world, world.objects.countries, function(a, b) { return a !== b; }
))
.attr("class", "boundary")
.attr("d", path);
svg.append("path")
.datum(graticule)
.attr("class", "graticule")
.attr("d", path);
});
</script>
Display the source blob
Display the rendered blob
Raw
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