Skip to content

Instantly share code, notes, and snippets.

@HarryStevens
Last active April 30, 2018 20:24
Show Gist options
  • Save HarryStevens/aa630b6b0a9f84aa22aa5dc3f336c8f4 to your computer and use it in GitHub Desktop.
Save HarryStevens/aa630b6b0a9f84aa22aa5dc3f336c8f4 to your computer and use it in GitHub Desktop.
Swiftmap Polygon Labels
license: gpl-3.0
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;
font-family: "Helvetica Neue", sans-serif;
}
#map {
width: 100%;
height: 100vh;
}
.label {
text-shadow: 1px 1px 1px #fff, 0 -1px 0 #eee, -1px 0 0 #fff;
fill: #000;
}
</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("delhi_1997-2012_district.json", ready);
function ready(error, districts){
var map = swiftmap.map("#map")
.layerPolygons(districts)
.draw()
.drawLabels(d => d.properties.DISTRICT);
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