Swiftmap labels polygons by finding each one's pole of inaccessibility or, in the case of complex multipolygons, its centroid.
Last active
April 30, 2018 20:24
-
-
Save HarryStevens/aa630b6b0a9f84aa22aa5dc3f336c8f4 to your computer and use it in GitHub Desktop.
Swiftmap Polygon Labels
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
license: gpl-3.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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