-
Notifications
You must be signed in to change notification settings - Fork 287
Expand file tree
/
Copy pathServiceBase.js
More file actions
66 lines (58 loc) · 2.01 KB
/
ServiceBase.js
File metadata and controls
66 lines (58 loc) · 2.01 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
/* Copyright© 2000 - 2025 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";
/**
* @class ServiceBase
* @classdesc L.supermap 服务基类。
* @category iServer Core
* @param {string} url - 服务地址。
* @param {Object} options - 参数。
* @param {string} [options.proxy] - 服务代理地址。
* @param {boolean} [options.withCredentials] - 请求是否携带凭据。默认情况下,仅同源请求包含凭据。
* @param {boolean} [options.crossOrigin] - 是否允许跨域请求。
* @param {Object} [options.headers] - 请求头。
* @fires ServiceBase#initialized
* @fires ServiceBase#destroy
* @extends {L.Evented}
* @usage
*/
export var ServiceBase = L.Evented.extend({
options: {
url: null,
proxy: null,
withCredentials: null,
crossOrigin: null
},
initialize: function (url, dataUrl, options) {
if (url) {
url = (url.indexOf("/") !== url.length - 1) ?
url : url.substr(0, url.length - 1);
}
this.url = url;
if (typeof dataUrl === 'object') {
L.setOptions(this, dataUrl);
} else {
this.dataUrl = dataUrl;
L.setOptions(this, options);
}
/**
* @event ServiceBase#initialized
* @description 构造函数构造成功后触发。
* @property {ServiceBase} this - this 对象。
*/
this.fire("initialized", this);
},
/**
* @function ServiceBase.prototype.destroy
* @description 释放资源,将引用的资源属性置空。
*/
destroy: function () {
/**
* @event ServiceBase#destroy
* @description 资源释放成功后触发。
* @property {ServiceBase} this - this 对象。
*/
this.fire("destroy", this);
}
});