Chile map made with Spam.js.
Custom labels.
height: 665 | |
license: mit | |
border: none |
<!DOCTYPE html> | |
<meta charset="utf-8" /> | |
<body> | |
<script src="https://d3js.org/d3.v3.min.js" charset="utf-8"></script> | |
<script src="https://d3js.org/topojson.v1.min.js"></script> | |
<script src="https://unpkg.com/rbush@1.4.3/rbush.js"></script> | |
<script src="https://unpkg.com/spamjs@1.1.0/spam.min.js"></script> | |
<script type='text/javascript'> | |
var cities = [ | |
{ name: "Santiago", coordinates: [-70.673813, -33.451278] }, | |
{ name: "Antofagasta", coordinates: [-70.378877, -23.636108] }, | |
{ name: "Easter Island", coordinates: [-109.348438, -27.115215] }, | |
{ name: "Robinson Crusoe", coordinates: [-78.927768, -33.412679] }, | |
{ name: "Puerto Montt", coordinates: [-72.930348, -41.462565] }, | |
{ name: "Punta Arenas", coordinates: [-70.900851, -53.146912] } | |
]; | |
d3.json("chile.json", function(error, d) { | |
topojson.presimplify(d); | |
var map = new StaticCanvasMap({ | |
element: "body", | |
width: 560, | |
data: [ | |
{ | |
features: topojson.feature(d, d.objects["chile"]), | |
static: { | |
paintfeature: function(parameters, d) { | |
parameters.context.lineWidth = 0.5 / parameters.scale; | |
parameters.context.strokeStyle = "rgb(170,170,170)"; | |
parameters.context.stroke(); | |
}, | |
postpaint: function(parameters, d) { | |
for (var i in cities) { | |
parameters.context.beginPath(); | |
parameters.context.textAlign = "center"; | |
var city = cities[i]; | |
var projectedPoint = parameters.map | |
.settings() | |
.projection(city.coordinates); | |
parameters.context.arc( | |
projectedPoint[0], | |
projectedPoint[1] / parameters.scale, | |
2 / parameters.scale, | |
0, | |
2 * Math.PI, | |
true | |
); | |
parameters.context.fillText( | |
city.name, | |
projectedPoint[0], | |
projectedPoint[1] - 5 | |
); | |
parameters.context.fill(); | |
} | |
} | |
} | |
} | |
] | |
}); | |
map.init(); | |
}); | |
</script> | |
</body> | |
</html> |