-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrender-world
executable file
·61 lines (47 loc) · 1.48 KB
/
render-world
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env node
var width = 960,
height = 500,
projectionName = process.argv[2],
projectionSymbol = "geo" + projectionName[0].toUpperCase() + projectionName.slice(1);
if (!/^[a-z0-9]+$/i.test(projectionName)) throw new Error;
var fs = require("fs"),
topojson = require("topojson"),
Canvas = require("canvas"),
d3_geo = require("../");
var canvas = new Canvas(width, height),
context = canvas.getContext("2d");
var world = require("./data/world-50m.json"),
graticule = d3_geo.geoGraticule(),
outline = {type: "Sphere"};
// switch (projectionName) {
// case "littrow": outline = graticule.extent([[-90, -60], [90, 60]]).outline(); break;
// }
var path = d3_geo.geoPath()
.projection(d3_geo[projectionSymbol]().precision(0.1))
.context(context);
context.fillStyle = "#fff";
context.fillRect(0, 0, width, height);
context.save();
// switch (projectionName) {
// case "armadillo": {
// context.beginPath();
// path(outline);
// context.clip();
// break;
// }
// }
context.beginPath();
path(topojson.feature(world, world.objects.land));
context.fillStyle = "#000";
context.fill();
context.beginPath();
path(graticule());
context.strokeStyle = "rgba(119,119,119,0.5)";
context.stroke();
context.restore();
context.beginPath();
path(outline);
context.strokeStyle = "#000";
context.stroke();
console.warn("↳ test/output/" + projectionName + ".png");
canvas.pngStream().pipe(fs.createWriteStream("test/output/" + projectionName + ".png"));