-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtableFeatureInfoView.js
139 lines (129 loc) · 3.86 KB
/
tableFeatureInfoView.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import { parseBoolean } from '@vcsuite/parsers';
import AbstractFeatureInfoView from './abstractFeatureInfoView.js';
import VcsTable from '../components/tables/VcsTable.vue';
/**
* @typedef {import("./abstractFeatureInfoView.js").FeatureInfoViewOptions & {
* itemsPerPage?: number,
* itemsPerPageArray?: number[],
* showSearchbar?: boolean,
* searchbarPlaceholder?: string
* }} TableFeatureInfoViewOptions
* @property {number} [itemsPerPage=10] - default has to be one of itemsPerPageArray
* @property {number[]} [itemsPerPageArray=[5, 10, 15]]
* @property {boolean} [showSearchbar]
* @property {string} [searchbarPlaceholder]
*/
/**
* @typedef {import("./abstractFeatureInfoView.js").FeatureInfoProps & {
* itemsPerPage?: number,
* itemsPerPageArray?: number[],
* showGroupBtn?: boolean,
* showSearchbar?: boolean,
* searchbarPlaceholder?: string
* }} TableFeatureInfoViewProps
*/
/**
* @class
* @description A table view for feature attributes
* @extends {AbstractFeatureInfoView}
*/
class TableFeatureInfoView extends AbstractFeatureInfoView {
/**
* @type {string}
*/
static get className() {
return 'TableFeatureInfoView';
}
/** @returns {TableFeatureInfoViewOptions} */
static getDefaultOptions() {
return {
itemsPerPageArray: [5, 10, 15],
itemsPerPage: 10,
showSearchbar: true,
};
}
/**
* @param {TableFeatureInfoViewOptions} options
*/
constructor(options) {
super(options, VcsTable);
const defaultOptions = TableFeatureInfoView.getDefaultOptions();
/**
* @type {number[]}
*/
this.itemsPerPageArray =
options.itemsPerPageArray || defaultOptions.itemsPerPageArray;
const itemsPerPage = options.itemsPerPage || defaultOptions.itemsPerPage;
/**
* @type {number}
*/
this.itemsPerPage = this.itemsPerPageArray.includes(itemsPerPage)
? itemsPerPage
: this.itemsPerPageArray[0];
/**
* @type {boolean}
*/
this.showSearchbar = parseBoolean(
options.showSearchbar,
defaultOptions.showSearchbar,
);
/**
* @type {string}
*/
this.searchbarPlaceholder = options.searchbarPlaceholder;
}
/**
* @param {undefined|import("ol").Feature|import("@vcmap-cesium/engine").Cesium3DTileFeature|import("@vcmap-cesium/engine").Cesium3DTilePointFeature} feature
* @returns {Object}
* @private
*/
_getAttributesFromFeature(feature) {
const attributes = super._getAttributesFromFeature(feature);
return {
...attributes,
featureId: feature.getId(),
};
}
/**
* @param {import("./featureInfo.js").FeatureInfoEvent} featureInfo
* @param {import("@vcmap/core").Layer} layer
* @returns {TableFeatureInfoViewProps}
*/
getProperties(featureInfo, layer) {
const properties = super.getProperties(featureInfo, layer);
return {
...properties,
itemsPerPage: this.itemsPerPage,
itemsPerPageArray: this.itemsPerPageArray,
showSearchbar: this.showSearchbar,
searchbarPlaceholder: this.searchbarPlaceholder,
};
}
/**
* @returns {TableFeatureInfoViewOptions}
*/
toJSON() {
const config = super.toJSON();
const defaultOptions = TableFeatureInfoView.getDefaultOptions();
if (
this.itemsPerPageArray.length !==
defaultOptions.itemsPerPageArray.length ||
this.itemsPerPageArray.some(
(e, idx) => e !== defaultOptions.itemsPerPageArray[idx],
)
) {
config.itemsPerPageArray = this.itemsPerPageArray;
}
if (this.itemsPerPage !== defaultOptions.itemsPerPage) {
config.itemsPerPage = this.itemsPerPage;
}
if (this.showSearchbar !== defaultOptions.showSearchbar) {
config.showSearchbar = this.showSearchbar;
}
if (this.searchbarPlaceholder) {
config.searchbarPlaceholder = this.searchbarPlaceholder;
}
return config;
}
}
export default TableFeatureInfoView;