forked from SuperMap/iClient-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataFlowService.js
More file actions
125 lines (110 loc) · 3.78 KB
/
DataFlowService.js
File metadata and controls
125 lines (110 loc) · 3.78 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
import mapboxgl from 'mapbox-gl';
import '../core/Base';
import {ServiceBase} from './ServiceBase';
import {DataFlowService as DataFlow} from '@supermap/iclient-common';
/**
* @class mapboxgl.supermap.DataFlowService
* @category iServer DataFlow
* @classdesc 实时数据服务
* @extends mapboxgl.supermap.ServiceBase
* @example
* new mapboxgl.supermap.DataFlowService(url)
* .queryChart(param,function(result){
* //doSomething
* })
* @param url - {string} 与客户端交互的实时数据服务地址。
* @param options - {Object} 加载实时数据可选参数。如:<br>
* style - {function} 设置数据加载样式。<br>
* onEachFeature - {function} 设置每个数据加载popup等。<br>
* geometry - {Array<Object>} 设置增添的几何要素对象数组。<br>
* excludeField - -{Object} 排除字段
*/
export class DataFlowService extends ServiceBase {
constructor(url, options) {
super(url, options);
options = options || {};
if (options.projection) {
this.options.prjCoordSys = options.projection;
}
ServiceBase.call(this, url, options);
this.dataFlow = new DataFlow(url, options);
this.dataFlow.events.on({
"broadcastSocketConnected": this._defaultEvent,
"broadcastSocketError": this._defaultEvent,
"broadcastFailed": this._defaultEvent,
"broadcastSuccessed": this._defaultEvent,
"subscribeSocketConnected": this._defaultEvent,
"subscribeSocketError": this._defaultEvent,
"messageSuccessed": this._defaultEvent,
"setFilterParamSuccessed": this._defaultEvent,
scope: this
});
var me = this;
me.on('subscribeSocketConnected', function (e) {
me.fire('subscribeSuccessed', e);
})
}
/**
* @function mapboxgl.supermap.DataFlowService.prototype.initBroadcast
* @description 初始化广播
* @returns {mapboxgl.supermap.DataFlowService}
*/
initBroadcast() {
this.dataFlow.initBroadcast();
return this;
}
/**
* @function mapboxgl.supermap.DataFlowService.prototype.broadcast
* @description 加载广播数据
* @param obj {JSON} json格式的要素数据
*/
broadcast(obj) {
this.dataFlow.broadcast(obj);
}
/**
* @function mapboxgl.supermap.DataFlowService.prototype.initSubscribe
* @description 初始化订阅数据
*/
initSubscribe() {
this.dataFlow.initSubscribe();
return this;
}
/**
* @function mapboxgl.supermap.DataFlowService.prototype.setExcludeField
* @description 设置排除字段
* @param excludeField - {Object} 排除字段
*/
setExcludeField(excludeField) {
this.dataFlow.setExcludeField(excludeField);
this.options.excludeField = excludeField;
return this;
}
/**
* @function mapboxgl.supermap.DataFlowService.prototype.setGeometry
* @description 设置添加的几何要素数据
* @param geometry - {Array<Object>} 设置增添的几何要素对象数组。
*/
setGeometry(geometry) {
this.dataFlow.setGeometry(geometry);
this.options.geometry = geometry;
return this;
}
/**
* @function mapboxgl.supermap.DataFlowService.prototype.unSubscribe
* @description 结束订阅数据
*/
unSubscribe() {
this.dataFlow.unSubscribe();
}
/**
* @function mapboxgl.supermap.DataFlowService.prototype.unBroadcast
* @description 结束加载广播
*/
unBroadcast() {
this.dataFlow.unBroadcast();
}
_defaultEvent(e) {
this.fire(e.eventType || e.type, e);
}
}
mapboxgl.supermap.DataFlowService = DataFlowService;