forked from MapGIS/WebClient-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFeatureSet.js
More file actions
172 lines (161 loc) · 4.82 KB
/
FeatureSet.js
File metadata and controls
172 lines (161 loc) · 4.82 KB
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import {
Zondy
} from './Base';
import {
extend
} from "./Util";
import {
CAttStruct
} from "./CAttStruct";
import {
Feature
} from "./Feature";
/**
* 要素集合信息对象
* @class Zondy.Object.FeatureSet
* @classdesc 要素集合信息对象
* @param {Object} option 属性键值对
* @param {Array} [option.TotalCount = null] 要素总数
* @param {Array} [option.AttStruct = null] 属性结构 Array<{@link Zondy.Object.CAttStruct}>
* @param {Array} [option.SFEleArray = new Array()] 要素数组 Array<{@link Zondy.Object.Feature}>
*/
var FeatureSet = function (option) {
var options = (option !== undefined) ? option : {};
extend(this, options);
/**
* @property TotalCount
* @description 一次查询的总要素个数,仅在做要素查询时有意义
* @type {Number}
* @readonly
*/
this.TotalCount = (options.TotalCount !== undefined && options.TotalCount !== null) ? options.TotalCount : 0;
/**
* @member Zondy.Object.FeatureSet.prototype.AttStruct
* @type {Array}
* @description 属性结构 Array<{@link Zondy.Object.CAttStruct}>
* @default null
*/
this.AttStruct = (options.AttStruct !== undefined && options.AttStruct !== null) ? options.AttStruct : null;
/**
* @member Zondy.Object.FeatureSet.prototype.SFEleArray
* @type {Array}
* @description 要素数组 Array<{@link Zondy.Object.Feature }>
* @default new Array()
*/
this.SFEleArray = (options.SFEleArray !== undefined && options.SFEleArray !== null) ? options.SFEleArray : new Array();
};
/**
* @function Zondy.Object.FeatureSet.prototype.clear
* @description 清空要素集合
*/
FeatureSet.prototype.clear = function () {
this.AttStruct = null;
this.SFEleArray = new Array();
};
/**
* @function Zondy.Object.FeatureSet.prototype.addFeature
* @description 添加一组或者一个要素
* @param {Array | Zondy.Object.Feature | Object} 一组要素,或者一个要素 Object代表Feature的属性键值对
*/
FeatureSet.prototype.addFeature = function (features) {
if (features instanceof Array) {
this.SFEleArray.concat(features);
} else {
this.SFEleArray.push(features);
}
};
/**
* @function Zondy.Object.FeatureSet.prototype.getFeaturesLength
* @description 获取要素集要素的记录条数
* @returns {Number} 要素集要素的记录条数
*/
FeatureSet.prototype.getFeaturesLength = function () {
if (this.SFEleArray instanceof Array) {
return this.SFEleArray.length;
} else {
return 0;
}
};
/**
* @function Zondy.Object.FeatureSet.prototype.getFeatureByIndex
* @description 获取指定要素对象
* @param {Number} i 对象索引下标
* @returns {Zondy.Object.Feature} 要素对象
*/
FeatureSet.prototype.getFeatureByIndex = function (i) {
if (i >= this.getFeaturesLength()) {
return null;
} else {
var feature = this.SFEleArray[i];
if (feature instanceof Feature) {
return feature;
} else {
return new Feature(this.SFEleArray[i]);
}
}
};
/**
* @function Zondy.Object.FeatureSet.prototype.getAttType
* @description 获取某属性字段的类型
* @param {String | Number} attKey 属性字段关键字,可以是{String}字段名,可以是序号{Interger}
* @returns {String} 字段类型
*/
FeatureSet.prototype.getAttType = function (attKey) {
var index;
if (this.AttStruct == null) {
return null;
}
if (typeof (attKey) == 'number') {
index = attKey;
} else {
index = this.getAttIndexByAttName(attKey);
}
if (index == null) {
return null;
} else {
return this.AttStruct.FldType[index];
}
};
/**
* @function Zondy.Object.FeatureSet.prototype.getAttIndexByAttName
* @description 通过属性的名称获取属性的序号
* @param {String} name 属性名
* @returns {Number} 属性序号
*/
FeatureSet.prototype.getAttIndexByAttName = function (name) {
if (this.AttStruct == null) {
return null;
}
if (this.AttStruct.FldName == null) {
return null;
}
var length = this.AttStruct.FldName.length;
for (var i = 0; i < length; i++) {
if (this.AttStruct.FldName[i] == name) {
return i;
}
}
return null;
};
/**
* @function Zondy.Object.FeatureSet.prototype.getAttNameByIndex
* @description 通过属性的序号获取属性名称
* @param {Number} index 属性序号
* @returns {String} 属性名称
*/
FeatureSet.prototype.getAttNameByIndex = function (index) {
if (this.AttStruct == null) {
return null;
}
if (this.AttStruct.FldName == null) {
return null;
}
if (this.AttStruct.FldName.length <= index) {
return null;
}
return this.AttStruct.FldName[index];
};
export {
FeatureSet
};
Zondy.Object.FeatureSet = FeatureSet;