Back in the day, I managed a website named covid19news.org that is no longer active. During my time there, I worked on something quite similar to what you see below.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
#map { position: relative; min-height: 500px;
width: 800px;
height: 770px;
background-color: white;
}
.district, .disputed, .state rect, .state path { stroke: #a9a9a9; stroke-width: 1px; }
.district:hover { stroke: #777777; stroke-width: 1px; fill-opacity: .7; }
.state:hover rect { stroke: #777777; stroke-width: 2px; fill-opacity: .7; }
.state:hover path { fill-opacity: .7; }
#select {
position:absolute;
left: 500px;
top: 100px;
font: 12px sans-serif;
color: #333;
}
#tooltip h3 {
margin:2px;
font-size:14px;
}
#tooltip h4 {
margin:2px;
font-size:10px;
}
#tooltip {
position: absolute;
background:rgba(0,0,0,0.8);
text-align: left;
border:1px;
border-radius:5px;
font: 12px sans-serif;
width:auto;
padding:4px;
color:white;
opacity:0;
pointer-events: none;
}
#tooltip table{
table-layout:fixed;
}
#tooltip tr td{
padding:2px;
margin:0;
}
</style>
</head>
<body>
<div id="map">
</div>
<script src="./topo/d3.v3.min.js" charset="utf-8"></script>
<script src="./topo/d3-queue.v3.min.js"></script>
<script src="./topo/topojson.v1.min.js"></script>
<script>
function districtMap(districts, disputed) {
var width = 800, height = 700, scale = 1200;
var propTag = 'zone', ttName = 'Zone', unit = '';
var extraTop = 0, extraLeft = 0;
function render(selection) {
selection.each(function() {
d3.select(this).select("svg").remove();
var svg = d3.select(this).append("svg")
.attr("width", width)
.attr("height", height);
d3.select(this).select("#tooltip").remove();
d3.select(this).append("div").attr("id", "tooltip").style("opacity", 1);
var projection = d3.geo.mercator()
.center([83, 23])
.scale(scale)
.translate([width / 2, height / 2]);
var path = d3.geo.path().projection(projection);
svg.selectAll(".district")
.data(districts.features)
.enter().append("path")
.attr("class", "district")
.style("fill", function(d) { return 'd.properties.zone.toLowerCase();' })
.attr("d", path)
.on("mouseover", function(d) {
d3.select("#tooltip").transition()
.duration(200)
.style("opacity", .9);
d3.select("#tooltip").html("<h3>"+(d.id)+"</h3><h4>("+(d.properties.NAME_1)+")</h4><table>"+
"<tr><td>"+ttName+"::</td><td>"+(d.properties[propTag])+"</td></tr>"+
"</table>")
.style("left", (d3.event.pageX-document.getElementById('map').offsetLeft - extraLeft) + "px")
.style("top", (d3.event.pageY-document.getElementById('map').offsetTop - 160 - extraTop) + "px");
})
.on("mouseout", function(d) {
d3.select("#tooltip").transition()
.duration(500)
.style("opacity", 1);
});
svg.selectAll(".disputed")
.data(disputed.features)
.enter().append("path")
.attr("class", "disputed")
.style("fill", function(d) { return d.color; })
.attr("d", path);
});
} // render
render.height = function(value) {
if (!arguments.length) return height;
height = value;
return render;
};
render.width = function(value) {
if (!arguments.length) return width;
width = value;
return render;
};
render.scale = function(value) {
if (!arguments.length) return scale;
scale = value;
return render;
};
render.propTag = function(value) {
if (!arguments.length) return propTag;
propTag = value;
return render;
};
render.ttName = function(value) {
if (!arguments.length) return ttName;
ttName = value;
return render;
};
render.unit = function(value) {
if (!arguments.length) return unit;
unit = value;
return render;
};
return render;
} // districtMap
(function() {
d3.queue()
.defer(d3.json, "./topo/zone-data.json")
.defer(d3.json, "./topo/Kashmir.json")
.await(function(error, topoMain, topoKashmir) {
var districts, disputed;
if (error) throw error;
districts = topojson.feature(topoMain, topoMain.objects.IND_adm2);
disputed = topojson.feature(topoKashmir, topoKashmir.objects.ne_10m_admin_0_Kashmir_Occupied);
colorDisputed(disputed.features);
// Map render
var map = districtMap(districts, disputed).width(800).height(700).scale(1200); //.propTag(filter);
d3.select("#map").call(map);
});
}());
function colorDisputed(data) {
var color = "#eaeafa";
data.forEach(function(d) {
d.color = color;
});
}
</script>
</body>
</html>
If you want to explore the full functioning code, check it out here: stackblitz