forked from SuperMap/iClient-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtil.js
More file actions
176 lines (167 loc) · 4.94 KB
/
Util.js
File metadata and controls
176 lines (167 loc) · 4.94 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
173
174
175
176
import { QueryOption } from '@supermapgis/iclient-common/REST';
import { GetFeaturesBySQLParameters } from '@supermapgis/iclient-common/iServer/GetFeaturesBySQLParameters';
import { QueryBySQLParameters } from '@supermapgis/iclient-common/iServer/QueryBySQLParameters';
import { FilterParameter } from '@supermapgis/iclient-common/iServer/FilterParameter';
import { QueryService } from '../../services/QueryService';
import { FeatureService } from '../../services/FeatureService';
export function getFeatureProperties(features) {
let properties = [];
if (isArray(features) && features.length) {
features.forEach((feature) => {
let property = feature.get('attributes');
property && properties.push(property);
});
}
return properties;
}
export function getFeatureBySQL(url, datasetNames, serviceOptions, processCompleted, processFaild, targetEpsgCode, restDataSingleRequestCount) {
getFeatureBySQLWithConcurrent(url, datasetNames, processCompleted, processFaild, serviceOptions, targetEpsgCode, restDataSingleRequestCount);
}
export function queryFeatureBySQL(
url,
layerName,
attributeFilter,
fields,
epsgCode,
processCompleted,
processFaild,
startRecord,
recordLength,
onlyAttribute
) {
const queryParam = new FilterParameter({
name: layerName,
attributeFilter: attributeFilter
});
if (fields) {
queryParam.fields = fields;
}
const params = {
queryParams: [queryParam]
};
if (onlyAttribute) {
params.queryOption = QueryOption.ATTRIBUTE;
}
startRecord && (params.startRecord = startRecord);
recordLength && (params.expectCount = recordLength);
if (epsgCode) {
params.prjCoordSys = {
epsgCode: epsgCode
};
}
const queryBySQLParams = new QueryBySQLParameters(params);
const queryBySQLService = new QueryService(url);
queryBySQLService.queryBySQL(queryBySQLParams, function (data) {
data.type === 'processCompleted' ? processCompleted(data) : processFaild(data);
});
}
export function getFeatureBySQLWithConcurrent(
url,
datasetNames,
processCompleted,
processFailed,
serviceOptions,
targetEpsgCode,
restDataSingleRequestCount
) {
let queryParameter = new FilterParameter({
name: datasetNames.join().replace(':', '@')
});
let maxFeatures = restDataSingleRequestCount || 1000, // 每次请求数据量
firstResult, // 存储每次请求的结果
allRequest = []; // 存储发出的请求Promise
// 发送请求获取获取总数据量
_getReasult(url, queryParameter, datasetNames, 0, 1, 1, serviceOptions, targetEpsgCode)
.then((result) => {
firstResult = result;
let totalCount = result.result.totalCount;
if (totalCount > 1) {
// 开始并发请求
for (let i = 1; i < totalCount; ) {
allRequest.push(
_getReasult(
url,
queryParameter,
datasetNames,
i,
i + maxFeatures,
maxFeatures,
serviceOptions,
targetEpsgCode
)
);
i += maxFeatures;
}
// 所有请求结束
Promise.all(allRequest)
.then((results) => {
// 结果合并
results.forEach((result) => {
if (result.type === 'processCompleted' && result.result.features && result.result.features.features) {
result.result.features.features.forEach((feature) => {
firstResult.result.features.features.push(feature);
});
} else {
// todo 提示 部分数据请求失败
firstResult.someRequestFailed = true;
}
});
processCompleted(firstResult);
})
.catch((error) => {
processFailed(error);
});
} else {
processCompleted(result);
}
})
.catch((error) => {
processFailed(error);
});
}
export function _getFeaturesBySQLParameters(
queryParameter,
datasetNames,
fromIndex,
toIndex,
maxFeatures,
targetEpsgCode
) {
return new GetFeaturesBySQLParameters({
queryParameter,
datasetNames,
fromIndex,
toIndex,
maxFeatures,
returnContent: true,
targetEpsgCode
});
}
export function _getReasult(
url,
queryParameter,
datasetNames,
fromIndex,
toIndex,
maxFeatures,
serviceOptions,
targetEpsgCode
) {
return new Promise((resolve, reject) => {
new FeatureService(url, serviceOptions).getFeaturesBySQL(
_getFeaturesBySQLParameters(queryParameter, datasetNames, fromIndex, toIndex, maxFeatures, targetEpsgCode),
(result) => {
let featuresResult = result.result;
//[bug] wt任务编号: 5223
if (result.type === 'processCompleted' && featuresResult && featuresResult.features) {
resolve(result);
} else {
reject(result);
}
}
);
});
}
function isArray(obj) {
return Object.prototype.toString.call(obj) === '[object Array]';
}