Skip to content

Instantly share code, notes, and snippets.

@duhaime
Last active September 9, 2018 14:52
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 duhaime/60e0558386aadcee09fdffbefcc9664d to your computer and use it in GitHub Desktop.
Save duhaime/60e0558386aadcee09fdffbefcc9664d to your computer and use it in GitHub Desktop.
GeoJson Mapping (D3)
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.
<!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