Skip to content

Commit

Permalink
fix: overlay of identical colors in quickdraw
Browse files Browse the repository at this point in the history
  • Loading branch information
neocarto committed Nov 3, 2022
1 parent e44b713 commit 9b175b8
Showing 1 changed file with 71 additions and 5 deletions.
76 changes: 71 additions & 5 deletions src/quickdraw.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,54 @@
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 = [];

export function quickdraw(layers, w = 1000, m = 5){
if (Array.isArray(layers)) {
let myarray = [];
layers.forEach((x) => myarray.push({ type: "layer", geojson: x }));
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 {
Expand All @@ -12,9 +57,30 @@ export function quickdraw(layers, w = 1000, m = 5){
layers: [
{
type: "layer",
geojson: layers
}
]
geojson: layers,
},
],
});
}
}

// import { draw } from "./draw.js";

// export function quickdraw(layers, w = 1000, m = 5){
// if (Array.isArray(layers)) {
// let myarray = [];
// layers.forEach((x) => myarray.push({ type: "layer", geojson: x }));

// return draw({ params: { margin: m, width: w }, layers: myarray });
// } else {
// return draw({
// params: { margin: m, width: w },
// layers: [
// {
// type: "layer",
// geojson: layers
// }
// ]
// });
// }
// }

0 comments on commit 9b175b8

Please sign in to comment.