Skip to content

Instantly share code, notes, and snippets.

@HarryStevens
Last active November 26, 2019 01:25
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save HarryStevens/5b705c13618e20706675135fd412b6d1 to your computer and use it in GitHub Desktop.
Swiftmap
license: gpl-3.0

Swiftmap is a JavaScript library for making data-driven maps.

<!DOCTYPE html>
<html>
<head>
<style>
body {
margin: 0;
}
#map {
width: 100%;
height: 100vh;
}
#map .boundary {
stroke-width: 2px;
}
</style>
</head>
<body>
<div id="map"></div>
<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/swiftmap@0.1.22/dist/swiftmap.min.js"></script>
<script>
// Create the map.
var map = swiftmap.map("#map");
d3.json("india_state.json", (error, data) => {
// Add geospatial data and draw it.
map
.layerPolygons(data)
.draw();
// Exposes DOM elements as D3 selections for styling.
var colors = ["#66c2a5", "#fc8d62", "#8da0cb", "#e78ac3", "#a6d854", "#ffd92f"];
map.layers[0].polygons
.transition().duration(2000)
.style("fill", (d, i) => colors[i % colors.length] );
// Makes it easy to create resizable maps for responsive designs.
window.onresize = function(){ map.resize(); }
});
</script>
</body>
</html>
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment