This is a simple example of Nuts2json API showing NUTS regions.
Last active
November 10, 2020 20:55
-
-
Save jgaffuri/e7e0a76a6e0f851b253d3b1c8fb17ffb to your computer and use it in GitHub Desktop.
NUTS regions (simple map)
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: EUPL-1.2 | |
height: 600 | |
scrolling: no | |
border: no |
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
<!DOCTYPE html> | |
<svg></svg> | |
<link rel="stylesheet" type="text/css" href="style.css"> | |
<script src="https://d3js.org/d3.v5.min.js"></script> | |
<script src="https://d3js.org/d3-request.v1.min.js"></script> | |
<script src="https://d3js.org/topojson.v3.min.js"></script> | |
<script> | |
d3.json("https://raw.githubusercontent.com/eurostat/Nuts2json/master/pub/v1/2016/3035/20M/3.json", | |
function(error, nuts) { | |
if (error) throw error; | |
//prepare SVG element | |
var width = 700, height = width*(nuts.bbox[3]-nuts.bbox[1])/(nuts.bbox[2]-nuts.bbox[0]), | |
svg = d3.select("svg").attr("width", width).attr("height", height) | |
path = d3.geoPath().projection(d3.geoIdentity() | |
.reflectY(true).fitSize([width,height], topojson.feature(nuts, nuts.objects.gra))); | |
//draw graticule | |
svg.append("g").selectAll("path").data(topojson.feature(nuts, nuts.objects.gra).features) | |
.enter().append("path").attr("d", path).attr("class","graticule"); | |
//draw regions | |
//countries | |
svg.append("g").selectAll("path").data(topojson.feature(nuts, nuts.objects.cntrg).features) | |
.enter().append("path").attr("d", path).attr("class","cntrg"); | |
//nuts | |
svg.append("g").selectAll("path").data(topojson.feature(nuts, nuts.objects.nutsrg).features) | |
.enter().append("path").attr("d", path).attr("class","nutsrg"); | |
//draw boundaries | |
//countries | |
svg.append("g").selectAll("path").data(topojson.feature(nuts, nuts.objects.cntbn).features) | |
.enter().append("path").attr("d", path) | |
.attr("class",function(bn) { return "cntbn" + (bn.properties.co==="T"?" coastal":""); }); | |
//nuts | |
svg.append("g").selectAll("path").data(topojson.feature(nuts, nuts.objects.nutsbn).features) | |
.enter().append("path").attr("d", path) | |
.attr("class",function(bn) { | |
return "nutsbn" + (bn.properties.co==="T"?" coastal":"") | |
+ ((bn.properties.oth==="T" || bn.properties.lvl==0)?" white":"") | |
+ (bn.properties.lvl==3?" thin":""); | |
}); | |
}); | |
</script> |
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
.graticule { | |
fill: none; | |
stroke-width: 2px; | |
stroke: lightgray; | |
} | |
.cntrg { | |
fill: lightgray; | |
} | |
.cntrg:hover { | |
fill: darkgray; | |
} | |
.nutsrg { | |
fill: #fdbf6f; | |
} | |
.nutsrg:hover { | |
fill: #ff7f00; | |
} | |
.cntbn { | |
fill: none; | |
stroke-width: 1px; | |
stroke: white; | |
} | |
.nutsbn { | |
fill: none; | |
stroke-width: 1px; | |
stroke: #333; | |
} | |
.white { stroke: white; } | |
.thin { stroke-width: 0.5px; } | |
.coastal { stroke: #1f78b4; } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment