Last active
September 9, 2018 14:52
-
-
Save duhaime/60e0558386aadcee09fdffbefcc9664d to your computer and use it in GitHub Desktop.
GeoJson Mapping (D3)
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> | |
<head> | |
<meta charset='UTF-8'> | |
<style> | |
svg { | |
background: #e7efef; | |
} | |
path { | |
stroke: #4a4a4a; | |
stroke-width: 0.01em; | |
fill: #1d920c; | |
} | |
path:hover { | |
fill: #166b38; | |
} | |
</style> | |
</head> | |
<body> | |
<script src='//cdnjs.cloudflare.com/ajax/libs/d3/4.3.0/d3.min.js'></script> | |
<script> | |
var projection = d3 | |
.geoMercator() | |
.scale(1400) | |
.center([0.0, 55.6]); | |
var path = d3.geoPath().projection(projection); | |
var map = d3.select('body') | |
.append('svg') | |
.attr('width', 700) | |
.attr('height', 500); | |
d3.json('british-isles.geojson', function(data) { | |
window.geojson = data; | |
map.selectAll('path') | |
.data(data.features) | |
.enter() | |
.append('path') | |
.attr('d', path) | |
.attr('fill', 'green') | |
.attr('fill-opacity', 0.5) | |
.attr('stroke', '#222'); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment