mobility-toolbox-js 2.0.1-beta.13 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api/RealtimeAPI.d.ts +279 -0
- package/api/RealtimeAPI.d.ts.map +1 -0
- package/api/RealtimeAPI.js +466 -0
- package/api/RoutingAPI.d.ts +37 -0
- package/api/RoutingAPI.d.ts.map +1 -0
- package/api/RoutingAPI.js +32 -12
- package/api/StopsAPI.d.ts +38 -0
- package/api/StopsAPI.d.ts.map +1 -0
- package/api/StopsAPI.js +33 -9
- package/api/index.d.ts +4 -0
- package/api/index.d.ts.map +1 -0
- package/api/index.js +3 -3
- package/api/typedefs.d.ts +179 -0
- package/api/typedefs.d.ts.map +1 -0
- package/api/typedefs.js +75 -0
- package/common/api/HttpAPI.d.ts +31 -0
- package/common/api/HttpAPI.d.ts.map +1 -0
- package/common/api/HttpAPI.js +54 -27
- package/common/api/WebSocketAPI.d.ts +153 -0
- package/common/api/WebSocketAPI.d.ts.map +1 -0
- package/common/api/WebSocketAPI.js +330 -164
- package/common/controls/ControlCommon.d.ts +76 -0
- package/common/controls/ControlCommon.d.ts.map +1 -0
- package/common/controls/ControlCommon.js +150 -0
- package/common/controls/CopyrightControlCommon.d.ts +13 -0
- package/common/controls/CopyrightControlCommon.d.ts.map +1 -0
- package/common/controls/CopyrightControlCommon.js +34 -0
- package/common/controls/StopFinderControlCommon.d.ts +55 -0
- package/common/controls/StopFinderControlCommon.d.ts.map +1 -0
- package/common/controls/StopFinderControlCommon.js +144 -0
- package/common/index.d.ts +3 -0
- package/common/index.d.ts.map +1 -0
- package/common/index.js +2 -4
- package/common/layers/LayerCommon.d.ts +94 -0
- package/common/layers/LayerCommon.d.ts.map +1 -0
- package/common/layers/LayerCommon.js +244 -0
- package/common/mixins/RealtimeLayerMixin.d.ts +286 -0
- package/common/mixins/RealtimeLayerMixin.d.ts.map +1 -0
- package/common/mixins/RealtimeLayerMixin.js +776 -0
- package/common/mixins/UserInteractionsLayerMixin.d.ts +60 -0
- package/common/mixins/UserInteractionsLayerMixin.d.ts.map +1 -0
- package/common/mixins/UserInteractionsLayerMixin.js +241 -0
- package/common/styles/index.d.ts +5 -0
- package/common/styles/index.d.ts.map +1 -0
- package/common/styles/index.js +4 -4
- package/common/styles/realtimeDefaultStyle.d.ts +36 -0
- package/common/styles/realtimeDefaultStyle.d.ts.map +1 -0
- package/common/styles/realtimeDefaultStyle.js +275 -0
- package/common/styles/realtimeDelayStyle.d.ts +12 -0
- package/common/styles/realtimeDelayStyle.d.ts.map +1 -0
- package/common/styles/realtimeDelayStyle.js +13 -0
- package/common/styles/realtimeHeadingStyle.d.ts +12 -0
- package/common/styles/realtimeHeadingStyle.d.ts.map +1 -0
- package/common/styles/realtimeHeadingStyle.js +85 -0
- package/common/styles/realtimeSimpleStyle.d.ts +4 -0
- package/common/styles/realtimeSimpleStyle.d.ts.map +1 -0
- package/common/styles/realtimeSimpleStyle.js +23 -0
- package/common/typedefs.d.ts +111 -0
- package/common/typedefs.d.ts.map +1 -0
- package/common/typedefs.js +52 -0
- package/common/utils/compareDepartures.d.ts +11 -0
- package/common/utils/compareDepartures.d.ts.map +1 -0
- package/common/utils/compareDepartures.js +35 -0
- package/common/utils/createCanvas.d.ts +10 -0
- package/common/utils/createCanvas.d.ts.map +1 -0
- package/common/utils/createCanvas.js +27 -0
- package/common/utils/createRealtimeFilters.d.ts +13 -0
- package/common/utils/createRealtimeFilters.d.ts.map +1 -0
- package/common/utils/createRealtimeFilters.js +74 -0
- package/common/utils/debounceDeparturesMessages.d.ts +12 -0
- package/common/utils/debounceDeparturesMessages.d.ts.map +1 -0
- package/common/utils/debounceDeparturesMessages.js +24 -0
- package/common/utils/debounceWebsocketMessages.d.ts +11 -0
- package/common/utils/debounceWebsocketMessages.d.ts.map +1 -0
- package/common/utils/debounceWebsocketMessages.js +29 -0
- package/common/utils/getLayersAsFlatArray.d.ts +3 -0
- package/common/utils/getLayersAsFlatArray.d.ts.map +1 -0
- package/common/utils/getLayersAsFlatArray.js +15 -0
- package/common/utils/getMapboxMapCopyrights.d.ts +18 -0
- package/common/utils/getMapboxMapCopyrights.d.ts.map +1 -0
- package/common/utils/getMapboxMapCopyrights.js +26 -15
- package/common/utils/getMapboxRender.d.ts +7 -0
- package/common/utils/getMapboxRender.d.ts.map +1 -0
- package/common/utils/getMapboxRender.js +87 -0
- package/common/utils/getMaplibreRender.d.ts +7 -0
- package/common/utils/getMaplibreRender.d.ts.map +1 -0
- package/common/utils/getMaplibreRender.js +38 -0
- package/common/utils/getRealtimeModeSuffix.d.ts +10 -0
- package/common/utils/getRealtimeModeSuffix.d.ts.map +1 -0
- package/common/utils/getRealtimeModeSuffix.js +7 -0
- package/common/utils/getUrlWithParams.d.ts +9 -0
- package/common/utils/getUrlWithParams.d.ts.map +1 -0
- package/common/utils/getUrlWithParams.js +18 -0
- package/common/utils/getVehiclePosition.d.ts +16 -0
- package/common/utils/getVehiclePosition.d.ts.map +1 -0
- package/common/utils/getVehiclePosition.js +67 -37
- package/common/utils/index.d.ts +17 -0
- package/common/utils/index.d.ts.map +1 -0
- package/common/utils/index.js +17 -5
- package/common/utils/realtimeConfig.d.ts +49 -0
- package/common/utils/realtimeConfig.d.ts.map +1 -0
- package/common/utils/realtimeConfig.js +173 -0
- package/common/utils/removeDuplicate.d.ts +10 -0
- package/common/utils/removeDuplicate.d.ts.map +1 -0
- package/common/utils/removeDuplicate.js +12 -5
- package/common/utils/renderTrajectories.d.ts +17 -0
- package/common/utils/renderTrajectories.d.ts.map +1 -0
- package/common/utils/renderTrajectories.js +110 -0
- package/common/utils/sortAndFilterDepartures.d.ts +16 -0
- package/common/utils/sortAndFilterDepartures.d.ts.map +1 -0
- package/common/utils/sortAndFilterDepartures.js +58 -0
- package/common/utils/sortByDelay.d.ts +3 -0
- package/common/utils/sortByDelay.d.ts.map +1 -0
- package/common/utils/sortByDelay.js +17 -15
- package/common/utils/timeUtils.d.ts +24 -0
- package/common/utils/timeUtils.d.ts.map +1 -0
- package/common/utils/timeUtils.js +34 -15
- package/iife.d.ts +3 -0
- package/iife.d.ts.map +1 -0
- package/iife.js +5 -0
- package/index.d.ts +10 -0
- package/index.d.ts.map +1 -0
- package/index.js +8 -6
- package/mapbox/controls/CopyrightControl.d.ts +29 -0
- package/mapbox/controls/CopyrightControl.d.ts.map +1 -0
- package/mapbox/controls/CopyrightControl.js +44 -25
- package/mapbox/controls/index.d.ts +2 -0
- package/mapbox/controls/index.d.ts.map +1 -0
- package/mapbox/controls/index.js +2 -1
- package/mapbox/index.d.ts +6 -0
- package/mapbox/index.d.ts.map +1 -0
- package/mapbox/index.js +5 -4
- package/mapbox/layers/Layer.d.ts +59 -0
- package/mapbox/layers/Layer.d.ts.map +1 -0
- package/mapbox/layers/Layer.js +99 -55
- package/mapbox/layers/RealtimeLayer.d.ts +181 -0
- package/mapbox/layers/RealtimeLayer.d.ts.map +1 -0
- package/mapbox/layers/RealtimeLayer.js +276 -0
- package/mapbox/layers/index.d.ts +3 -0
- package/mapbox/layers/index.d.ts.map +1 -0
- package/mapbox/layers/index.js +2 -2
- package/mapbox/utils/getMercatorResolution.d.ts +9 -0
- package/mapbox/utils/getMercatorResolution.d.ts.map +1 -0
- package/mapbox/utils/getMercatorResolution.js +18 -0
- package/mapbox/utils/getSourceCoordinates.d.ts +9 -0
- package/mapbox/utils/getSourceCoordinates.d.ts.map +1 -0
- package/mapbox/utils/getSourceCoordinates.js +27 -0
- package/mapbox/utils/index.d.ts +3 -0
- package/mapbox/utils/index.d.ts.map +1 -0
- package/mapbox/utils/index.js +2 -0
- package/mbt.js +26061 -16500
- package/mbt.js.map +4 -4
- package/mbt.min.js +205 -126
- package/mbt.min.js.map +4 -4
- package/ol/controls/CopyrightControl.d.ts +31 -0
- package/ol/controls/CopyrightControl.d.ts.map +1 -0
- package/ol/controls/CopyrightControl.js +62 -36
- package/ol/controls/RoutingControl.d.ts +193 -0
- package/ol/controls/RoutingControl.d.ts.map +1 -0
- package/ol/controls/RoutingControl.js +601 -357
- package/ol/controls/StopFinderControl.d.ts +30 -0
- package/ol/controls/StopFinderControl.d.ts.map +1 -0
- package/ol/controls/StopFinderControl.js +30 -8
- package/ol/controls/index.d.ts +4 -0
- package/ol/controls/index.d.ts.map +1 -0
- package/ol/controls/index.js +3 -3
- package/ol/index.d.ts +6 -0
- package/ol/index.d.ts.map +1 -0
- package/ol/index.js +5 -5
- package/ol/layers/Layer.d.ts +86 -0
- package/ol/layers/Layer.d.ts.map +1 -0
- package/ol/layers/Layer.js +163 -77
- package/ol/layers/MapGlLayer.d.ts +67 -0
- package/ol/layers/MapGlLayer.d.ts.map +1 -0
- package/ol/layers/MapGlLayer.js +218 -0
- package/ol/layers/MapboxLayer.d.ts +50 -0
- package/ol/layers/MapboxLayer.d.ts.map +1 -0
- package/ol/layers/MapboxLayer.js +99 -193
- package/ol/layers/MapboxStyleLayer.d.ts +129 -0
- package/ol/layers/MapboxStyleLayer.d.ts.map +1 -0
- package/ol/layers/MapboxStyleLayer.js +362 -171
- package/ol/layers/MaplibreLayer.d.ts +28 -0
- package/ol/layers/MaplibreLayer.d.ts.map +1 -0
- package/ol/layers/MaplibreLayer.js +30 -135
- package/ol/layers/RealtimeLayer.d.ts +202 -0
- package/ol/layers/RealtimeLayer.d.ts.map +1 -0
- package/ol/layers/RealtimeLayer.js +340 -0
- package/ol/layers/RoutingLayer.d.ts +34 -0
- package/ol/layers/RoutingLayer.d.ts.map +1 -0
- package/ol/layers/RoutingLayer.js +72 -48
- package/ol/layers/VectorLayer.d.ts +25 -0
- package/ol/layers/VectorLayer.d.ts.map +1 -0
- package/ol/layers/VectorLayer.js +34 -18
- package/ol/layers/WMSLayer.d.ts +42 -0
- package/ol/layers/WMSLayer.d.ts.map +1 -0
- package/ol/layers/WMSLayer.js +84 -34
- package/ol/layers/index.d.ts +9 -0
- package/ol/layers/index.d.ts.map +1 -0
- package/ol/layers/index.js +8 -8
- package/ol/styles/fullTrajectoryDelayStyle.d.ts +4 -0
- package/ol/styles/fullTrajectoryDelayStyle.d.ts.map +1 -0
- package/ol/styles/fullTrajectoryDelayStyle.js +26 -24
- package/ol/styles/fullTrajectoryStyle.d.ts +5 -0
- package/ol/styles/fullTrajectoryStyle.d.ts.map +1 -0
- package/ol/styles/fullTrajectoryStyle.js +40 -39
- package/ol/styles/index.d.ts +3 -0
- package/ol/styles/index.d.ts.map +1 -0
- package/ol/styles/index.js +2 -2
- package/package.json +81 -133
- package/setupTests.d.ts +2 -0
- package/setupTests.d.ts.map +1 -0
- package/setupTests.js +26 -0
- package/types/common.d.ts +122 -0
- package/types/index.d.ts +11 -0
- package/types/realtime.d.ts +320 -0
- package/types/routing.d.ts +206 -0
- package/types/stops.d.ts +143 -0
- package/README.md +0 -23
- package/api/RoutingAPI.test.js +0 -25
- package/api/StopsAPI.test.js +0 -22
- package/api/TralisAPI.js +0 -359
- package/api/TralisAPI.test.js +0 -67
- package/api/TralisAPIUtils.js +0 -43
- package/common/Tracker.js +0 -93
- package/common/api/HttpAPI.test.js +0 -50
- package/common/api/WebSocketAPI.test.js +0 -311
- package/common/controls/Control.js +0 -81
- package/common/controls/Control.test.js +0 -87
- package/common/layers/Layer.js +0 -213
- package/common/layers/Layer.test.js +0 -526
- package/common/mixins/CopyrightMixin.js +0 -24
- package/common/mixins/SearchMixin.js +0 -110
- package/common/mixins/TralisLayerMixin.js +0 -479
- package/common/styles/trackerDefaultStyle.js +0 -197
- package/common/styles/trackerDelayStyle.js +0 -8
- package/common/styles/trackerSimpleStyle.js +0 -18
- package/common/trackerConfig.js +0 -152
- package/common/trackerConfig.test.js +0 -23
- package/common/utils/createTrackerFilters.js +0 -56
- package/common/utils/createTrackerFilters.test.js +0 -79
- package/common/utils/getMapboxMapCopyrights.test.js +0 -40
- package/common/utils/getMapboxStyleUrl.js +0 -22
- package/common/utils/removeDuplicate.test.js +0 -19
- package/common/utils/timeUtils.test.js +0 -10
- package/mapbox/layers/Layer.test.js +0 -182
- package/mapbox/layers/TralisLayer.js +0 -182
- package/mapbox/layers/TralisLayer.test.js +0 -38
- package/mapbox/utils.js +0 -32
- package/ol/controls/CopyrightControl.test.js +0 -165
- package/ol/controls/RoutingControl.test.js +0 -151
- package/ol/controls/StopFinderControl.test.js +0 -48
- package/ol/layers/Layer.test.js +0 -174
- package/ol/layers/MapboxLayer.test.js +0 -160
- package/ol/layers/MapboxStyleLayer.test.js +0 -231
- package/ol/layers/RoutingLayer.test.js +0 -40
- package/ol/layers/TralisLayer.js +0 -185
- package/ol/layers/TralisLayer.test.js +0 -79
- package/ol/layers/VectorLayer.test.js +0 -87
- package/ol/layers/WMSLayer.test.js +0 -76
|
@@ -1,175 +1,341 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
},
|
|
10
|
-
closing: {
|
|
11
|
-
get: () => !!(this.websocket && this.websocket.readyState === this.websocket.CLOSING)
|
|
12
|
-
},
|
|
13
|
-
connecting: {
|
|
14
|
-
get: () => !!(this.websocket && this.websocket.readyState === this.websocket.CONNECTING)
|
|
15
|
-
},
|
|
16
|
-
open: {
|
|
17
|
-
get: () => !!(this.websocket && this.websocket.readyState === this.websocket.OPEN)
|
|
18
|
-
},
|
|
19
|
-
messagesOnOpen: {
|
|
20
|
-
value: [],
|
|
21
|
-
writable: true
|
|
22
|
-
},
|
|
23
|
-
subscriptions: {
|
|
24
|
-
value: [],
|
|
25
|
-
writable: true
|
|
26
|
-
},
|
|
27
|
-
subscribed: {
|
|
28
|
-
value: {},
|
|
29
|
-
writable: true
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
static getRequestString(method, params) {
|
|
34
|
-
let reqStr = `${method} ${params.channel}`;
|
|
35
|
-
reqStr += params.args ? ` ${params.args}` : "";
|
|
36
|
-
reqStr += params.id ? ` ${params.id}` : "";
|
|
37
|
-
return reqStr.trim();
|
|
38
|
-
}
|
|
39
|
-
connect(url, onOpen = () => {
|
|
40
|
-
}) {
|
|
41
|
-
if (this.websocket && !this.closed) {
|
|
42
|
-
this.websocket.close();
|
|
1
|
+
/**
|
|
2
|
+
* Class used to facilitate connection to a WebSocketAPI and
|
|
3
|
+
* also to manage properly messages send to the WebSocketAPI.
|
|
4
|
+
* This class must not contain any specific implementation.
|
|
5
|
+
*/
|
|
6
|
+
class WebSocketAPI {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.defineProperties();
|
|
43
9
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
10
|
+
defineProperties() {
|
|
11
|
+
Object.defineProperties(this, {
|
|
12
|
+
closed: {
|
|
13
|
+
get: () => !!(!this.websocket ||
|
|
14
|
+
this.websocket.readyState === this.websocket.CLOSED),
|
|
15
|
+
},
|
|
16
|
+
closing: {
|
|
17
|
+
get: () => !!(this.websocket &&
|
|
18
|
+
this.websocket.readyState === this.websocket.CLOSING),
|
|
19
|
+
},
|
|
20
|
+
connecting: {
|
|
21
|
+
get: () => !!(this.websocket &&
|
|
22
|
+
this.websocket.readyState === this.websocket.CONNECTING),
|
|
23
|
+
},
|
|
24
|
+
open: {
|
|
25
|
+
get: () => !!(this.websocket && this.websocket.readyState === this.websocket.OPEN),
|
|
26
|
+
},
|
|
27
|
+
/**
|
|
28
|
+
* Array of message to send on open.
|
|
29
|
+
* @type {Array<string>}
|
|
30
|
+
* @private
|
|
31
|
+
*/
|
|
32
|
+
messagesOnOpen: {
|
|
33
|
+
value: [],
|
|
34
|
+
writable: true,
|
|
35
|
+
},
|
|
36
|
+
/**
|
|
37
|
+
* Array of subscriptions.
|
|
38
|
+
* @type {Array<WebSocketSubscription>}
|
|
39
|
+
* @private
|
|
40
|
+
*/
|
|
41
|
+
subscriptions: {
|
|
42
|
+
value: [],
|
|
43
|
+
writable: true,
|
|
44
|
+
},
|
|
45
|
+
/**
|
|
46
|
+
* List of channels subscribed.
|
|
47
|
+
* @type {WebSocketSubscribed}
|
|
48
|
+
* @private
|
|
49
|
+
*/
|
|
50
|
+
subscribed: {
|
|
51
|
+
value: {},
|
|
52
|
+
writable: true,
|
|
53
|
+
},
|
|
54
|
+
});
|
|
53
55
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
/**
|
|
57
|
+
* Get the websocket request string.
|
|
58
|
+
*
|
|
59
|
+
* @param {string} method Request mehtod {GET, SUB}.
|
|
60
|
+
* @param {WebSocketParameters} params Request parameters.
|
|
61
|
+
* @param {string} params.channel Channel name
|
|
62
|
+
* @param {string} [params.args] Request arguments
|
|
63
|
+
* @param {Number|string} [params.id] Request identifier
|
|
64
|
+
* @return {string} request string
|
|
65
|
+
* @private
|
|
66
|
+
*/
|
|
67
|
+
static getRequestString(method, params = {}) {
|
|
68
|
+
let reqStr = `${method} ${params.channel}`;
|
|
69
|
+
reqStr += params.args ? ` ${params.args}` : '';
|
|
70
|
+
reqStr += params.id ? ` ${params.id}` : '';
|
|
71
|
+
return reqStr.trim();
|
|
61
72
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
73
|
+
/**
|
|
74
|
+
* (Re)connect the websocket.
|
|
75
|
+
*
|
|
76
|
+
* @param {string} url Websocket url.
|
|
77
|
+
* @param {function} onOpen Callback called when the websocket connection is opened and before subscriptions of previous subscriptions.
|
|
78
|
+
* @private
|
|
79
|
+
*/
|
|
80
|
+
connect(url, onOpen = () => { }) {
|
|
81
|
+
var _a;
|
|
82
|
+
// if no url specify, close the current websocket and do nothing.
|
|
83
|
+
if (!url) {
|
|
84
|
+
(_a = this.websocket) === null || _a === void 0 ? void 0 : _a.close();
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
// Behavior when a websocket already exists.
|
|
88
|
+
if (this.websocket) {
|
|
89
|
+
// If the current websocket has the same url and is open or is connecting, do nothing.
|
|
90
|
+
if (this.websocket.url === url && (this.open || this.connecting)) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
// If the current websocket has not the same url and is open or is connecting, close it.
|
|
94
|
+
if (this.websocket.url !== url && (this.open || this.connecting)) {
|
|
95
|
+
this.websocket.close();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/** @ignore */
|
|
99
|
+
this.websocket = new WebSocket(url);
|
|
100
|
+
if (!this.open) {
|
|
101
|
+
this.websocket.addEventListener('open', () => {
|
|
102
|
+
onOpen();
|
|
103
|
+
this.subscribePreviousSubscriptions();
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
onOpen();
|
|
108
|
+
this.subscribePreviousSubscriptions();
|
|
109
|
+
}
|
|
66
110
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
this.websocket.
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
111
|
+
/**
|
|
112
|
+
* Close the websocket definitively.
|
|
113
|
+
*
|
|
114
|
+
* @private
|
|
115
|
+
*/
|
|
116
|
+
close() {
|
|
117
|
+
if (this.websocket && (this.open || this.connecting)) {
|
|
118
|
+
this.websocket.onclose = () => { };
|
|
119
|
+
this.websocket.close();
|
|
120
|
+
this.messagesOnOpen = [];
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Sends a message to the websocket.
|
|
125
|
+
*
|
|
126
|
+
* @param {message} message Message to send.
|
|
127
|
+
* @private
|
|
128
|
+
*/
|
|
129
|
+
send(message) {
|
|
130
|
+
if (!this.websocket || this.closed || this.closing) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const send = () => {
|
|
134
|
+
var _a;
|
|
135
|
+
(_a = this.websocket) === null || _a === void 0 ? void 0 : _a.send(message);
|
|
136
|
+
};
|
|
137
|
+
if (!this.open) {
|
|
138
|
+
// This 'if' avoid sending 2 identical BBOX message on open,
|
|
139
|
+
if (!this.messagesOnOpen.includes(message)) {
|
|
140
|
+
this.messagesOnOpen.push(message);
|
|
141
|
+
this.websocket.addEventListener('open', () => {
|
|
142
|
+
this.messagesOnOpen = [];
|
|
143
|
+
send();
|
|
144
|
+
});
|
|
145
|
+
this.websocket.addEventListener('close', () => {
|
|
146
|
+
this.messagesOnOpen = [];
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
else if (!this.messagesOnOpen.includes(message)) {
|
|
151
|
+
send();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
addEvents(onMessage, onError) {
|
|
155
|
+
if (this.websocket) {
|
|
156
|
+
this.websocket.addEventListener('message', onMessage);
|
|
157
|
+
if (onError) {
|
|
158
|
+
this.websocket.addEventListener('error', onError);
|
|
159
|
+
this.websocket.addEventListener('close', onError);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
83
162
|
}
|
|
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
|
-
|
|
163
|
+
removeEvents(onMessage, onError) {
|
|
164
|
+
if (this.websocket) {
|
|
165
|
+
this.websocket.removeEventListener('message', onMessage);
|
|
166
|
+
if (onError) {
|
|
167
|
+
this.websocket.removeEventListener('error', onError);
|
|
168
|
+
this.websocket.removeEventListener('close', onError);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Listen to websocket messages.
|
|
174
|
+
*
|
|
175
|
+
* @param {WebSocketParameters} params Parameters for the websocket get request
|
|
176
|
+
* @param {function} cb callback on listen
|
|
177
|
+
* @param {function} errorCb Callback on error
|
|
178
|
+
* @return {{onMessage: function, errorCb: function}} Object with onMessage and error callbacks
|
|
179
|
+
* @private
|
|
180
|
+
*/
|
|
181
|
+
listen(params, cb, errorCb) {
|
|
182
|
+
// Remove the previous identical callback
|
|
183
|
+
this.unlisten(params, cb);
|
|
184
|
+
// We wrap the message callback to be sure we only propagate the message if it is for the right channel.
|
|
185
|
+
const onMessage = (evt) => {
|
|
186
|
+
let data;
|
|
187
|
+
try {
|
|
188
|
+
data = JSON.parse(evt.data);
|
|
189
|
+
}
|
|
190
|
+
catch (err) {
|
|
191
|
+
// eslint-disable-next-line no-console
|
|
192
|
+
console.error('WebSocket: unable to parse JSON data', err, evt.data);
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
let source = params.channel;
|
|
196
|
+
source += params.args ? ` ${params.args}` : '';
|
|
197
|
+
// Buffer channel message return a list of other channels to propagate to proper callbacks.
|
|
198
|
+
let contents;
|
|
199
|
+
if (data.source === 'buffer') {
|
|
200
|
+
contents = data
|
|
201
|
+
.content;
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
contents = [data];
|
|
205
|
+
}
|
|
206
|
+
contents.forEach((content) => {
|
|
207
|
+
// Because of backend optimization, the last content is null.
|
|
208
|
+
if ((content === null || content === void 0 ? void 0 : content.source) === source &&
|
|
209
|
+
(!params.id || params.id === data.client_reference)) {
|
|
210
|
+
cb(content);
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
};
|
|
214
|
+
this.addEvents(onMessage, errorCb);
|
|
215
|
+
return { onMessageCb: onMessage, onErrorCb: errorCb };
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Unlisten websocket messages.
|
|
219
|
+
*
|
|
220
|
+
* @param {Object} params Parameters for the websocket get request.
|
|
221
|
+
* @param {function} cb Callback used when listen.
|
|
222
|
+
* @private
|
|
223
|
+
*/
|
|
224
|
+
unlisten(params, cb) {
|
|
225
|
+
[...(this.subscriptions || []), ...(this.requests || [])]
|
|
226
|
+
.filter((s) => s.params.channel === params.channel && (!cb || s.cb === cb))
|
|
227
|
+
.forEach(({ onMessageCb, onErrorCb }) => {
|
|
228
|
+
this.removeEvents(onMessageCb, onErrorCb);
|
|
229
|
+
});
|
|
109
230
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
231
|
+
/**
|
|
232
|
+
* Sends a get request to the websocket.
|
|
233
|
+
* The callback is called only once, when the response is received or when the call returns an error.
|
|
234
|
+
*
|
|
235
|
+
* @param {Object} params Parameters for the websocket get request
|
|
236
|
+
* @param {function} onMessage callback on message event
|
|
237
|
+
* @param {function} onError Callback on error and close event
|
|
238
|
+
* @private
|
|
239
|
+
*/
|
|
240
|
+
get(params, cb, errorCb) {
|
|
241
|
+
const requestString = WebSocketAPI.getRequestString('GET', params);
|
|
242
|
+
this.send(requestString);
|
|
243
|
+
// We wrap the callbacks to make sure they are called only once.
|
|
244
|
+
const once = (callback) =>
|
|
245
|
+
// @ts-ignore: Spread error
|
|
246
|
+
(...args) => {
|
|
247
|
+
// @ts-ignore: Spread error
|
|
248
|
+
callback(...args);
|
|
249
|
+
const index = this.requests.findIndex((request) => requestString === request.requestString && cb === request.cb);
|
|
250
|
+
const { onMessageCb, onErrorCb } = this.requests[index];
|
|
251
|
+
this.removeEvents(onMessageCb, onErrorCb);
|
|
252
|
+
this.requests.splice(index, 1);
|
|
253
|
+
};
|
|
254
|
+
const { onMessageCb, onErrorCb } = this.listen(params, once(cb), errorCb && once(errorCb));
|
|
255
|
+
// Store requests and callbacks to be able to remove them.
|
|
256
|
+
if (!this.requests) {
|
|
257
|
+
this.requests = [];
|
|
258
|
+
}
|
|
259
|
+
const index = this.requests.findIndex((request) => requestString === request.requestString && cb === request.cb);
|
|
260
|
+
const newReq = {
|
|
261
|
+
params,
|
|
262
|
+
requestString,
|
|
263
|
+
cb,
|
|
264
|
+
errorCb,
|
|
265
|
+
onMessageCb,
|
|
266
|
+
onErrorCb,
|
|
267
|
+
};
|
|
268
|
+
if (index > -1) {
|
|
269
|
+
this.requests[index] = newReq;
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
this.requests.push(newReq);
|
|
273
|
+
}
|
|
115
274
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
275
|
+
/**
|
|
276
|
+
* Subscribe to a given channel.
|
|
277
|
+
*
|
|
278
|
+
* @param {Object} params Parameters for the websocket get request
|
|
279
|
+
* @param {function} cb callback on listen
|
|
280
|
+
* @param {function} errorCb Callback on error
|
|
281
|
+
* @param {boolean} quiet if false, no GET or SUB requests are send, only the callback is registered.
|
|
282
|
+
* @private
|
|
283
|
+
*/
|
|
284
|
+
subscribe(params, cb, errorCb, quiet = false) {
|
|
285
|
+
const { onMessageCb, onErrorCb } = this.listen(params, cb, errorCb);
|
|
286
|
+
const reqStr = WebSocketAPI.getRequestString('', params);
|
|
287
|
+
const index = this.subscriptions.findIndex((subcr) => params.channel === subcr.params.channel && cb === subcr.cb);
|
|
288
|
+
const newSubscr = { params, cb, errorCb, onMessageCb, onErrorCb, quiet };
|
|
289
|
+
if (index > -1) {
|
|
290
|
+
this.subscriptions[index] = newSubscr;
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
this.subscriptions.push(newSubscr);
|
|
294
|
+
}
|
|
295
|
+
if (!this.subscribed[reqStr]) {
|
|
296
|
+
if (!newSubscr.quiet) {
|
|
297
|
+
this.send(`GET ${reqStr}`);
|
|
298
|
+
this.send(`SUB ${reqStr}`);
|
|
299
|
+
}
|
|
300
|
+
this.subscribed[reqStr] = true;
|
|
301
|
+
}
|
|
140
302
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
303
|
+
/**
|
|
304
|
+
* Unsubscribe from a channel.
|
|
305
|
+
* @param {string} source source to unsubscribe from
|
|
306
|
+
* @param {function} cb Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
|
|
307
|
+
* @private
|
|
308
|
+
*/
|
|
309
|
+
unsubscribe(source, cb) {
|
|
310
|
+
const toRemove = this.subscriptions.filter((s) => s.params.channel === source && (!cb || s.cb === cb));
|
|
311
|
+
toRemove.forEach(({ onMessageCb, onErrorCb }) => {
|
|
312
|
+
this.removeEvents(onMessageCb, onErrorCb);
|
|
313
|
+
});
|
|
314
|
+
this.subscriptions = this.subscriptions.filter((s) => s.params.channel !== source || (cb && s.cb !== cb));
|
|
315
|
+
// If there is no more subscriptions to this channel, and the removed subscriptions didn't register quietly,
|
|
316
|
+
// we DEL it.
|
|
317
|
+
if (source &&
|
|
318
|
+
this.subscribed[source] &&
|
|
319
|
+
!this.subscriptions.find((s) => s.params.channel === source) &&
|
|
320
|
+
toRemove.find((subscr) => !subscr.quiet)) {
|
|
321
|
+
this.send(`DEL ${source}`);
|
|
322
|
+
this.subscribed[source] = false;
|
|
323
|
+
}
|
|
147
324
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
this.send(`DEL ${source}`);
|
|
163
|
-
this.subscribed[source] = false;
|
|
325
|
+
/**
|
|
326
|
+
* After an auto reconnection we need to re-subscribe to the channels.
|
|
327
|
+
*/
|
|
328
|
+
subscribePreviousSubscriptions() {
|
|
329
|
+
// Before to subscribe previous subscriptions we make sure they
|
|
330
|
+
// are all defined as unsubscribed, because this code is asynchrone
|
|
331
|
+
// and a subscription could have been added in between.
|
|
332
|
+
Object.keys(this.subscribed).forEach((key) => {
|
|
333
|
+
this.subscribed[key] = false;
|
|
334
|
+
});
|
|
335
|
+
// Subscribe all previous subscriptions.
|
|
336
|
+
[...this.subscriptions].forEach((s) => {
|
|
337
|
+
this.subscribe(s.params, s.cb, s.errorCb, s.quiet);
|
|
338
|
+
});
|
|
164
339
|
}
|
|
165
|
-
}
|
|
166
|
-
subscribePreviousSubscriptions() {
|
|
167
|
-
Object.keys(this.subscribed).forEach((key) => {
|
|
168
|
-
this.subscribed[key] = false;
|
|
169
|
-
});
|
|
170
|
-
[...this.subscriptions].forEach((s) => {
|
|
171
|
-
this.subscribe(s.params, s.cb, s.errorCb, s.quiet);
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
340
|
}
|
|
175
|
-
export default
|
|
341
|
+
export default WebSocketAPI;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import BaseObject from 'ol/Object';
|
|
2
|
+
import type { AnyMap } from '../../types';
|
|
3
|
+
export type ControlCommonOptions = {
|
|
4
|
+
active?: Boolean;
|
|
5
|
+
element?: HTMLElement;
|
|
6
|
+
target?: HTMLElement;
|
|
7
|
+
render?: () => void;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* A class representing a control to display on map.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const control = new Control();
|
|
14
|
+
*
|
|
15
|
+
* @classproperty {ol/Map~Map|mapboxgl.Map} map - The map which the control refers to.
|
|
16
|
+
* @classproperty {boolean} active - Active the control.
|
|
17
|
+
* @classproperty {HTMLElement} element - The HTML element used to render the control.
|
|
18
|
+
* @classproperty {HTMLElement} target - The HTML element where to render the element property. Default is the map's element. Read only.
|
|
19
|
+
*/
|
|
20
|
+
declare class ControlCommon extends BaseObject {
|
|
21
|
+
active: Boolean;
|
|
22
|
+
map?: AnyMap;
|
|
23
|
+
target?: HTMLElement;
|
|
24
|
+
element?: HTMLElement;
|
|
25
|
+
/**
|
|
26
|
+
* Constructor
|
|
27
|
+
*
|
|
28
|
+
* @param {Object} [options] Control options.
|
|
29
|
+
* @param {boolean} [options.active = true] Whether the control is active or not.
|
|
30
|
+
* @param {HTMLElement} [options.element] The HTML element used to render the control.
|
|
31
|
+
* @param {HTMLElement} [options.target] The HTML element where to render the element property. Default is the map's element.
|
|
32
|
+
* @param {function} [options.render] Render function called whenever the control needs to be rerendered.
|
|
33
|
+
*/
|
|
34
|
+
constructor(options?: ControlCommonOptions);
|
|
35
|
+
/**
|
|
36
|
+
* Define control's properties.
|
|
37
|
+
*
|
|
38
|
+
* @private
|
|
39
|
+
* @ignore
|
|
40
|
+
*/
|
|
41
|
+
defineProperties(options: ControlCommonOptions): void;
|
|
42
|
+
/**
|
|
43
|
+
* Attach the control to the map. Add events, html element ...
|
|
44
|
+
*/
|
|
45
|
+
attachToMap(map: AnyMap): void;
|
|
46
|
+
/**
|
|
47
|
+
* Detach the control From the map. Remove events, html element ..
|
|
48
|
+
*/
|
|
49
|
+
detachFromMap(): void;
|
|
50
|
+
/**
|
|
51
|
+
* Add listeners then renders the control.
|
|
52
|
+
* To be defined in inherited classes.
|
|
53
|
+
*/
|
|
54
|
+
activate(): void;
|
|
55
|
+
/**
|
|
56
|
+
* Remove listeners added by activate() function then renders the control.
|
|
57
|
+
* To be defined in inherited classes.
|
|
58
|
+
*/
|
|
59
|
+
deactivate(): void;
|
|
60
|
+
/**
|
|
61
|
+
* The default render function. It renders content in the HTML element.
|
|
62
|
+
* To be defined in inherited classes.
|
|
63
|
+
*
|
|
64
|
+
* @private
|
|
65
|
+
*/
|
|
66
|
+
render(options?: any): void;
|
|
67
|
+
/**
|
|
68
|
+
* The default element to display if this.element is not defined.
|
|
69
|
+
* To be defined in inherited classes.
|
|
70
|
+
*
|
|
71
|
+
* @private
|
|
72
|
+
*/
|
|
73
|
+
createDefaultElement(): void;
|
|
74
|
+
}
|
|
75
|
+
export default ControlCommon;
|
|
76
|
+
//# sourceMappingURL=ControlCommon.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ControlCommon.d.ts","sourceRoot":"","sources":["../../../src/common/controls/ControlCommon.ts"],"names":[],"mappings":"AACA,OAAO,UAAU,MAAM,WAAW,CAAC;AACnC,OAAO,KAAK,EAAE,MAAM,EAAgB,MAAM,aAAa,CAAC;AAExD,MAAM,MAAM,oBAAoB,GAAG;IACjC,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;CACrB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,cAAM,aAAc,SAAQ,UAAU;IACpC,MAAM,EAAE,OAAO,CAAC;IAEhB,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb,MAAM,CAAC,EAAE,WAAW,CAAC;IAErB,OAAO,CAAC,EAAE,WAAW,CAAC;IAEtB;;;;;;;;OAQG;gBACS,OAAO,GAAE,oBAAyB;IAe9C;;;;;OAKG;IACH,gBAAgB,CAAC,OAAO,EAAE,oBAAoB;IAuE9C;;OAEG;IACH,WAAW,CAAC,GAAG,EAAE,MAAM;IAIvB;;OAEG;IACH,aAAa;IAIb;;;OAGG;IACH,QAAQ;IAIR;;;OAGG;IAEH,UAAU;IAOV;;;;;OAKG;IAEH,MAAM,CAAC,OAAO,CAAC,EAAE,GAAG;IAKpB;;;;;OAKG;IAEH,oBAAoB;CAMrB;AAED,eAAe,aAAa,CAAC"}
|