Skip to content

Instantly share code, notes, and snippets.

@robinkraft
Created June 20, 2013 19:23
Show Gist options
  • Save robinkraft/5825794 to your computer and use it in GitHub Desktop.
Save robinkraft/5825794 to your computer and use it in GitHub Desktop.
uk geo
{"description":"uk geo","endpoint":"","display":"svg","public":true,"require":[{"name":"topojson","url":"http://d3js.org/topojson.v0.min.js"},{"name":"d3","url":"http://d3js.org/d3.v3.min.js"}],"fileconfigs":{"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"uk.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"style.css":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"tab":"edit","display_percent":0.5356901472710293,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"editor_editor":{"coffee":false,"vim":false,"emacs":false,"width":600,"height":300,"hide":false},"hidepanel":false,"fullscreen":false}
var width = 960,
height = 591;
var svg = d3.select("svg")
.attr("width", width)
.attr("height", height);
var projection = d3.geo.albers()
.center([0, 55.4])
.rotate([4.4, 0])
.parallels([50, 60])
.scale(624 * 5)
.translate([width / 2, height / 2]);
var path = d3.geo.path()
.projection(projection);
// var wales_only = uk.objects.subunits.geometries =
var uk = tributary.uk;
svg.append("path")
.datum(topojson.object(uk, uk.objects.subunits))
.attr("d", path);
//console.log('geojson', JSON.stringify(topojson.object(uk, uk.objects.subunits)))
svg.selectAll(".subunit")
.data(topojson.object(uk, uk.objects.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");
//console.log(JSON.stringify(topojson.object(uk, uk.objects.places)))
console.log(topojson.object(uk, uk.objects.places).geometries)
svg.append("path")
.datum(topojson.object(uk, uk.objects.places))
.attr("d", path.pointRadius(19))
.attr("class", "place");
svg.selectAll(".place-label")
.data(topojson.object(uk, uk.objects.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 ? 8 : -6; })
.attr("dy", ".35em")
.attr('font-size', 8)
.style("text-anchor", function(d) { return d.coordinates[0] > -1 ? "start" : "end"; })
.text(function(d) { return d.properties.name; });
svg.selectAll(".subunit-label")
.data(topojson.object(uk, uk.objects.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; });
.subunit.SCT { fill: #ddc; }
.subunit.WLS { fill: #cdd; }
.subunit.NIR { fill: #cdc; }
.subunit.ENG { fill: #dcd; }
.subunit.IRL { fill: white; }
//.subunit.IRL { display: none; }
.subunit-boundary {
fill: none;
stroke: #4D53B3
stroke-dasharray: 2,2;
stroke-linejoin: round;
}
.subunit-boundary.IRL {
stroke: #aaa;
}
.place{
fill:#130077
}
.subunit-label {
fill: #770034;
fill-opacity: .5;
font-size: 20px;
font-weight: 300;
text-anchor: middle;
}
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment