Created
November 13, 2015 12:46
-
-
Save tts/de5c270a6d802e828d2a to your computer and use it in GitHub Desktop.
Mercator projection map of Finland
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> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>Mercator projection map of Finland</title> | |
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script> | |
<style type="text/css"> | |
body { | |
background-color: whitesmoke; | |
font-family: Helvetica, Arial, sans-serif; | |
margin: 0; | |
} | |
#container { | |
width: 700px; | |
margin-left: auto; | |
margin-right: auto; | |
margin-top: 50px; | |
padding: 50px; | |
background-color: white; | |
box-shadow: 6px 6px 6px 12px #ccc; | |
} | |
h1 { | |
font-size: 20px; | |
margin: 0; | |
} | |
svg { | |
background-color: white; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="container"> | |
<h1>Finland</h1> | |
</div> | |
<script type="text/javascript"> | |
//Width and height | |
var w = 700; | |
var h = 800; | |
var padding = [ 20, 10, 50, 100 ]; | |
//Define map projection | |
var projection = d3.geo.mercator() | |
.center([ 27, 65 ]) | |
.translate([ w/2, h/2 ]) | |
.scale( [w * 2] ); | |
//Define path generator | |
var path = d3.geo.path() | |
.projection(projection); | |
//Create SVG | |
var svg = d3.select("#container") | |
.append("svg") | |
.attr("width", w) | |
.attr("height", h); | |
//Load in GeoJSON data | |
d3.json("finland.geojson", function(json) { | |
//Bind data and create one path per GeoJSON feature | |
svg.selectAll("path") | |
.data(json.features) | |
.enter() | |
.append("path") | |
.attr("d", path) | |
.attr("fill", "white") | |
.attr("stroke", "black") | |
.attr("stroke-width", .75 ); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment