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,41 +1,13 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
var GeoJSON_1 = require("ol/format/GeoJSON");
|
|
30
|
-
var layer_1 = require("ol/layer");
|
|
31
|
-
var Source_1 = require("ol/source/Source");
|
|
32
|
-
var transform_1 = require("ol/transform");
|
|
33
|
-
var source_1 = require("ol/source");
|
|
34
|
-
var Layer_1 = require("./Layer");
|
|
35
|
-
var RealtimeLayerMixin_1 = require("../../common/mixins/RealtimeLayerMixin");
|
|
36
|
-
var styles_1 = require("../styles");
|
|
1
|
+
import GeoJSON from 'ol/format/GeoJSON';
|
|
2
|
+
import { Layer as OLLayer, Group, Vector as VectorLayer } from 'ol/layer';
|
|
3
|
+
import Source from 'ol/source/Source';
|
|
4
|
+
import { composeCssTransform } from 'ol/transform';
|
|
5
|
+
import { Vector as VectorSource } from 'ol/source';
|
|
6
|
+
import Layer from './Layer';
|
|
7
|
+
import mixin from '../../common/mixins/RealtimeLayerMixin';
|
|
8
|
+
import { fullTrajectoryStyle } from '../styles';
|
|
37
9
|
/** @private */
|
|
38
|
-
|
|
10
|
+
const format = new GeoJSON();
|
|
39
11
|
/**
|
|
40
12
|
* Responsible for loading and display data from a Realtime service.
|
|
41
13
|
*
|
|
@@ -54,128 +26,123 @@ var format = new GeoJSON_1.default();
|
|
|
54
26
|
* @implements {UserInteractionsLayerInterface}
|
|
55
27
|
* @implements {RealtimeLayerInterface}
|
|
56
28
|
*/
|
|
57
|
-
|
|
58
|
-
__extends(RealtimeLayer, _super);
|
|
29
|
+
class RealtimeLayer extends mixin(Layer) {
|
|
59
30
|
/**
|
|
60
31
|
* Constructor.
|
|
61
32
|
*
|
|
62
33
|
* @param {Object} options
|
|
63
34
|
* @private
|
|
64
35
|
*/
|
|
65
|
-
|
|
66
|
-
if (options === void 0) { options = {}; }
|
|
67
|
-
var _this =
|
|
36
|
+
constructor(options = {}) {
|
|
68
37
|
// We use a group to be able to add custom vector layer in extended class.
|
|
69
38
|
// For example TrajservLayer use a vectorLayer to display the complete trajectory.
|
|
70
|
-
|
|
39
|
+
super(Object.assign({}, options));
|
|
71
40
|
/** @ignore */
|
|
72
|
-
|
|
41
|
+
this.olLayer =
|
|
73
42
|
options.olLayer ||
|
|
74
|
-
new
|
|
43
|
+
new Group({
|
|
75
44
|
layers: [
|
|
76
|
-
new
|
|
77
|
-
source: new
|
|
78
|
-
style:
|
|
79
|
-
return (options.fullTrajectoryStyle ||
|
|
45
|
+
new VectorLayer({
|
|
46
|
+
source: new VectorSource({ features: [] }),
|
|
47
|
+
style: (feature, resolution) => {
|
|
48
|
+
return (options.fullTrajectoryStyle || fullTrajectoryStyle)(feature, resolution, this.styleOptions);
|
|
80
49
|
},
|
|
81
50
|
}),
|
|
82
|
-
new
|
|
83
|
-
source: new
|
|
84
|
-
render:
|
|
85
|
-
if (!
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
51
|
+
new OLLayer({
|
|
52
|
+
source: new Source({}),
|
|
53
|
+
render: (frameState) => {
|
|
54
|
+
if (!this.container) {
|
|
55
|
+
this.container = document.createElement('div');
|
|
56
|
+
this.container.style.position = 'absolute';
|
|
57
|
+
this.container.style.width = '100%';
|
|
58
|
+
this.container.style.height = '100%';
|
|
59
|
+
this.transformContainer = document.createElement('div');
|
|
60
|
+
this.transformContainer.style.position = 'absolute';
|
|
61
|
+
this.transformContainer.style.width = '100%';
|
|
62
|
+
this.transformContainer.style.height = '100%';
|
|
63
|
+
this.container.appendChild(this.transformContainer);
|
|
64
|
+
this.canvas.style.position = 'absolute';
|
|
65
|
+
this.canvas.style.top = '0';
|
|
66
|
+
this.canvas.style.left = '0';
|
|
67
|
+
this.canvas.style.transformOrigin = 'top left';
|
|
68
|
+
this.transformContainer.appendChild(this.canvas);
|
|
100
69
|
}
|
|
101
|
-
if (
|
|
102
|
-
|
|
103
|
-
|
|
70
|
+
if (this.renderedViewState) {
|
|
71
|
+
const { center, resolution, rotation } = frameState.viewState;
|
|
72
|
+
const { center: renderedCenter, resolution: renderedResolution, rotation: renderedRotation, } = this.renderedViewState;
|
|
104
73
|
if (renderedResolution / resolution >= 3) {
|
|
105
74
|
// Avoid having really big points when zooming fast.
|
|
106
|
-
|
|
107
|
-
context.clearRect(0, 0,
|
|
75
|
+
const context = this.canvas.getContext('2d');
|
|
76
|
+
context.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
|
108
77
|
}
|
|
109
78
|
else {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
79
|
+
const pixelCenterRendered = this.map.getPixelFromCoordinate(renderedCenter);
|
|
80
|
+
const pixelCenter = this.map.getPixelFromCoordinate(center);
|
|
81
|
+
this.transformContainer.style.transform = composeCssTransform(pixelCenterRendered[0] - pixelCenter[0], pixelCenterRendered[1] - pixelCenter[1], renderedResolution / resolution, renderedResolution / resolution, rotation - renderedRotation, 0, 0);
|
|
113
82
|
}
|
|
114
83
|
}
|
|
115
|
-
return
|
|
84
|
+
return this.container;
|
|
116
85
|
},
|
|
117
86
|
}),
|
|
118
87
|
],
|
|
119
88
|
});
|
|
120
89
|
// We store the layer used to highlight the full Trajectory
|
|
121
|
-
|
|
90
|
+
this.vectorLayer = this.olLayer.getLayers().item(0);
|
|
122
91
|
// Options the last render run did happen. If something changes
|
|
123
92
|
// we have to render again
|
|
124
93
|
/** @ignore */
|
|
125
|
-
|
|
94
|
+
this.renderState = {
|
|
126
95
|
center: [0, 0],
|
|
127
96
|
zoom: null,
|
|
128
97
|
rotation: 0,
|
|
129
98
|
};
|
|
130
|
-
return _this;
|
|
131
99
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
_super.prototype.attachToMap.call(this, map);
|
|
100
|
+
attachToMap(map) {
|
|
101
|
+
super.attachToMap(map);
|
|
135
102
|
if (this.map) {
|
|
136
|
-
this.olListenersKeys.push(this.map.on(['moveend', 'change:target'],
|
|
137
|
-
|
|
103
|
+
this.olListenersKeys.push(this.map.on(['moveend', 'change:target'], (evt) => {
|
|
104
|
+
const view = this.map.getView();
|
|
138
105
|
if (view.getAnimating() || view.getInteracting()) {
|
|
139
106
|
return;
|
|
140
107
|
}
|
|
141
|
-
|
|
108
|
+
const zoom = view.getZoom();
|
|
142
109
|
// Update the interval between render updates
|
|
143
|
-
if (
|
|
144
|
-
|
|
110
|
+
if (this.currentZoom !== zoom) {
|
|
111
|
+
this.onZoomEnd(evt);
|
|
145
112
|
}
|
|
146
|
-
|
|
147
|
-
|
|
113
|
+
this.currentZoom = zoom;
|
|
114
|
+
this.onMoveEnd(evt);
|
|
148
115
|
}));
|
|
149
116
|
}
|
|
150
|
-
}
|
|
117
|
+
}
|
|
151
118
|
/**
|
|
152
119
|
* Destroy the container of the tracker.
|
|
153
120
|
*/
|
|
154
|
-
|
|
155
|
-
|
|
121
|
+
detachFromMap() {
|
|
122
|
+
super.detachFromMap();
|
|
156
123
|
this.container = null;
|
|
157
|
-
}
|
|
124
|
+
}
|
|
158
125
|
/**
|
|
159
126
|
* Detect in the canvas if there is data to query at a specific coordinate.
|
|
160
127
|
* @param {ol/coordinate~Coordinate} coordinate The coordinate to test
|
|
161
128
|
* @returns
|
|
162
129
|
*/
|
|
163
|
-
|
|
130
|
+
hasFeatureInfoAtCoordinate(coordinate) {
|
|
164
131
|
if (this.map && this.canvas) {
|
|
165
|
-
|
|
166
|
-
|
|
132
|
+
const context = this.canvas.getContext('2d');
|
|
133
|
+
const pixel = this.map.getPixelFromCoordinate(coordinate);
|
|
167
134
|
return !!context.getImageData(pixel[0] * this.pixelRatio, pixel[1] * this.pixelRatio, 1, 1).data[3];
|
|
168
135
|
}
|
|
169
136
|
return false;
|
|
170
|
-
}
|
|
137
|
+
}
|
|
171
138
|
/**
|
|
172
139
|
* Render the trajectories using current map's size, resolution and rotation.
|
|
173
140
|
* @param {boolean} noInterpolate if true, renders the vehicles without interpolating theirs positions.
|
|
174
141
|
* @overrides
|
|
175
142
|
*/
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
143
|
+
renderTrajectories(noInterpolate) {
|
|
144
|
+
const view = this.map.getView();
|
|
145
|
+
super.renderTrajectories({
|
|
179
146
|
size: this.map.getSize(),
|
|
180
147
|
center: this.map.getView().getCenter(),
|
|
181
148
|
extent: view.calculateExtent(),
|
|
@@ -184,49 +151,48 @@ var RealtimeLayer = /** @class */ (function (_super) {
|
|
|
184
151
|
zoom: view.getZoom(),
|
|
185
152
|
pixelRatio: this.pixelRatio,
|
|
186
153
|
}, noInterpolate);
|
|
187
|
-
}
|
|
154
|
+
}
|
|
188
155
|
/**
|
|
189
156
|
* Launch renderTrajectories. it avoids duplicating code in renderTrajectories methhod.
|
|
190
157
|
* @private
|
|
191
158
|
* @override
|
|
192
159
|
*/
|
|
193
|
-
|
|
160
|
+
renderTrajectoriesInternal(viewState, noInterpolate) {
|
|
194
161
|
if (!this.map) {
|
|
195
162
|
return false;
|
|
196
163
|
}
|
|
197
|
-
|
|
198
|
-
|
|
164
|
+
let isRendered = false;
|
|
165
|
+
const blockRendering = this.map.getView().getAnimating() || this.map.getView().getInteracting();
|
|
199
166
|
// Don't render the map when the map is animating or interacting.
|
|
200
167
|
isRendered = blockRendering
|
|
201
168
|
? false
|
|
202
|
-
:
|
|
169
|
+
: super.renderTrajectoriesInternal(viewState, noInterpolate);
|
|
203
170
|
// We update the current render state.
|
|
204
171
|
if (isRendered) {
|
|
205
|
-
this.renderedViewState =
|
|
172
|
+
this.renderedViewState = Object.assign({}, viewState);
|
|
206
173
|
if (this.transformContainer) {
|
|
207
174
|
this.transformContainer.style.transform = '';
|
|
208
175
|
}
|
|
209
176
|
}
|
|
210
177
|
return isRendered;
|
|
211
|
-
}
|
|
178
|
+
}
|
|
212
179
|
/**
|
|
213
180
|
* Return the delay in ms before the next rendering.
|
|
214
181
|
*/
|
|
215
|
-
|
|
216
|
-
return
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
};
|
|
182
|
+
getRefreshTimeInMs() {
|
|
183
|
+
return super.getRefreshTimeInMs(this.map.getView().getZoom());
|
|
184
|
+
}
|
|
185
|
+
getFeatureInfoAtCoordinate(coordinate, options = {}) {
|
|
186
|
+
const resolution = this.map.getView().getResolution();
|
|
187
|
+
return super.getFeatureInfoAtCoordinate(coordinate, Object.assign({ resolution }, options));
|
|
188
|
+
}
|
|
223
189
|
/**
|
|
224
190
|
* On move end we update the websocket with the new bbox.
|
|
225
191
|
*
|
|
226
192
|
* @private
|
|
227
193
|
* @override
|
|
228
194
|
*/
|
|
229
|
-
|
|
195
|
+
onMoveEnd() {
|
|
230
196
|
if (this.visible && this.isUpdateBboxOnMoveEnd) {
|
|
231
197
|
this.setBbox();
|
|
232
198
|
}
|
|
@@ -236,7 +202,7 @@ var RealtimeLayer = /** @class */ (function (_super) {
|
|
|
236
202
|
this.selectedVehicleId) {
|
|
237
203
|
this.highlightTrajectory(this.selectedVehicleId);
|
|
238
204
|
}
|
|
239
|
-
}
|
|
205
|
+
}
|
|
240
206
|
/**
|
|
241
207
|
* Function called on moveend event only when the zoom has changed.
|
|
242
208
|
*
|
|
@@ -245,86 +211,84 @@ var RealtimeLayer = /** @class */ (function (_super) {
|
|
|
245
211
|
* @override
|
|
246
212
|
*/
|
|
247
213
|
// eslint-disable-next-line no-unused-vars
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
}
|
|
214
|
+
onZoomEnd(evt) {
|
|
215
|
+
super.onZoomEnd(evt);
|
|
216
|
+
}
|
|
251
217
|
/**
|
|
252
218
|
* Update the cursor style when hovering a vehicle.
|
|
253
219
|
*
|
|
254
220
|
* @private
|
|
255
221
|
* @override
|
|
256
222
|
*/
|
|
257
|
-
|
|
258
|
-
|
|
223
|
+
onFeatureHover(features, layer, coordinate) {
|
|
224
|
+
super.onFeatureHover(features, layer, coordinate);
|
|
259
225
|
this.map.getTargetElement().style.cursor = features.length
|
|
260
226
|
? 'pointer'
|
|
261
227
|
: 'auto';
|
|
262
|
-
}
|
|
228
|
+
}
|
|
263
229
|
/**
|
|
264
230
|
* Display the complete trajectory of the vehicle.
|
|
265
231
|
*
|
|
266
232
|
* @private
|
|
267
233
|
* @override
|
|
268
234
|
*/
|
|
269
|
-
|
|
270
|
-
|
|
235
|
+
onFeatureClick(features, layer, coordinate) {
|
|
236
|
+
super.onFeatureClick(features, layer, coordinate);
|
|
271
237
|
if (!features.length && this.vectorLayer) {
|
|
272
238
|
this.vectorLayer.getSource().clear();
|
|
273
239
|
}
|
|
274
240
|
if (this.selectedVehicleId) {
|
|
275
241
|
this.highlightTrajectory(this.selectedVehicleId);
|
|
276
242
|
}
|
|
277
|
-
}
|
|
243
|
+
}
|
|
278
244
|
/**
|
|
279
245
|
* Remove the trajectory form the list if necessary.
|
|
280
246
|
*
|
|
281
247
|
* @private
|
|
282
248
|
*/
|
|
283
|
-
|
|
284
|
-
return
|
|
285
|
-
}
|
|
249
|
+
purgeTrajectory(trajectory, extent, zoom) {
|
|
250
|
+
return super.purgeTrajectory(trajectory, extent || this.map.getView().calculateExtent(), zoom || this.map.getView().getZoom());
|
|
251
|
+
}
|
|
286
252
|
/**
|
|
287
253
|
* Send the current bbox to the websocket
|
|
288
254
|
*
|
|
289
255
|
* @private
|
|
290
256
|
*/
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
257
|
+
setBbox(extent, zoom) {
|
|
258
|
+
let newExtent = extent;
|
|
259
|
+
let newZoom = zoom;
|
|
294
260
|
if (!newExtent && this.isUpdateBboxOnMoveEnd) {
|
|
295
261
|
newExtent = extent || this.map.getView().calculateExtent();
|
|
296
262
|
newZoom = Math.floor(this.map.getView().getZoom());
|
|
297
263
|
}
|
|
298
|
-
|
|
299
|
-
}
|
|
264
|
+
super.setBbox(newExtent, newZoom);
|
|
265
|
+
}
|
|
300
266
|
/**
|
|
301
267
|
* Highlight the trajectory of journey.
|
|
302
268
|
* @private
|
|
303
269
|
*/
|
|
304
|
-
|
|
305
|
-
var _this = this;
|
|
270
|
+
highlightTrajectory(id) {
|
|
306
271
|
this.api
|
|
307
272
|
.getFullTrajectory(id, this.mode, this.generalizationLevel)
|
|
308
|
-
.then(
|
|
309
|
-
|
|
273
|
+
.then((fullTrajectory) => {
|
|
274
|
+
const vectorSource = this.vectorLayer.getSource();
|
|
310
275
|
vectorSource.clear();
|
|
311
276
|
if (!fullTrajectory ||
|
|
312
277
|
!fullTrajectory.features ||
|
|
313
278
|
!fullTrajectory.features.length) {
|
|
314
279
|
return;
|
|
315
280
|
}
|
|
316
|
-
|
|
317
|
-
|
|
281
|
+
const features = format.readFeatures(fullTrajectory);
|
|
282
|
+
this.vectorLayer.getSource().addFeatures(features);
|
|
318
283
|
});
|
|
319
|
-
}
|
|
284
|
+
}
|
|
320
285
|
/**
|
|
321
286
|
* Create a copy of the RealtimeLayer.
|
|
322
287
|
* @param {Object} newOptions Options to override
|
|
323
288
|
* @return {RealtimeLayer} A RealtimeLayer
|
|
324
289
|
*/
|
|
325
|
-
|
|
326
|
-
return new RealtimeLayer(
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
exports.default = RealtimeLayer;
|
|
290
|
+
clone(newOptions) {
|
|
291
|
+
return new RealtimeLayer(Object.assign(Object.assign({}, this.options), newOptions));
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
export default RealtimeLayer;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RealtimeLayer.test.d.ts","sourceRoot":"","sources":["../../../src/ol/layers/RealtimeLayer.test.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import fetch from 'jest-fetch-mock';
|
|
2
|
+
import Map from 'ol/Map';
|
|
3
|
+
import View from 'ol/View';
|
|
4
|
+
import WS from 'jest-websocket-mock';
|
|
5
|
+
import RealtimeLayer from './RealtimeLayer';
|
|
6
|
+
// create a WS instance, listening on port 1234 on localhost
|
|
7
|
+
let layer;
|
|
8
|
+
let onClick;
|
|
9
|
+
let olMap;
|
|
10
|
+
let server;
|
|
11
|
+
describe('RealtimeLayer', () => {
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
server = new WS('ws://localhost:1234');
|
|
14
|
+
global.fetch = fetch;
|
|
15
|
+
fetch.resetMocks();
|
|
16
|
+
onClick = jest.fn();
|
|
17
|
+
layer = new RealtimeLayer({
|
|
18
|
+
url: 'ws://localhost:1234',
|
|
19
|
+
apiKey: 'apiKey',
|
|
20
|
+
onClick,
|
|
21
|
+
});
|
|
22
|
+
olMap = new Map({
|
|
23
|
+
view: new View({
|
|
24
|
+
center: [831634, 5933959],
|
|
25
|
+
zoom: 9,
|
|
26
|
+
}),
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
afterEach(() => {
|
|
30
|
+
// ...or gracefully close the connection
|
|
31
|
+
server.close();
|
|
32
|
+
// The WS class also has a static "clean" method to gracefully close all open connections,
|
|
33
|
+
// particularly useful to reset the environment between test runs.
|
|
34
|
+
WS.clean();
|
|
35
|
+
});
|
|
36
|
+
test('should be instanced.', () => {
|
|
37
|
+
expect(layer).toBeInstanceOf(RealtimeLayer);
|
|
38
|
+
});
|
|
39
|
+
test('should called terminate on initalization.', () => {
|
|
40
|
+
const spy = jest.spyOn(layer, 'detachFromMap');
|
|
41
|
+
fetch.mockResponseOnce(JSON.stringify(global.fetchTrajectoriesResponse));
|
|
42
|
+
layer.attachToMap(olMap);
|
|
43
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
44
|
+
});
|
|
45
|
+
test('should clone', () => {
|
|
46
|
+
const clone = layer.clone({ name: 'clone' });
|
|
47
|
+
expect(clone).not.toBe(layer);
|
|
48
|
+
expect(clone.name).toBe('clone');
|
|
49
|
+
expect(clone).toBeInstanceOf(RealtimeLayer);
|
|
50
|
+
});
|
|
51
|
+
test('should use the sort function.', () => {
|
|
52
|
+
const fn = () => true;
|
|
53
|
+
const laye = new RealtimeLayer({
|
|
54
|
+
url: 'ws://localhost:1234',
|
|
55
|
+
apiKey: 'apiKey',
|
|
56
|
+
sort: fn,
|
|
57
|
+
});
|
|
58
|
+
expect(laye).toBeInstanceOf(RealtimeLayer);
|
|
59
|
+
expect(laye.sort).toBe(fn);
|
|
60
|
+
});
|
|
61
|
+
test('should use filter function.', () => {
|
|
62
|
+
const fn = () => true;
|
|
63
|
+
const laye = new RealtimeLayer({
|
|
64
|
+
url: 'ws://localhost:1234',
|
|
65
|
+
apiKey: 'apiKey',
|
|
66
|
+
filter: fn, // reverse the array
|
|
67
|
+
});
|
|
68
|
+
expect(laye).toBeInstanceOf(RealtimeLayer);
|
|
69
|
+
expect(laye.filter).toBe(fn);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
@@ -11,14 +11,14 @@ declare class RoutingLayer extends Layer {
|
|
|
11
11
|
* @param {Object} [options]
|
|
12
12
|
* @param {ol/style/Style~StyleLike} [options.style] Style to be used for routes, uses (ol/StyleLike) [https://openlayers.org/en/latest/apidoc/module-ol_style_Style.html#~StyleLike] instances
|
|
13
13
|
*/
|
|
14
|
-
constructor(options?:
|
|
14
|
+
constructor(options?: Object | undefined);
|
|
15
15
|
olLayer: any;
|
|
16
16
|
/**
|
|
17
17
|
* Create a copy of the RoutingLayer.
|
|
18
18
|
* @param {Object} newOptions Options to override
|
|
19
19
|
* @return {RoutingLayer} A RoutingLayer
|
|
20
20
|
*/
|
|
21
|
-
clone(newOptions:
|
|
21
|
+
clone(newOptions: Object): RoutingLayer;
|
|
22
22
|
}
|
|
23
23
|
import Layer from "./Layer";
|
|
24
24
|
//# sourceMappingURL=RoutingLayer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RoutingLayer.d.ts","sourceRoot":"","sources":["../../../src/ol/layers/RoutingLayer.js"],"names":[],"mappings":";AA8DA;;;;;GAKG;AACH;IACE;;;;OAIG;IACH,
|
|
1
|
+
{"version":3,"file":"RoutingLayer.d.ts","sourceRoot":"","sources":["../../../src/ol/layers/RoutingLayer.js"],"names":[],"mappings":";AA8DA;;;;;GAKG;AACH;IACE;;;;OAIG;IACH,0CASC;IANC,aAKI;IAGN;;;;OAIG;IACH,kBAHW,MAAM,GACL,YAAY,CAIvB;CACF"}
|