Skip to content

Commit 0c5a853

Browse files
修改所有端services
1 parent bca5daa commit 0c5a853

File tree

88 files changed

+3846
-5821
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+3846
-5821
lines changed

src/common/iServer/AddressMatchService.js

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export class AddressMatchService extends CommonServiceBase {
2020
constructor(url, options) {
2121
super(url, options);
2222
this.options = options || {};
23+
this.eventCount = 0;
2324
this.CLASS_NAME = 'SuperMap.AddressMatchService';
2425
}
2526

@@ -36,23 +37,23 @@ export class AddressMatchService extends CommonServiceBase {
3637
* @param {string} url - 正向地址匹配服务地址。
3738
* @param {GeoCodingParameter} params - 正向地址匹配服务参数。
3839
*/
39-
code(url, params) {
40+
code(url, params, callback) {
4041
if (!(params instanceof GeoCodingParameter)) {
4142
return;
4243
}
43-
this.processAsync(url, params);
44+
this.processAsync(url, params, callback);
4445
}
4546

4647
/**
4748
* @function AddressMatchService.prototype.decode
4849
* @param {string} url - 反向地址匹配服务地址。
4950
* @param {GeoDecodingParameter} params - 反向地址匹配服务参数。
5051
*/
51-
decode(url, params) {
52+
decode(url, params, callback) {
5253
if (!(params instanceof GeoDecodingParameter)) {
5354
return;
5455
}
55-
this.processAsync(url, params);
56+
this.processAsync(url, params, callback);
5657
}
5758

5859
/**
@@ -62,17 +63,37 @@ export class AddressMatchService extends CommonServiceBase {
6263
* @param {Object} params - 参数。
6364
*/
6465

65-
processAsync(url, params) {
66-
this.request({
67-
method: 'GET',
68-
url,
69-
params,
70-
scope: this,
71-
success: this.serviceProcessCompleted,
72-
failure: this.serviceProcessFailed
73-
});
66+
processAsync(url, params, callback) {
67+
let eventId = ++this.eventCount;
68+
let eventListeners = {
69+
scope: this,
70+
processCompleted: function(result) {
71+
if (eventId === result.result.eventId) {
72+
callback(result);
73+
}
74+
},
75+
processFailed: function(result) {
76+
if (eventId === result.result.eventId) {
77+
callback(result);
78+
}
79+
}
80+
}
81+
this.events.on(eventListeners);
82+
this.request({
83+
method: 'GET',
84+
url,
85+
params,
86+
scope: this,
87+
success(result) {
88+
result.eventId = eventId;
89+
this.serviceProcessCompleted(result, eventId);
90+
},
91+
failure(result) {
92+
result.eventId = eventId;
93+
this.serviceProcessFailed(result, eventId);
94+
}
95+
});
7496
}
75-
7697
/**
7798
* @function AddressMatchService.prototype.serviceProcessCompleted
7899
* @param {Object} result - 服务器返回的结果对象。

src/common/iServer/ChartService.js

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/* Copyright© 2000 - 2022 SuperMap Software Co.Ltd. All rights reserved.
2+
* This program are made available under the terms of the Apache License, Version 2.0
3+
* which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
4+
import { Util as CommonUtil} from '@supermap/iclient-common/commontypes/Util';
5+
import { DataFormat } from '@supermap/iclient-common/REST';
6+
import { ChartQueryService } from '@supermap/iclient-common/iServer/ChartQueryService';
7+
import { ChartFeatureInfoSpecsService } from '@supermap/iclient-common/iServer/ChartFeatureInfoSpecsService';
8+
9+
/**
10+
* @class ChartService
11+
* @category iServer Map Chart
12+
* @classdesc 海图服务。
13+
* @extends {ServiceBase}
14+
* @example
15+
* new ChartService(url).queryChart(param,function(result){
16+
* //doSomething
17+
* })
18+
* @param {string} url - 服务地址。
19+
* @param {Object} options - 参数。
20+
* @param {string} [options.proxy] - 服务代理地址。
21+
* @param {boolean} [options.withCredentials=false] - 请求是否携带 cookie。
22+
* @param {boolean} [options.crossOrigin] - 是否允许跨域请求。
23+
* @param {Object} [options.headers] - 请求头。
24+
* @usage
25+
*/
26+
export class ChartService {
27+
28+
constructor(url, options) {
29+
this.url = url;
30+
this.options = options || {};
31+
}
32+
33+
/**
34+
* @function ChartService.prototype.queryChart
35+
* @description 查询海图服务。
36+
* @param {ChartQueryParameters} params - 海图查询所需参数类。
37+
* @param {RequestCallback} callback - 回调函数。
38+
* @param {DataFormat} resultFormat - 返回结果类型。
39+
*/
40+
queryChart(params, callback, resultFormat) {
41+
var me = this,
42+
param = params,
43+
format = me._processFormat(resultFormat);
44+
var chartQueryService = new ChartQueryService(me.url, {
45+
proxy: me.options.proxy,
46+
withCredentials: me.options.withCredentials,
47+
crossOrigin: me.options.crossOrigin,
48+
headers: me.options.headers,
49+
50+
eventListeners: {
51+
scope: me,
52+
processCompleted: callback,
53+
processFailed: callback
54+
},
55+
format: format
56+
});
57+
58+
chartQueryService.processAsync(param);
59+
}
60+
61+
/**
62+
* @function ChartService.prototype.getChartFeatureInfo
63+
* @description 获取海图物标信息服务。
64+
* @param {RequestCallback} callback 回调函数。
65+
*/
66+
getChartFeatureInfo(callback) {
67+
var me = this;
68+
var url = CommonUtil.urlPathAppend(me.url, 'chartFeatureInfoSpecs');
69+
var chartFeatureInfoSpecsService = new ChartFeatureInfoSpecsService(url, {
70+
proxy: me.options.proxy,
71+
withCredentials: me.options.withCredentials,
72+
crossOrigin: me.options.crossOrigin,
73+
headers: me.options.headers,
74+
75+
eventListeners: {
76+
scope: me,
77+
processCompleted: callback,
78+
processFailed: callback
79+
}
80+
});
81+
chartFeatureInfoSpecsService.processAsync();
82+
}
83+
84+
_processFormat(resultFormat) {
85+
return (resultFormat) ? resultFormat : DataFormat.GEOJSON;
86+
}
87+
}
88+

src/common/iServer/DatasetService.js

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class DatasetService extends CommonServiceBase {
3636
* @description 要查询的数据集名称。
3737
*/
3838
this.dataset = null;
39-
39+
this.eventCount = 0;
4040
if (options) {
4141
Util.extend(this, options);
4242
}
@@ -59,66 +59,67 @@ export class DatasetService extends CommonServiceBase {
5959
* @function DatasetService.prototype.getDatasetsService
6060
* @description 执行服务,查询数据集服务。
6161
*/
62-
getDatasetsService(params) {
63-
var me = this;
64-
me.url = Util.urlPathAppend(me.url,`datasources/name/${params}/datasets`);
65-
me.request({
66-
method: "GET",
67-
data: null,
68-
scope: me,
69-
success: me.serviceProcessCompleted,
70-
failure: me.serviceProcessFailed
71-
});
62+
getDatasetsService(params, callback) {
63+
const url = Util.urlPathAppend(this.url,`datasources/name/${params}/datasets`);
64+
this.processAsync(url, 'GET', callback);
7265
}
7366

7467
/**
7568
* @function DatasetService.prototype.getDatasetService
7669
* @description 执行服务,查询数据集信息服务。
7770
*/
78-
getDatasetService(datasourceName, datasetName) {
79-
var me = this;
80-
me.url = Util.urlPathAppend(me.url,`datasources/name/${datasourceName}/datasets/name/${datasetName}`);
81-
me.request({
82-
method: "GET",
83-
data: null,
84-
scope: me,
85-
success: me.serviceProcessCompleted,
86-
failure: me.serviceProcessFailed
87-
});
71+
getDatasetService(datasourceName, datasetName, callback) {
72+
const url = Util.urlPathAppend(this.url,`datasources/name/${datasourceName}/datasets/name/${datasetName}`);
73+
this.processAsync(url, 'GET', callback);
8874
}
8975

9076
/**
9177
* @function DatasetService.prototype.setDatasetService
9278
* @description 执行服务,更改数据集信息服务。
9379
*/
94-
setDatasetService(params) {
80+
setDatasetService(params, callback) {
9581
if (!params) {
9682
return;
9783
}
98-
var me = this;
99-
var jsonParamsStr = Util.toJSON(params);
100-
me.request({
101-
method: "PUT",
102-
data: jsonParamsStr,
103-
scope: me,
104-
success: me.serviceProcessCompleted,
105-
failure: me.serviceProcessFailed
106-
});
84+
this.processAsync(this.url, 'PUT', callback, params);
10785
}
10886

10987
/**
11088
* @function DatasetService.prototype.deleteDatasetService
11189
* @description 执行服务,删除数据集信息服务。
11290
*/
113-
deleteDatasetService() {
114-
var me = this;
115-
me.request({
116-
method: "DELETE",
117-
data: null,
118-
scope: me,
119-
success: me.serviceProcessCompleted,
120-
failure: me.serviceProcessFailed
121-
});
91+
deleteDatasetService(datasourceName, datasetName, callback) {
92+
const url = Util.urlPathAppend(this.url, `datasources/name/${datasourceName}/datasets/name/${datasetName}`);
93+
this.processAsync(url, 'DELETE', callback);
12294
}
12395

96+
processAsync(url, method, callback, params) {
97+
let eventId = ++this.eventCount;
98+
let eventListeners = {
99+
scope: this,
100+
processCompleted: function(result) {
101+
if (eventId === result.result.eventId) {
102+
callback(result);
103+
}
104+
},
105+
processFailed: callback
106+
}
107+
this.events.on(eventListeners);
108+
var me = this;
109+
let requestConfig = {
110+
url,
111+
method,
112+
scope: me,
113+
success(result) {
114+
result.eventId = eventId;
115+
me.serviceProcessCompleted(result);
116+
},
117+
failure(result) {
118+
result.eventId = eventId;
119+
me.serviceProcessFailed(result);
120+
}
121+
}
122+
params && (requestConfig.data = Util.toJSON(params));
123+
me.request(requestConfig);
124+
}
124125
}

src/common/iServer/DatasourceService.js

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export class DatasourceService extends CommonServiceBase {
2828
if (options) {
2929
Util.extend(this, options);
3030
}
31+
this.eventCount = 0;
3132
this.CLASS_NAME = "SuperMap.DatasourceService";
3233
}
3334

@@ -37,6 +38,7 @@ export class DatasourceService extends CommonServiceBase {
3738
* @override
3839
*/
3940
destroy() {
41+
this.eventCount = 0;
4042
super.destroy();
4143
}
4244

@@ -45,49 +47,58 @@ export class DatasourceService extends CommonServiceBase {
4547
* @function DatasourceService.prototype.getDatasourceService
4648
* @description 获取指定数据源信息。
4749
*/
48-
getDatasourceService(datasourceName) {
49-
var me = this;
50-
me.url = Util.urlPathAppend(me.url,`datasources/name/${datasourceName}`);
51-
me.request({
52-
method: "GET",
53-
data: null,
54-
scope: me,
55-
success: me.serviceProcessCompleted,
56-
failure: me.serviceProcessFailed
57-
});
50+
getDatasourceService(datasourceName, callback) {
51+
let url = Util.urlPathAppend(this.url,`datasources/name/${datasourceName}`);
52+
this.processAsync(url, "GET", callback);
5853
}
5954

6055
/**
6156
* @function DatasourceService.prototype.getDatasourcesService
6257
* @description 获取所有数据源信息。
6358
*/
64-
getDatasourcesService() {
65-
var me = this;
66-
me.url = Util.urlPathAppend(me.url,`datasources`);
67-
me.request({
68-
method: "GET",
69-
data: null,
70-
scope: me,
71-
success: me.serviceProcessCompleted,
72-
failure: me.serviceProcessFailed
73-
});
59+
getDatasourcesService(callback) {
60+
let url = Util.urlPathAppend(this.url,`datasources`);
61+
this.processAsync(url, "GET", callback);
7462
}
7563
/**
7664
* @function DatasourceService.prototype.setDatasourceService
7765
* @description 更新数据源信息。
7866
*/
79-
setDatasourceService(params) {
67+
setDatasourceService(params, callback) {
8068
if (!params) {
8169
return;
8270
}
83-
var me = this;
84-
var jsonParamsStr = Util.toJSON(params);
85-
me.request({
86-
method: "PUT",
87-
data: jsonParamsStr,
88-
scope: me,
89-
success: me.serviceProcessCompleted,
90-
failure: me.serviceProcessFailed
91-
});
71+
const url = Util.urlPathAppend(this.url,`datasources/name/${params.datasourceName}`);
72+
this.processAsync(url, "PUT", callback, params);
73+
}
74+
75+
processAsync(url, method, callback, params) {
76+
let eventId = ++this.eventCount;
77+
let eventListeners = {
78+
scope: this,
79+
processCompleted: function(result) {
80+
if (eventId === result.result.eventId) {
81+
callback(result);
82+
}
83+
},
84+
processFailed: callback
85+
}
86+
this.events.on(eventListeners);
87+
var me = this;
88+
let requestConfig = {
89+
url,
90+
method,
91+
scope: me,
92+
success(result) {
93+
result.eventId = eventId;
94+
this.serviceProcessCompleted(result);
95+
},
96+
failure(result) {
97+
result.eventId = eventId;
98+
this.serviceProcessFailed(result);
99+
}
100+
}
101+
params && (requestConfig.data = Util.toJSON(params));
102+
me.request(requestConfig);
92103
}
93104
}

0 commit comments

Comments
 (0)