This is a simple map of Sweden, created with D3.js and TopoJSON. The municipality polygons have been replaced by circles.
Last active
August 29, 2015 14:02
-
-
Save miroli/4280679f81d0006e3142 to your computer and use it in GitHub Desktop.
Simple Circle Map of Sweden
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"> | |
<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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment