mobility-toolbox-js 2.0.0-beta.34 → 2.0.0-beta.37
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/README.md +14 -8
- package/api/RealtimeAPI.d.ts +6 -6
- package/api/RealtimeAPI.d.ts.map +1 -1
- package/api/RealtimeAPI.js +170 -197
- package/api/RealtimeAPI.test.d.ts +2 -0
- package/api/RealtimeAPI.test.d.ts.map +1 -0
- package/api/RealtimeAPI.test.js +67 -0
- package/api/RoutingAPI.d.ts +6 -2
- package/api/RoutingAPI.d.ts.map +1 -1
- package/api/RoutingAPI.js +8 -38
- package/api/RoutingAPI.test.d.ts +2 -0
- package/api/RoutingAPI.test.d.ts.map +1 -0
- package/api/RoutingAPI.test.js +29 -0
- package/api/StopsAPI.d.ts +1 -1
- package/api/StopsAPI.d.ts.map +1 -1
- package/api/StopsAPI.js +8 -40
- package/api/StopsAPI.test.d.ts +2 -0
- package/api/StopsAPI.test.d.ts.map +1 -0
- package/api/StopsAPI.test.js +26 -0
- package/api/index.d.ts +3 -4
- package/api/index.d.ts.map +1 -1
- package/api/index.js +3 -10
- package/api/typedefs.js +1 -0
- package/common/api/HttpAPI.d.ts +2 -2
- package/common/api/HttpAPI.d.ts.map +1 -1
- package/common/api/HttpAPI.js +21 -48
- package/common/api/HttpAPI.test.d.ts +2 -0
- package/common/api/HttpAPI.test.d.ts.map +1 -0
- package/common/api/HttpAPI.test.js +54 -0
- package/common/api/WebSocketAPI.d.ts +8 -4
- package/common/api/WebSocketAPI.d.ts.map +1 -1
- package/common/api/WebSocketAPI.js +125 -129
- package/common/api/WebSocketAPI.test.d.ts +2 -0
- package/common/api/WebSocketAPI.test.d.ts.map +1 -0
- package/common/api/WebSocketAPI.test.js +380 -0
- package/common/controls/Control.d.ts +5 -5
- package/common/controls/Control.d.ts.map +1 -1
- package/common/controls/Control.js +44 -77
- package/common/controls/Control.test.d.ts +2 -0
- package/common/controls/Control.test.d.ts.map +1 -0
- package/common/controls/Control.test.js +89 -0
- package/common/index.js +2 -18
- package/common/layers/Layer.d.ts +11 -11
- package/common/layers/Layer.d.ts.map +1 -1
- package/common/layers/Layer.js +70 -104
- package/common/layers/Layer.test.d.ts +2 -0
- package/common/layers/Layer.test.d.ts.map +1 -0
- package/common/layers/Layer.test.js +137 -0
- package/common/mixins/CopyrightMixin.js +23 -52
- package/common/mixins/MapboxLayerMixin.js +162 -204
- package/common/mixins/RealtimeLayerMixin.js +580 -635
- package/common/mixins/StopFinderMixin.d.ts +3 -3
- package/common/mixins/StopFinderMixin.d.ts.map +1 -1
- package/common/mixins/StopFinderMixin.js +115 -157
- package/common/mixins/UserInteractionsLayerMixin.js +142 -175
- package/common/mixins/UserInteractionsLayerMixin.test.d.ts +2 -0
- package/common/mixins/UserInteractionsLayerMixin.test.d.ts.map +1 -0
- package/common/mixins/UserInteractionsLayerMixin.test.js +214 -0
- package/common/styles/index.js +4 -24
- package/common/styles/realtimeDefaultStyle.d.ts.map +1 -1
- package/common/styles/realtimeDefaultStyle.js +67 -78
- package/common/styles/realtimeDelayStyle.js +4 -17
- package/common/styles/realtimeSimpleStyle.js +5 -7
- package/common/typedefs.js +1 -0
- package/common/utils/cleanStopTime.js +3 -5
- package/common/utils/compareDepartures.d.ts +1 -1
- package/common/utils/compareDepartures.d.ts.map +1 -1
- package/common/utils/compareDepartures.js +8 -11
- package/common/utils/createCanvas.js +3 -5
- package/common/utils/createTrackerFilters.d.ts +1 -1
- package/common/utils/createTrackerFilters.d.ts.map +1 -1
- package/common/utils/createTrackerFilters.js +22 -32
- package/common/utils/createTrackerFilters.test.d.ts +2 -0
- package/common/utils/createTrackerFilters.test.d.ts.map +1 -0
- package/common/utils/createTrackerFilters.test.js +79 -0
- package/common/utils/getLayersAsFlatArray.js +6 -8
- package/common/utils/getMapboxMapCopyrights.js +9 -11
- package/common/utils/getMapboxMapCopyrights.test.d.ts +2 -0
- package/common/utils/getMapboxMapCopyrights.test.d.ts.map +1 -0
- package/common/utils/getMapboxMapCopyrights.test.js +40 -0
- package/common/utils/getMapboxRender.js +12 -15
- package/common/utils/getMaplibreRender.js +10 -13
- package/common/utils/getRealtimeModeSuffix.js +2 -6
- package/common/utils/getUrlWithParams.js +5 -8
- package/common/utils/getVehiclePosition.js +20 -23
- package/common/utils/index.js +12 -37
- package/common/utils/removeDuplicate.d.ts +1 -1
- package/common/utils/removeDuplicate.d.ts.map +1 -1
- package/common/utils/removeDuplicate.js +6 -21
- package/common/utils/removeDuplicate.test.d.ts +2 -0
- package/common/utils/removeDuplicate.test.d.ts.map +1 -0
- package/common/utils/removeDuplicate.test.js +19 -0
- package/common/utils/renderTrajectories.js +31 -43
- package/common/utils/sortByDelay.js +4 -6
- package/common/utils/timeUtils.js +14 -24
- package/common/utils/timeUtils.test.d.ts +2 -0
- package/common/utils/timeUtils.test.d.ts.map +1 -0
- package/common/utils/timeUtils.test.js +10 -0
- package/common/utils/trackerConfig.js +27 -39
- package/common/utils/trackerConfig.test.d.ts +2 -0
- package/common/utils/trackerConfig.test.d.ts.map +1 -0
- package/common/utils/trackerConfig.test.js +23 -0
- package/iife.js +3 -5
- package/index.d.ts +4 -0
- package/index.js +9 -10
- package/mapbox/controls/CopyrightControl.d.ts +0 -1
- package/mapbox/controls/CopyrightControl.d.ts.map +1 -1
- package/mapbox/controls/CopyrightControl.js +18 -38
- package/mapbox/controls/index.js +1 -5
- package/mapbox/index.js +4 -20
- package/mapbox/layers/Layer.d.ts +1 -1
- package/mapbox/layers/Layer.d.ts.map +1 -1
- package/mapbox/layers/Layer.js +29 -71
- package/mapbox/layers/Layer.test.d.ts +2 -0
- package/mapbox/layers/Layer.test.d.ts.map +1 -0
- package/mapbox/layers/Layer.test.js +204 -0
- package/mapbox/layers/RealtimeLayer.d.ts +4 -4
- package/mapbox/layers/RealtimeLayer.d.ts.map +1 -1
- package/mapbox/layers/RealtimeLayer.js +83 -125
- package/mapbox/layers/RealtimeLayer.test.d.ts +2 -0
- package/mapbox/layers/RealtimeLayer.test.d.ts.map +1 -0
- package/mapbox/layers/RealtimeLayer.test.js +10 -0
- package/mapbox/layers/index.js +2 -7
- package/mapbox/utils.js +19 -33
- package/mbt.js +59 -37
- package/mbt.js.map +2 -2
- package/mbt.min.js +10 -10
- package/mbt.min.js.map +2 -2
- package/ol/controls/CopyrightControl.js +26 -47
- package/ol/controls/CopyrightControl.test.d.ts +2 -0
- package/ol/controls/CopyrightControl.test.d.ts.map +1 -0
- package/ol/controls/CopyrightControl.test.js +177 -0
- package/ol/controls/RoutingControl.d.ts +6 -5
- package/ol/controls/RoutingControl.d.ts.map +1 -1
- package/ol/controls/RoutingControl.js +209 -270
- package/ol/controls/RoutingControl.test.d.ts +2 -0
- package/ol/controls/RoutingControl.test.d.ts.map +1 -0
- package/ol/controls/RoutingControl.test.js +150 -0
- package/ol/controls/StopFinderControl.js +9 -32
- package/ol/controls/StopFinderControl.test.d.ts +2 -0
- package/ol/controls/StopFinderControl.test.d.ts.map +1 -0
- package/ol/controls/StopFinderControl.test.js +49 -0
- package/ol/controls/index.js +3 -9
- package/ol/index.js +5 -21
- package/ol/layers/Layer.d.ts +1 -1
- package/ol/layers/Layer.d.ts.map +1 -1
- package/ol/layers/Layer.js +40 -72
- package/ol/layers/Layer.test.d.ts +2 -0
- package/ol/layers/Layer.test.d.ts.map +1 -0
- package/ol/layers/Layer.test.js +196 -0
- package/ol/layers/MapboxLayer.d.ts +7 -7
- package/ol/layers/MapboxLayer.d.ts.map +1 -1
- package/ol/layers/MapboxLayer.js +30 -66
- package/ol/layers/MapboxLayer.test.d.ts +2 -0
- package/ol/layers/MapboxLayer.test.d.ts.map +1 -0
- package/ol/layers/MapboxLayer.test.js +164 -0
- package/ol/layers/MapboxStyleLayer.d.ts +3 -3
- package/ol/layers/MapboxStyleLayer.d.ts.map +1 -1
- package/ol/layers/MapboxStyleLayer.js +92 -135
- package/ol/layers/MapboxStyleLayer.test.d.ts +2 -0
- package/ol/layers/MapboxStyleLayer.test.d.ts.map +1 -0
- package/ol/layers/MapboxStyleLayer.test.js +232 -0
- package/ol/layers/MaplibreLayer.d.ts +1 -1
- package/ol/layers/MaplibreLayer.d.ts.map +1 -1
- package/ol/layers/MaplibreLayer.js +14 -48
- package/ol/layers/RealtimeLayer.d.ts +2 -2
- package/ol/layers/RealtimeLayer.d.ts.map +1 -1
- package/ol/layers/RealtimeLayer.js +111 -147
- package/ol/layers/RealtimeLayer.test.d.ts +2 -0
- package/ol/layers/RealtimeLayer.test.d.ts.map +1 -0
- package/ol/layers/RealtimeLayer.test.js +71 -0
- package/ol/layers/RoutingLayer.d.ts +2 -2
- package/ol/layers/RoutingLayer.d.ts.map +1 -1
- package/ol/layers/RoutingLayer.js +29 -61
- package/ol/layers/RoutingLayer.test.d.ts +2 -0
- package/ol/layers/RoutingLayer.test.d.ts.map +1 -0
- package/ol/layers/RoutingLayer.test.js +39 -0
- package/ol/layers/VectorLayer.d.ts +1 -1
- package/ol/layers/VectorLayer.d.ts.map +1 -1
- package/ol/layers/VectorLayer.js +14 -48
- package/ol/layers/VectorLayer.test.d.ts +2 -0
- package/ol/layers/VectorLayer.test.d.ts.map +1 -0
- package/ol/layers/VectorLayer.test.js +87 -0
- package/ol/layers/WMSLayer.d.ts +1 -1
- package/ol/layers/WMSLayer.d.ts.map +1 -1
- package/ol/layers/WMSLayer.js +34 -68
- package/ol/layers/WMSLayer.test.d.ts +2 -0
- package/ol/layers/WMSLayer.test.d.ts.map +1 -0
- package/ol/layers/WMSLayer.test.js +66 -0
- package/ol/layers/index.js +8 -19
- package/ol/styles/fullTrajectoryDelayStyle.js +11 -13
- package/ol/styles/fullTrajectoryStyle.js +16 -18
- package/ol/styles/index.js +2 -7
- package/package.json +5 -2
- package/setupTests.js +12 -14
|
@@ -1,48 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __assign = (this && this.__assign) || function () {
|
|
18
|
-
__assign = Object.assign || function(t) {
|
|
19
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
-
s = arguments[i];
|
|
21
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
-
t[p] = s[p];
|
|
23
|
-
}
|
|
24
|
-
return t;
|
|
25
|
-
};
|
|
26
|
-
return __assign.apply(this, arguments);
|
|
27
|
-
};
|
|
28
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
29
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
30
|
-
if (ar || !(i in from)) {
|
|
31
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
32
|
-
ar[i] = from[i];
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
36
|
-
};
|
|
37
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
var proj_1 = require("ol/proj");
|
|
39
|
-
var Observable_1 = require("ol/Observable");
|
|
40
|
-
var extent_1 = require("ol/extent");
|
|
41
|
-
var transform_rotate_1 = require("@turf/transform-rotate");
|
|
42
|
-
var helpers_1 = require("@turf/helpers");
|
|
43
|
-
var RealtimeLayerMixin_1 = require("../../common/mixins/RealtimeLayerMixin");
|
|
44
|
-
var Layer_1 = require("./Layer");
|
|
45
|
-
var utils_1 = require("../utils");
|
|
1
|
+
import { fromLonLat } from 'ol/proj';
|
|
2
|
+
import { unByKey } from 'ol/Observable';
|
|
3
|
+
import { getWidth, getHeight } from 'ol/extent';
|
|
4
|
+
import transformRotate from '@turf/transform-rotate';
|
|
5
|
+
import { point } from '@turf/helpers';
|
|
6
|
+
import mixin from '../../common/mixins/RealtimeLayerMixin';
|
|
7
|
+
import Layer from './Layer';
|
|
8
|
+
import { getSourceCoordinates, getMercatorResolution } from '../utils';
|
|
46
9
|
/**
|
|
47
10
|
* Responsible for loading and display data from a Realtime service.
|
|
48
11
|
*
|
|
@@ -60,22 +23,19 @@ var utils_1 = require("../utils");
|
|
|
60
23
|
* @extends {Layer}
|
|
61
24
|
* @implements {RealtimeLayerInterface}
|
|
62
25
|
*/
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (options === void 0) { options = {}; }
|
|
67
|
-
var _this = _super.call(this, __assign({}, options)) || this;
|
|
26
|
+
class RealtimeLayer extends mixin(Layer) {
|
|
27
|
+
constructor(options = {}) {
|
|
28
|
+
super(Object.assign({}, options));
|
|
68
29
|
/** @ignore */
|
|
69
|
-
|
|
30
|
+
this.onLoad = this.onLoad.bind(this);
|
|
70
31
|
/** @ignore */
|
|
71
|
-
|
|
32
|
+
this.onMove = this.onMove.bind(this);
|
|
72
33
|
/** @ignore */
|
|
73
|
-
|
|
34
|
+
this.onMoveEnd = this.onMoveEnd.bind(this);
|
|
74
35
|
/** @ignore */
|
|
75
|
-
|
|
36
|
+
this.onZoomEnd = this.onZoomEnd.bind(this);
|
|
76
37
|
/** @ignore */
|
|
77
|
-
|
|
78
|
-
return _this;
|
|
38
|
+
this.onVisibilityChange = this.onVisibilityChange.bind(this);
|
|
79
39
|
}
|
|
80
40
|
/**
|
|
81
41
|
* Initialize the layer.
|
|
@@ -84,19 +44,19 @@ var RealtimeLayer = /** @class */ (function (_super) {
|
|
|
84
44
|
* @param {string} beforeId Layer's id before which we want to add the new layer.
|
|
85
45
|
* @override
|
|
86
46
|
*/
|
|
87
|
-
|
|
47
|
+
attachToMap(map, beforeId) {
|
|
88
48
|
if (!map) {
|
|
89
49
|
return;
|
|
90
50
|
}
|
|
91
|
-
|
|
92
|
-
|
|
51
|
+
const canvas = map.getCanvas();
|
|
52
|
+
super.attachToMap(map, {
|
|
93
53
|
width: canvas.width / this.pixelRatio,
|
|
94
54
|
height: canvas.height / this.pixelRatio,
|
|
95
55
|
});
|
|
96
56
|
this.source = {
|
|
97
57
|
type: 'canvas',
|
|
98
58
|
canvas: this.canvas,
|
|
99
|
-
coordinates:
|
|
59
|
+
coordinates: getSourceCoordinates(map, this.pixelRatio),
|
|
100
60
|
// Set to true if the canvas source is animated. If the canvas is static, animate should be set to false to improve performance.
|
|
101
61
|
animate: true,
|
|
102
62
|
attribution: this.copyrights && this.copyrights.join(', '),
|
|
@@ -120,15 +80,15 @@ var RealtimeLayer = /** @class */ (function (_super) {
|
|
|
120
80
|
}
|
|
121
81
|
this.map.on('load', this.onLoad);
|
|
122
82
|
this.listeners = [this.on('change:visible', this.onVisibilityChange)];
|
|
123
|
-
}
|
|
83
|
+
}
|
|
124
84
|
/**
|
|
125
85
|
* Remove listeners from the Mapbox Map.
|
|
126
86
|
*/
|
|
127
|
-
|
|
87
|
+
detachFromMap() {
|
|
128
88
|
if (this.map) {
|
|
129
89
|
this.map.off('load', this.onLoad);
|
|
130
|
-
this.listeners.forEach(
|
|
131
|
-
|
|
90
|
+
this.listeners.forEach((listener) => {
|
|
91
|
+
unByKey(listener);
|
|
132
92
|
});
|
|
133
93
|
if (this.map.style && this.map.getLayer(this.key)) {
|
|
134
94
|
this.map.removeLayer(this.key);
|
|
@@ -137,8 +97,8 @@ var RealtimeLayer = /** @class */ (function (_super) {
|
|
|
137
97
|
this.map.removeSource(this.key);
|
|
138
98
|
}
|
|
139
99
|
}
|
|
140
|
-
|
|
141
|
-
}
|
|
100
|
+
super.detachFromMap();
|
|
101
|
+
}
|
|
142
102
|
/**
|
|
143
103
|
* Start updating vehicles position.
|
|
144
104
|
*
|
|
@@ -146,91 +106,90 @@ var RealtimeLayer = /** @class */ (function (_super) {
|
|
|
146
106
|
* @listens {mapboxgl.map.event:mousemove} Listen to mousemove end.
|
|
147
107
|
* @override
|
|
148
108
|
*/
|
|
149
|
-
|
|
150
|
-
|
|
109
|
+
start() {
|
|
110
|
+
super.start();
|
|
151
111
|
this.map.on('move', this.onMove);
|
|
152
112
|
this.map.on('moveend', this.onMoveEnd);
|
|
153
113
|
this.map.on('zoomend', this.onZoomEnd);
|
|
154
|
-
}
|
|
114
|
+
}
|
|
155
115
|
/**
|
|
156
116
|
* Stop updating vehicles position, and unlisten events.
|
|
157
117
|
*
|
|
158
118
|
* @override
|
|
159
119
|
*/
|
|
160
|
-
|
|
161
|
-
|
|
120
|
+
stop() {
|
|
121
|
+
super.stop();
|
|
162
122
|
if (this.map) {
|
|
163
123
|
this.map.off('move', this.onMove);
|
|
164
124
|
this.map.off('moveend', this.onMoveEnd);
|
|
165
125
|
this.map.off('zoomend', this.onZoomEnd);
|
|
166
126
|
}
|
|
167
|
-
}
|
|
168
|
-
|
|
127
|
+
}
|
|
128
|
+
onLoad() {
|
|
169
129
|
if (!this.map.getSource(this.key)) {
|
|
170
130
|
this.map.addSource(this.key, this.source);
|
|
171
131
|
}
|
|
172
132
|
if (!this.map.getLayer(this.key)) {
|
|
173
133
|
this.map.addLayer(this.layer, this.beforeId);
|
|
174
134
|
}
|
|
175
|
-
}
|
|
135
|
+
}
|
|
176
136
|
/**
|
|
177
137
|
* Function triggered when the user moves the cursor over the map.
|
|
178
138
|
* @override
|
|
179
139
|
*/
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}
|
|
140
|
+
onUserMoveCallback(evt) {
|
|
141
|
+
super.onUserMoveCallback(Object.assign({ coordinate: fromLonLat(evt.lngLat.toArray()) }, evt));
|
|
142
|
+
}
|
|
183
143
|
/**
|
|
184
144
|
* Render the trajectories using current map's size, resolution and rotation.
|
|
185
145
|
* @param {boolean} noInterpolate if true, renders the vehicles without interpolating theirs positions.
|
|
186
146
|
* @overrides
|
|
187
147
|
*/
|
|
188
|
-
|
|
148
|
+
renderTrajectories(noInterpolate) {
|
|
189
149
|
if (!this.map) {
|
|
190
150
|
return;
|
|
191
151
|
}
|
|
192
|
-
|
|
193
|
-
|
|
152
|
+
const { width, height } = this.map.getCanvas();
|
|
153
|
+
const center = this.map.getCenter();
|
|
194
154
|
// We use turf here to have good transform.
|
|
195
|
-
|
|
155
|
+
const leftBottom = this.map.unproject({
|
|
196
156
|
x: 0,
|
|
197
157
|
y: height / this.pixelRatio,
|
|
198
158
|
}); // southWest
|
|
199
|
-
|
|
200
|
-
|
|
159
|
+
const rightTop = this.map.unproject({ x: width / this.pixelRatio, y: 0 }); // north east
|
|
160
|
+
const coord0 = transformRotate(point([leftBottom.lng, leftBottom.lat]), -this.map.getBearing(), {
|
|
201
161
|
pivot: [center.lng, center.lat],
|
|
202
162
|
}).geometry.coordinates;
|
|
203
|
-
|
|
163
|
+
const coord1 = transformRotate(point([rightTop.lng, rightTop.lat]), -this.map.getBearing(), {
|
|
204
164
|
pivot: [center.lng, center.lat],
|
|
205
165
|
}).geometry.coordinates;
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
166
|
+
const bounds = [...fromLonLat(coord0), ...fromLonLat(coord1)];
|
|
167
|
+
const xResolution = getWidth(bounds) / (width / this.pixelRatio);
|
|
168
|
+
const yResolution = getHeight(bounds) / (height / this.pixelRatio);
|
|
169
|
+
const res = Math.max(xResolution, yResolution);
|
|
210
170
|
// Coordinate of trajectories are in mercator so we have to pass the proper resolution and center in mercator.
|
|
211
|
-
|
|
171
|
+
const viewState = {
|
|
212
172
|
size: [width / this.pixelRatio, height / this.pixelRatio],
|
|
213
|
-
center:
|
|
173
|
+
center: fromLonLat([center.lng, center.lat]),
|
|
214
174
|
extent: bounds,
|
|
215
175
|
resolution: res,
|
|
216
176
|
zoom: this.map.getZoom(),
|
|
217
177
|
rotation: -(this.map.getBearing() * Math.PI) / 180,
|
|
218
178
|
pixelRatio: this.pixelRatio,
|
|
219
179
|
};
|
|
220
|
-
|
|
221
|
-
}
|
|
180
|
+
super.renderTrajectories(viewState, noInterpolate);
|
|
181
|
+
}
|
|
222
182
|
/**
|
|
223
183
|
* Return the delay in ms before the next rendering.
|
|
224
184
|
*/
|
|
225
|
-
|
|
226
|
-
return
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
RealtimeLayer.prototype.onVisibilityChange = function () {
|
|
185
|
+
getRefreshTimeInMs() {
|
|
186
|
+
return super.getRefreshTimeInMs(this.map.getZoom());
|
|
187
|
+
}
|
|
188
|
+
getFeatureInfoAtCoordinate(coordinate, options = {}) {
|
|
189
|
+
const resolution = getMercatorResolution(this.map);
|
|
190
|
+
return super.getFeatureInfoAtCoordinate(coordinate, Object.assign({ resolution }, options));
|
|
191
|
+
}
|
|
192
|
+
onVisibilityChange() {
|
|
234
193
|
if (this.visible && !this.map.getLayer(this.key)) {
|
|
235
194
|
this.map.addLayer(this.layer, this.beforeId);
|
|
236
195
|
}
|
|
@@ -243,70 +202,69 @@ var RealtimeLayer = /** @class */ (function (_super) {
|
|
|
243
202
|
// 'visibilty',
|
|
244
203
|
// this.visible ? 'visible' : 'none',
|
|
245
204
|
// );
|
|
246
|
-
}
|
|
205
|
+
}
|
|
247
206
|
/**
|
|
248
207
|
* Remove the trajectory form the list if necessary.
|
|
249
208
|
*
|
|
250
209
|
* @private
|
|
251
210
|
*/
|
|
252
|
-
|
|
253
|
-
return
|
|
254
|
-
}
|
|
211
|
+
purgeTrajectory(trajectory, extent, zoom) {
|
|
212
|
+
return super.purgeTrajectory(trajectory, extent || this.getMercatorExtent(), zoom || Math.floor(this.map.getZoom() + 1));
|
|
213
|
+
}
|
|
255
214
|
/**
|
|
256
215
|
* Send the current bbox to the websocket
|
|
257
216
|
*/
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
217
|
+
setBbox(extent, zoom) {
|
|
218
|
+
let newExtent = extent;
|
|
219
|
+
let newZoom = zoom;
|
|
261
220
|
if (!newExtent && this.isUpdateBboxOnMoveEnd) {
|
|
262
221
|
newExtent = extent || this.getMercatorExtent();
|
|
263
222
|
newZoom = Math.floor(this.getOlZoom());
|
|
264
223
|
}
|
|
265
|
-
|
|
266
|
-
}
|
|
224
|
+
super.setBbox(newExtent, newZoom);
|
|
225
|
+
}
|
|
267
226
|
/**
|
|
268
227
|
* Callback on 'move' event.
|
|
269
228
|
*
|
|
270
229
|
* @private
|
|
271
230
|
*/
|
|
272
|
-
|
|
231
|
+
onMove() {
|
|
273
232
|
this.renderTrajectories();
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
|
|
233
|
+
}
|
|
234
|
+
renderTrajectoriesInternal(viewState, noInterpolate) {
|
|
235
|
+
const render = super.renderTrajectoriesInternal(viewState, noInterpolate);
|
|
277
236
|
if (render && this.map.style) {
|
|
278
|
-
|
|
279
|
-
|
|
237
|
+
const extent = getSourceCoordinates(this.map, this.pixelRatio);
|
|
238
|
+
const source = this.map.getSource(this.key);
|
|
280
239
|
if (source) {
|
|
281
240
|
source.setCoordinates(extent);
|
|
282
241
|
}
|
|
283
242
|
}
|
|
284
243
|
return render;
|
|
285
|
-
}
|
|
244
|
+
}
|
|
286
245
|
/**
|
|
287
246
|
* Send the new BBOX to the websocket.
|
|
288
247
|
*
|
|
289
248
|
* @private
|
|
290
249
|
* @override
|
|
291
250
|
*/
|
|
292
|
-
|
|
251
|
+
onMoveEnd() {
|
|
293
252
|
this.renderTrajectories();
|
|
294
253
|
if (this.visible && this.isUpdateBboxOnMoveEnd) {
|
|
295
254
|
this.setBbox();
|
|
296
255
|
}
|
|
297
|
-
}
|
|
256
|
+
}
|
|
298
257
|
/**
|
|
299
258
|
* Update the cursor style when hovering a vehicle.
|
|
300
259
|
*
|
|
301
260
|
* @private
|
|
302
261
|
* @override
|
|
303
262
|
*/
|
|
304
|
-
|
|
305
|
-
|
|
263
|
+
onFeatureHover(features, layer, coordinate) {
|
|
264
|
+
super.onFeatureHover(features, layer, coordinate);
|
|
306
265
|
this.map.getCanvasContainer().style.cursor = features.length
|
|
307
266
|
? 'pointer'
|
|
308
267
|
: 'auto';
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
exports.default = RealtimeLayer;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
export default RealtimeLayer;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RealtimeLayer.test.d.ts","sourceRoot":"","sources":["../../../src/mapbox/layers/RealtimeLayer.test.js"],"names":[],"mappings":""}
|
package/mapbox/layers/index.js
CHANGED
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.RealtimeLayer = exports.Layer = void 0;
|
|
4
|
-
var Layer_1 = require("./Layer");
|
|
5
|
-
Object.defineProperty(exports, "Layer", { enumerable: true, get: function () { return Layer_1.default; } });
|
|
6
|
-
var RealtimeLayer_1 = require("./RealtimeLayer");
|
|
7
|
-
Object.defineProperty(exports, "RealtimeLayer", { enumerable: true, get: function () { return RealtimeLayer_1.default; } });
|
|
1
|
+
export { default as Layer } from './Layer';
|
|
2
|
+
export { default as RealtimeLayer } from './RealtimeLayer';
|
package/mapbox/utils.js
CHANGED
|
@@ -1,48 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
-
if (ar || !(i in from)) {
|
|
5
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
-
ar[i] = from[i];
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.getSourceCoordinates = exports.getMercatorResolution = void 0;
|
|
13
|
-
var extent_1 = require("ol/extent");
|
|
14
|
-
var proj_1 = require("ol/proj");
|
|
1
|
+
import { getWidth, getHeight } from 'ol/extent';
|
|
2
|
+
import { fromLonLat } from 'ol/proj';
|
|
15
3
|
/**
|
|
16
4
|
* Get the current resolution of a Mapbox map.
|
|
17
5
|
* @param {mapboxgl.Map} map A map object.
|
|
18
6
|
* @private
|
|
19
7
|
*/
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
8
|
+
export const getMercatorResolution = (map) => {
|
|
9
|
+
const bounds = map.getBounds().toArray();
|
|
10
|
+
const a = fromLonLat(bounds[0]);
|
|
11
|
+
const b = fromLonLat(bounds[1]);
|
|
12
|
+
const extent = [...a, ...b];
|
|
13
|
+
const { width, height } = map.getCanvas();
|
|
14
|
+
const xResolution = getWidth(extent) / width;
|
|
15
|
+
const yResolution = getHeight(extent) / height;
|
|
28
16
|
return Math.max(xResolution, yResolution);
|
|
29
17
|
};
|
|
30
|
-
exports.getMercatorResolution = getMercatorResolution;
|
|
31
18
|
/**
|
|
32
19
|
* Get the canvas source coordinates of the current map's extent.
|
|
33
20
|
* @param {mapboxgl.Map} map A map object.
|
|
34
21
|
* @private
|
|
35
22
|
*/
|
|
36
|
-
|
|
23
|
+
export const getSourceCoordinates = (map, pixelRatio) => {
|
|
37
24
|
// Requesting getBounds is not enough when we rotate the map, so we request manually each corner.
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
25
|
+
const { width, height } = map.getCanvas();
|
|
26
|
+
const leftTop = map.unproject({ x: 0, y: 0 });
|
|
27
|
+
const leftBottom = map.unproject({ x: 0, y: height / pixelRatio }); // southWest
|
|
28
|
+
const rightBottom = map.unproject({
|
|
42
29
|
x: width / pixelRatio,
|
|
43
30
|
y: height / pixelRatio,
|
|
44
31
|
});
|
|
45
|
-
|
|
32
|
+
const rightTop = map.unproject({ x: width / pixelRatio, y: 0 }); // north east
|
|
46
33
|
return [
|
|
47
34
|
[leftTop.lng, leftTop.lat],
|
|
48
35
|
[rightTop.lng, rightTop.lat],
|
|
@@ -50,8 +37,7 @@ var getSourceCoordinates = function (map, pixelRatio) {
|
|
|
50
37
|
[leftBottom.lng, leftBottom.lat],
|
|
51
38
|
];
|
|
52
39
|
};
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
getSourceCoordinates: exports.getSourceCoordinates,
|
|
40
|
+
export default {
|
|
41
|
+
getMercatorResolution,
|
|
42
|
+
getSourceCoordinates,
|
|
57
43
|
};
|
package/mbt.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
(() => {
|
|
2
3
|
var __create = Object.create;
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
@@ -33355,7 +33356,10 @@ uniform ${i3} ${o3} u_${a3};
|
|
|
33355
33356
|
this.apiKey = options.apiKey;
|
|
33356
33357
|
}
|
|
33357
33358
|
fetch(path, params, config) {
|
|
33358
|
-
if (!this.
|
|
33359
|
+
if (!this.url) {
|
|
33360
|
+
return Promise.reject(new Error(`No url defined for request to ${this.url}/${path}`));
|
|
33361
|
+
}
|
|
33362
|
+
if (!this.url && !this.apiKey && !/key=/.test(this.url)) {
|
|
33359
33363
|
return Promise.reject(new Error(`No apiKey defined for request to ${this.url}`));
|
|
33360
33364
|
}
|
|
33361
33365
|
const searchParams = params || {};
|
|
@@ -33382,10 +33386,7 @@ uniform ${i3} ${o3} u_${a3};
|
|
|
33382
33386
|
// src/api/RoutingAPI.ts
|
|
33383
33387
|
var RoutingAPI = class extends HttpAPI_default {
|
|
33384
33388
|
constructor(options) {
|
|
33385
|
-
super({
|
|
33386
|
-
url: "https://api.geops.io/routing/v1/",
|
|
33387
|
-
...options || {}
|
|
33388
|
-
});
|
|
33389
|
+
super({ url: "https://api.geops.io/routing/v1/", ...options });
|
|
33389
33390
|
}
|
|
33390
33391
|
route(params, config) {
|
|
33391
33392
|
return this.fetch("", params, config);
|
|
@@ -33491,8 +33492,26 @@ uniform ${i3} ${o3} u_${a3};
|
|
|
33491
33492
|
send();
|
|
33492
33493
|
}
|
|
33493
33494
|
}
|
|
33495
|
+
addEvents(onMessage, onError) {
|
|
33496
|
+
if (this.websocket) {
|
|
33497
|
+
this.websocket.addEventListener("message", onMessage);
|
|
33498
|
+
if (onError) {
|
|
33499
|
+
this.websocket.addEventListener("error", onError);
|
|
33500
|
+
this.websocket.addEventListener("close", onError);
|
|
33501
|
+
}
|
|
33502
|
+
}
|
|
33503
|
+
}
|
|
33504
|
+
removeEvents(onMessage, onError) {
|
|
33505
|
+
if (this.websocket) {
|
|
33506
|
+
this.websocket.removeEventListener("message", onMessage);
|
|
33507
|
+
if (onError) {
|
|
33508
|
+
this.websocket.removeEventListener("error", onError);
|
|
33509
|
+
this.websocket.removeEventListener("close", onError);
|
|
33510
|
+
}
|
|
33511
|
+
}
|
|
33512
|
+
}
|
|
33494
33513
|
listen(params, cb, errorCb) {
|
|
33495
|
-
this.unlisten(params, cb);
|
|
33514
|
+
this.unlisten(params, cb, errorCb);
|
|
33496
33515
|
const onMessage = (evt) => {
|
|
33497
33516
|
let data = {};
|
|
33498
33517
|
try {
|
|
@@ -33509,33 +33528,42 @@ uniform ${i3} ${o3} u_${a3};
|
|
|
33509
33528
|
}
|
|
33510
33529
|
});
|
|
33511
33530
|
};
|
|
33512
|
-
|
|
33513
|
-
this.websocket.addEventListener("message", onMessage);
|
|
33514
|
-
if (errorCb) {
|
|
33515
|
-
this.websocket.addEventListener("error", errorCb);
|
|
33516
|
-
this.websocket.addEventListener("close", errorCb);
|
|
33517
|
-
}
|
|
33518
|
-
}
|
|
33531
|
+
this.addEvents(onMessage, errorCb);
|
|
33519
33532
|
return { onMessageCb: onMessage, onErrorCb: errorCb };
|
|
33520
33533
|
}
|
|
33521
33534
|
unlisten(params, cb) {
|
|
33522
|
-
|
|
33523
|
-
|
|
33524
|
-
}
|
|
33525
|
-
this.subscriptions.filter((s) => s.params.channel === params.channel && (!cb || s.cb === cb)).forEach(({ onMessageCb, onErrorCb }) => {
|
|
33526
|
-
if (this.websocket) {
|
|
33527
|
-
this.websocket.removeEventListener("message", onMessageCb);
|
|
33528
|
-
if (onErrorCb) {
|
|
33529
|
-
this.websocket.removeEventListener("error", onErrorCb);
|
|
33530
|
-
this.websocket.removeEventListener("close", onErrorCb);
|
|
33531
|
-
}
|
|
33532
|
-
}
|
|
33535
|
+
[...this.subscriptions || [], ...this.requests || []].filter((s) => s.params.channel === params.channel && (!cb || s.cb === cb)).forEach(({ onMessageCb, onErrorCb }) => {
|
|
33536
|
+
this.removeEvents(onMessageCb, onErrorCb);
|
|
33533
33537
|
});
|
|
33534
33538
|
}
|
|
33535
33539
|
get(params, cb, errorCb) {
|
|
33536
|
-
const
|
|
33537
|
-
this.send(
|
|
33538
|
-
|
|
33540
|
+
const requestString = WebSocketAPI.getRequestString("GET", params);
|
|
33541
|
+
this.send(requestString);
|
|
33542
|
+
const once = (callback) => (...args) => {
|
|
33543
|
+
callback(...args);
|
|
33544
|
+
const index2 = this.requests.findIndex((request) => requestString === request.requestString && cb === request.cb);
|
|
33545
|
+
const { onMessageCb: onMessageCb2, onErrorCb: onErrorCb2 } = this.requests[index2];
|
|
33546
|
+
this.removeEvents(onMessageCb2, onErrorCb2);
|
|
33547
|
+
this.requests.splice(index2, 1);
|
|
33548
|
+
};
|
|
33549
|
+
const { onMessageCb, onErrorCb } = this.listen(params, once(cb), once(errorCb));
|
|
33550
|
+
if (!this.requests) {
|
|
33551
|
+
this.requests = [];
|
|
33552
|
+
}
|
|
33553
|
+
const index = this.requests.findIndex((request) => requestString === request.requestString && cb === request.cb);
|
|
33554
|
+
const newReq = {
|
|
33555
|
+
params,
|
|
33556
|
+
requestString,
|
|
33557
|
+
cb,
|
|
33558
|
+
errorCb,
|
|
33559
|
+
onMessageCb,
|
|
33560
|
+
onErrorCb
|
|
33561
|
+
};
|
|
33562
|
+
if (index > -1) {
|
|
33563
|
+
this.requests[index] = newReq;
|
|
33564
|
+
} else {
|
|
33565
|
+
this.requests.push(newReq);
|
|
33566
|
+
}
|
|
33539
33567
|
}
|
|
33540
33568
|
subscribe(params, cb, errorCb, quiet = false) {
|
|
33541
33569
|
const { onMessageCb, onErrorCb } = this.listen(params, cb, errorCb);
|
|
@@ -33558,13 +33586,7 @@ uniform ${i3} ${o3} u_${a3};
|
|
|
33558
33586
|
unsubscribe(source, cb) {
|
|
33559
33587
|
const toRemove = this.subscriptions.filter((s) => s.params.channel === source && (!cb || s.cb === cb));
|
|
33560
33588
|
toRemove.forEach(({ onMessageCb, onErrorCb }) => {
|
|
33561
|
-
|
|
33562
|
-
this.websocket.removeEventListener("message", onMessageCb);
|
|
33563
|
-
if (onErrorCb) {
|
|
33564
|
-
this.websocket.removeEventListener("error", onErrorCb);
|
|
33565
|
-
this.websocket.removeEventListener("close", onErrorCb);
|
|
33566
|
-
}
|
|
33567
|
-
}
|
|
33589
|
+
this.removeEvents(onMessageCb, onErrorCb);
|
|
33568
33590
|
});
|
|
33569
33591
|
this.subscriptions = this.subscriptions.filter((s) => s.params.channel !== source || cb && s.cb !== cb);
|
|
33570
33592
|
if (source && this.subscribed[source] && !this.subscriptions.find((s) => s.params.channel === source) && toRemove.find((subscr) => !subscr.quiet)) {
|
|
@@ -35648,7 +35670,7 @@ uniform ${i3} ${o3} u_${a3};
|
|
|
35648
35670
|
getTextSize: getTextSize2
|
|
35649
35671
|
} = options;
|
|
35650
35672
|
const { zoom, pixelRatio } = viewState;
|
|
35651
|
-
let { type
|
|
35673
|
+
let { type } = trajectory.properties;
|
|
35652
35674
|
const {
|
|
35653
35675
|
train_id: id,
|
|
35654
35676
|
line,
|
|
@@ -35657,7 +35679,7 @@ uniform ${i3} ${o3} u_${a3};
|
|
|
35657
35679
|
operator_provides_realtime_journey: operatorProvidesRealtime
|
|
35658
35680
|
} = trajectory.properties;
|
|
35659
35681
|
let { name, text_color: textColor, color } = line || {};
|
|
35660
|
-
cancelled =
|
|
35682
|
+
const cancelled = state === "JOURNEY_CANCELLED";
|
|
35661
35683
|
if (!type) {
|
|
35662
35684
|
type = "Rail";
|
|
35663
35685
|
}
|
|
@@ -35755,7 +35777,7 @@ uniform ${i3} ${o3} u_${a3};
|
|
|
35755
35777
|
var canvas;
|
|
35756
35778
|
var realtimeSimpleStyle = () => {
|
|
35757
35779
|
if (!canvas) {
|
|
35758
|
-
document.createElement("canvas");
|
|
35780
|
+
canvas = document.createElement("canvas");
|
|
35759
35781
|
canvas.width = 15;
|
|
35760
35782
|
canvas.height = 15;
|
|
35761
35783
|
const ctx = canvas.getContext("2d");
|