Created
December 2, 2015 20:59
-
-
Save pfloh/ae03cdabca0c822d5283 to your computer and use it in GitHub Desktop.
Berlin as geojson map
This file contains hidden or 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>Berlin (City state area)</title> | |
<script type="text/javascript" src="//d3js.org/d3.v3.min.js"></script> | |
<style type="text/css"> | |
body { | |
margin: 0; | |
background-color: grey; | |
font-family: Helvetica, Arial, sans-serif; | |
} | |
#container { | |
width: 600px; | |
margin-left: 248px; | |
margin-right: auto; | |
margin-top: 10px; | |
margin-bottom: -1px; | |
padding: 50px; | |
background-color: white; | |
border: 2px solid grey; | |
} | |
h1 { | |
font-size: 24px; | |
margin: 0; | |
padding: 3px; | |
color: black; | |
} | |
p { | |
font-size: 14px; | |
margin: 10px 0 10px 0; | |
padding: 3px; | |
color: black; | |
} | |
svg { | |
background-color: white; | |
margin-left: 250px; | |
margin-right: auto; | |
margin-top: -2px; | |
margin-bottom: 50px; | |
padding: 50px; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="container"> | |
<h1>Berlin (City state area) as Geojson map</h1> | |
<p>Berlin, City state area, as a shape. Source: <a href="http://opendatalab.de/projects/geojson-utilities/">opendatalab.de</a>, 2015</p> | |
</div> | |
<script type="text/javascript"> | |
//Width and height | |
var w = 600; | |
var h = 600; | |
//Define map projection | |
//var projection = d3.geo.mercator() | |
var projection = d3.geo.mercator() | |
.center([ 13.4, 52.5 ]) | |
.translate([ w/2, h/2 ]) | |
.scale([ w/0.013 ]); | |
//Define path generator | |
var path = d3.geo.path() | |
.projection(projection); | |
//Create SVG | |
var svg = d3.select("body") | |
.append("svg") | |
.attr("width", w) | |
.attr("height", h); | |
//Load in GeoJSON data | |
d3.json("Berlin_gemeinden_simplify0.geojson", function(json) { | |
//Bind data and create one path per GeoJSON feature | |
svg.selectAll("path") | |
.data(json.features) | |
.enter() | |
.append("path") | |
.attr("d", path); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment