mobility-toolbox-js 2.0.1-beta.13 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api/RealtimeAPI.d.ts +279 -0
- package/api/RealtimeAPI.d.ts.map +1 -0
- package/api/RealtimeAPI.js +466 -0
- package/api/RoutingAPI.d.ts +37 -0
- package/api/RoutingAPI.d.ts.map +1 -0
- package/api/RoutingAPI.js +32 -12
- package/api/StopsAPI.d.ts +38 -0
- package/api/StopsAPI.d.ts.map +1 -0
- package/api/StopsAPI.js +33 -9
- package/api/index.d.ts +4 -0
- package/api/index.d.ts.map +1 -0
- package/api/index.js +3 -3
- package/api/typedefs.d.ts +179 -0
- package/api/typedefs.d.ts.map +1 -0
- package/api/typedefs.js +75 -0
- package/common/api/HttpAPI.d.ts +31 -0
- package/common/api/HttpAPI.d.ts.map +1 -0
- package/common/api/HttpAPI.js +54 -27
- package/common/api/WebSocketAPI.d.ts +153 -0
- package/common/api/WebSocketAPI.d.ts.map +1 -0
- package/common/api/WebSocketAPI.js +330 -164
- package/common/controls/ControlCommon.d.ts +76 -0
- package/common/controls/ControlCommon.d.ts.map +1 -0
- package/common/controls/ControlCommon.js +150 -0
- package/common/controls/CopyrightControlCommon.d.ts +13 -0
- package/common/controls/CopyrightControlCommon.d.ts.map +1 -0
- package/common/controls/CopyrightControlCommon.js +34 -0
- package/common/controls/StopFinderControlCommon.d.ts +55 -0
- package/common/controls/StopFinderControlCommon.d.ts.map +1 -0
- package/common/controls/StopFinderControlCommon.js +144 -0
- package/common/index.d.ts +3 -0
- package/common/index.d.ts.map +1 -0
- package/common/index.js +2 -4
- package/common/layers/LayerCommon.d.ts +94 -0
- package/common/layers/LayerCommon.d.ts.map +1 -0
- package/common/layers/LayerCommon.js +244 -0
- package/common/mixins/RealtimeLayerMixin.d.ts +286 -0
- package/common/mixins/RealtimeLayerMixin.d.ts.map +1 -0
- package/common/mixins/RealtimeLayerMixin.js +776 -0
- package/common/mixins/UserInteractionsLayerMixin.d.ts +60 -0
- package/common/mixins/UserInteractionsLayerMixin.d.ts.map +1 -0
- package/common/mixins/UserInteractionsLayerMixin.js +241 -0
- package/common/styles/index.d.ts +5 -0
- package/common/styles/index.d.ts.map +1 -0
- package/common/styles/index.js +4 -4
- package/common/styles/realtimeDefaultStyle.d.ts +36 -0
- package/common/styles/realtimeDefaultStyle.d.ts.map +1 -0
- package/common/styles/realtimeDefaultStyle.js +275 -0
- package/common/styles/realtimeDelayStyle.d.ts +12 -0
- package/common/styles/realtimeDelayStyle.d.ts.map +1 -0
- package/common/styles/realtimeDelayStyle.js +13 -0
- package/common/styles/realtimeHeadingStyle.d.ts +12 -0
- package/common/styles/realtimeHeadingStyle.d.ts.map +1 -0
- package/common/styles/realtimeHeadingStyle.js +85 -0
- package/common/styles/realtimeSimpleStyle.d.ts +4 -0
- package/common/styles/realtimeSimpleStyle.d.ts.map +1 -0
- package/common/styles/realtimeSimpleStyle.js +23 -0
- package/common/typedefs.d.ts +111 -0
- package/common/typedefs.d.ts.map +1 -0
- package/common/typedefs.js +52 -0
- package/common/utils/compareDepartures.d.ts +11 -0
- package/common/utils/compareDepartures.d.ts.map +1 -0
- package/common/utils/compareDepartures.js +35 -0
- package/common/utils/createCanvas.d.ts +10 -0
- package/common/utils/createCanvas.d.ts.map +1 -0
- package/common/utils/createCanvas.js +27 -0
- package/common/utils/createRealtimeFilters.d.ts +13 -0
- package/common/utils/createRealtimeFilters.d.ts.map +1 -0
- package/common/utils/createRealtimeFilters.js +74 -0
- package/common/utils/debounceDeparturesMessages.d.ts +12 -0
- package/common/utils/debounceDeparturesMessages.d.ts.map +1 -0
- package/common/utils/debounceDeparturesMessages.js +24 -0
- package/common/utils/debounceWebsocketMessages.d.ts +11 -0
- package/common/utils/debounceWebsocketMessages.d.ts.map +1 -0
- package/common/utils/debounceWebsocketMessages.js +29 -0
- package/common/utils/getLayersAsFlatArray.d.ts +3 -0
- package/common/utils/getLayersAsFlatArray.d.ts.map +1 -0
- package/common/utils/getLayersAsFlatArray.js +15 -0
- package/common/utils/getMapboxMapCopyrights.d.ts +18 -0
- package/common/utils/getMapboxMapCopyrights.d.ts.map +1 -0
- package/common/utils/getMapboxMapCopyrights.js +26 -15
- package/common/utils/getMapboxRender.d.ts +7 -0
- package/common/utils/getMapboxRender.d.ts.map +1 -0
- package/common/utils/getMapboxRender.js +87 -0
- package/common/utils/getMaplibreRender.d.ts +7 -0
- package/common/utils/getMaplibreRender.d.ts.map +1 -0
- package/common/utils/getMaplibreRender.js +38 -0
- package/common/utils/getRealtimeModeSuffix.d.ts +10 -0
- package/common/utils/getRealtimeModeSuffix.d.ts.map +1 -0
- package/common/utils/getRealtimeModeSuffix.js +7 -0
- package/common/utils/getUrlWithParams.d.ts +9 -0
- package/common/utils/getUrlWithParams.d.ts.map +1 -0
- package/common/utils/getUrlWithParams.js +18 -0
- package/common/utils/getVehiclePosition.d.ts +16 -0
- package/common/utils/getVehiclePosition.d.ts.map +1 -0
- package/common/utils/getVehiclePosition.js +67 -37
- package/common/utils/index.d.ts +17 -0
- package/common/utils/index.d.ts.map +1 -0
- package/common/utils/index.js +17 -5
- package/common/utils/realtimeConfig.d.ts +49 -0
- package/common/utils/realtimeConfig.d.ts.map +1 -0
- package/common/utils/realtimeConfig.js +173 -0
- package/common/utils/removeDuplicate.d.ts +10 -0
- package/common/utils/removeDuplicate.d.ts.map +1 -0
- package/common/utils/removeDuplicate.js +12 -5
- package/common/utils/renderTrajectories.d.ts +17 -0
- package/common/utils/renderTrajectories.d.ts.map +1 -0
- package/common/utils/renderTrajectories.js +110 -0
- package/common/utils/sortAndFilterDepartures.d.ts +16 -0
- package/common/utils/sortAndFilterDepartures.d.ts.map +1 -0
- package/common/utils/sortAndFilterDepartures.js +58 -0
- package/common/utils/sortByDelay.d.ts +3 -0
- package/common/utils/sortByDelay.d.ts.map +1 -0
- package/common/utils/sortByDelay.js +17 -15
- package/common/utils/timeUtils.d.ts +24 -0
- package/common/utils/timeUtils.d.ts.map +1 -0
- package/common/utils/timeUtils.js +34 -15
- package/iife.d.ts +3 -0
- package/iife.d.ts.map +1 -0
- package/iife.js +5 -0
- package/index.d.ts +10 -0
- package/index.d.ts.map +1 -0
- package/index.js +8 -6
- package/mapbox/controls/CopyrightControl.d.ts +29 -0
- package/mapbox/controls/CopyrightControl.d.ts.map +1 -0
- package/mapbox/controls/CopyrightControl.js +44 -25
- package/mapbox/controls/index.d.ts +2 -0
- package/mapbox/controls/index.d.ts.map +1 -0
- package/mapbox/controls/index.js +2 -1
- package/mapbox/index.d.ts +6 -0
- package/mapbox/index.d.ts.map +1 -0
- package/mapbox/index.js +5 -4
- package/mapbox/layers/Layer.d.ts +59 -0
- package/mapbox/layers/Layer.d.ts.map +1 -0
- package/mapbox/layers/Layer.js +99 -55
- package/mapbox/layers/RealtimeLayer.d.ts +181 -0
- package/mapbox/layers/RealtimeLayer.d.ts.map +1 -0
- package/mapbox/layers/RealtimeLayer.js +276 -0
- package/mapbox/layers/index.d.ts +3 -0
- package/mapbox/layers/index.d.ts.map +1 -0
- package/mapbox/layers/index.js +2 -2
- package/mapbox/utils/getMercatorResolution.d.ts +9 -0
- package/mapbox/utils/getMercatorResolution.d.ts.map +1 -0
- package/mapbox/utils/getMercatorResolution.js +18 -0
- package/mapbox/utils/getSourceCoordinates.d.ts +9 -0
- package/mapbox/utils/getSourceCoordinates.d.ts.map +1 -0
- package/mapbox/utils/getSourceCoordinates.js +27 -0
- package/mapbox/utils/index.d.ts +3 -0
- package/mapbox/utils/index.d.ts.map +1 -0
- package/mapbox/utils/index.js +2 -0
- package/mbt.js +26061 -16500
- package/mbt.js.map +4 -4
- package/mbt.min.js +205 -126
- package/mbt.min.js.map +4 -4
- package/ol/controls/CopyrightControl.d.ts +31 -0
- package/ol/controls/CopyrightControl.d.ts.map +1 -0
- package/ol/controls/CopyrightControl.js +62 -36
- package/ol/controls/RoutingControl.d.ts +193 -0
- package/ol/controls/RoutingControl.d.ts.map +1 -0
- package/ol/controls/RoutingControl.js +601 -357
- package/ol/controls/StopFinderControl.d.ts +30 -0
- package/ol/controls/StopFinderControl.d.ts.map +1 -0
- package/ol/controls/StopFinderControl.js +30 -8
- package/ol/controls/index.d.ts +4 -0
- package/ol/controls/index.d.ts.map +1 -0
- package/ol/controls/index.js +3 -3
- package/ol/index.d.ts +6 -0
- package/ol/index.d.ts.map +1 -0
- package/ol/index.js +5 -5
- package/ol/layers/Layer.d.ts +86 -0
- package/ol/layers/Layer.d.ts.map +1 -0
- package/ol/layers/Layer.js +163 -77
- package/ol/layers/MapGlLayer.d.ts +67 -0
- package/ol/layers/MapGlLayer.d.ts.map +1 -0
- package/ol/layers/MapGlLayer.js +218 -0
- package/ol/layers/MapboxLayer.d.ts +50 -0
- package/ol/layers/MapboxLayer.d.ts.map +1 -0
- package/ol/layers/MapboxLayer.js +99 -193
- package/ol/layers/MapboxStyleLayer.d.ts +129 -0
- package/ol/layers/MapboxStyleLayer.d.ts.map +1 -0
- package/ol/layers/MapboxStyleLayer.js +362 -171
- package/ol/layers/MaplibreLayer.d.ts +28 -0
- package/ol/layers/MaplibreLayer.d.ts.map +1 -0
- package/ol/layers/MaplibreLayer.js +30 -135
- package/ol/layers/RealtimeLayer.d.ts +202 -0
- package/ol/layers/RealtimeLayer.d.ts.map +1 -0
- package/ol/layers/RealtimeLayer.js +340 -0
- package/ol/layers/RoutingLayer.d.ts +34 -0
- package/ol/layers/RoutingLayer.d.ts.map +1 -0
- package/ol/layers/RoutingLayer.js +72 -48
- package/ol/layers/VectorLayer.d.ts +25 -0
- package/ol/layers/VectorLayer.d.ts.map +1 -0
- package/ol/layers/VectorLayer.js +34 -18
- package/ol/layers/WMSLayer.d.ts +42 -0
- package/ol/layers/WMSLayer.d.ts.map +1 -0
- package/ol/layers/WMSLayer.js +84 -34
- package/ol/layers/index.d.ts +9 -0
- package/ol/layers/index.d.ts.map +1 -0
- package/ol/layers/index.js +8 -8
- package/ol/styles/fullTrajectoryDelayStyle.d.ts +4 -0
- package/ol/styles/fullTrajectoryDelayStyle.d.ts.map +1 -0
- package/ol/styles/fullTrajectoryDelayStyle.js +26 -24
- package/ol/styles/fullTrajectoryStyle.d.ts +5 -0
- package/ol/styles/fullTrajectoryStyle.d.ts.map +1 -0
- package/ol/styles/fullTrajectoryStyle.js +40 -39
- package/ol/styles/index.d.ts +3 -0
- package/ol/styles/index.d.ts.map +1 -0
- package/ol/styles/index.js +2 -2
- package/package.json +81 -133
- package/setupTests.d.ts +2 -0
- package/setupTests.d.ts.map +1 -0
- package/setupTests.js +26 -0
- package/types/common.d.ts +122 -0
- package/types/index.d.ts +11 -0
- package/types/realtime.d.ts +320 -0
- package/types/routing.d.ts +206 -0
- package/types/stops.d.ts +143 -0
- package/README.md +0 -23
- package/api/RoutingAPI.test.js +0 -25
- package/api/StopsAPI.test.js +0 -22
- package/api/TralisAPI.js +0 -359
- package/api/TralisAPI.test.js +0 -67
- package/api/TralisAPIUtils.js +0 -43
- package/common/Tracker.js +0 -93
- package/common/api/HttpAPI.test.js +0 -50
- package/common/api/WebSocketAPI.test.js +0 -311
- package/common/controls/Control.js +0 -81
- package/common/controls/Control.test.js +0 -87
- package/common/layers/Layer.js +0 -213
- package/common/layers/Layer.test.js +0 -526
- package/common/mixins/CopyrightMixin.js +0 -24
- package/common/mixins/SearchMixin.js +0 -110
- package/common/mixins/TralisLayerMixin.js +0 -479
- package/common/styles/trackerDefaultStyle.js +0 -197
- package/common/styles/trackerDelayStyle.js +0 -8
- package/common/styles/trackerSimpleStyle.js +0 -18
- package/common/trackerConfig.js +0 -152
- package/common/trackerConfig.test.js +0 -23
- package/common/utils/createTrackerFilters.js +0 -56
- package/common/utils/createTrackerFilters.test.js +0 -79
- package/common/utils/getMapboxMapCopyrights.test.js +0 -40
- package/common/utils/getMapboxStyleUrl.js +0 -22
- package/common/utils/removeDuplicate.test.js +0 -19
- package/common/utils/timeUtils.test.js +0 -10
- package/mapbox/layers/Layer.test.js +0 -182
- package/mapbox/layers/TralisLayer.js +0 -182
- package/mapbox/layers/TralisLayer.test.js +0 -38
- package/mapbox/utils.js +0 -32
- package/ol/controls/CopyrightControl.test.js +0 -165
- package/ol/controls/RoutingControl.test.js +0 -151
- package/ol/controls/StopFinderControl.test.js +0 -48
- package/ol/layers/Layer.test.js +0 -174
- package/ol/layers/MapboxLayer.test.js +0 -160
- package/ol/layers/MapboxStyleLayer.test.js +0 -231
- package/ol/layers/RoutingLayer.test.js +0 -40
- package/ol/layers/TralisLayer.js +0 -185
- package/ol/layers/TralisLayer.test.js +0 -79
- package/ol/layers/VectorLayer.test.js +0 -87
- package/ol/layers/WMSLayer.test.js +0 -76
|
@@ -1,182 +0,0 @@
|
|
|
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/TralisLayerMixin";
|
|
7
|
-
import Layer from "./Layer";
|
|
8
|
-
import { getSourceCoordinates, getMercatorResolution } from "../utils";
|
|
9
|
-
class TralisLayer extends mixin(Layer) {
|
|
10
|
-
constructor(options = {}) {
|
|
11
|
-
super({
|
|
12
|
-
...options
|
|
13
|
-
});
|
|
14
|
-
this.onLoad = this.onLoad.bind(this);
|
|
15
|
-
this.onMove = this.onMove.bind(this);
|
|
16
|
-
this.onMoveEnd = this.onMoveEnd.bind(this);
|
|
17
|
-
this.onZoomEnd = this.onZoomEnd.bind(this);
|
|
18
|
-
this.onVisibilityChange = this.onVisibilityChange.bind(this);
|
|
19
|
-
}
|
|
20
|
-
attachToMap(map, beforeId) {
|
|
21
|
-
if (!map) {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
const canvas = map.getCanvas();
|
|
25
|
-
super.attachToMap(map, {
|
|
26
|
-
width: canvas.width / this.pixelRatio,
|
|
27
|
-
height: canvas.height / this.pixelRatio
|
|
28
|
-
});
|
|
29
|
-
this.source = {
|
|
30
|
-
type: "canvas",
|
|
31
|
-
canvas: this.tracker.canvas,
|
|
32
|
-
coordinates: getSourceCoordinates(map, this.pixelRatio),
|
|
33
|
-
animate: true,
|
|
34
|
-
attribution: this.copyrights && this.copyrights.join(", ")
|
|
35
|
-
};
|
|
36
|
-
this.beforeId = beforeId;
|
|
37
|
-
this.layer = {
|
|
38
|
-
id: this.key,
|
|
39
|
-
type: "raster",
|
|
40
|
-
source: this.key,
|
|
41
|
-
layout: {
|
|
42
|
-
visibility: this.visible ? "visible" : "none"
|
|
43
|
-
},
|
|
44
|
-
paint: {
|
|
45
|
-
"raster-opacity": 1,
|
|
46
|
-
"raster-fade-duration": 0,
|
|
47
|
-
"raster-resampling": "nearest"
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
if (map.isStyleLoaded()) {
|
|
51
|
-
this.onLoad();
|
|
52
|
-
}
|
|
53
|
-
this.map.on("load", this.onLoad);
|
|
54
|
-
this.listeners = [this.on("change:visible", this.onVisibilityChange)];
|
|
55
|
-
}
|
|
56
|
-
detachFromMap() {
|
|
57
|
-
if (this.map) {
|
|
58
|
-
this.map.off("load", this.onLoad);
|
|
59
|
-
this.listeners.forEach((listener) => {
|
|
60
|
-
unByKey(listener);
|
|
61
|
-
});
|
|
62
|
-
if (this.map.getLayer(this.key)) {
|
|
63
|
-
this.map.removeLayer(this.key);
|
|
64
|
-
}
|
|
65
|
-
if (this.map.getSource(this.key)) {
|
|
66
|
-
this.map.removeSource(this.key);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
super.detachFromMap();
|
|
70
|
-
}
|
|
71
|
-
start() {
|
|
72
|
-
super.start();
|
|
73
|
-
this.map.on("move", this.onMove);
|
|
74
|
-
this.map.on("moveend", this.onMoveEnd);
|
|
75
|
-
this.map.on("zoomend", this.onZoomEnd);
|
|
76
|
-
}
|
|
77
|
-
stop() {
|
|
78
|
-
super.stop();
|
|
79
|
-
if (this.map) {
|
|
80
|
-
this.map.off("move", this.onMove);
|
|
81
|
-
this.map.off("moveend", this.onMoveEnd);
|
|
82
|
-
this.map.off("zoomend", this.onZoomEnd);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
onLoad() {
|
|
86
|
-
if (!this.map.getSource(this.key)) {
|
|
87
|
-
this.map.addSource(this.key, this.source);
|
|
88
|
-
}
|
|
89
|
-
if (!this.map.getLayer(this.key)) {
|
|
90
|
-
this.map.addLayer(this.layer, this.beforeId);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
onUserClickCallback(evt) {
|
|
94
|
-
super.onUserClickCallback({
|
|
95
|
-
coordinate: fromLonLat(evt.lngLat.toArray()),
|
|
96
|
-
...evt
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
onUserMoveCallback(evt) {
|
|
100
|
-
super.onUserMoveCallback({
|
|
101
|
-
coordinate: fromLonLat(evt.lngLat.toArray()),
|
|
102
|
-
...evt
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
renderTrajectories(noInterpolate) {
|
|
106
|
-
const { width, height } = this.map.getCanvas();
|
|
107
|
-
const center = this.map.getCenter();
|
|
108
|
-
const leftBottom = this.map.unproject({
|
|
109
|
-
x: 0,
|
|
110
|
-
y: height / this.pixelRatio
|
|
111
|
-
});
|
|
112
|
-
const rightTop = this.map.unproject({ x: width / this.pixelRatio, y: 0 });
|
|
113
|
-
const coord0 = transformRotate(point([leftBottom.lng, leftBottom.lat]), -this.map.getBearing(), {
|
|
114
|
-
pivot: [center.lng, center.lat]
|
|
115
|
-
}).geometry.coordinates;
|
|
116
|
-
const coord1 = transformRotate(point([rightTop.lng, rightTop.lat]), -this.map.getBearing(), {
|
|
117
|
-
pivot: [center.lng, center.lat]
|
|
118
|
-
}).geometry.coordinates;
|
|
119
|
-
const bounds = [...fromLonLat(coord0), ...fromLonLat(coord1)];
|
|
120
|
-
const xResolution = getWidth(bounds) / (width / this.pixelRatio);
|
|
121
|
-
const yResolution = getHeight(bounds) / (height / this.pixelRatio);
|
|
122
|
-
const res = Math.max(xResolution, yResolution);
|
|
123
|
-
const viewState = {
|
|
124
|
-
size: [width / this.pixelRatio, height / this.pixelRatio],
|
|
125
|
-
center: fromLonLat([center.lng, center.lat]),
|
|
126
|
-
extent: bounds,
|
|
127
|
-
resolution: res,
|
|
128
|
-
zoom: this.map.getZoom(),
|
|
129
|
-
rotation: -(this.map.getBearing() * Math.PI) / 180,
|
|
130
|
-
pixelRatio: this.pixelRatio
|
|
131
|
-
};
|
|
132
|
-
super.renderTrajectories(viewState, noInterpolate);
|
|
133
|
-
}
|
|
134
|
-
getRefreshTimeInMs() {
|
|
135
|
-
return super.getRefreshTimeInMs(this.map.getZoom());
|
|
136
|
-
}
|
|
137
|
-
getFeatureInfoAtCoordinate(coordinate, options = {}) {
|
|
138
|
-
const resolution = getMercatorResolution(this.map);
|
|
139
|
-
return super.getFeatureInfoAtCoordinate(coordinate, {
|
|
140
|
-
resolution,
|
|
141
|
-
...options
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
onVisibilityChange() {
|
|
145
|
-
if (this.visible && !this.map.getLayer(this.key)) {
|
|
146
|
-
this.map.addLayer(this.layer, this.beforeId);
|
|
147
|
-
} else if (this.map.getLayer(this.key)) {
|
|
148
|
-
this.map.removeLayer(this.key);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
purgeTrajectory(trajectory, extent, zoom) {
|
|
152
|
-
return super.purgeTrajectory(trajectory, extent || this.getMercatorExtent(), zoom || Math.floor(this.map.getZoom() + 1));
|
|
153
|
-
}
|
|
154
|
-
setBbox(extent, zoom) {
|
|
155
|
-
let newExtent = extent;
|
|
156
|
-
let newZoom = zoom;
|
|
157
|
-
if (!newExtent && this.isUpdateBboxOnMoveEnd) {
|
|
158
|
-
newExtent = extent || this.getMercatorExtent();
|
|
159
|
-
newZoom = Math.floor(this.getOlZoom());
|
|
160
|
-
}
|
|
161
|
-
super.setBbox(newExtent, newZoom);
|
|
162
|
-
}
|
|
163
|
-
onMove() {
|
|
164
|
-
const extent = getSourceCoordinates(this.map, this.pixelRatio);
|
|
165
|
-
const source = this.map.getSource(this.key);
|
|
166
|
-
if (source) {
|
|
167
|
-
source.setCoordinates(extent);
|
|
168
|
-
}
|
|
169
|
-
this.renderTrajectories();
|
|
170
|
-
}
|
|
171
|
-
onMoveEnd() {
|
|
172
|
-
this.renderTrajectories();
|
|
173
|
-
if (this.visible && this.isUpdateBboxOnMoveEnd) {
|
|
174
|
-
this.setBbox();
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
onFeatureHover(features, layer, coordinate) {
|
|
178
|
-
super.onFeatureHover(features, layer, coordinate);
|
|
179
|
-
this.map.getCanvasContainer().style.cursor = features.length ? "pointer" : "auto";
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
export default TralisLayer;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import TralisLayer from "./TralisLayer";
|
|
2
|
-
let layer;
|
|
3
|
-
let onClick;
|
|
4
|
-
describe("TralisLayer", () => {
|
|
5
|
-
beforeEach(() => {
|
|
6
|
-
onClick = jest.fn();
|
|
7
|
-
layer = new TralisLayer({
|
|
8
|
-
onClick
|
|
9
|
-
});
|
|
10
|
-
});
|
|
11
|
-
test("should be instanced.", () => {
|
|
12
|
-
expect(layer).toBeInstanceOf(TralisLayer);
|
|
13
|
-
expect(layer.clickCallbacks[0]).toBe(onClick);
|
|
14
|
-
});
|
|
15
|
-
test("#onClick", () => {
|
|
16
|
-
const f = () => {
|
|
17
|
-
};
|
|
18
|
-
layer.onClick(f);
|
|
19
|
-
expect(layer.clickCallbacks[1]).toBe(f);
|
|
20
|
-
expect(layer.clickCallbacks.length).toBe(2);
|
|
21
|
-
layer.onClick(f);
|
|
22
|
-
expect(layer.clickCallbacks.length).toBe(2);
|
|
23
|
-
});
|
|
24
|
-
test("#unClick", () => {
|
|
25
|
-
const foo = () => {
|
|
26
|
-
};
|
|
27
|
-
const bar = () => {
|
|
28
|
-
};
|
|
29
|
-
layer.onClick(foo);
|
|
30
|
-
layer.onClick(bar);
|
|
31
|
-
expect(layer.clickCallbacks[1]).toBe(foo);
|
|
32
|
-
expect(layer.clickCallbacks[2]).toBe(bar);
|
|
33
|
-
expect(layer.clickCallbacks.length).toBe(3);
|
|
34
|
-
layer.unClick(foo);
|
|
35
|
-
expect(layer.clickCallbacks[1]).toBe(bar);
|
|
36
|
-
expect(layer.clickCallbacks.length).toBe(2);
|
|
37
|
-
});
|
|
38
|
-
});
|
package/mapbox/utils.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { getWidth, getHeight } from "ol/extent";
|
|
2
|
-
import { fromLonLat } from "ol/proj";
|
|
3
|
-
export const getMercatorResolution = (map) => {
|
|
4
|
-
const bounds = map.getBounds().toArray();
|
|
5
|
-
const a = fromLonLat(bounds[0]);
|
|
6
|
-
const b = fromLonLat(bounds[1]);
|
|
7
|
-
const extent = [...a, ...b];
|
|
8
|
-
const { width, height } = map.getCanvas();
|
|
9
|
-
const xResolution = getWidth(extent) / width;
|
|
10
|
-
const yResolution = getHeight(extent) / height;
|
|
11
|
-
return Math.max(xResolution, yResolution);
|
|
12
|
-
};
|
|
13
|
-
export const getSourceCoordinates = (map, pixelRatio) => {
|
|
14
|
-
const { width, height } = map.getCanvas();
|
|
15
|
-
const leftTop = map.unproject({ x: 0, y: 0 });
|
|
16
|
-
const leftBottom = map.unproject({ x: 0, y: height / pixelRatio });
|
|
17
|
-
const rightBottom = map.unproject({
|
|
18
|
-
x: width / pixelRatio,
|
|
19
|
-
y: height / pixelRatio
|
|
20
|
-
});
|
|
21
|
-
const rightTop = map.unproject({ x: width / pixelRatio, y: 0 });
|
|
22
|
-
return [
|
|
23
|
-
[leftTop.lng, leftTop.lat],
|
|
24
|
-
[rightTop.lng, rightTop.lat],
|
|
25
|
-
[rightBottom.lng, rightBottom.lat],
|
|
26
|
-
[leftBottom.lng, leftBottom.lat]
|
|
27
|
-
];
|
|
28
|
-
};
|
|
29
|
-
export default {
|
|
30
|
-
getMercatorResolution,
|
|
31
|
-
getSourceCoordinates
|
|
32
|
-
};
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
import View from "ol/View";
|
|
2
|
-
import Tile from "ol/Tile";
|
|
3
|
-
import TileLayer from "ol/layer/Tile";
|
|
4
|
-
import TileSource from "ol/source/Tile";
|
|
5
|
-
import { createXYZ } from "ol/tilegrid";
|
|
6
|
-
import { Map } from "ol";
|
|
7
|
-
import Layer from "../layers/Layer";
|
|
8
|
-
import CopyrightControl from "./CopyrightControl";
|
|
9
|
-
const tileLoadFunction = () => {
|
|
10
|
-
const tile = new Tile([0, 0, -1], 2);
|
|
11
|
-
tile.getImage = () => {
|
|
12
|
-
const image = new Image();
|
|
13
|
-
image.width = 256;
|
|
14
|
-
image.height = 256;
|
|
15
|
-
return image;
|
|
16
|
-
};
|
|
17
|
-
return tile;
|
|
18
|
-
};
|
|
19
|
-
const getOLTileLayer = () => {
|
|
20
|
-
const layer = new TileLayer({
|
|
21
|
-
source: new TileSource({
|
|
22
|
-
projection: "EPSG:3857",
|
|
23
|
-
tileGrid: createXYZ()
|
|
24
|
-
})
|
|
25
|
-
});
|
|
26
|
-
layer.getSource().getTile = tileLoadFunction;
|
|
27
|
-
return layer;
|
|
28
|
-
};
|
|
29
|
-
const getLayer = (copyrights, visible = true) => new Layer({
|
|
30
|
-
visible,
|
|
31
|
-
copyrights,
|
|
32
|
-
olLayer: getOLTileLayer()
|
|
33
|
-
});
|
|
34
|
-
describe("CopyrightControl", () => {
|
|
35
|
-
let map;
|
|
36
|
-
beforeEach(() => {
|
|
37
|
-
const target = document.createElement("div");
|
|
38
|
-
document.body.appendChild(target);
|
|
39
|
-
map = new Map({
|
|
40
|
-
target,
|
|
41
|
-
view: new View({
|
|
42
|
-
center: [0, 0],
|
|
43
|
-
zoom: 0
|
|
44
|
-
})
|
|
45
|
-
});
|
|
46
|
-
getLayer(true, "bar").attachToMap(map);
|
|
47
|
-
map.setSize([200, 200]);
|
|
48
|
-
map.renderSync();
|
|
49
|
-
});
|
|
50
|
-
afterEach(() => {
|
|
51
|
-
if (map) {
|
|
52
|
-
map.setTarget(null);
|
|
53
|
-
map = null;
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
test("should be activate by default", () => {
|
|
57
|
-
const control = new CopyrightControl();
|
|
58
|
-
expect(control.active).toBe(true);
|
|
59
|
-
});
|
|
60
|
-
test("renders a string copyright", () => {
|
|
61
|
-
const control = new CopyrightControl();
|
|
62
|
-
control.attachToMap(map);
|
|
63
|
-
expect(control.element.innerHTML).toBe("");
|
|
64
|
-
getLayer("copyright").attachToMap(map);
|
|
65
|
-
map.renderSync();
|
|
66
|
-
expect(control.element.innerHTML).toBe("copyright");
|
|
67
|
-
});
|
|
68
|
-
test("renders an array of copyrights", () => {
|
|
69
|
-
const control = new CopyrightControl();
|
|
70
|
-
control.attachToMap(map);
|
|
71
|
-
expect(control.element.innerHTML).toBe("");
|
|
72
|
-
getLayer(["copyright 1", "copyright 2"]).attachToMap(map);
|
|
73
|
-
map.renderSync();
|
|
74
|
-
expect(control.element.innerHTML).toBe("copyright 1 | copyright 2");
|
|
75
|
-
});
|
|
76
|
-
test("renders unique copyrights", () => {
|
|
77
|
-
const control = new CopyrightControl();
|
|
78
|
-
control.attachToMap(map);
|
|
79
|
-
expect(control.element.innerHTML).toBe("");
|
|
80
|
-
getLayer(["copyright 1", "copyright 2"]).attachToMap(map);
|
|
81
|
-
getLayer("copyright 1").attachToMap(map);
|
|
82
|
-
getLayer(["copyright 2"]).attachToMap(map);
|
|
83
|
-
map.renderSync();
|
|
84
|
-
expect(control.element.innerHTML).toBe("copyright 1 | copyright 2");
|
|
85
|
-
});
|
|
86
|
-
test("doesn't render copyright of an hidden layer", () => {
|
|
87
|
-
const control = new CopyrightControl();
|
|
88
|
-
control.attachToMap(map);
|
|
89
|
-
expect(control.element.innerHTML).toBe("");
|
|
90
|
-
const layer1 = getLayer("copyright hidden", false);
|
|
91
|
-
layer1.attachToMap(map);
|
|
92
|
-
const layer2 = getLayer("copyright", true);
|
|
93
|
-
layer2.attachToMap(map);
|
|
94
|
-
map.renderSync();
|
|
95
|
-
expect(control.element.innerHTML).toBe("copyright");
|
|
96
|
-
layer1.setVisible(true);
|
|
97
|
-
map.renderSync();
|
|
98
|
-
layer2.setVisible(false);
|
|
99
|
-
map.renderSync();
|
|
100
|
-
expect(control.element.innerHTML).toBe("copyright hidden");
|
|
101
|
-
});
|
|
102
|
-
test("should activate the control on construction then deactivate it", () => {
|
|
103
|
-
getLayer("copyright 1").attachToMap(map);
|
|
104
|
-
const control = new CopyrightControl({ active: true });
|
|
105
|
-
control.attachToMap(map);
|
|
106
|
-
map.renderSync();
|
|
107
|
-
expect(control.element.parentNode).toBe(map.getTargetElement());
|
|
108
|
-
expect(control.active).toBe(true);
|
|
109
|
-
expect(control.element.innerHTML).toBe("copyright 1");
|
|
110
|
-
control.active = false;
|
|
111
|
-
map.renderSync();
|
|
112
|
-
expect(control.element.innerHTML).toBe("");
|
|
113
|
-
});
|
|
114
|
-
test("should deactivate the control on constrcution then activate it", () => {
|
|
115
|
-
getLayer("copyright 1").attachToMap(map);
|
|
116
|
-
const control = new CopyrightControl({ active: false });
|
|
117
|
-
control.attachToMap(map);
|
|
118
|
-
map.renderSync();
|
|
119
|
-
expect(control.element.parentNode).toBe(map.getTargetElement());
|
|
120
|
-
expect(control.active).toBe(false);
|
|
121
|
-
map.renderSync();
|
|
122
|
-
expect(control.element.innerHTML).toBe("");
|
|
123
|
-
control.active = true;
|
|
124
|
-
map.renderSync();
|
|
125
|
-
expect(control.element.innerHTML).toBe("copyright 1");
|
|
126
|
-
});
|
|
127
|
-
test("should add copyrights in the map container element then remove it.", () => {
|
|
128
|
-
getLayer("copyright value").attachToMap(map);
|
|
129
|
-
map.renderSync();
|
|
130
|
-
const control = new CopyrightControl();
|
|
131
|
-
control.attachToMap(map);
|
|
132
|
-
expect(control.element.parentNode).toBe(map.getTargetElement());
|
|
133
|
-
control.detachFromMap();
|
|
134
|
-
expect(control.element.parentNode).toBe(null);
|
|
135
|
-
});
|
|
136
|
-
test("should add copyrights in the target element then remove it.", () => {
|
|
137
|
-
getLayer(["copyright value"]).attachToMap(map);
|
|
138
|
-
map.renderSync();
|
|
139
|
-
const target = document.createElement("div");
|
|
140
|
-
target.setAttribute("id", "copyright");
|
|
141
|
-
document.body.appendChild(target);
|
|
142
|
-
const control = new CopyrightControl({
|
|
143
|
-
target: document.getElementById("copyright")
|
|
144
|
-
});
|
|
145
|
-
control.attachToMap(map);
|
|
146
|
-
expect(control.element.parentNode).toBe(target);
|
|
147
|
-
control.detachFromMap();
|
|
148
|
-
expect(control.element.parentNode).toBe(null);
|
|
149
|
-
});
|
|
150
|
-
test("renders custom copyrights with the render method ", () => {
|
|
151
|
-
const control = new CopyrightControl({
|
|
152
|
-
active: true,
|
|
153
|
-
render() {
|
|
154
|
-
if (!this.element) {
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
this.element.innerHTML = this.active ? this.getCopyrights().join(", ") : "";
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
control.attachToMap(map);
|
|
161
|
-
getLayer(["copyright 1", "copyright 2", "copyright 3"]).attachToMap(map);
|
|
162
|
-
map.renderSync();
|
|
163
|
-
expect(control.element.innerHTML).toBe("copyright 1, copyright 2, copyright 3");
|
|
164
|
-
});
|
|
165
|
-
});
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import fetch from "jest-fetch-mock";
|
|
2
|
-
import View from "ol/View";
|
|
3
|
-
import qs from "query-string";
|
|
4
|
-
import Map from "ol/Map";
|
|
5
|
-
import RoutingControl from "./RoutingControl";
|
|
6
|
-
import RoutingControlStation1 from "./snapshots/RoutingControlStation1.json";
|
|
7
|
-
import RoutingControlStation2 from "./snapshots/RoutingControlStation2.json";
|
|
8
|
-
import RoutingControlRouteGen5 from "./snapshots/RoutingControlRouteGen5.json";
|
|
9
|
-
import RoutingControlRouteGen10 from "./snapshots/RoutingControlRouteGen10.json";
|
|
10
|
-
import RoutingControlRouteGen30 from "./snapshots/RoutingControlRouteGen30.json";
|
|
11
|
-
import RoutingControlRouteGen100 from "./snapshots/RoutingControlRouteGen100.json";
|
|
12
|
-
import RoutingControlRouteOSM from "./snapshots/RoutingControlRouteOSM.json";
|
|
13
|
-
describe("RoutingControl", () => {
|
|
14
|
-
let map;
|
|
15
|
-
beforeEach(() => {
|
|
16
|
-
const target = document.createElement("div");
|
|
17
|
-
document.body.appendChild(target);
|
|
18
|
-
map = new Map({
|
|
19
|
-
target,
|
|
20
|
-
view: new View({
|
|
21
|
-
center: [0, 0],
|
|
22
|
-
zoom: 0
|
|
23
|
-
})
|
|
24
|
-
});
|
|
25
|
-
global.fetch = fetch;
|
|
26
|
-
});
|
|
27
|
-
afterEach(() => {
|
|
28
|
-
if (map) {
|
|
29
|
-
map.setTarget(null);
|
|
30
|
-
map = null;
|
|
31
|
-
}
|
|
32
|
-
fetch.resetMocks();
|
|
33
|
-
});
|
|
34
|
-
test("should be activate by default", () => {
|
|
35
|
-
const control = new RoutingControl();
|
|
36
|
-
expect(control.active).toBe(true);
|
|
37
|
-
expect(control.snapToClosestStation).toBe(false);
|
|
38
|
-
expect(control.useRawViaPoints).toBe(false);
|
|
39
|
-
});
|
|
40
|
-
test("launch routing and add features", (done) => {
|
|
41
|
-
fetch.mockResponseOnce(JSON.stringify(global.fetchRouteResponse));
|
|
42
|
-
const control = new RoutingControl({
|
|
43
|
-
url: "https://foo.ch",
|
|
44
|
-
apiKey: "foo"
|
|
45
|
-
});
|
|
46
|
-
control.attachToMap(map);
|
|
47
|
-
expect(map.getTarget().querySelector("#ol-toggle-routing")).toBeDefined();
|
|
48
|
-
control.viaPoints = [
|
|
49
|
-
[950476.4055933182, 6003322253698345e-9],
|
|
50
|
-
[950389.0813034325, 6003656659274571e-9]
|
|
51
|
-
];
|
|
52
|
-
control.drawRoute(control.viaPoints).then(() => {
|
|
53
|
-
expect(fetch.mock.calls[0][0]).toEqual("https://foo.ch?coord-punish=1000&coord-radius=100&elevation=false&graph=osm&key=foo&mot=bus&resolve-hops=false&via=47.3739194713294%2C8.538274823394632%7C47.37595378493421%2C8.537490375951839");
|
|
54
|
-
expect(control.routingLayer.olLayer.getSource().getFeatures().length).toEqual(3);
|
|
55
|
-
done();
|
|
56
|
-
}).catch(() => {
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
test("launch routing and add features for multiple graphs", (done) => {
|
|
60
|
-
fetch.mockResponses([JSON.stringify(RoutingControlStation1), { status: 200 }], [JSON.stringify(RoutingControlStation2), { status: 200 }], [JSON.stringify(RoutingControlRouteGen5), { status: 200 }], [JSON.stringify(RoutingControlRouteGen10), { status: 200 }], [JSON.stringify(RoutingControlRouteGen30), { status: 200 }], [JSON.stringify(RoutingControlRouteGen100), { status: 200 }], [JSON.stringify(RoutingControlRouteOSM), { status: 200 }]);
|
|
61
|
-
const control = new RoutingControl({
|
|
62
|
-
url: "https://foo.ch/",
|
|
63
|
-
stopsApiUrl: "https://foo.ch/",
|
|
64
|
-
apiKey: "foo",
|
|
65
|
-
graphs: [
|
|
66
|
-
["gen5", 6, 7],
|
|
67
|
-
["gen10", 8],
|
|
68
|
-
["gen30", 9, 10],
|
|
69
|
-
["gen100", 11, 13],
|
|
70
|
-
["osm", 14, 99]
|
|
71
|
-
]
|
|
72
|
-
});
|
|
73
|
-
control.attachToMap(map);
|
|
74
|
-
control.viaPoints = ["a4dca961d199ff76", "e3666f03cba06b2b"];
|
|
75
|
-
control.drawRoute(control.viaPoints).then(() => {
|
|
76
|
-
expect(fetch.mock.calls[0][0]).toEqual("https://foo.ch/lookup/a4dca961d199ff76?key=foo");
|
|
77
|
-
expect(fetch.mock.calls[1][0]).toEqual("https://foo.ch/lookup/e3666f03cba06b2b?key=foo");
|
|
78
|
-
expect(fetch.mock.calls[2][0]).toEqual("https://foo.ch/?coord-punish=1000&coord-radius=100&elevation=false&graph=gen5&key=foo&mot=bus&resolve-hops=false&via=%21a4dca961d199ff76%7C%21e3666f03cba06b2b");
|
|
79
|
-
expect(fetch.mock.calls[3][0]).toEqual("https://foo.ch/?coord-punish=1000&coord-radius=100&elevation=false&graph=gen10&key=foo&mot=bus&resolve-hops=false&via=%21a4dca961d199ff76%7C%21e3666f03cba06b2b");
|
|
80
|
-
expect(fetch.mock.calls[4][0]).toEqual("https://foo.ch/?coord-punish=1000&coord-radius=100&elevation=false&graph=gen30&key=foo&mot=bus&resolve-hops=false&via=%21a4dca961d199ff76%7C%21e3666f03cba06b2b");
|
|
81
|
-
expect(fetch.mock.calls[5][0]).toEqual("https://foo.ch/?coord-punish=1000&coord-radius=100&elevation=false&graph=gen100&key=foo&mot=bus&resolve-hops=false&via=%21a4dca961d199ff76%7C%21e3666f03cba06b2b");
|
|
82
|
-
expect(fetch.mock.calls[6][0]).toEqual("https://foo.ch/?coord-punish=1000&coord-radius=100&elevation=false&graph=osm&key=foo&mot=bus&resolve-hops=false&via=%21a4dca961d199ff76%7C%21e3666f03cba06b2b");
|
|
83
|
-
expect(control.routingLayer.olLayer.getSource().getFeatures().length).toEqual(7);
|
|
84
|
-
done();
|
|
85
|
-
}).catch(() => {
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
test("ignores Abort Error and returns undefined", (done) => {
|
|
89
|
-
const control = new RoutingControl({
|
|
90
|
-
url: "https://foo.ch",
|
|
91
|
-
apiKey: "foo"
|
|
92
|
-
});
|
|
93
|
-
control.attachToMap(map);
|
|
94
|
-
control.viaPoints = [
|
|
95
|
-
[950476.4055933182, 6003322253698345e-9],
|
|
96
|
-
[950389.0813034325, 6003656659274571e-9]
|
|
97
|
-
];
|
|
98
|
-
const error = new Error("Error");
|
|
99
|
-
error.name = "AbortError";
|
|
100
|
-
fetch.mockRejectOnce(error);
|
|
101
|
-
return control.drawRoute().then((data) => {
|
|
102
|
-
expect(data).toEqual([void 0]);
|
|
103
|
-
done();
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
test("calls routing api with @ before the coordinates when snapToClosestStation is true", (done) => {
|
|
107
|
-
fetch.mockResponses([JSON.stringify(RoutingControlStation1), { status: 200 }], [JSON.stringify(global.fetchRouteResponse), { status: 200 }]);
|
|
108
|
-
const control = new RoutingControl({
|
|
109
|
-
apiKey: "foo",
|
|
110
|
-
snapToClosestStation: true
|
|
111
|
-
});
|
|
112
|
-
control.attachToMap(map);
|
|
113
|
-
expect(map.getTarget().querySelector("#ol-toggle-routing")).toBeDefined();
|
|
114
|
-
control.viaPoints = [
|
|
115
|
-
[950476.4055933182, 6003322253698345e-9],
|
|
116
|
-
[950389.0813034325, 6003656659274571e-9],
|
|
117
|
-
"e3666f03cba06b2b"
|
|
118
|
-
];
|
|
119
|
-
control.drawRoute(control.viaPoints).then(() => {
|
|
120
|
-
const params = qs.parseUrl(fetch.mock.calls[1][0]).query;
|
|
121
|
-
expect(params.via).toBe("@47.3739194713294,8.538274823394632|@47.37595378493421,8.537490375951839|!e3666f03cba06b2b");
|
|
122
|
-
done();
|
|
123
|
-
}).catch(() => {
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
test("calls routing api with raw via points", (done) => {
|
|
127
|
-
fetch.mockResponses([JSON.stringify(RoutingControlStation1), { status: 200 }], [JSON.stringify(RoutingControlStation2), { status: 200 }], [JSON.stringify(global.fetchRouteResponse), { status: 200 }]);
|
|
128
|
-
const control = new RoutingControl({
|
|
129
|
-
apiKey: "foo",
|
|
130
|
-
useRawViaPoints: true
|
|
131
|
-
});
|
|
132
|
-
control.attachToMap(map);
|
|
133
|
-
expect(map.getTarget().querySelector("#ol-toggle-routing")).toBeDefined();
|
|
134
|
-
control.viaPoints = [
|
|
135
|
-
"46.2,7.1",
|
|
136
|
-
"@46.2,7.1",
|
|
137
|
-
"@46.2,7$1",
|
|
138
|
-
"station name$2",
|
|
139
|
-
"station name@46.2,7",
|
|
140
|
-
"stationname@46.2,7.7$3",
|
|
141
|
-
"!stationid",
|
|
142
|
-
[950389, 6003656]
|
|
143
|
-
];
|
|
144
|
-
control.drawRoute(control.viaPoints).then(() => {
|
|
145
|
-
const params = qs.parseUrl(fetch.mock.calls[2][0]).query;
|
|
146
|
-
expect(params.via).toBe("46.2,7.1|@46.2,7.1|@46.2,7$1|station name$2|station name@46.2,7|stationname@46.2,7.7$3|!stationid|47.375949774398805,8.537489645590679");
|
|
147
|
-
done();
|
|
148
|
-
}).catch(() => {
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
});
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import fetch from "jest-fetch-mock";
|
|
2
|
-
import View from "ol/View";
|
|
3
|
-
import Map from "ol/Map";
|
|
4
|
-
import StopFinderControl from "./StopFinderControl";
|
|
5
|
-
describe("StopFinderControl", () => {
|
|
6
|
-
let map;
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
const target = document.createElement("div");
|
|
9
|
-
document.body.appendChild(target);
|
|
10
|
-
map = new Map({
|
|
11
|
-
target,
|
|
12
|
-
view: new View({
|
|
13
|
-
center: [0, 0],
|
|
14
|
-
zoom: 0
|
|
15
|
-
})
|
|
16
|
-
});
|
|
17
|
-
global.fetch = fetch;
|
|
18
|
-
});
|
|
19
|
-
afterEach(() => {
|
|
20
|
-
if (map) {
|
|
21
|
-
map.setTarget(null);
|
|
22
|
-
map = null;
|
|
23
|
-
}
|
|
24
|
-
fetch.resetMocks();
|
|
25
|
-
});
|
|
26
|
-
test("should be activate by default", () => {
|
|
27
|
-
const control = new StopFinderControl();
|
|
28
|
-
expect(control.active).toBe(true);
|
|
29
|
-
});
|
|
30
|
-
test("launch a search and display results", (done) => {
|
|
31
|
-
fetch.mockResponseOnce(JSON.stringify(global.stopsSearchResponse));
|
|
32
|
-
const control = new StopFinderControl({
|
|
33
|
-
url: "https://foo.ch",
|
|
34
|
-
apiKey: "foo",
|
|
35
|
-
apiParams: {
|
|
36
|
-
limit: 10,
|
|
37
|
-
foo: "bar"
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
control.attachToMap(map);
|
|
41
|
-
expect(control.element).toBeDefined();
|
|
42
|
-
control.search("foo").then(() => {
|
|
43
|
-
expect(fetch.mock.calls[0][0]).toEqual("https://foo.ch?foo=bar&key=foo&limit=10&q=foo");
|
|
44
|
-
expect(control.element.querySelector("div").querySelector("div").innerHTML).toBe("Bern");
|
|
45
|
-
done();
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
});
|