forked from SuperMap/iClient-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatasourceService.js
More file actions
126 lines (120 loc) · 4.83 KB
/
DatasourceService.js
File metadata and controls
126 lines (120 loc) · 4.83 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
/* Copyright© 2000 - 2021 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 L from "leaflet";
import '../core/Base';
import {ServiceBase} from './ServiceBase';
import {DatasourceService as CommonDatasourceService} from '@supermap/iclient-common/iServer/DatasourceService';
import {SetDatasourceParameters,
CommonUtil
} from '@supermap/iclient-common';
/**
* @class L.supermap.datasourceService
* @classdesc 数据源服务类。
* @category iServer Data Datasource
* @extends {L.supermap.ServiceBase}
* @param {string} url - 数据源服务地址。
* @param {Object} options - 参数。
* @param {string} [options.proxy] - 服务代理地址。
* @param {SuperMap.ServerType} [options.serverType=SuperMap.ServerType.ISERVER] - 服务来源 ISERVER|IPORTAL|ONLINE。
* @param {boolean} [options.withCredentials=false] - 请求是否携带 cookie。
* @param {boolean} [options.crossOrigin] - 是否允许跨域请求。
* @param {Object} [options.headers] - 请求头。
*/
export var DatasourceService = ServiceBase.extend({
initialize: function (url,options) {
ServiceBase.prototype.initialize.call(this, url, options);
},
/**
* @function L.supermap.datasourceService.prototype.getDatasources
* @description 数据源集查询服务。
* @example
* L.supermap.datasourceService(url).getDatasources(function(result){
* //doSomething
* });
* @param {RequestCallback} callback - 回调函数。
*/
getDatasources: function (callback) {
const me = this;
const datasourceService = new CommonDatasourceService(me.url, {
proxy: me.options.proxy,
withCredentials: me.options.withCredentials,
crossOrigin: me.options.crossOrigin,
headers: me.options.headers,
serverType: me.options.serverType,
eventListeners: {
scope: me,
processCompleted: callback,
processFailed: callback
}
});
datasourceService.getDatasourcesService();
},
/**
* @function L.supermap.datasourceService.prototype.getDatasource
* @description 数据源信息查询服务。
* @example
* L.supermap.datasourceService(url).getDatasource(datasourceName,function(result){
* //doSomething
* });
* @param datasourceName - 数据源名称。
* @param {RequestCallback} callback - 回调函数。
*/
getDatasource: function (datasourceName, callback) {
if (!datasourceName) {
return;
}
const me = this;
const datasourceService = new CommonDatasourceService(me.url, {
proxy: me.options.proxy,
withCredentials: me.options.withCredentials,
crossOrigin:me.options.crossOrigin,
headers: me.options.headers,
serverType: me.options.serverType,
eventListeners: {
scope: me,
processCompleted: callback,
processFailed: callback
}
});
datasourceService.getDatasourceService(datasourceName);
},
/**
* @function L.supermap.datasourceService.prototype.setDatasource
* @description 数据源信息设置服务。可实现更改当前数据源信息。
* @example
* L.supermap.datasourceService(url).setDatasource(params, function(result){
* //doSomething
* });
* @param {SuperMap.SetDatasourceParameters} params - 数据源信息设置参数类。
* @param {RequestCallback} callback - 回调函数。
*/
setDatasource: function(params, callback) {
if (!(params instanceof SetDatasourceParameters)) {
return;
}
const datasourceParams = {
description: params.description ,
coordUnit: params.coordUnit,
distanceUnit: params.distanceUnit
};
const me = this;
const url = CommonUtil.urlPathAppend(me.url,`datasources/name/${params.datasourceName}`);
const datasourceService = new CommonDatasourceService(url, {
proxy: me.options.proxy,
withCredentials: me.options.withCredentials,
crossOrigin: me.options.crossOrigin,
headers: me.options.headers,
serverType: me.options.serverType,
eventListeners: {
processCompleted: callback,
processFailed: callback
}
});
datasourceService.setDatasourceService(datasourceParams);
}
});
export var datasourceService = function (url, options) {
return new DatasourceService(url, options);
};
L.supermap.datasourceService = datasourceService;