mobility-toolbox-js 2.0.1-beta.13 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api/RealtimeAPI.d.ts +279 -0
- package/api/RealtimeAPI.d.ts.map +1 -0
- package/api/RealtimeAPI.js +466 -0
- package/api/RoutingAPI.d.ts +37 -0
- package/api/RoutingAPI.d.ts.map +1 -0
- package/api/RoutingAPI.js +32 -12
- package/api/StopsAPI.d.ts +38 -0
- package/api/StopsAPI.d.ts.map +1 -0
- package/api/StopsAPI.js +33 -9
- package/api/index.d.ts +4 -0
- package/api/index.d.ts.map +1 -0
- package/api/index.js +3 -3
- package/api/typedefs.d.ts +179 -0
- package/api/typedefs.d.ts.map +1 -0
- package/api/typedefs.js +75 -0
- package/common/api/HttpAPI.d.ts +31 -0
- package/common/api/HttpAPI.d.ts.map +1 -0
- package/common/api/HttpAPI.js +54 -27
- package/common/api/WebSocketAPI.d.ts +153 -0
- package/common/api/WebSocketAPI.d.ts.map +1 -0
- package/common/api/WebSocketAPI.js +330 -164
- package/common/controls/ControlCommon.d.ts +76 -0
- package/common/controls/ControlCommon.d.ts.map +1 -0
- package/common/controls/ControlCommon.js +150 -0
- package/common/controls/CopyrightControlCommon.d.ts +13 -0
- package/common/controls/CopyrightControlCommon.d.ts.map +1 -0
- package/common/controls/CopyrightControlCommon.js +34 -0
- package/common/controls/StopFinderControlCommon.d.ts +55 -0
- package/common/controls/StopFinderControlCommon.d.ts.map +1 -0
- package/common/controls/StopFinderControlCommon.js +144 -0
- package/common/index.d.ts +3 -0
- package/common/index.d.ts.map +1 -0
- package/common/index.js +2 -4
- package/common/layers/LayerCommon.d.ts +94 -0
- package/common/layers/LayerCommon.d.ts.map +1 -0
- package/common/layers/LayerCommon.js +244 -0
- package/common/mixins/RealtimeLayerMixin.d.ts +286 -0
- package/common/mixins/RealtimeLayerMixin.d.ts.map +1 -0
- package/common/mixins/RealtimeLayerMixin.js +776 -0
- package/common/mixins/UserInteractionsLayerMixin.d.ts +60 -0
- package/common/mixins/UserInteractionsLayerMixin.d.ts.map +1 -0
- package/common/mixins/UserInteractionsLayerMixin.js +241 -0
- package/common/styles/index.d.ts +5 -0
- package/common/styles/index.d.ts.map +1 -0
- package/common/styles/index.js +4 -4
- package/common/styles/realtimeDefaultStyle.d.ts +36 -0
- package/common/styles/realtimeDefaultStyle.d.ts.map +1 -0
- package/common/styles/realtimeDefaultStyle.js +275 -0
- package/common/styles/realtimeDelayStyle.d.ts +12 -0
- package/common/styles/realtimeDelayStyle.d.ts.map +1 -0
- package/common/styles/realtimeDelayStyle.js +13 -0
- package/common/styles/realtimeHeadingStyle.d.ts +12 -0
- package/common/styles/realtimeHeadingStyle.d.ts.map +1 -0
- package/common/styles/realtimeHeadingStyle.js +85 -0
- package/common/styles/realtimeSimpleStyle.d.ts +4 -0
- package/common/styles/realtimeSimpleStyle.d.ts.map +1 -0
- package/common/styles/realtimeSimpleStyle.js +23 -0
- package/common/typedefs.d.ts +111 -0
- package/common/typedefs.d.ts.map +1 -0
- package/common/typedefs.js +52 -0
- package/common/utils/compareDepartures.d.ts +11 -0
- package/common/utils/compareDepartures.d.ts.map +1 -0
- package/common/utils/compareDepartures.js +35 -0
- package/common/utils/createCanvas.d.ts +10 -0
- package/common/utils/createCanvas.d.ts.map +1 -0
- package/common/utils/createCanvas.js +27 -0
- package/common/utils/createRealtimeFilters.d.ts +13 -0
- package/common/utils/createRealtimeFilters.d.ts.map +1 -0
- package/common/utils/createRealtimeFilters.js +74 -0
- package/common/utils/debounceDeparturesMessages.d.ts +12 -0
- package/common/utils/debounceDeparturesMessages.d.ts.map +1 -0
- package/common/utils/debounceDeparturesMessages.js +24 -0
- package/common/utils/debounceWebsocketMessages.d.ts +11 -0
- package/common/utils/debounceWebsocketMessages.d.ts.map +1 -0
- package/common/utils/debounceWebsocketMessages.js +29 -0
- package/common/utils/getLayersAsFlatArray.d.ts +3 -0
- package/common/utils/getLayersAsFlatArray.d.ts.map +1 -0
- package/common/utils/getLayersAsFlatArray.js +15 -0
- package/common/utils/getMapboxMapCopyrights.d.ts +18 -0
- package/common/utils/getMapboxMapCopyrights.d.ts.map +1 -0
- package/common/utils/getMapboxMapCopyrights.js +26 -15
- package/common/utils/getMapboxRender.d.ts +7 -0
- package/common/utils/getMapboxRender.d.ts.map +1 -0
- package/common/utils/getMapboxRender.js +87 -0
- package/common/utils/getMaplibreRender.d.ts +7 -0
- package/common/utils/getMaplibreRender.d.ts.map +1 -0
- package/common/utils/getMaplibreRender.js +38 -0
- package/common/utils/getRealtimeModeSuffix.d.ts +10 -0
- package/common/utils/getRealtimeModeSuffix.d.ts.map +1 -0
- package/common/utils/getRealtimeModeSuffix.js +7 -0
- package/common/utils/getUrlWithParams.d.ts +9 -0
- package/common/utils/getUrlWithParams.d.ts.map +1 -0
- package/common/utils/getUrlWithParams.js +18 -0
- package/common/utils/getVehiclePosition.d.ts +16 -0
- package/common/utils/getVehiclePosition.d.ts.map +1 -0
- package/common/utils/getVehiclePosition.js +67 -37
- package/common/utils/index.d.ts +17 -0
- package/common/utils/index.d.ts.map +1 -0
- package/common/utils/index.js +17 -5
- package/common/utils/realtimeConfig.d.ts +49 -0
- package/common/utils/realtimeConfig.d.ts.map +1 -0
- package/common/utils/realtimeConfig.js +173 -0
- package/common/utils/removeDuplicate.d.ts +10 -0
- package/common/utils/removeDuplicate.d.ts.map +1 -0
- package/common/utils/removeDuplicate.js +12 -5
- package/common/utils/renderTrajectories.d.ts +17 -0
- package/common/utils/renderTrajectories.d.ts.map +1 -0
- package/common/utils/renderTrajectories.js +110 -0
- package/common/utils/sortAndFilterDepartures.d.ts +16 -0
- package/common/utils/sortAndFilterDepartures.d.ts.map +1 -0
- package/common/utils/sortAndFilterDepartures.js +58 -0
- package/common/utils/sortByDelay.d.ts +3 -0
- package/common/utils/sortByDelay.d.ts.map +1 -0
- package/common/utils/sortByDelay.js +17 -15
- package/common/utils/timeUtils.d.ts +24 -0
- package/common/utils/timeUtils.d.ts.map +1 -0
- package/common/utils/timeUtils.js +34 -15
- package/iife.d.ts +3 -0
- package/iife.d.ts.map +1 -0
- package/iife.js +5 -0
- package/index.d.ts +10 -0
- package/index.d.ts.map +1 -0
- package/index.js +8 -6
- package/mapbox/controls/CopyrightControl.d.ts +29 -0
- package/mapbox/controls/CopyrightControl.d.ts.map +1 -0
- package/mapbox/controls/CopyrightControl.js +44 -25
- package/mapbox/controls/index.d.ts +2 -0
- package/mapbox/controls/index.d.ts.map +1 -0
- package/mapbox/controls/index.js +2 -1
- package/mapbox/index.d.ts +6 -0
- package/mapbox/index.d.ts.map +1 -0
- package/mapbox/index.js +5 -4
- package/mapbox/layers/Layer.d.ts +59 -0
- package/mapbox/layers/Layer.d.ts.map +1 -0
- package/mapbox/layers/Layer.js +99 -55
- package/mapbox/layers/RealtimeLayer.d.ts +181 -0
- package/mapbox/layers/RealtimeLayer.d.ts.map +1 -0
- package/mapbox/layers/RealtimeLayer.js +276 -0
- package/mapbox/layers/index.d.ts +3 -0
- package/mapbox/layers/index.d.ts.map +1 -0
- package/mapbox/layers/index.js +2 -2
- package/mapbox/utils/getMercatorResolution.d.ts +9 -0
- package/mapbox/utils/getMercatorResolution.d.ts.map +1 -0
- package/mapbox/utils/getMercatorResolution.js +18 -0
- package/mapbox/utils/getSourceCoordinates.d.ts +9 -0
- package/mapbox/utils/getSourceCoordinates.d.ts.map +1 -0
- package/mapbox/utils/getSourceCoordinates.js +27 -0
- package/mapbox/utils/index.d.ts +3 -0
- package/mapbox/utils/index.d.ts.map +1 -0
- package/mapbox/utils/index.js +2 -0
- package/mbt.js +26061 -16500
- package/mbt.js.map +4 -4
- package/mbt.min.js +205 -126
- package/mbt.min.js.map +4 -4
- package/ol/controls/CopyrightControl.d.ts +31 -0
- package/ol/controls/CopyrightControl.d.ts.map +1 -0
- package/ol/controls/CopyrightControl.js +62 -36
- package/ol/controls/RoutingControl.d.ts +193 -0
- package/ol/controls/RoutingControl.d.ts.map +1 -0
- package/ol/controls/RoutingControl.js +601 -357
- package/ol/controls/StopFinderControl.d.ts +30 -0
- package/ol/controls/StopFinderControl.d.ts.map +1 -0
- package/ol/controls/StopFinderControl.js +30 -8
- package/ol/controls/index.d.ts +4 -0
- package/ol/controls/index.d.ts.map +1 -0
- package/ol/controls/index.js +3 -3
- package/ol/index.d.ts +6 -0
- package/ol/index.d.ts.map +1 -0
- package/ol/index.js +5 -5
- package/ol/layers/Layer.d.ts +86 -0
- package/ol/layers/Layer.d.ts.map +1 -0
- package/ol/layers/Layer.js +163 -77
- package/ol/layers/MapGlLayer.d.ts +67 -0
- package/ol/layers/MapGlLayer.d.ts.map +1 -0
- package/ol/layers/MapGlLayer.js +218 -0
- package/ol/layers/MapboxLayer.d.ts +50 -0
- package/ol/layers/MapboxLayer.d.ts.map +1 -0
- package/ol/layers/MapboxLayer.js +99 -193
- package/ol/layers/MapboxStyleLayer.d.ts +129 -0
- package/ol/layers/MapboxStyleLayer.d.ts.map +1 -0
- package/ol/layers/MapboxStyleLayer.js +362 -171
- package/ol/layers/MaplibreLayer.d.ts +28 -0
- package/ol/layers/MaplibreLayer.d.ts.map +1 -0
- package/ol/layers/MaplibreLayer.js +30 -135
- package/ol/layers/RealtimeLayer.d.ts +202 -0
- package/ol/layers/RealtimeLayer.d.ts.map +1 -0
- package/ol/layers/RealtimeLayer.js +340 -0
- package/ol/layers/RoutingLayer.d.ts +34 -0
- package/ol/layers/RoutingLayer.d.ts.map +1 -0
- package/ol/layers/RoutingLayer.js +72 -48
- package/ol/layers/VectorLayer.d.ts +25 -0
- package/ol/layers/VectorLayer.d.ts.map +1 -0
- package/ol/layers/VectorLayer.js +34 -18
- package/ol/layers/WMSLayer.d.ts +42 -0
- package/ol/layers/WMSLayer.d.ts.map +1 -0
- package/ol/layers/WMSLayer.js +84 -34
- package/ol/layers/index.d.ts +9 -0
- package/ol/layers/index.d.ts.map +1 -0
- package/ol/layers/index.js +8 -8
- package/ol/styles/fullTrajectoryDelayStyle.d.ts +4 -0
- package/ol/styles/fullTrajectoryDelayStyle.d.ts.map +1 -0
- package/ol/styles/fullTrajectoryDelayStyle.js +26 -24
- package/ol/styles/fullTrajectoryStyle.d.ts +5 -0
- package/ol/styles/fullTrajectoryStyle.d.ts.map +1 -0
- package/ol/styles/fullTrajectoryStyle.js +40 -39
- package/ol/styles/index.d.ts +3 -0
- package/ol/styles/index.d.ts.map +1 -0
- package/ol/styles/index.js +2 -2
- package/package.json +81 -133
- package/setupTests.d.ts +2 -0
- package/setupTests.d.ts.map +1 -0
- package/setupTests.js +26 -0
- package/types/common.d.ts +122 -0
- package/types/index.d.ts +11 -0
- package/types/realtime.d.ts +320 -0
- package/types/routing.d.ts +206 -0
- package/types/stops.d.ts +143 -0
- package/README.md +0 -23
- package/api/RoutingAPI.test.js +0 -25
- package/api/StopsAPI.test.js +0 -22
- package/api/TralisAPI.js +0 -359
- package/api/TralisAPI.test.js +0 -67
- package/api/TralisAPIUtils.js +0 -43
- package/common/Tracker.js +0 -93
- package/common/api/HttpAPI.test.js +0 -50
- package/common/api/WebSocketAPI.test.js +0 -311
- package/common/controls/Control.js +0 -81
- package/common/controls/Control.test.js +0 -87
- package/common/layers/Layer.js +0 -213
- package/common/layers/Layer.test.js +0 -526
- package/common/mixins/CopyrightMixin.js +0 -24
- package/common/mixins/SearchMixin.js +0 -110
- package/common/mixins/TralisLayerMixin.js +0 -479
- package/common/styles/trackerDefaultStyle.js +0 -197
- package/common/styles/trackerDelayStyle.js +0 -8
- package/common/styles/trackerSimpleStyle.js +0 -18
- package/common/trackerConfig.js +0 -152
- package/common/trackerConfig.test.js +0 -23
- package/common/utils/createTrackerFilters.js +0 -56
- package/common/utils/createTrackerFilters.test.js +0 -79
- package/common/utils/getMapboxMapCopyrights.test.js +0 -40
- package/common/utils/getMapboxStyleUrl.js +0 -22
- package/common/utils/removeDuplicate.test.js +0 -19
- package/common/utils/timeUtils.test.js +0 -10
- package/mapbox/layers/Layer.test.js +0 -182
- package/mapbox/layers/TralisLayer.js +0 -182
- package/mapbox/layers/TralisLayer.test.js +0 -38
- package/mapbox/utils.js +0 -32
- package/ol/controls/CopyrightControl.test.js +0 -165
- package/ol/controls/RoutingControl.test.js +0 -151
- package/ol/controls/StopFinderControl.test.js +0 -48
- package/ol/layers/Layer.test.js +0 -174
- package/ol/layers/MapboxLayer.test.js +0 -160
- package/ol/layers/MapboxStyleLayer.test.js +0 -231
- package/ol/layers/RoutingLayer.test.js +0 -40
- package/ol/layers/TralisLayer.js +0 -185
- package/ol/layers/TralisLayer.test.js +0 -79
- package/ol/layers/VectorLayer.test.js +0 -87
- package/ol/layers/WMSLayer.test.js +0 -76
package/ol/layers/TralisLayer.js
DELETED
|
@@ -1,185 +0,0 @@
|
|
|
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/TralisLayerMixin";
|
|
8
|
-
import { fullTrajectoryStyle } from "../styles";
|
|
9
|
-
const format = new GeoJSON();
|
|
10
|
-
class TralisLayer extends mixin(Layer) {
|
|
11
|
-
constructor(options = {}) {
|
|
12
|
-
super({
|
|
13
|
-
...options
|
|
14
|
-
});
|
|
15
|
-
this.olLayer = options.olLayer || new Group({
|
|
16
|
-
layers: [
|
|
17
|
-
new VectorLayer({
|
|
18
|
-
source: new VectorSource({ features: [] }),
|
|
19
|
-
style: options.fullTrajectoryStyle || fullTrajectoryStyle
|
|
20
|
-
}),
|
|
21
|
-
new OLLayer({
|
|
22
|
-
source: new Source({}),
|
|
23
|
-
render: (frameState) => {
|
|
24
|
-
if (!this.tracker || !this.tracker.canvas) {
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
if (!this.container) {
|
|
28
|
-
this.container = document.createElement("div");
|
|
29
|
-
this.container.style.position = "absolute";
|
|
30
|
-
this.container.style.width = "100%";
|
|
31
|
-
this.container.style.height = "100%";
|
|
32
|
-
this.transformContainer = document.createElement("div");
|
|
33
|
-
this.transformContainer.style.position = "absolute";
|
|
34
|
-
this.transformContainer.style.width = "100%";
|
|
35
|
-
this.transformContainer.style.height = "100%";
|
|
36
|
-
this.container.appendChild(this.transformContainer);
|
|
37
|
-
this.tracker.canvas.style.position = "absolute";
|
|
38
|
-
this.tracker.canvas.style.top = "0";
|
|
39
|
-
this.tracker.canvas.style.left = "0";
|
|
40
|
-
this.tracker.canvas.style.transformOrigin = "top left";
|
|
41
|
-
this.transformContainer.appendChild(this.tracker.canvas);
|
|
42
|
-
}
|
|
43
|
-
if (this.renderedViewState) {
|
|
44
|
-
const { center, resolution, rotation } = frameState.viewState;
|
|
45
|
-
const {
|
|
46
|
-
center: renderedCenter,
|
|
47
|
-
resolution: renderedResolution,
|
|
48
|
-
rotation: renderedRotation
|
|
49
|
-
} = this.renderedViewState;
|
|
50
|
-
if (renderedResolution / resolution >= 3) {
|
|
51
|
-
const { canvas } = this.tracker;
|
|
52
|
-
const context = canvas.getContext("2d");
|
|
53
|
-
context.clearRect(0, 0, canvas.width, canvas.height);
|
|
54
|
-
} else {
|
|
55
|
-
const pixelCenterRendered = this.map.getPixelFromCoordinate(renderedCenter);
|
|
56
|
-
const pixelCenter = this.map.getPixelFromCoordinate(center);
|
|
57
|
-
this.transformContainer.style.transform = composeCssTransform(pixelCenterRendered[0] - pixelCenter[0], pixelCenterRendered[1] - pixelCenter[1], renderedResolution / resolution, renderedResolution / resolution, rotation - renderedRotation, 0, 0);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return this.container;
|
|
61
|
-
}
|
|
62
|
-
})
|
|
63
|
-
]
|
|
64
|
-
});
|
|
65
|
-
this.vectorLayer = this.olLayer.getLayers().item(0);
|
|
66
|
-
this.renderState = {
|
|
67
|
-
center: [0, 0],
|
|
68
|
-
zoom: null,
|
|
69
|
-
rotation: 0
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
attachToMap(map) {
|
|
73
|
-
super.attachToMap(map);
|
|
74
|
-
if (this.map) {
|
|
75
|
-
this.olListenersKeys.push(this.map.on(["moveend", "change:target"], (evt) => {
|
|
76
|
-
const view = this.map.getView();
|
|
77
|
-
if (view.getAnimating() || view.getInteracting()) {
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
const zoom = view.getZoom();
|
|
81
|
-
if (this.currentZoom !== zoom) {
|
|
82
|
-
this.onZoomEnd(evt);
|
|
83
|
-
}
|
|
84
|
-
this.currentZoom = zoom;
|
|
85
|
-
this.onMoveEnd(evt);
|
|
86
|
-
}));
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
detachFromMap() {
|
|
90
|
-
super.detachFromMap();
|
|
91
|
-
this.container = null;
|
|
92
|
-
}
|
|
93
|
-
hasFeatureInfoAtCoordinate(coordinate) {
|
|
94
|
-
if (this.map && this.tracker && this.tracker.canvas) {
|
|
95
|
-
const context = this.tracker.canvas.getContext("2d");
|
|
96
|
-
const pixel = this.map.getPixelFromCoordinate(coordinate);
|
|
97
|
-
return !!context.getImageData(pixel[0] * this.pixelRatio, pixel[1] * this.pixelRatio, 1, 1).data[3];
|
|
98
|
-
}
|
|
99
|
-
return false;
|
|
100
|
-
}
|
|
101
|
-
renderTrajectories(noInterpolate) {
|
|
102
|
-
const view = this.map.getView();
|
|
103
|
-
super.renderTrajectories({
|
|
104
|
-
size: this.map.getSize(),
|
|
105
|
-
center: this.map.getView().getCenter(),
|
|
106
|
-
extent: view.calculateExtent(),
|
|
107
|
-
resolution: view.getResolution(),
|
|
108
|
-
rotation: view.getRotation(),
|
|
109
|
-
zoom: view.getZoom(),
|
|
110
|
-
pixelRatio: this.pixelRatio
|
|
111
|
-
}, noInterpolate);
|
|
112
|
-
}
|
|
113
|
-
renderTrajectoriesInternal(viewState, noInterpolate) {
|
|
114
|
-
let isRendered = false;
|
|
115
|
-
const blockRendering = this.map.getView().getAnimating() || this.map.getView().getInteracting();
|
|
116
|
-
isRendered = blockRendering ? false : super.renderTrajectoriesInternal(viewState, noInterpolate);
|
|
117
|
-
if (isRendered) {
|
|
118
|
-
this.renderedViewState = { ...viewState };
|
|
119
|
-
if (this.transformContainer) {
|
|
120
|
-
this.transformContainer.style.transform = "";
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
getRefreshTimeInMs() {
|
|
125
|
-
return super.getRefreshTimeInMs(this.map.getView().getZoom());
|
|
126
|
-
}
|
|
127
|
-
getFeatureInfoAtCoordinate(coordinate, options = {}) {
|
|
128
|
-
const resolution = this.map.getView().getResolution();
|
|
129
|
-
return super.getFeatureInfoAtCoordinate(coordinate, {
|
|
130
|
-
resolution,
|
|
131
|
-
...options
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
onMoveEnd() {
|
|
135
|
-
if (this.visible && this.isUpdateBboxOnMoveEnd) {
|
|
136
|
-
this.setBbox();
|
|
137
|
-
}
|
|
138
|
-
if (this.visible && this.isUpdateBboxOnMoveEnd && this.isClickActive && this.selectedVehicleId) {
|
|
139
|
-
this.highlightTrajectory(this.selectedVehicleId);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
onZoomEnd(evt) {
|
|
143
|
-
super.onZoomEnd(evt);
|
|
144
|
-
}
|
|
145
|
-
onFeatureHover(features, layer, coordinate) {
|
|
146
|
-
super.onFeatureHover(features, layer, coordinate);
|
|
147
|
-
this.map.getTargetElement().style.cursor = features.length ? "pointer" : "auto";
|
|
148
|
-
}
|
|
149
|
-
onFeatureClick(features, layer, coordinate) {
|
|
150
|
-
super.onFeatureClick(features, layer, coordinate);
|
|
151
|
-
if (!features.length && this.vectorLayer) {
|
|
152
|
-
this.vectorLayer.getSource().clear();
|
|
153
|
-
}
|
|
154
|
-
if (this.selectedVehicleId) {
|
|
155
|
-
this.highlightTrajectory(this.selectedVehicleId);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
purgeTrajectory(trajectory, extent, zoom) {
|
|
159
|
-
return super.purgeTrajectory(trajectory, extent || this.map.getView().calculateExtent(), zoom || this.map.getView().getZoom());
|
|
160
|
-
}
|
|
161
|
-
setBbox(extent, zoom) {
|
|
162
|
-
let newExtent = extent;
|
|
163
|
-
let newZoom = zoom;
|
|
164
|
-
if (!newExtent && this.isUpdateBboxOnMoveEnd) {
|
|
165
|
-
newExtent = extent || this.map.getView().calculateExtent();
|
|
166
|
-
newZoom = Math.floor(this.map.getView().getZoom());
|
|
167
|
-
}
|
|
168
|
-
super.setBbox(newExtent, newZoom);
|
|
169
|
-
}
|
|
170
|
-
highlightTrajectory(id) {
|
|
171
|
-
this.api.getFullTrajectory(id, this.mode, this.generalizationLevel).then((fullTrajectory) => {
|
|
172
|
-
const vectorSource = this.vectorLayer.getSource();
|
|
173
|
-
vectorSource.clear();
|
|
174
|
-
if (!fullTrajectory || !fullTrajectory.features || !fullTrajectory.features.length) {
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
const features = format.readFeatures(fullTrajectory);
|
|
178
|
-
this.vectorLayer.getSource().addFeatures(features);
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
clone(newOptions) {
|
|
182
|
-
return new TralisLayer({ ...this.options, ...newOptions });
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
export default TralisLayer;
|
|
@@ -1,79 +0,0 @@
|
|
|
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 TralisLayer from "./TralisLayer";
|
|
6
|
-
let layer;
|
|
7
|
-
let onClick;
|
|
8
|
-
let olMap;
|
|
9
|
-
let server;
|
|
10
|
-
describe("TralisLayer", () => {
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
server = new WS("ws://localhost:1234");
|
|
13
|
-
global.fetch = fetch;
|
|
14
|
-
fetch.resetMocks();
|
|
15
|
-
onClick = jest.fn();
|
|
16
|
-
layer = new TralisLayer({
|
|
17
|
-
url: "ws://localhost:1234",
|
|
18
|
-
apiKey: "apiKey",
|
|
19
|
-
onClick
|
|
20
|
-
});
|
|
21
|
-
olMap = new Map({
|
|
22
|
-
view: new View({
|
|
23
|
-
center: [831634, 5933959],
|
|
24
|
-
zoom: 9
|
|
25
|
-
})
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
afterEach(() => {
|
|
29
|
-
server.close();
|
|
30
|
-
WS.clean();
|
|
31
|
-
});
|
|
32
|
-
test("should be instanced.", () => {
|
|
33
|
-
expect(layer).toBeInstanceOf(TralisLayer);
|
|
34
|
-
expect(layer.clickCallbacks[0]).toBe(onClick);
|
|
35
|
-
});
|
|
36
|
-
test("should called terminate on initalization.", () => {
|
|
37
|
-
const spy = jest.spyOn(layer, "detachFromMap");
|
|
38
|
-
fetch.mockResponseOnce(JSON.stringify(global.fetchTrajectoriesResponse));
|
|
39
|
-
layer.attachToMap(olMap);
|
|
40
|
-
expect(spy).toHaveBeenCalledTimes(1);
|
|
41
|
-
});
|
|
42
|
-
test("should clone", () => {
|
|
43
|
-
const clone = layer.clone({ name: "clone" });
|
|
44
|
-
expect(clone).not.toBe(layer);
|
|
45
|
-
expect(clone.name).toBe("clone");
|
|
46
|
-
expect(clone).toBeInstanceOf(TralisLayer);
|
|
47
|
-
});
|
|
48
|
-
test("should use the sort function.", () => {
|
|
49
|
-
const fn = () => true;
|
|
50
|
-
const laye = new TralisLayer({
|
|
51
|
-
url: "ws://localhost:1234",
|
|
52
|
-
apiKey: "apiKey",
|
|
53
|
-
sort: fn
|
|
54
|
-
});
|
|
55
|
-
expect(laye).toBeInstanceOf(TralisLayer);
|
|
56
|
-
expect(laye.sort).toBe(fn);
|
|
57
|
-
});
|
|
58
|
-
test("should use filter function.", () => {
|
|
59
|
-
const fn = () => true;
|
|
60
|
-
const laye = new TralisLayer({
|
|
61
|
-
url: "ws://localhost:1234",
|
|
62
|
-
apiKey: "apiKey",
|
|
63
|
-
filter: fn
|
|
64
|
-
});
|
|
65
|
-
expect(laye).toBeInstanceOf(TralisLayer);
|
|
66
|
-
expect(laye.filter).toBe(fn);
|
|
67
|
-
});
|
|
68
|
-
test("should override filter function if operator, tripNumber, regexPublishedLineName is set.", () => {
|
|
69
|
-
const fn = () => true;
|
|
70
|
-
const laye = new TralisLayer({
|
|
71
|
-
url: "ws://localhost:1234",
|
|
72
|
-
apiKey: "apiKey",
|
|
73
|
-
filter: fn,
|
|
74
|
-
publishedLineName: ".*"
|
|
75
|
-
});
|
|
76
|
-
expect(laye).toBeInstanceOf(TralisLayer);
|
|
77
|
-
expect(laye.filter).not.toBe(fn);
|
|
78
|
-
});
|
|
79
|
-
});
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import OLVectorLayer from "ol/layer/Vector";
|
|
2
|
-
import VectorSource from "ol/source/Vector";
|
|
3
|
-
import View from "ol/View";
|
|
4
|
-
import Feature from "ol/Feature";
|
|
5
|
-
import Point from "ol/geom/Point";
|
|
6
|
-
import Map from "ol/Map";
|
|
7
|
-
import VectorLayer from "./VectorLayer";
|
|
8
|
-
const feature1 = new Feature({
|
|
9
|
-
attribute: "bar",
|
|
10
|
-
geometry: new Point([500, 500])
|
|
11
|
-
});
|
|
12
|
-
const olLayer = new OLVectorLayer({
|
|
13
|
-
source: new VectorSource({
|
|
14
|
-
features: [
|
|
15
|
-
feature1,
|
|
16
|
-
new Feature({
|
|
17
|
-
attribute: "foo",
|
|
18
|
-
geometry: new Point([50, 50])
|
|
19
|
-
})
|
|
20
|
-
]
|
|
21
|
-
})
|
|
22
|
-
});
|
|
23
|
-
let layer;
|
|
24
|
-
let map;
|
|
25
|
-
let onClick;
|
|
26
|
-
describe("VectorLayer", () => {
|
|
27
|
-
beforeEach(() => {
|
|
28
|
-
onClick = jest.fn();
|
|
29
|
-
layer = new VectorLayer({
|
|
30
|
-
name: "Layer",
|
|
31
|
-
olLayer,
|
|
32
|
-
onClick
|
|
33
|
-
});
|
|
34
|
-
map = new Map({
|
|
35
|
-
view: new View({ resolution: 5 }),
|
|
36
|
-
target: document.body
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
test("should be instanced.", () => {
|
|
40
|
-
expect(layer).toBeInstanceOf(VectorLayer);
|
|
41
|
-
expect(layer.clickCallbacks[0]).toBe(onClick);
|
|
42
|
-
expect(layer.hitTolerance).toBe(5);
|
|
43
|
-
});
|
|
44
|
-
test("should add onClick callback.", () => {
|
|
45
|
-
const onClick2 = jest.fn();
|
|
46
|
-
layer.onClick(onClick2);
|
|
47
|
-
expect(layer.clickCallbacks[1]).toBe(onClick2);
|
|
48
|
-
});
|
|
49
|
-
test("should onClick throw error.", () => {
|
|
50
|
-
expect(() => {
|
|
51
|
-
layer.onClick("not of type function");
|
|
52
|
-
}).toThrow(Error);
|
|
53
|
-
});
|
|
54
|
-
test("should called terminate on initalization.", () => {
|
|
55
|
-
const spy = jest.spyOn(layer, "detachFromMap");
|
|
56
|
-
layer.attachToMap();
|
|
57
|
-
expect(spy).toHaveBeenCalledTimes(1);
|
|
58
|
-
});
|
|
59
|
-
test("should call getFeatureInfoAtCoordinate on click then the callback", async () => {
|
|
60
|
-
const coordinate = [500, 500];
|
|
61
|
-
const px = [10, 10];
|
|
62
|
-
const features = [feature1];
|
|
63
|
-
const evt = { type: "singleclick", map, coordinate };
|
|
64
|
-
const spy = jest.spyOn(layer, "getFeatureInfoAtCoordinate");
|
|
65
|
-
const spy2 = jest.spyOn(map, "getPixelFromCoordinate").mockReturnValue(px);
|
|
66
|
-
const spy3 = jest.spyOn(map, "getFeaturesAtPixel").mockReturnValue(features);
|
|
67
|
-
layer.attachToMap(map);
|
|
68
|
-
expect(onClick).toHaveBeenCalledTimes(0);
|
|
69
|
-
await map.dispatchEvent(evt);
|
|
70
|
-
expect(spy).toHaveBeenCalledTimes(1);
|
|
71
|
-
expect(spy).toHaveBeenCalledWith(coordinate);
|
|
72
|
-
expect(spy2).toHaveBeenCalledTimes(1);
|
|
73
|
-
expect(spy2).toHaveBeenCalledWith(coordinate);
|
|
74
|
-
expect(spy3).toHaveBeenCalledTimes(1);
|
|
75
|
-
expect(spy3.mock.calls[0][0]).toBe(px);
|
|
76
|
-
expect(spy3.mock.calls[0][1].layerFilter(layer.olLayer)).toBe(true);
|
|
77
|
-
expect(spy3.mock.calls[0][1].layerFilter({})).toBe(false);
|
|
78
|
-
expect(onClick).toHaveBeenCalledTimes(1);
|
|
79
|
-
expect(onClick).toHaveBeenCalledWith(features, layer, coordinate);
|
|
80
|
-
});
|
|
81
|
-
test("should clone", () => {
|
|
82
|
-
const clone = layer.clone({ name: "clone" });
|
|
83
|
-
expect(clone).not.toBe(layer);
|
|
84
|
-
expect(clone.name).toBe("clone");
|
|
85
|
-
expect(clone).toBeInstanceOf(VectorLayer);
|
|
86
|
-
});
|
|
87
|
-
});
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import OLView from "ol/View";
|
|
2
|
-
import ImageLayer from "ol/layer/Image";
|
|
3
|
-
import ImageWMS from "ol/source/ImageWMS";
|
|
4
|
-
import fetch from "jest-fetch-mock";
|
|
5
|
-
import qs from "query-string";
|
|
6
|
-
import Map from "ol/Map";
|
|
7
|
-
import WMSLayer from "./WMSLayer";
|
|
8
|
-
describe("WMSLayer", () => {
|
|
9
|
-
let map;
|
|
10
|
-
let layer;
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
map = new Map({
|
|
13
|
-
view: new OLView({ resolution: 5 }),
|
|
14
|
-
target: document.body
|
|
15
|
-
});
|
|
16
|
-
layer = new WMSLayer({
|
|
17
|
-
olLayer: new ImageLayer({
|
|
18
|
-
source: new ImageWMS({
|
|
19
|
-
url: "dummy",
|
|
20
|
-
params: { LAYERS: "layers" }
|
|
21
|
-
})
|
|
22
|
-
})
|
|
23
|
-
});
|
|
24
|
-
layer.attachToMap(map);
|
|
25
|
-
fetch.mockResponseOnce(JSON.stringify({ features: [] }));
|
|
26
|
-
global.fetch = fetch;
|
|
27
|
-
});
|
|
28
|
-
afterEach(() => {
|
|
29
|
-
layer.detachFromMap();
|
|
30
|
-
});
|
|
31
|
-
test("should initialize.", () => {
|
|
32
|
-
expect(layer).toBeInstanceOf(WMSLayer);
|
|
33
|
-
});
|
|
34
|
-
test("should called terminate on initalization.", () => {
|
|
35
|
-
const spy = jest.spyOn(layer, "detachFromMap");
|
|
36
|
-
layer.attachToMap();
|
|
37
|
-
expect(spy).toHaveBeenCalledTimes(1);
|
|
38
|
-
});
|
|
39
|
-
test("should return a promise resolving features.", async () => {
|
|
40
|
-
const data = await layer.getFeatureInfoAtCoordinate([50, 50]);
|
|
41
|
-
const params = qs.parse(fetch.mock.calls[0][0].split("?")[1]);
|
|
42
|
-
expect(params.REQUEST).toBe("GetFeatureInfo");
|
|
43
|
-
expect(params.I).toBe("50");
|
|
44
|
-
expect(params.J).toBe("50");
|
|
45
|
-
expect(data.features).toEqual([]);
|
|
46
|
-
});
|
|
47
|
-
test("should return a layer instance and a coordinate.", async () => {
|
|
48
|
-
const data = await layer.getFeatureInfoAtCoordinate([50, 50]);
|
|
49
|
-
expect(data.coordinate).toEqual([50, 50]);
|
|
50
|
-
expect(data.layer).toBeInstanceOf(WMSLayer);
|
|
51
|
-
});
|
|
52
|
-
test("#onClick", () => {
|
|
53
|
-
const f = () => {
|
|
54
|
-
};
|
|
55
|
-
const f2 = () => {
|
|
56
|
-
};
|
|
57
|
-
layer.onClick(f);
|
|
58
|
-
expect(layer.clickCallbacks[0]).toBe(f);
|
|
59
|
-
expect(layer.clickCallbacks.length).toBe(1);
|
|
60
|
-
layer.onClick(f);
|
|
61
|
-
expect(layer.clickCallbacks.length).toBe(1);
|
|
62
|
-
layer.onClick(f2);
|
|
63
|
-
expect(layer.clickCallbacks.length).toBe(2);
|
|
64
|
-
});
|
|
65
|
-
test("should onClick throw error.", () => {
|
|
66
|
-
expect(() => {
|
|
67
|
-
layer.onClick("not of type function");
|
|
68
|
-
}).toThrow(Error);
|
|
69
|
-
});
|
|
70
|
-
test("should clone", () => {
|
|
71
|
-
const clone = layer.clone({ name: "clone" });
|
|
72
|
-
expect(clone).not.toBe(layer);
|
|
73
|
-
expect(clone.name).toBe("clone");
|
|
74
|
-
expect(clone).toBeInstanceOf(WMSLayer);
|
|
75
|
-
});
|
|
76
|
-
});
|