An interactive world map displaying country names on hoover, based on maptimeLEX .
xxxxxxxxxx
<html>
<head>
<meta charset="utf-8">
<title>A D3 map using topojson</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.10.0/d3.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3-queue/3.0.7/d3-queue.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/topojson/3.0.0/topojson.min.js"></script>
<link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet" type="text/css">
<style>
body {
padding: 0;
margin: 0;
background: whitesmoke;
}
h1 {
position: absolute;
left: 20px;
top: 10px;
font-family: "Proxima Nova", Montserrat, sans-serif;
font-size: 2em;
font-weight: 100;
color: #005DAA; /* offical UK Kentucky blue */
}
.country {
stroke: #fff;
fill:#005DAA;
}
</style>
</head>
<body>
<h1>World Countries</h1>
<script>
var width = 900,
height = 600;
var svg = d3.select( "body" )
.append( "svg" )
.attr( "width", width )
.attr( "height", height );
var projection = d3.geoEquirectangular()
.scale(170)
.translate([width / 2, height / 2]);
var geoPath = d3.geoPath()
.projection(projection);
d3.queue()
.defer(d3.json, "world-topo.json")
.await(ready);
function ready(error, countries){
svg.append("g")
.selectAll("path")
.data( topojson.feature(countries, countries.objects.countries).features)
.enter()
.append("path")
.attr( "d", geoPath )
.attr("class","country");
}
</script>
</body>
</html>
https://cdnjs.cloudflare.com/ajax/libs/d3/4.10.0/d3.min.js
https://cdnjs.cloudflare.com/ajax/libs/d3-queue/3.0.7/d3-queue.min.js
https://cdnjs.cloudflare.com/ajax/libs/topojson/3.0.0/topojson.min.js