-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmap-image-preview.js
More file actions
executable file
·50 lines (42 loc) · 1.49 KB
/
map-image-preview.js
File metadata and controls
executable file
·50 lines (42 loc) · 1.49 KB
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
#! /usr/bin/env node
const fs = require("fs");
const path = require("path");
const draw = require("./draw");
const geometry = require("./geometry");
const commandLineArgs = require("./commandLineArgs");
const package = require("./package");
const args = commandLineArgs.parse();
console.log(package.name + " v" + package.version);
const meta = args.meta
? JSON.parse(fs.readFileSync(args.meta))
: { farge: args.fillColor };
const geojsonFile = args._[0];
const geojson = JSON.parse(fs.readFileSync(geojsonFile));
let bbox = geometry.bbox(geojson);
if (args.maxbounds) bbox = geometry.limitBounds(bbox, args.maxbounds);
const options = {
bounds: geometry.grow(bbox, args.bboxscale - 1),
colorProperty: args.colorProperty,
output: args.output || geojsonFile,
stroke: args.stroke,
strokeColor: args.strokeColor,
strokeWidth: args.strokeWidth,
width: args.width
};
console.log("bbox: ", bbox);
console.log("bounds: ", options.bounds);
console.log("bounds2: ", options.bounds);
const render = draw(geojson, meta, options);
const { width, height } = render;
const summary = {
bbox: options.bounds,
image: { width, height },
color: meta.farge,
strokeColor: options.strokeColor,
strokeWidth: args.stroke,
crs: geojson.crs && geojson.crs.properties && geojson.crs.properties.name
};
const parsed = path.parse(options.output);
const basename = path.join(parsed.dir, parsed.name);
fs.writeFileSync(basename + ".json", JSON.stringify(summary));
fs.writeFileSync(basename + ".png", render.buffer);