D3 Map that is responsive to screen size on load
xxxxxxxxxx
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.js"></script>
<!--<script src="https://d3js.org/topojson.v2.min.js"></script>-->
<script src="https://unpkg.com/topojson-client@3"></script>
<style>
body { margin:10px;position:fixed;top:0;right:0;bottom:0;left:0; }
#map { border:1px solid #000; }
</style>
</head>
<body>
<div id="map"></div>
<script>
var map = d3.select("#map");
var width = map.node().getBoundingClientRect().width;
var height = width / 2;
var svg = map.append("svg")
.attr("width", width)
.attr("height", height);
var projection = d3.geoMercator();
var path = d3.geoPath().projection(projection);
d3.json("https://unpkg.com/world-atlas@1/world/110m.json", function(error, world) {
if (error) throw error;
svg.selectAll("path")
.data(topojson.feature(world, world.objects.countries).features)
.enter().append("path")
.attr("d", path);
});
</script>
</body>
https://d3js.org/d3.v4.js
https://d3js.org/topojson.v2.min.js
https://unpkg.com/topojson-client@3