Built with blockbuilder.org
Last active
December 12, 2019 01:32
-
-
Save da1fujimoto/abeff3fd50ba3ce4eee5dfadeb889f6b to your computer and use it in GitHub Desktop.
topojson Map v5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
license: mit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment