Reproducing the UK map and uk.json topojson data by Mike Bostock (http://bost.ocks.org/mike/map/). Currently the uk.json file does not contain place information - there must be something wrong with the way I am producing the uk.json here: https://github.com/samuelleach/uk-atlas
Last active
December 20, 2018 09:31
-
-
Save samuelleach/5130413 to your computer and use it in GitHub Desktop.
UK 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
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<style> | |
.subunit.SCT { fill: #ddc; } | |
.subunit.WLS { fill: #cdd; } | |
.subunit.NIR { fill: #cdc; } | |
.subunit.ENG { fill: #dcd; } | |
.subunit.IRL, | |
.subunit-label.IRL { | |
display: none; | |
} | |
.subunit-boundary { | |
fill: none; | |
stroke: #777; | |
stroke-dasharray: 2,2; | |
stroke-linejoin: round; | |
} | |
.subunit-boundary.IRL { | |
stroke: #aaa; | |
} | |
.subunit-label { | |
fill: #777; | |
fill-opacity: .5; | |
font-size: 20px; | |
font-weight: 300; | |
text-anchor: middle; | |
} | |
.place, | |
.place-label { | |
fill: #444; | |
} | |
text { | |
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; | |
font-size: 10px; | |
pointer-events: none; | |
} | |
</style> | |
<body> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<script src="http://d3js.org/topojson.v0.min.js"></script> | |
<script> | |
var width = 960, | |
height = 1160; | |
var projection = d3.geo.albers() | |
.center([0, 55.4]) | |
.rotate([4.4, 0]) | |
.parallels([50, 60]) | |
.scale(1200 * 5) | |
.translate([width / 2, height / 2]); | |
var path = d3.geo.path() | |
.projection(projection) | |
.pointRadius(2); | |
var svg = d3.select("body").append("svg") | |
.attr("width", width) | |
.attr("height", height); | |
d3.json("uk.json", function(error, uk) { | |
var subunits = topojson.object(uk, uk.objects.subunits), | |
places = topojson.object(uk, uk.objects.places); | |
svg.selectAll(".subunit") | |
.data(subunits.geometries) | |
.enter().append("path") | |
.attr("class", function(d) { return "subunit " + d.id; }) | |
.attr("d", path); | |
svg.append("path") | |
.datum(topojson.mesh(uk, uk.objects.subunits, function(a, b) { return a !== b && a.id !== "IRL"; })) | |
.attr("d", path) | |
.attr("class", "subunit-boundary"); | |
svg.append("path") | |
.datum(topojson.mesh(uk, uk.objects.subunits, function(a, b) { return a === b && a.id === "IRL"; })) | |
.attr("d", path) | |
.attr("class", "subunit-boundary IRL"); | |
svg.selectAll(".subunit-label") | |
.data(subunits.geometries) | |
.enter().append("text") | |
.attr("class", function(d) { return "subunit-label " + d.id; }) | |
.attr("transform", function(d) { return "translate(" + path.centroid(d) + ")"; }) | |
.attr("dy", ".35em") | |
.text(function(d) { return d.properties.name; }); | |
svg.append("path") | |
.datum(places) | |
.attr("d", path) | |
.attr("class", "place"); | |
svg.selectAll(".place-label") | |
.data(places.geometries) | |
.enter().append("text") | |
.attr("class", "place-label") | |
.attr("transform", function(d) { return "translate(" + projection(d.coordinates) + ")"; }) | |
.attr("x", function(d) { return d.coordinates[0] > -1 ? 6 : -6; }) | |
.attr("dy", ".35em") | |
.style("text-anchor", function(d) { return d.coordinates[0] > -1 ? "start" : "end"; }) | |
.text(function(d) { return d.properties.name; }); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment