Skip to content

Instantly share code, notes, and snippets.

@miroli
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miroli/4280679f81d0006e3142 to your computer and use it in GitHub Desktop.
Save miroli/4280679f81d0006e3142 to your computer and use it in GitHub Desktop.
Simple Circle Map of Sweden

This is a simple map of Sweden, created with D3.js and TopoJSON. The municipality polygons have been replaced by circles.

<!DOCTYPE html>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no">
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<style>
* {
margin: 0;
padding: 0;
}
svg, body {
background-color: steelblue;
}
svg {
width: 360px;
height: 600px;
margin: 0 auto;
}
circle {
fill: yellowgreen;
stroke: olivedrab;
}
</style>
<body>
<div id="container"></div>
<script>
var width = 360,
height = 600;
var projection = d3.geo.mercator().scale(1000).translate([-160,1700]);
var path = d3.geo.path().projection(projection);
var svg = d3.select("#container").append("svg");
d3.json("kommun.json", function(error, data) {
svg.selectAll("circle")
.data(topojson.feature(data, data.objects.kommuner).features)
.enter().append("circle")
.attr("transform", function(d) { return "translate(" + path.centroid(d) + ")"; })
.attr("r", function(d) { return Math.sqrt(d.properties.LANDAREAKM) / 5; });
});
</script>
</body>
</html>
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