forked from SuperMap/iClient-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEditFeaturesService.js
More file actions
138 lines (124 loc) · 5.22 KB
/
EditFeaturesService.js
File metadata and controls
138 lines (124 loc) · 5.22 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
/* Copyright© 2000 - 2023 SuperMap Software Co.Ltd. All rights reserved.
* This program are made available under the terms of the Apache License, Version 2.0
* which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
import {Util} from '../commontypes/Util';
import {EditType} from '../REST';
import {CommonServiceBase} from './CommonServiceBase';
import {EditFeaturesParameters} from './EditFeaturesParameters';
import { FetchRequest } from '../util/FetchRequest';
/**
* @class EditFeaturesService
* @deprecatedclass SuperMap.EditFeaturesService
* @category iServer Data Feature
* @classdesc 数据服务中数据集添加、更新、删除服务类。
* @extends {CommonServiceBase}
* @param {string} url - 服务端的数据服务资源地址。请求数据服务中数据集编辑服务,URL 应为:</br>
* http://{服务器地址}:{服务端口号}/iserver/services/{数据服务名}/rest/data/datasources/name/{数据源名}/datasets/name/{数据集名} 。</br>
* 例如:http://localhost:8090/iserver/services/data-jingjin/rest/data/datasources/name/Jingjin/datasets/name/Landuse_R
* @param {Object} options - 参数。
* @param {Object} options.eventListeners - 事件监听器对象。有processCompleted属性可传入处理完成后的回调函数。processFailed属性传入处理失败后的回调函数。
* @param {DataFormat} [format] -查询结果返回格式,目前支持iServerJSON 和GeoJSON两种格式。参数格式为"ISERVER","GEOJSON"。
* @param {boolean} [options.crossOrigin] - 是否允许跨域请求。
* @param {Object} [options.headers] - 请求头。
* @example
* var myService = new EditFeaturesService(url, {eventListeners: {
* "processCompleted": editFeatureCompleted,
* "processFailed": editFeatureError
* }
* };
* @usage
*/
export class EditFeaturesService extends CommonServiceBase {
constructor(url, options) {
super(url, options);
/**
* @member {boolean} [EditFeaturesService.prototype.returnContent=false]
* @description要素添加时,isUseBatch 不传或传为 false 的情况下有效。true 表示直接返回新创建的要素的 ID 数组;false 表示返回创建的 featureResult 资源的 URI。
*/
this.returnContent = false;
/**
* @member {boolean} [EditFeaturesService.prototype.isUseBatch=false]
* @description 是否使用批量添加要素功能,要素添加时有效。
* 批量添加能够提高要素编辑效率。
* true 表示批量添加;false 表示不使用批量添加。
*/
this.isUseBatch = false;
if (options) {
Util.extend(this, options);
}
this.url = Util.urlPathAppend(this.url, 'features');
this.CLASS_NAME = "SuperMap.EditFeaturesService";
}
/**
* @function EditFeaturesService.prototype.destroy
* @override
*/
destroy() {
super.destroy();
var me = this;
me.returnContent = null;
me.isUseBatch = null;
me.fromIndex = null;
me.toIndex = null;
}
/**
* @function EditFeaturesService.prototype.processAsync
* @description 负责将客户端的更新参数传递到服务端。
* @param {EditFeaturesParameters} params - 编辑要素参数。
*/
processAsync(params) {
if (!(params instanceof EditFeaturesParameters)) {
return;
}
var me = this,
method = "POST",
ids = "",
editType = params.editType,
jsonParameters = null;
me.returnContent = params.returnContent;
me.isUseBatch = params.isUseBatch;
jsonParameters = EditFeaturesParameters.toJsonParameters(params);
if (editType === EditType.DELETE) {
ids = Util.toJSON(params.IDs);
jsonParameters = ids;
var urlWithIds = Util.urlAppend(me.url, Util.getParameterString({ids}))
if(FetchRequest.urlIsLong(urlWithIds)) {
me.url = Util.urlAppend(me.url, Util.getParameterString({_method: 'DELETE'}));
method = "POST";
} else{
me.url = urlWithIds;
method = "DELETE";
}
} else if (editType === EditType.UPDATE) {
method = "PUT";
} else {
if (me.isUseBatch) {
me.url = Util.urlAppend(me.url, `isUseBatch=${me.isUseBatch}`);
me.returnContent = false;
}
if (me.returnContent) {
me.url = Util.urlAppend(me.url, 'returnContent=true');
method = "POST";
}
}
me.request({
method: method,
data: jsonParameters,
scope: me,
success: me.serviceProcessCompleted,
failure: me.serviceProcessFailed
});
}
getMetaData(params){
var me = this;
var featureId = params.featureId;
me.url = Util.urlPathAppend(me.url, featureId +'/metadata');
me.request({
method: "GET",
data: null,
scope: me,
success: me.serviceProcessCompleted,
failure: me.serviceProcessFailed
});
}
}