mobility-toolbox-js 2.0.0 → 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 +35 -0
- package/api/StopsAPI.d.ts +38 -0
- package/api/StopsAPI.d.ts.map +1 -0
- package/api/StopsAPI.js +36 -0
- 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/{tralis/typedefs.js → typedefs.js} +4 -10
- package/common/api/HttpAPI.d.ts +31 -0
- package/common/api/HttpAPI.d.ts.map +1 -0
- package/common/api/HttpAPI.js +57 -0
- package/common/api/WebSocketAPI.d.ts +153 -0
- package/common/api/WebSocketAPI.d.ts.map +1 -0
- package/common/api/WebSocketAPI.js +341 -0
- 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 -0
- 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/{trackerDelayStyle.js → realtimeDelayStyle.d.ts} +4 -9
- 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 +35 -6
- 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 +21 -23
- 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 +60 -60
- package/common/utils/index.d.ts +17 -0
- package/common/utils/index.d.ts.map +1 -0
- package/common/utils/index.js +13 -2
- 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 +5 -12
- 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 -20
- package/common/utils/timeUtils.d.ts +24 -0
- package/common/utils/timeUtils.d.ts.map +1 -0
- package/common/utils/timeUtils.js +13 -18
- 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 +10 -2
- package/mapbox/controls/CopyrightControl.d.ts +29 -0
- package/mapbox/controls/CopyrightControl.d.ts.map +1 -0
- package/mapbox/controls/CopyrightControl.js +25 -35
- package/mapbox/controls/index.d.ts +2 -0
- package/mapbox/controls/index.d.ts.map +1 -0
- package/mapbox/controls/index.js +2 -0
- package/mapbox/index.d.ts +6 -0
- package/mapbox/index.d.ts.map +1 -0
- package/mapbox/index.js +5 -3
- package/mapbox/layers/Layer.d.ts +59 -0
- package/mapbox/layers/Layer.d.ts.map +1 -0
- package/mapbox/layers/Layer.js +78 -95
- 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 -0
- 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 +60005 -0
- package/mbt.js.map +7 -0
- package/mbt.min.js +1084 -0
- package/mbt.min.js.map +7 -0
- package/ol/controls/CopyrightControl.d.ts +31 -0
- package/ol/controls/CopyrightControl.d.ts.map +1 -0
- package/ol/controls/CopyrightControl.js +44 -56
- package/ol/controls/RoutingControl.d.ts +193 -0
- package/ol/controls/RoutingControl.d.ts.map +1 -0
- package/ol/controls/RoutingControl.js +546 -667
- package/ol/controls/StopFinderControl.d.ts +30 -0
- package/ol/controls/StopFinderControl.d.ts.map +1 -0
- package/ol/controls/StopFinderControl.js +10 -16
- package/ol/controls/index.d.ts +4 -0
- package/ol/controls/index.d.ts.map +1 -0
- package/ol/controls/index.js +3 -0
- package/ol/index.d.ts +6 -0
- package/ol/index.d.ts.map +1 -0
- package/ol/index.js +4 -12
- package/ol/layers/Layer.d.ts +86 -0
- package/ol/layers/Layer.d.ts.map +1 -0
- package/ol/layers/Layer.js +147 -166
- 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 +79 -348
- package/ol/layers/MapboxStyleLayer.d.ts +129 -0
- package/ol/layers/MapboxStyleLayer.d.ts.map +1 -0
- package/ol/layers/MapboxStyleLayer.js +329 -368
- package/ol/layers/MaplibreLayer.d.ts +28 -0
- package/ol/layers/MaplibreLayer.d.ts.map +1 -0
- package/ol/layers/MaplibreLayer.js +13 -259
- 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 +62 -68
- package/ol/layers/VectorLayer.d.ts +25 -0
- package/ol/layers/VectorLayer.d.ts.map +1 -0
- package/ol/layers/VectorLayer.js +27 -32
- package/ol/layers/WMSLayer.d.ts +42 -0
- package/ol/layers/WMSLayer.d.ts.map +1 -0
- package/ol/layers/WMSLayer.js +74 -66
- package/ol/layers/index.d.ts +9 -0
- package/ol/layers/index.d.ts.map +1 -0
- package/ol/layers/index.js +8 -0
- package/ol/styles/fullTrajectoryDelayStyle.d.ts +4 -0
- package/ol/styles/fullTrajectoryDelayStyle.d.ts.map +1 -0
- package/ol/styles/fullTrajectoryDelayStyle.js +23 -25
- package/ol/styles/fullTrajectoryStyle.d.ts +5 -0
- package/ol/styles/fullTrajectoryStyle.d.ts.map +1 -0
- package/ol/styles/fullTrajectoryStyle.js +37 -44
- package/ol/styles/index.d.ts +3 -0
- package/ol/styles/index.d.ts.map +1 -0
- package/package.json +98 -177
- 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/routing/RoutingAPI.js +0 -44
- package/api/routing/RoutingAPI.test.js +0 -41
- package/api/stops/StopsAPI.js +0 -41
- package/api/stops/StopsAPI.test.js +0 -34
- package/api/tralis/TralisAPI.js +0 -731
- package/api/tralis/TralisAPI.test.js +0 -75
- package/api/tralis/TralisAPIUtils.js +0 -73
- package/api/tralis/WebSocketConnector.js +0 -338
- package/api/tralis/WebSocketConnector.test.js +0 -356
- package/common/Tracker.js +0 -197
- package/common/api/api.js +0 -64
- package/common/api/api.test.js +0 -68
- package/common/controls/Control.js +0 -146
- package/common/controls/Control.test.js +0 -98
- package/common/layers/Layer.js +0 -404
- package/common/layers/Layer.test.js +0 -585
- package/common/mixins/CopyrightMixin.js +0 -48
- package/common/mixins/SearchMixin.js +0 -176
- package/common/mixins/TralisLayerMixin.js +0 -930
- package/common/styles/trackerDefaultStyle.js +0 -333
- package/common/styles/trackerSimpleStyle.js +0 -22
- package/common/trackerConfig.js +0 -190
- package/common/trackerConfig.test.js +0 -25
- package/common/utils/createTrackerFilters.js +0 -87
- package/common/utils/createTrackerFilters.test.js +0 -95
- package/common/utils/getMapboxMapCopyrights.test.js +0 -47
- package/common/utils/getMapboxStyleUrl.js +0 -32
- package/common/utils/removeDuplicate.test.js +0 -22
- package/common/utils/timeUtils.test.js +0 -16
- package/index.js.map +0 -1
- package/mapbox/layers/Layer.test.js +0 -202
- package/mapbox/layers/TralisLayer.js +0 -329
- package/mapbox/layers/TralisLayer.test.js +0 -40
- package/mapbox/utils.js +0 -46
- package/module.js +0 -23
- package/ol/README.md +0 -0
- package/ol/controls/CopyrightControl.test.js +0 -211
- package/ol/controls/RoutingControl.test.js +0 -216
- package/ol/controls/StopFinderControl.test.js +0 -59
- package/ol/controls/snapshots/RoutingControlRouteGen10.json +0 -58
- package/ol/controls/snapshots/RoutingControlRouteGen100.json +0 -292
- package/ol/controls/snapshots/RoutingControlRouteGen30.json +0 -69
- package/ol/controls/snapshots/RoutingControlRouteGen5.json +0 -58
- package/ol/controls/snapshots/RoutingControlRouteOSM.json +0 -759
- package/ol/controls/snapshots/RoutingControlStation1.json +0 -60
- package/ol/controls/snapshots/RoutingControlStation2.json +0 -49
- package/ol/layers/Layer.test.js +0 -197
- package/ol/layers/MapboxLayer.test.js +0 -186
- package/ol/layers/MapboxStyleLayer.test.js +0 -262
- package/ol/layers/RoutingLayer.test.js +0 -49
- package/ol/layers/TralisLayer.js +0 -359
- package/ol/layers/TralisLayer.test.js +0 -97
- package/ol/layers/VectorLayer.test.js +0 -98
- package/ol/layers/WMSLayer.test.js +0 -84
|
@@ -0,0 +1,341 @@
|
|
|
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();
|
|
9
|
+
}
|
|
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
|
+
});
|
|
55
|
+
}
|
|
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();
|
|
72
|
+
}
|
|
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
|
+
}
|
|
110
|
+
}
|
|
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
|
+
}
|
|
162
|
+
}
|
|
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
|
+
});
|
|
230
|
+
}
|
|
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
|
+
}
|
|
274
|
+
}
|
|
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
|
+
}
|
|
302
|
+
}
|
|
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
|
+
}
|
|
324
|
+
}
|
|
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
|
+
});
|
|
339
|
+
}
|
|
340
|
+
}
|
|
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"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import BaseObject from 'ol/Object';
|
|
2
|
+
/**
|
|
3
|
+
* A class representing a control to display on map.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* const control = new Control();
|
|
7
|
+
*
|
|
8
|
+
* @classproperty {ol/Map~Map|mapboxgl.Map} map - The map which the control refers to.
|
|
9
|
+
* @classproperty {boolean} active - Active the control.
|
|
10
|
+
* @classproperty {HTMLElement} element - The HTML element used to render the control.
|
|
11
|
+
* @classproperty {HTMLElement} target - The HTML element where to render the element property. Default is the map's element. Read only.
|
|
12
|
+
*/
|
|
13
|
+
class ControlCommon extends BaseObject {
|
|
14
|
+
/**
|
|
15
|
+
* Constructor
|
|
16
|
+
*
|
|
17
|
+
* @param {Object} [options] Control options.
|
|
18
|
+
* @param {boolean} [options.active = true] Whether the control is active or not.
|
|
19
|
+
* @param {HTMLElement} [options.element] The HTML element used to render the control.
|
|
20
|
+
* @param {HTMLElement} [options.target] The HTML element where to render the element property. Default is the map's element.
|
|
21
|
+
* @param {function} [options.render] Render function called whenever the control needs to be rerendered.
|
|
22
|
+
*/
|
|
23
|
+
constructor(options = {}) {
|
|
24
|
+
super(options);
|
|
25
|
+
this.defineProperties(options);
|
|
26
|
+
const { active } = Object.assign({ active: options.active !== false }, options);
|
|
27
|
+
/**
|
|
28
|
+
* @ignore
|
|
29
|
+
*/
|
|
30
|
+
this.active = active;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Define control's properties.
|
|
34
|
+
*
|
|
35
|
+
* @private
|
|
36
|
+
* @ignore
|
|
37
|
+
*/
|
|
38
|
+
defineProperties(options) {
|
|
39
|
+
const { target, element, render } = Object.assign({}, options);
|
|
40
|
+
Object.defineProperties(this, {
|
|
41
|
+
active: {
|
|
42
|
+
get: () => this.get('active'),
|
|
43
|
+
set: (newActive) => {
|
|
44
|
+
this.set('active', newActive);
|
|
45
|
+
if (newActive) {
|
|
46
|
+
this.activate();
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
this.deactivate();
|
|
50
|
+
}
|
|
51
|
+
this.render();
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
map: {
|
|
55
|
+
get: () => this.get('map'),
|
|
56
|
+
set: (map) => {
|
|
57
|
+
// Remove previous node.
|
|
58
|
+
if (this.map && this.element && this.element.parentNode) {
|
|
59
|
+
this.element.parentNode.removeChild(this.element);
|
|
60
|
+
}
|
|
61
|
+
// Clean listeners
|
|
62
|
+
this.deactivate();
|
|
63
|
+
this.set('map', map);
|
|
64
|
+
if (this.map) {
|
|
65
|
+
// Add new node
|
|
66
|
+
const targett = this.target ||
|
|
67
|
+
(this.map.getTargetElement &&
|
|
68
|
+
this.map.getTargetElement()) ||
|
|
69
|
+
(this.map.getContainer &&
|
|
70
|
+
this.map.getContainer());
|
|
71
|
+
if (!this.element) {
|
|
72
|
+
this.createDefaultElement();
|
|
73
|
+
}
|
|
74
|
+
if (this.element) {
|
|
75
|
+
targett.appendChild(this.element);
|
|
76
|
+
}
|
|
77
|
+
// Add listeners
|
|
78
|
+
if (this.active) {
|
|
79
|
+
this.activate();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
this.render();
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
target: {
|
|
86
|
+
value: target,
|
|
87
|
+
},
|
|
88
|
+
element: {
|
|
89
|
+
value: element,
|
|
90
|
+
writable: true,
|
|
91
|
+
},
|
|
92
|
+
render: {
|
|
93
|
+
/** @ignore */
|
|
94
|
+
value: render || this.render,
|
|
95
|
+
writable: true,
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Attach the control to the map. Add events, html element ...
|
|
101
|
+
*/
|
|
102
|
+
attachToMap(map) {
|
|
103
|
+
this.map = map;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Detach the control From the map. Remove events, html element ..
|
|
107
|
+
*/
|
|
108
|
+
detachFromMap() {
|
|
109
|
+
this.map = undefined;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Add listeners then renders the control.
|
|
113
|
+
* To be defined in inherited classes.
|
|
114
|
+
*/
|
|
115
|
+
activate() {
|
|
116
|
+
this.deactivate();
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Remove listeners added by activate() function then renders the control.
|
|
120
|
+
* To be defined in inherited classes.
|
|
121
|
+
*/
|
|
122
|
+
// eslint-disable-next-line class-methods-use-this
|
|
123
|
+
deactivate() {
|
|
124
|
+
// eslint-disable-next-line no-console
|
|
125
|
+
console.error('The function deactivate() must be implemented in subclasses');
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* The default render function. It renders content in the HTML element.
|
|
129
|
+
* To be defined in inherited classes.
|
|
130
|
+
*
|
|
131
|
+
* @private
|
|
132
|
+
*/
|
|
133
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
134
|
+
render(options) {
|
|
135
|
+
// eslint-disable-next-line no-console
|
|
136
|
+
console.error('The function render() must be implemented in subclasses');
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* The default element to display if this.element is not defined.
|
|
140
|
+
* To be defined in inherited classes.
|
|
141
|
+
*
|
|
142
|
+
* @private
|
|
143
|
+
*/
|
|
144
|
+
// eslint-disable-next-line class-methods-use-this
|
|
145
|
+
createDefaultElement() {
|
|
146
|
+
// eslint-disable-next-line no-console
|
|
147
|
+
console.error('The function createDefaultElement() must be implemented in subclasses');
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
export default ControlCommon;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import ControlCommon from './ControlCommon';
|
|
2
|
+
/**
|
|
3
|
+
* A class representing a copyright control to display on map.
|
|
4
|
+
* This class only draw an html element, with an empty string in it.
|
|
5
|
+
* Use subclasses to use it in an ol or mapbox map.
|
|
6
|
+
*/
|
|
7
|
+
declare class CopyrightControlCommon extends ControlCommon {
|
|
8
|
+
render(): void;
|
|
9
|
+
createDefaultElement(): void;
|
|
10
|
+
getCopyrights(): string[];
|
|
11
|
+
}
|
|
12
|
+
export default CopyrightControlCommon;
|
|
13
|
+
//# sourceMappingURL=CopyrightControlCommon.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CopyrightControlCommon.d.ts","sourceRoot":"","sources":["../../../src/common/controls/CopyrightControlCommon.ts"],"names":[],"mappings":"AACA,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAE5C;;;;GAIG;AACH,cAAM,sBAAuB,SAAQ,aAAa;IAChD,MAAM;IASN,oBAAoB;IAYpB,aAAa;CAQd;AAED,eAAe,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/* eslint-disable max-classes-per-file */
|
|
2
|
+
import ControlCommon from './ControlCommon';
|
|
3
|
+
/**
|
|
4
|
+
* A class representing a copyright control to display on map.
|
|
5
|
+
* This class only draw an html element, with an empty string in it.
|
|
6
|
+
* Use subclasses to use it in an ol or mapbox map.
|
|
7
|
+
*/
|
|
8
|
+
class CopyrightControlCommon extends ControlCommon {
|
|
9
|
+
render() {
|
|
10
|
+
if (!this.element) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
this.element.innerHTML = this.active
|
|
14
|
+
? this.getCopyrights().join(' | ')
|
|
15
|
+
: '';
|
|
16
|
+
}
|
|
17
|
+
createDefaultElement() {
|
|
18
|
+
this.element = document.createElement('div');
|
|
19
|
+
this.element.id = 'mbt-copyright';
|
|
20
|
+
Object.assign(this.element.style, {
|
|
21
|
+
position: 'absolute',
|
|
22
|
+
bottom: 0,
|
|
23
|
+
right: 0,
|
|
24
|
+
fontSize: '.8rem',
|
|
25
|
+
padding: '0 10px',
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
getCopyrights() {
|
|
29
|
+
// eslint-disable-next-line no-console
|
|
30
|
+
console.error('The getCopyrights() function must be implemented in subclasses.', this);
|
|
31
|
+
return [];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export default CopyrightControlCommon;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { FeatureCollection } from '@turf/helpers';
|
|
2
|
+
import { Feature } from 'geojson';
|
|
3
|
+
import { StopsAPI } from '../../api';
|
|
4
|
+
import { StopsAPIOptions } from '../../api/StopsAPI';
|
|
5
|
+
import { StopsParameters } from '../../types';
|
|
6
|
+
import ControlCommon, { ControlCommonOptions } from './ControlCommon';
|
|
7
|
+
export type StopFinderControlCommonOptions = ControlCommonOptions & StopsAPIOptions & {
|
|
8
|
+
placeholder?: string;
|
|
9
|
+
apiParams: StopsParameters;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* A class representing a stop finder control to display on map.
|
|
13
|
+
* This class only draw the html elements.
|
|
14
|
+
* The geographic logic must be implemented by subclasses.
|
|
15
|
+
*/
|
|
16
|
+
declare class StopFinderControlCommon extends ControlCommon {
|
|
17
|
+
apiParams: StopsParameters;
|
|
18
|
+
placeholder: string;
|
|
19
|
+
api: StopsAPI;
|
|
20
|
+
abortController?: AbortController;
|
|
21
|
+
suggestionsElt?: HTMLElement;
|
|
22
|
+
inputElt?: HTMLInputElement;
|
|
23
|
+
clearElt?: HTMLDivElement;
|
|
24
|
+
/**
|
|
25
|
+
* Constructor.
|
|
26
|
+
*
|
|
27
|
+
* @param {Object} options Map options
|
|
28
|
+
* @param {string} options.apiKey Access key for [geOps services](https://developer.geops.io/). See StopsAPI.
|
|
29
|
+
* @param {string} [options.url='https://api.geops.io/tracker/v1'] Stops service url. See StopsAPI.
|
|
30
|
+
* @param {string} [options.placeholder='Search for a stop...'] Input field placeholder.
|
|
31
|
+
* @param {StopsSearchParams} [options.apiParams={ limit: 20 }] Request parameters. See [Stops service documentation](https://developer.geops.io/apis/5dcbd702a256d90001cf1361/).
|
|
32
|
+
*/
|
|
33
|
+
constructor(options: StopFinderControlCommonOptions);
|
|
34
|
+
deactivate(): void;
|
|
35
|
+
render(featureCollection?: FeatureCollection): void;
|
|
36
|
+
createDefaultElement(): void;
|
|
37
|
+
/**
|
|
38
|
+
* Launch a search.
|
|
39
|
+
*
|
|
40
|
+
* @param {String} query The query to search for.
|
|
41
|
+
* @param {AbortController} abortController Abort controller used to cancel the request.
|
|
42
|
+
* @return {Promise<Array<GeoJSONFeature>>} An array of GeoJSON features with coordinates in [EPSG:4326](http://epsg.io/4326).
|
|
43
|
+
*/
|
|
44
|
+
search(q: string, abortController: AbortController): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* To be defined in inherited class
|
|
47
|
+
*/
|
|
48
|
+
onSuggestionClick(suggestion: Feature): void;
|
|
49
|
+
/**
|
|
50
|
+
* Clear the search field and close the control.
|
|
51
|
+
*/
|
|
52
|
+
clear(): void;
|
|
53
|
+
}
|
|
54
|
+
export default StopFinderControlCommon;
|
|
55
|
+
//# sourceMappingURL=StopFinderControlCommon.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StopFinderControlCommon.d.ts","sourceRoot":"","sources":["../../../src/common/controls/StopFinderControlCommon.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,aAAa,EAAE,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAEtE,MAAM,MAAM,8BAA8B,GAAG,oBAAoB,GAC/D,eAAe,GAAG;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,eAAe,CAAC;CAC5B,CAAC;AAEJ;;;;GAIG;AACH,cAAM,uBAAwB,SAAQ,aAAa;IACjD,SAAS,EAAE,eAAe,CAAC;IAE3B,WAAW,EAAE,MAAM,CAAC;IAEpB,GAAG,EAAE,QAAQ,CAAC;IAEd,eAAe,CAAC,EAAE,eAAe,CAAC;IAElC,cAAc,CAAC,EAAE,WAAW,CAAC;IAE7B,QAAQ,CAAC,EAAE,gBAAgB,CAAC;IAE5B,QAAQ,CAAC,EAAE,cAAc,CAAC;IAE1B;;;;;;;;OAQG;gBACS,OAAO,EAAE,8BAA8B;IAenD,UAAU;IAEV,MAAM,CAAC,iBAAiB,CAAC,EAAE,iBAAiB;IAwB5C,oBAAoB;IAuDpB;;;;;;OAMG;IACH,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,eAAe,EAAE,eAAe;IAsBlD;;OAEG;IAEH,iBAAiB,CAAC,UAAU,EAAE,OAAO;IAErC;;OAEG;IACH,KAAK;CASN;AAED,eAAe,uBAAuB,CAAC"}
|