This map demonstrates the TopoJSON us-atlas. The same TopoJSON file can also be used to show states.
forked from mbostock's block: COTE D'IVOIRE
license: gpl-3.0 | |
height: 600 | |
border: no |
<!DOCTYPE html> | |
<style> | |
.districts :hover { | |
fill: red; | |
} | |
.districts-borders { | |
fill: none; | |
stroke: #fff; | |
stroke-width: 1px; | |
stroke-linejoin: round; | |
stroke-linecap: round; | |
pointer-events: none; | |
} | |
.sousprefecture :hover { | |
fill: yellow; | |
} | |
.sousprefectures-borders { | |
fill: none; | |
stroke: #fff; | |
stroke-width: 0.5px; | |
stroke-linejoin: round; | |
stroke-linecap: round; | |
pointer-events: none; | |
} | |
</style> | |
<svg width="960" height="600"></svg> | |
<script src="https://d3js.org/d3.v4.min.js"></script> | |
<script src="https://d3js.org/topojson.v2.min.js"></script> | |
<script> | |
var width = 1000, | |
height = 800; | |
var svg = d3.select("svg"); | |
var projection = d3.geoMercator() | |
.scale(2000) | |
.translate([width / 2, height / 2]); | |
var path = d3.geoPath().projection(projection); | |
d3.json("gadm36_CIV.json", function(error, civ) { | |
if (error) throw error; | |
svg.append("g") | |
.attr("class", "districts") | |
.selectAll("path") | |
.data(topojson.feature(civ, civ.objects.DISTRICT).features) | |
.enter().append("path") | |
.attr("d", path); | |
svg.append("path") | |
.attr("class", "districts-borders") | |
.attr("d", path(topojson.mesh(civ, civ.objects.REGION, function(a, b) { return a !== b; }))); | |
svg.append("path") | |
.attr("class", "districts-borders") | |
.attr("d", path(topojson.mesh(civ, civ.objects.DEPARTEMENT, function(a,b) {return a !==b;}))); | |
svg.append("path") | |
.attr("class", "sousprefectures-borders") | |
.attr("d", path(topojson.mesh(civ,civ.objects.SOUS_PREFECTURE, function(a,b) {return a !== b;}))) | |
}); | |
</script> |