generated from arnofiva/arcgis-core-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCountryPalette.ts
43 lines (35 loc) · 930 Bytes
/
CountryPalette.ts
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
import Color from "@arcgis/core/Color";
import Accessor from "@arcgis/core/core/Accessor";
import { property } from "@arcgis/core/core/accessorSupport/decorators";
export type CountryColor = {
main: Color;
light: Color;
dark: Color;
};
function shuffle(array: any[]) {
let currentIndex = array.length;
while (currentIndex != 0) {
const randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex--;
[array[currentIndex], array[randomIndex]] = [
array[randomIndex],
array[currentIndex],
];
}
}
export default class CountryPalette extends Accessor {
@property()
get selectionColor() {
return this.colors.length ? this.colors[0] : undefined;
}
constructor(private colors: CountryColor[]) {
super();
shuffle(colors);
}
allocate() {
this.colors.length && this.colors.shift();
}
reinstate(color: CountryColor) {
this.colors.push(color);
}
}