Skip to content

Instantly share code, notes, and snippets.

@HarryStevens
Last active April 30, 2018 22:52
Show Gist options
  • Save HarryStevens/30daa8a31d0d444aceb55a58adedf7c8 to your computer and use it in GitHub Desktop.
Save HarryStevens/30daa8a31d0d444aceb55a58adedf7c8 to your computer and use it in GitHub Desktop.
Swiftmap Graticule
license: mit
Display the source blob
Display the rendered blob
Raw
Loading
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>
<style>
body {
margin: 0;
}
#map {
width: 100%;
height: 100vh;
}
</style>
</head>
<body>
<div id="map"></div>
<!-- Use d3-request to load a TopoJSON file. -->
<script src="https://d3js.org/d3-collection.v1.min.js"></script>
<script src="https://d3js.org/d3-dispatch.v1.min.js"></script>
<script src="https://d3js.org/d3-dsv.v1.min.js"></script>
<script src="https://d3js.org/d3-request.v1.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/swiftmap.min.js"></script>
<script>
d3.json("countries.json", ready);
function ready (error, data){
var map = swiftmap.map("#map")
.graticule([18, 18])
.projection("equirectangular")
.layerPolygons(data)
.fit()
.drawPolygons();
var colors = ["#66c2a5", "#fc8d62", "#8da0cb", "#e78ac3", "#a6d854", "#ffd92f"];
map.layers[0].polygons
.transition().duration(2000)
.style("fill", (d, i) => colors[i % colors.length] );
window.onresize = () => map.resize();
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment