/
icons.ts
58 lines (55 loc) · 1.48 KB
/
icons.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { IconRow } from './iconRow';
import { GeometryType } from '@ngageoint/simple-features-js';
/**
* @class Icons
*/
export class Icons {
defaultIcon: IconRow = null;
icons: Map<GeometryType, IconRow>;
tableIcons: boolean;
/**
* Icons constructor
* @constructor
*/
constructor(tableIcons = false) {
this.icons = new Map();
this.tableIcons = tableIcons;
}
setDefault(iconRow: IconRow): void {
if (iconRow !== null && iconRow !== undefined) {
iconRow.setTableIcon(this.tableIcons);
}
this.defaultIcon = iconRow;
}
getDefault(): IconRow {
return this.defaultIcon;
}
setIcon(iconRow: IconRow, geometryType: GeometryType = null): void {
if (geometryType !== null) {
if (iconRow !== null && iconRow !== undefined) {
iconRow.setTableIcon(this.tableIcons);
this.icons.set(geometryType, iconRow);
} else {
this.icons.delete(geometryType);
}
} else {
this.setDefault(iconRow);
}
}
getIcon(geometryType: GeometryType = null): IconRow {
let iconRow = null;
if (geometryType !== null && this.icons.has(geometryType)) {
iconRow = this.icons.get(geometryType);
}
if (iconRow === null || iconRow === undefined || geometryType === null) {
iconRow = this.getDefault();
}
return iconRow;
}
isEmpty(): boolean {
return this.icons.size === 0 && this.defaultIcon === null;
}
getGeometryTypes(): GeometryType[] {
return Array.from(this.icons.keys());
}
}