-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathquickdraw.js
65 lines (56 loc) · 1.29 KB
/
quickdraw.js
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
65
import { draw } from "./draw.js";
import { figuration } from "./helpers/figuration.js";
export function quickdraw(layers, w = 1000, m = 5) {
let cols = [
"#66c2a5",
"#fc8d62",
"#8da0cb",
"#e78ac3",
"#a6d854",
"#ffd92f",
"#e5c494",
"#b3b3b3",
];
let used = [];
if (Array.isArray(layers)) {
let myarray = [];
layers.forEach((x) => {
let remainingcols = cols.filter((x) => !used.includes(x));
let col;
if (remainingcols.length > 0) {
col = remainingcols[Math.floor(Math.random() * remainingcols.length)];
used.push(col);
} else {
col = "#" + ((Math.random() * 0xffffff) << 0).toString(16);
}
let stroke;
let fill;
// Auto colors
if (figuration(x) == "l") {
stroke = col;
fill = "none";
}
if (figuration(x) == "p" || figuration(x) == "z") {
stroke = "none";
fill = col;
}
myarray.push({
type: "layer",
geojson: x,
fill,
stroke,
});
});
return draw({ params: { margin: m, width: w }, layers: myarray });
} else {
return draw({
params: { margin: m, width: w },
layers: [
{
type: "layer",
geojson: layers,
},
],
});
}
}