Skip to content

Commit 8b15434

Browse files
committed
【API】优化service callback回调的API,定义RequestCallback类型
1 parent 401addb commit 8b15434

Some content is hidden

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

46 files changed

+322
-277
lines changed

src/common/iServer/CommonServiceBase.js

Lines changed: 57 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,30 @@
1-
import {SuperMap} from '../SuperMap';
2-
import {FetchRequest} from "../util/FetchRequest";
3-
import {Events} from '../commontypes/Events';
4-
import {Credential} from '../commontypes/Credential';
5-
import {SecurityManager} from '../security/SecurityManager';
6-
import {Util} from '../commontypes/Util';
7-
import {ServerType} from '../REST';
8-
import {JSONFormat as JSON} from '../format/JSON';
9-
import {FunctionExt} from '../commontypes/BaseTypes';
1+
import {
2+
SuperMap
3+
} from '../SuperMap';
4+
import {
5+
FetchRequest
6+
} from "../util/FetchRequest";
7+
import {
8+
Events
9+
} from '../commontypes/Events';
10+
import {
11+
Credential
12+
} from '../commontypes/Credential';
13+
import {
14+
SecurityManager
15+
} from '../security/SecurityManager';
16+
import {
17+
Util
18+
} from '../commontypes/Util';
19+
import {
20+
ServerType
21+
} from '../REST';
22+
import {
23+
JSONFormat as JSON
24+
} from '../format/JSON';
25+
import {
26+
FunctionExt
27+
} from '../commontypes/BaseTypes';
1028

1129
/**
1230
* @class SuperMap.CommonServiceBase
@@ -176,7 +194,8 @@ export class CommonServiceBase {
176194
* @return {SuperMap.Credential} 凭据信息对象。
177195
*/
178196
getCredential(url) {
179-
let keyUrl = url, credential, value;
197+
let keyUrl = url,
198+
credential, value;
180199
switch (this.serverType) {
181200
case ServerType.IPORTAL:
182201
value = SecurityManager.getToken(keyUrl);
@@ -290,7 +309,9 @@ export class CommonServiceBase {
290309
*/
291310
serviceProcessCompleted(result) {
292311
result = Util.transformResult(result);
293-
this.events.triggerEvent("processCompleted", {result: result});
312+
this.events.triggerEvent("processCompleted", {
313+
result: result
314+
});
294315
}
295316

296317
/**
@@ -301,7 +322,9 @@ export class CommonServiceBase {
301322
serviceProcessFailed(result) {
302323
result = Util.transformResult(result);
303324
let error = result.error || result;
304-
this.events.triggerEvent("processFailed", {error: error});
325+
this.events.triggerEvent("processFailed", {
326+
error: error
327+
});
305328
}
306329

307330
_commit(options) {
@@ -321,7 +344,7 @@ export class CommonServiceBase {
321344
if (response.text) {
322345
return response.text();
323346
}
324-
if(response.json){
347+
if (response.json) {
325348
return response.json();
326349
}
327350
return response;
@@ -332,9 +355,13 @@ export class CommonServiceBase {
332355
}
333356
if (!result || result.error || result.code >= 300 && result.code !== 304) {
334357
if (result && result.error) {
335-
result = {error: result.error};
358+
result = {
359+
error: result.error
360+
};
336361
} else {
337-
result = {error: result};
362+
result = {
363+
error: result
364+
};
338365
}
339366
}
340367
if (result.error) {
@@ -351,3 +378,18 @@ export class CommonServiceBase {
351378
}
352379

353380
SuperMap.CommonServiceBase = CommonServiceBase;
381+
382+
/**
383+
* 服务器请求回调函数
384+
* @callback RequestCallback
385+
* @example
386+
* var requestCallback = function (serviceResult){
387+
* console.log(serviceResult.result);
388+
* }
389+
* new QueryService(url).queryByBounds(param, requestCallback);
390+
* @param {Object} serviceResult
391+
* @param {Object} serviceResult.result 服务器返回结果
392+
* @param {Object} serviceResult.object 发布应用程序事件的对象
393+
* @param {Object} serviceResult.type 事件类型
394+
* @param {Object} serviceResult.element 接受浏览器事件的DOM节点
395+
*/

src/leaflet/services/AddressMatchService.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export var AddressMatchService = ServiceBase.extend({
2828
* @function L.supermap.addressMatchService.prototype.code
2929
* @description 获取正向地址匹配结果。
3030
* @param params - {Object} 正向匹配参数。
31-
* @param callback - {function} 请求结果的回调函数。
31+
* @param {RequestCallback} callback 请求结果的回调函数。
3232
*/
3333
code: function (params, callback) {
3434
var me = this;
@@ -49,7 +49,7 @@ export var AddressMatchService = ServiceBase.extend({
4949
* @function L.supermap.addressMatchService.prototype.decode
5050
* @description 获取反向地址匹配结果。
5151
* @param params -{Object} 反向匹配参数。
52-
* @param callback -{function} 请求结果的回调函数。
52+
* @param {RequestCallback} callback 请求结果的回调函数。
5353
*/
5454
decode: function (params, callback) {
5555
var me = this;

src/leaflet/services/ChartService.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export var ChartService = ServiceBase.extend({
2828
* @function L.supermap.chartService.prototype.queryChart
2929
* @description 查询海图
3030
* @param params -{SuperMap.ChartQueryParameters} 海图查询所需参数类。
31-
* @param callback -{function} 回调函数。
31+
* @param {RequestCallback} callback 回调函数。
3232
* @param resultFormat -{SuperMap.DataFormat} 返回的结果格式类型。
3333
*/
3434
queryChart: function (params, callback, resultFormat) {
@@ -53,7 +53,7 @@ export var ChartService = ServiceBase.extend({
5353
/**
5454
* @function L.supermap.chartService.prototype.getChartFeatureInfo
5555
* @description 获取海图物标信息
56-
* @param callback -{function} 回调函数
56+
* @param {RequestCallback} callback 回调函数
5757
*/
5858
getChartFeatureInfo: function (callback) {
5959
var me = this, url = me.url.concat();

src/leaflet/services/FeatureService.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export var FeatureService = ServiceBase.extend({
3737
* @function L.supermap.featureService.prototype.getFeaturesByIDs
3838
* @description 数据集ID查询服务
3939
* @param params {SuperMap.GetFeaturesByIDsParameters} ID 查询参数类
40-
* @param callback - {function} 回调函数
40+
* @param {RequestCallback} callback 回调函数
4141
* @param resultFormat {SuperMap.DataFormat} 返回结果类型
4242
*/
4343
getFeaturesByIDs: function (params, callback, resultFormat) {
@@ -60,7 +60,7 @@ export var FeatureService = ServiceBase.extend({
6060
* @function L.supermap.featureService.prototype.getFeaturesByBounds
6161
* @description 数据集Bounds查询服务
6262
* @param params {SuperMap.GetFeaturesByBoundsParameters} 数据集范围查询参数类
63-
* @param callback - {function} 回调函数
63+
* @param {RequestCallback} callback 回调函数
6464
* @param resultFormat {SuperMap.DataFormat} 返回结果类型
6565
*/
6666
getFeaturesByBounds: function (params, callback, resultFormat) {
@@ -82,7 +82,7 @@ export var FeatureService = ServiceBase.extend({
8282
* @function L.supermap.featureService.prototype.getFeaturesByBuffer
8383
* @description 数据集Buffer查询服务
8484
* @param params {SuperMap.GetFeaturesByBufferParameters} 数据服务中数据集缓冲区查询参数类
85-
* @param callback - {function} 回调函数
85+
* @param {RequestCallback} callback 回调函数
8686
* @param resultFormat {SuperMap.DataFormat} 返回结果类型
8787
*/
8888
getFeaturesByBuffer: function (params, callback, resultFormat) {
@@ -104,7 +104,7 @@ export var FeatureService = ServiceBase.extend({
104104
* @function L.supermap.featureService.prototype.getFeaturesBySQL
105105
* @description 数据集SQL查询服务
106106
* @param params {SuperMap.GetFeaturesBySQLParameters} 数据服务中数据集SQL查询参数类
107-
* @param callback - {function} 回调函数
107+
* @param {RequestCallback} callback 回调函数
108108
* @param resultFormat {SuperMap.DataFormat} 返回结果类型
109109
*/
110110
getFeaturesBySQL: function (params, callback, resultFormat) {
@@ -126,7 +126,7 @@ export var FeatureService = ServiceBase.extend({
126126
* @function L.supermap.featureService.prototype.getFeaturesByGeometry
127127
* @description 数据集几何查询服务类
128128
* @param params {SuperMap.GetFeaturesByGeometryParameters} 数据集几何查询参数类
129-
* @param callback - {function} 回调函数
129+
* @param {RequestCallback} callback 回调函数
130130
* @param resultFormat {SuperMap.DataFormat} 返回结果类型
131131
*/
132132
getFeaturesByGeometry: function (params, callback, resultFormat) {
@@ -148,7 +148,7 @@ export var FeatureService = ServiceBase.extend({
148148
* @function L.supermap.featureService.prototype.editFeatures
149149
* @description 地物编辑服务
150150
* @param params {SuperMap.EditFeaturesParameters} 数据服务中数据集添加、修改、删除参数类
151-
* @param callback - {function} 回调函数
151+
* @param {RequestCallback} callback 回调函数
152152
*/
153153
editFeatures: function (params, callback) {
154154

src/leaflet/services/FieldService.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export var FieldService = ServiceBase.extend({
2828
* @function L.supermap.fieldService.prototype.getFields
2929
* @description 字段查询服务
3030
* @param params {SuperMap.FieldParameters} 字段信息查询参数类
31-
* @param callback - {function} 回调函数
31+
* @param {RequestCallback} callback 回调函数
3232
*/
3333
getFields: function (params, callback) {
3434
var me = this;
@@ -51,7 +51,7 @@ export var FieldService = ServiceBase.extend({
5151
* @function L.supermap.fieldService.prototype.getFieldStatisticsInfo
5252
* @description 字段统计服务
5353
* @param params {SuperMap.FieldStatisticsParameters} 字段统计信息查询参数类
54-
* @param callback - {function} 回调函数
54+
* @param {RequestCallback} callback 回调函数
5555
*/
5656
getFieldStatisticsInfo: function (params, callback) {
5757
if (!(params instanceof FieldStatisticsParameters)) {

src/leaflet/services/GridCellInfosService.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export var GridCellInfosService = ServiceBase.extend({
2626
/**
2727
* @function L.supermap.gridCellInfosService.prototype.getGridCellInfos
2828
* @param params {SuperMap.GetGridCellInfosParameters} 数据服务栅格查询参数类
29-
* @param callback - {function} 回调函数
29+
* @param {RequestCallback} callback 回调函数
3030
*/
3131
getGridCellInfos: function (params, callback) {
3232
if (!(params instanceof GetGridCellInfosParameters)) {

src/leaflet/services/LayerInfoService.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export var LayerInfoService = ServiceBase.extend({
3434
/**
3535
* @function L.supermap.layerInfoService.prototype.getLayerInfo
3636
* @description 获取图层信息
37-
* @param callback - {function} 获取信息完成后的回调函数
37+
* @param {RequestCallback} callback 获取信息完成后的回调函数
3838
*/
3939
getLayersInfo: function (callback) {
4040
var me = this;
@@ -54,7 +54,7 @@ export var LayerInfoService = ServiceBase.extend({
5454
* @function L.supermap.layerInfoService.prototype.setLayerInfo
5555
* @description 设置图层信息服务。可以实现临时图层中子图层的修改
5656
* @param params - {SuperMap.SetLayerInfoParameters} 图层信息相关参数
57-
* @param callback - {function} 回调函数
57+
* @param {RequestCallback} callback 回调函数
5858
*/
5959
setLayerInfo: function (params, callback) {
6060
if (!(params instanceof SetLayerInfoParameters)) {
@@ -88,7 +88,7 @@ export var LayerInfoService = ServiceBase.extend({
8888
* @function L.supermap.layerInfoService.prototype.setLayersInfo
8989
* @description 设置图层信息。可以实现创建新的临时图层和对现有临时图层的修改
9090
* @param params -{SuperMap.SetLayersInfoParameters} 图层信息设置参数,包括临时图层。
91-
* @param callback -{function} 回调函数
91+
* @param {RequestCallback} callback 回调函数
9292
*/
9393
setLayersInfo: function (params, callback) {
9494
if (!(params instanceof SetLayersInfoParameters)) {
@@ -121,7 +121,7 @@ export var LayerInfoService = ServiceBase.extend({
121121
* @function L.supermap.layerInfoService.prototype.setLayerStatus
122122
* @description 负责将子图层显示控制参数传递到服务端,并获取服务端返回的图层显示状态。
123123
* @param params -{SuperMap.SetLayerStatusParameters} 图层信息显示控制参数
124-
* @param callback -{function} 回调函数
124+
* @param {RequestCallback} callback 回调函数
125125
*/
126126
setLayerStatus: function (params, callback) {
127127
if (!(params instanceof SetLayerStatusParameters)) {

src/leaflet/services/MapService.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export var MapService = ServiceBase.extend({
3535
/**
3636
* @function L.supermap.mapService.prototype.getMapInfo
3737
* @description 获取地图信息
38-
* @param callback -{function} 回调函数
38+
* @param {RequestCallback} callback 回调函数
3939
*/
4040
getMapInfo: function (callback) {
4141
var me = this;
@@ -55,7 +55,7 @@ export var MapService = ServiceBase.extend({
5555
/**
5656
* @function L.supermap.mapService.prototype.getTilesets
5757
* @description 获取切片列表信息
58-
* @param callback -{function} 回调函数
58+
* @param {RequestCallback} callback 回调函数
5959
*/
6060
getTilesets: function (callback) {
6161
var me = this;

src/leaflet/services/MeasureService.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export var MeasureService = ServiceBase.extend({
3232
* @function L.supermap.measureService.prototype.measureDistance
3333
* @description 测距
3434
* @param params -{SuperMap.MeasureParameters} 测量相关参数类
35-
* @param callback - {function} 回调函数
35+
* @param {RequestCallback} callback 回调函数
3636
*/
3737
measureDistance: function (params, callback) {
3838
this.measure(MeasureMode.DISTANCE, params, callback);
@@ -43,7 +43,7 @@ export var MeasureService = ServiceBase.extend({
4343
* @function L.supermap.measureService.prototype.measureArea
4444
* @description 测面积
4545
* @param params -{SuperMap.MeasureParameters} 测量相关参数类
46-
* @param callback - {function} 回调函数
46+
* @param {RequestCallback} callback 回调函数
4747
*/
4848
measureArea: function (params, callback) {
4949
this.measure(MeasureMode.AREA, params, callback);
@@ -54,7 +54,7 @@ export var MeasureService = ServiceBase.extend({
5454
* @function L.supermap.measureService.measure
5555
* @param type -{SuperMap.MeasureMode} 量算模式
5656
* @param params -{SuperMap.MeasureParameters} 测量相关参数类
57-
* @param callback - {function} 回调函数
57+
* @param {RequestCallback} callback 回调函数
5858
*/
5959
measure: function (type, params, callback) {
6060
if (!(params instanceof MeasureParameters)) {

src/leaflet/services/NetworkAnalyst3DService.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export var NetworkAnalyst3DService = ServiceBase.extend({
3333
* @function L.supermap.networkAnalyst3DService.prototype.sinksFacilityAnalyst
3434
* @description 汇查找服务
3535
* @param params - {SuperMap.FacilityAnalystSinks3DParameters} 最近设施分析参数类(汇查找资源)
36-
* @param callback - {function} 回调函数
36+
* @param {RequestCallback} callback 回调函数
3737
*/
3838
sinksFacilityAnalyst: function (params, callback) {
3939
var me = this;
@@ -54,7 +54,7 @@ export var NetworkAnalyst3DService = ServiceBase.extend({
5454
* @function L.supermap.networkAnalyst3DService.prototype.sourcesFacilityAnalyst
5555
* @description 源查找服务
5656
* @param params -{SuperMap.FacilityAnalystSources3DParameters} 最近设施分析参数类(源查找服务)
57-
* @param callback - {function} 回调函数
57+
* @param {RequestCallback} callback 回调函数
5858
* @return {this} this
5959
*/
6060
sourcesFacilityAnalyst: function (params, callback) {
@@ -76,7 +76,7 @@ export var NetworkAnalyst3DService = ServiceBase.extend({
7676
* @function L.supermap.networkAnalyst3DService.prototype.traceUpFacilityAnalyst
7777
* @description 上游追踪资源服务
7878
* @param params - {SuperMap.FacilityAnalystTraceup3DParameters} 上游追踪资源参数类
79-
* @param callback - {function} 回调函数
79+
* @param {RequestCallback} callback 回调函数
8080
* @return {this} this
8181
*/
8282
traceUpFacilityAnalyst: function (params, callback) {
@@ -98,7 +98,7 @@ export var NetworkAnalyst3DService = ServiceBase.extend({
9898
* @function L.supermap.networkAnalyst3DService.prototype.traceDownFacilityAnalyst
9999
* @description 下游追踪资源服务
100100
* @param params {SuperMap.FacilityAnalystTracedown3DParameters} 下游追踪资源服务参数类
101-
* @param callback - {function} 回调函数
101+
* @param {RequestCallback} callback 回调函数
102102
*/
103103
traceDownFacilityAnalyst: function (params, callback) {
104104
var me = this;
@@ -119,7 +119,7 @@ export var NetworkAnalyst3DService = ServiceBase.extend({
119119
* @function L.supermap.networkAnalyst3DService.prototype.upstreamFacilityAnalyst
120120
* @description 上游关键设施查找服务
121121
* @param params -{SuperMap.FacilityAnalystUpstream3DParameters} 上游关键设施查找服务参数类
122-
* @param callback - {function} 回调函数
122+
* @param {RequestCallback} callback 回调函数
123123
*/
124124
upstreamFacilityAnalyst: function (params, callback) {
125125
var me = this;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy