Skip to content

Instantly share code, notes, and snippets.

@lemoogle
Forked from milafrerichs/eu.topojson
Created May 31, 2017 14:03
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 lemoogle/0a2fedf19bbde2efabd78a502d7b91a2 to your computer and use it in GitHub Desktop.
Save lemoogle/0a2fedf19bbde2efabd78a502d7b91a2 to your computer and use it in GitHub Desktop.
Simple Map of Europe TopoJSON
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>
<meta charset="utf-8">
<style>
#map {
width: 400px;
height: 300px;
}
</style>
<body>
<div id="map"></div>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/d3.geo.projection.v0.min.js"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script>
(function() {
var center, countries, height, path, projection, scale, svg, width;
width = 300;
height = 400;
center = [5, 70];
scale = 600;
projection = d3.geo.mercator().scale(scale).translate([width / 2, 0]).center(center);
path = d3.geo.path().projection(projection);
svg = d3.select("#map").append("svg").attr("height", height).attr("width", width);
countries = svg.append("g");
d3.json("eu.topojson", function(data) {
countries.selectAll('.country')
.data(topojson.feature(data, data.objects.europe).features)
.enter()
.append('path')
.attr('class', 'country')
.attr('d', path);
return;
});
}).call(this);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment