-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-node.js
More file actions
64 lines (51 loc) · 1.74 KB
/
test-node.js
File metadata and controls
64 lines (51 loc) · 1.74 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const Profiler = require("./src/utils/profiler")
const { PerformanceObserver } = require('perf_hooks');
const Kothic = require("./src/kothic");
const fs = require('fs');
const MapCSS = Kothic.MapCSS;
const { createCanvas, loadImage } = require('canvas')
const canvas = createCanvas(512* 4, 512 *4)
const css = fs.readFileSync("./experiments/styles/contours.mapcss").toString();
const kothic = new Kothic(css, {
//Synchronous mode for testing reasons
getFrame: (callback) => callback(),
browserOptimizations: false,
gallery: {
localImagesDirectory: '../../sandbox/maki/png',
loadImage: loadImage
},
mapcss: {
cache: {},
locales: []
},
rendering: {
drawOnTileEdges: true
},
debug: true
});
const observer = new PerformanceObserver((list) => {
list.getEntries().forEach((item) => {
console.log(item.name, (item.duration).toFixed(2) + "ms");
});
});
observer.observe({ entryTypes: ['function', 'measure'] });
Profiler.mark("Loading GeoJSON");
//const geojson = JSON.parse(fs.readFileSync('../../sandbox/relief/contours-json/N50E086.json'));
const geojson = JSON.parse(fs.readFileSync('../../sandbox/relief/contours-json/N052E085.json'));
geojson.bbox = [85, 52, 85.1, 52.1];
//const geojson = JSON.parse(fs.readFileSync('tile.geojson'));
//const geojson = JSON.parse(fs.readFileSync('ridges.geojson'));
Profiler.measure("Loading GeoJSON");
// console.log(Profiler.stats());
Profiler.mark("Rendering");
kothic.render(canvas, geojson, 16, function() {
Profiler.measure("Rendering");
Profiler.mark("Saving PNG")
const stream = canvas.createPNGStream();
const file = fs.createWriteStream("./test.png");
stream.pipe(file);
stream.on('end', () => {
Profiler.measure("Saving PNG");
observer.disconnect();
})
});