Skip to content

Instantly share code, notes, and snippets.

@da1fujimoto
Last active December 12, 2019 01:32
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 da1fujimoto/abeff3fd50ba3ce4eee5dfadeb889f6b to your computer and use it in GitHub Desktop.
Save da1fujimoto/abeff3fd50ba3ce4eee5dfadeb889f6b to your computer and use it in GitHub Desktop.
topojson Map v5
license: mit
<!--
Adapted from Mike Bostock at bl.ocks.org
https://bl.ocks.org/mbostock/3734333
-->
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<meta name="description" content="">
<title>8.2 - Visualization around the globe</title>
<!-- Custom CSS -->
<link rel="stylesheet" href="style.css">
</head>
<body>
<nav class="navbar navbar-default"></nav>
<script src="https://d3js.org/d3.v5.min.js"></script>
<script src="https://d3js.org/topojson.v2.min.js"></script>
<script>
var width = 600,
height = 400;
var projection = d3.geoNaturalEarth1()
.scale(153)
.translate([width / 2, height / 2])
.precision(.1);
var path = d3.geoPath()
.projection(projection);
var graticule = d3.geoGraticule();
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
d3.json("world-110m.json").then(world => {
console.log(world)
console.log(topojson.feature(world, world.objects.land));
console.log(graticule)
svg.append("path")
.datum(topojson.feature(world, world.objects.land))
.attr("class", "land")
.attr("d", path);
svg.append("path")
.datum(topojson.mesh(world, world.objects.countries, (a, b) => a !== b))
.attr("class", "boundary")
.attr("d", path);
svg.append("path")
.datum(graticule)
.attr("class", "graticule")
.attr("d", path);
});
d3.select(self.frameElement).style("height", height + "px");
</script>
</body>
svg {
margin-left: auto;
margin-right: auto;
display: block;
}
.graticule {
fill: none;
stroke: #777;
stroke-width: .5px;
stroke-opacity: .5;
}
.land {
fill: #999;
}
.boundary {
fill: none;
stroke: #fff;
stroke-width: .5px;
}
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