Skip to content

Instantly share code, notes, and snippets.

@crofty
Created November 15, 2011 10:29
Show Gist options
  • Save crofty/1366698 to your computer and use it in GitHub Desktop.
Save crofty/1366698 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>UK Map</title>
<script type="text/javascript" src="http://d3js.org/d3.v3.min.js"></script>
<style type="text/css">
svg {
width: 500px;
height: 500px;
border: solid 1px #ccc;
background: #eee;
}
path {
fill: steelblue;
stroke: steelblue;
}
</style>
</head>
<body>
<script type="text/javascript" src="./uk-map.js"></script>
</body>
</html>
states = d3.select('body')
.append('svg:svg')
.append("svg:g")
.attr("id", "states")
svg = d3.select('svg')
width = parseInt svg.style('width'), 10
height = parseInt svg.style('height'), 10
projection = d3.geo.mercator()
.center([-2, 54])
.scale(1100)
.translate([width / 2, height / 2])
console.log projection.scale()
path = d3.geo.path()
.projection(projection)
d3.json "uk.json", (collection) ->
console.log(collection.features)
states
.selectAll("path")
.data(collection.features)
.enter().append("svg:path")
.attr("d", path)
.append("svg:title")
.text((d) -> d.properties.name )
(function() {
var height, path, projection, states, svg, width;
states = d3.select('body').append('svg:svg').append("svg:g").attr("id", "states");
svg = d3.select('svg');
width = parseInt(svg.style('width'), 10);
height = parseInt(svg.style('height'), 10);
projection = d3.geo.mercator().center([-2, 54]).scale(1100).translate([width / 2, height / 2]);
console.log(projection.scale());
path = d3.geo.path().projection(projection);
d3.json("uk.json", function(collection) {
console.log(collection.features);
return states.selectAll("path").data(collection.features).enter().append("svg:path").attr("d", path).append("svg:title").text(function(d) {
return d.properties.name;
});
});
}).call(this);
Display the source blob
Display the rendered blob
Raw
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