mobility-toolbox-js 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api/RealtimeAPI.d.ts +279 -0
- package/api/RealtimeAPI.d.ts.map +1 -0
- package/api/RealtimeAPI.js +466 -0
- package/api/RoutingAPI.d.ts +37 -0
- package/api/RoutingAPI.d.ts.map +1 -0
- package/api/RoutingAPI.js +35 -0
- package/api/StopsAPI.d.ts +38 -0
- package/api/StopsAPI.d.ts.map +1 -0
- package/api/StopsAPI.js +36 -0
- package/api/index.d.ts +4 -0
- package/api/index.d.ts.map +1 -0
- package/api/index.js +3 -3
- package/api/typedefs.d.ts +179 -0
- package/api/typedefs.d.ts.map +1 -0
- package/api/{tralis/typedefs.js → typedefs.js} +4 -10
- package/common/api/HttpAPI.d.ts +31 -0
- package/common/api/HttpAPI.d.ts.map +1 -0
- package/common/api/HttpAPI.js +57 -0
- package/common/api/WebSocketAPI.d.ts +153 -0
- package/common/api/WebSocketAPI.d.ts.map +1 -0
- package/common/api/WebSocketAPI.js +341 -0
- package/common/controls/ControlCommon.d.ts +76 -0
- package/common/controls/ControlCommon.d.ts.map +1 -0
- package/common/controls/ControlCommon.js +150 -0
- package/common/controls/CopyrightControlCommon.d.ts +13 -0
- package/common/controls/CopyrightControlCommon.d.ts.map +1 -0
- package/common/controls/CopyrightControlCommon.js +34 -0
- package/common/controls/StopFinderControlCommon.d.ts +55 -0
- package/common/controls/StopFinderControlCommon.d.ts.map +1 -0
- package/common/controls/StopFinderControlCommon.js +144 -0
- package/common/index.d.ts +3 -0
- package/common/index.d.ts.map +1 -0
- package/common/index.js +2 -0
- package/common/layers/LayerCommon.d.ts +94 -0
- package/common/layers/LayerCommon.d.ts.map +1 -0
- package/common/layers/LayerCommon.js +244 -0
- package/common/mixins/RealtimeLayerMixin.d.ts +286 -0
- package/common/mixins/RealtimeLayerMixin.d.ts.map +1 -0
- package/common/mixins/RealtimeLayerMixin.js +776 -0
- package/common/mixins/UserInteractionsLayerMixin.d.ts +60 -0
- package/common/mixins/UserInteractionsLayerMixin.d.ts.map +1 -0
- package/common/mixins/UserInteractionsLayerMixin.js +241 -0
- package/common/styles/index.d.ts +5 -0
- package/common/styles/index.d.ts.map +1 -0
- package/common/styles/index.js +4 -4
- package/common/styles/realtimeDefaultStyle.d.ts +36 -0
- package/common/styles/realtimeDefaultStyle.d.ts.map +1 -0
- package/common/styles/realtimeDefaultStyle.js +275 -0
- package/common/styles/{trackerDelayStyle.js → realtimeDelayStyle.d.ts} +4 -9
- package/common/styles/realtimeDelayStyle.d.ts.map +1 -0
- package/common/styles/realtimeDelayStyle.js +13 -0
- package/common/styles/realtimeHeadingStyle.d.ts +12 -0
- package/common/styles/realtimeHeadingStyle.d.ts.map +1 -0
- package/common/styles/realtimeHeadingStyle.js +85 -0
- package/common/styles/realtimeSimpleStyle.d.ts +4 -0
- package/common/styles/realtimeSimpleStyle.d.ts.map +1 -0
- package/common/styles/realtimeSimpleStyle.js +23 -0
- package/common/typedefs.d.ts +111 -0
- package/common/typedefs.d.ts.map +1 -0
- package/common/typedefs.js +35 -6
- package/common/utils/compareDepartures.d.ts +11 -0
- package/common/utils/compareDepartures.d.ts.map +1 -0
- package/common/utils/compareDepartures.js +35 -0
- package/common/utils/createCanvas.d.ts +10 -0
- package/common/utils/createCanvas.d.ts.map +1 -0
- package/common/utils/createCanvas.js +27 -0
- package/common/utils/createRealtimeFilters.d.ts +13 -0
- package/common/utils/createRealtimeFilters.d.ts.map +1 -0
- package/common/utils/createRealtimeFilters.js +74 -0
- package/common/utils/debounceDeparturesMessages.d.ts +12 -0
- package/common/utils/debounceDeparturesMessages.d.ts.map +1 -0
- package/common/utils/debounceDeparturesMessages.js +24 -0
- package/common/utils/debounceWebsocketMessages.d.ts +11 -0
- package/common/utils/debounceWebsocketMessages.d.ts.map +1 -0
- package/common/utils/debounceWebsocketMessages.js +29 -0
- package/common/utils/getLayersAsFlatArray.d.ts +3 -0
- package/common/utils/getLayersAsFlatArray.d.ts.map +1 -0
- package/common/utils/getLayersAsFlatArray.js +15 -0
- package/common/utils/getMapboxMapCopyrights.d.ts +18 -0
- package/common/utils/getMapboxMapCopyrights.d.ts.map +1 -0
- package/common/utils/getMapboxMapCopyrights.js +21 -23
- package/common/utils/getMapboxRender.d.ts +7 -0
- package/common/utils/getMapboxRender.d.ts.map +1 -0
- package/common/utils/getMapboxRender.js +87 -0
- package/common/utils/getMaplibreRender.d.ts +7 -0
- package/common/utils/getMaplibreRender.d.ts.map +1 -0
- package/common/utils/getMaplibreRender.js +38 -0
- package/common/utils/getRealtimeModeSuffix.d.ts +10 -0
- package/common/utils/getRealtimeModeSuffix.d.ts.map +1 -0
- package/common/utils/getRealtimeModeSuffix.js +7 -0
- package/common/utils/getUrlWithParams.d.ts +9 -0
- package/common/utils/getUrlWithParams.d.ts.map +1 -0
- package/common/utils/getUrlWithParams.js +18 -0
- package/common/utils/getVehiclePosition.d.ts +16 -0
- package/common/utils/getVehiclePosition.d.ts.map +1 -0
- package/common/utils/getVehiclePosition.js +60 -60
- package/common/utils/index.d.ts +17 -0
- package/common/utils/index.d.ts.map +1 -0
- package/common/utils/index.js +13 -2
- package/common/utils/realtimeConfig.d.ts +49 -0
- package/common/utils/realtimeConfig.d.ts.map +1 -0
- package/common/utils/realtimeConfig.js +173 -0
- package/common/utils/removeDuplicate.d.ts +10 -0
- package/common/utils/removeDuplicate.d.ts.map +1 -0
- package/common/utils/removeDuplicate.js +5 -12
- package/common/utils/renderTrajectories.d.ts +17 -0
- package/common/utils/renderTrajectories.d.ts.map +1 -0
- package/common/utils/renderTrajectories.js +110 -0
- package/common/utils/sortAndFilterDepartures.d.ts +16 -0
- package/common/utils/sortAndFilterDepartures.d.ts.map +1 -0
- package/common/utils/sortAndFilterDepartures.js +58 -0
- package/common/utils/sortByDelay.d.ts +3 -0
- package/common/utils/sortByDelay.d.ts.map +1 -0
- package/common/utils/sortByDelay.js +17 -20
- package/common/utils/timeUtils.d.ts +24 -0
- package/common/utils/timeUtils.d.ts.map +1 -0
- package/common/utils/timeUtils.js +13 -18
- package/iife.d.ts +3 -0
- package/iife.d.ts.map +1 -0
- package/iife.js +5 -0
- package/index.d.ts +10 -0
- package/index.d.ts.map +1 -0
- package/index.js +10 -2
- package/mapbox/controls/CopyrightControl.d.ts +29 -0
- package/mapbox/controls/CopyrightControl.d.ts.map +1 -0
- package/mapbox/controls/CopyrightControl.js +25 -35
- package/mapbox/controls/index.d.ts +2 -0
- package/mapbox/controls/index.d.ts.map +1 -0
- package/mapbox/controls/index.js +2 -0
- package/mapbox/index.d.ts +6 -0
- package/mapbox/index.d.ts.map +1 -0
- package/mapbox/index.js +5 -3
- package/mapbox/layers/Layer.d.ts +59 -0
- package/mapbox/layers/Layer.d.ts.map +1 -0
- package/mapbox/layers/Layer.js +78 -95
- package/mapbox/layers/RealtimeLayer.d.ts +181 -0
- package/mapbox/layers/RealtimeLayer.d.ts.map +1 -0
- package/mapbox/layers/RealtimeLayer.js +276 -0
- package/mapbox/layers/index.d.ts +3 -0
- package/mapbox/layers/index.d.ts.map +1 -0
- package/mapbox/layers/index.js +2 -0
- package/mapbox/utils/getMercatorResolution.d.ts +9 -0
- package/mapbox/utils/getMercatorResolution.d.ts.map +1 -0
- package/mapbox/utils/getMercatorResolution.js +18 -0
- package/mapbox/utils/getSourceCoordinates.d.ts +9 -0
- package/mapbox/utils/getSourceCoordinates.d.ts.map +1 -0
- package/mapbox/utils/getSourceCoordinates.js +27 -0
- package/mapbox/utils/index.d.ts +3 -0
- package/mapbox/utils/index.d.ts.map +1 -0
- package/mapbox/utils/index.js +2 -0
- package/mbt.js +60005 -0
- package/mbt.js.map +7 -0
- package/mbt.min.js +1084 -0
- package/mbt.min.js.map +7 -0
- package/ol/controls/CopyrightControl.d.ts +31 -0
- package/ol/controls/CopyrightControl.d.ts.map +1 -0
- package/ol/controls/CopyrightControl.js +44 -56
- package/ol/controls/RoutingControl.d.ts +193 -0
- package/ol/controls/RoutingControl.d.ts.map +1 -0
- package/ol/controls/RoutingControl.js +546 -667
- package/ol/controls/StopFinderControl.d.ts +30 -0
- package/ol/controls/StopFinderControl.d.ts.map +1 -0
- package/ol/controls/StopFinderControl.js +10 -16
- package/ol/controls/index.d.ts +4 -0
- package/ol/controls/index.d.ts.map +1 -0
- package/ol/controls/index.js +3 -0
- package/ol/index.d.ts +6 -0
- package/ol/index.d.ts.map +1 -0
- package/ol/index.js +4 -12
- package/ol/layers/Layer.d.ts +86 -0
- package/ol/layers/Layer.d.ts.map +1 -0
- package/ol/layers/Layer.js +147 -166
- package/ol/layers/MapGlLayer.d.ts +67 -0
- package/ol/layers/MapGlLayer.d.ts.map +1 -0
- package/ol/layers/MapGlLayer.js +218 -0
- package/ol/layers/MapboxLayer.d.ts +50 -0
- package/ol/layers/MapboxLayer.d.ts.map +1 -0
- package/ol/layers/MapboxLayer.js +79 -348
- package/ol/layers/MapboxStyleLayer.d.ts +129 -0
- package/ol/layers/MapboxStyleLayer.d.ts.map +1 -0
- package/ol/layers/MapboxStyleLayer.js +329 -368
- package/ol/layers/MaplibreLayer.d.ts +28 -0
- package/ol/layers/MaplibreLayer.d.ts.map +1 -0
- package/ol/layers/MaplibreLayer.js +13 -259
- package/ol/layers/RealtimeLayer.d.ts +202 -0
- package/ol/layers/RealtimeLayer.d.ts.map +1 -0
- package/ol/layers/RealtimeLayer.js +340 -0
- package/ol/layers/RoutingLayer.d.ts +34 -0
- package/ol/layers/RoutingLayer.d.ts.map +1 -0
- package/ol/layers/RoutingLayer.js +62 -68
- package/ol/layers/VectorLayer.d.ts +25 -0
- package/ol/layers/VectorLayer.d.ts.map +1 -0
- package/ol/layers/VectorLayer.js +27 -32
- package/ol/layers/WMSLayer.d.ts +42 -0
- package/ol/layers/WMSLayer.d.ts.map +1 -0
- package/ol/layers/WMSLayer.js +74 -66
- package/ol/layers/index.d.ts +9 -0
- package/ol/layers/index.d.ts.map +1 -0
- package/ol/layers/index.js +8 -0
- package/ol/styles/fullTrajectoryDelayStyle.d.ts +4 -0
- package/ol/styles/fullTrajectoryDelayStyle.d.ts.map +1 -0
- package/ol/styles/fullTrajectoryDelayStyle.js +23 -25
- package/ol/styles/fullTrajectoryStyle.d.ts +5 -0
- package/ol/styles/fullTrajectoryStyle.d.ts.map +1 -0
- package/ol/styles/fullTrajectoryStyle.js +37 -44
- package/ol/styles/index.d.ts +3 -0
- package/ol/styles/index.d.ts.map +1 -0
- package/package.json +98 -177
- package/setupTests.d.ts +2 -0
- package/setupTests.d.ts.map +1 -0
- package/setupTests.js +26 -0
- package/types/common.d.ts +122 -0
- package/types/index.d.ts +11 -0
- package/types/realtime.d.ts +320 -0
- package/types/routing.d.ts +206 -0
- package/types/stops.d.ts +143 -0
- package/README.md +0 -23
- package/api/routing/RoutingAPI.js +0 -44
- package/api/routing/RoutingAPI.test.js +0 -41
- package/api/stops/StopsAPI.js +0 -41
- package/api/stops/StopsAPI.test.js +0 -34
- package/api/tralis/TralisAPI.js +0 -731
- package/api/tralis/TralisAPI.test.js +0 -75
- package/api/tralis/TralisAPIUtils.js +0 -73
- package/api/tralis/WebSocketConnector.js +0 -338
- package/api/tralis/WebSocketConnector.test.js +0 -356
- package/common/Tracker.js +0 -197
- package/common/api/api.js +0 -64
- package/common/api/api.test.js +0 -68
- package/common/controls/Control.js +0 -146
- package/common/controls/Control.test.js +0 -98
- package/common/layers/Layer.js +0 -404
- package/common/layers/Layer.test.js +0 -585
- package/common/mixins/CopyrightMixin.js +0 -48
- package/common/mixins/SearchMixin.js +0 -176
- package/common/mixins/TralisLayerMixin.js +0 -930
- package/common/styles/trackerDefaultStyle.js +0 -333
- package/common/styles/trackerSimpleStyle.js +0 -22
- package/common/trackerConfig.js +0 -190
- package/common/trackerConfig.test.js +0 -25
- package/common/utils/createTrackerFilters.js +0 -87
- package/common/utils/createTrackerFilters.test.js +0 -95
- package/common/utils/getMapboxMapCopyrights.test.js +0 -47
- package/common/utils/getMapboxStyleUrl.js +0 -32
- package/common/utils/removeDuplicate.test.js +0 -22
- package/common/utils/timeUtils.test.js +0 -16
- package/index.js.map +0 -1
- package/mapbox/layers/Layer.test.js +0 -202
- package/mapbox/layers/TralisLayer.js +0 -329
- package/mapbox/layers/TralisLayer.test.js +0 -40
- package/mapbox/utils.js +0 -46
- package/module.js +0 -23
- package/ol/README.md +0 -0
- package/ol/controls/CopyrightControl.test.js +0 -211
- package/ol/controls/RoutingControl.test.js +0 -216
- package/ol/controls/StopFinderControl.test.js +0 -59
- package/ol/controls/snapshots/RoutingControlRouteGen10.json +0 -58
- package/ol/controls/snapshots/RoutingControlRouteGen100.json +0 -292
- package/ol/controls/snapshots/RoutingControlRouteGen30.json +0 -69
- package/ol/controls/snapshots/RoutingControlRouteGen5.json +0 -58
- package/ol/controls/snapshots/RoutingControlRouteOSM.json +0 -759
- package/ol/controls/snapshots/RoutingControlStation1.json +0 -60
- package/ol/controls/snapshots/RoutingControlStation2.json +0 -49
- package/ol/layers/Layer.test.js +0 -197
- package/ol/layers/MapboxLayer.test.js +0 -186
- package/ol/layers/MapboxStyleLayer.test.js +0 -262
- package/ol/layers/RoutingLayer.test.js +0 -49
- package/ol/layers/TralisLayer.js +0 -359
- package/ol/layers/TralisLayer.test.js +0 -97
- package/ol/layers/VectorLayer.test.js +0 -98
- package/ol/layers/WMSLayer.test.js +0 -84
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"type": "FeatureCollection",
|
|
3
|
-
"features": [
|
|
4
|
-
{
|
|
5
|
-
"type": "Feature",
|
|
6
|
-
"properties": {
|
|
7
|
-
"uid": "a4dca961d199ff76",
|
|
8
|
-
"name": "Z\u00fcrich HB",
|
|
9
|
-
"country_code": "CH",
|
|
10
|
-
"rank": null,
|
|
11
|
-
"translated_names": [],
|
|
12
|
-
"mot": {
|
|
13
|
-
"bus": false,
|
|
14
|
-
"rail": true,
|
|
15
|
-
"tram": false,
|
|
16
|
-
"ferry": false,
|
|
17
|
-
"subway": false,
|
|
18
|
-
"gondola": false,
|
|
19
|
-
"cable_car": false,
|
|
20
|
-
"funicular": false
|
|
21
|
-
},
|
|
22
|
-
"platforms": {
|
|
23
|
-
"rail": [
|
|
24
|
-
"3",
|
|
25
|
-
"4",
|
|
26
|
-
"5",
|
|
27
|
-
"6",
|
|
28
|
-
"7",
|
|
29
|
-
"8",
|
|
30
|
-
"9",
|
|
31
|
-
"10",
|
|
32
|
-
"11",
|
|
33
|
-
"12",
|
|
34
|
-
"13",
|
|
35
|
-
"14",
|
|
36
|
-
"15",
|
|
37
|
-
"16",
|
|
38
|
-
"17",
|
|
39
|
-
"18",
|
|
40
|
-
"21",
|
|
41
|
-
"22",
|
|
42
|
-
"31",
|
|
43
|
-
"32",
|
|
44
|
-
"33",
|
|
45
|
-
"34",
|
|
46
|
-
"41",
|
|
47
|
-
"42",
|
|
48
|
-
"43",
|
|
49
|
-
"44"
|
|
50
|
-
]
|
|
51
|
-
},
|
|
52
|
-
"ifopt": null,
|
|
53
|
-
"ident_source": "sbb",
|
|
54
|
-
"id": "8503000",
|
|
55
|
-
"code": "ZUE"
|
|
56
|
-
},
|
|
57
|
-
"geometry": { "type": "Point", "coordinates": [8.540212, 47.378177] }
|
|
58
|
-
}
|
|
59
|
-
]
|
|
60
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"type": "FeatureCollection",
|
|
3
|
-
"features": [
|
|
4
|
-
{
|
|
5
|
-
"type": "Feature",
|
|
6
|
-
"properties": {
|
|
7
|
-
"uid": "e3666f03cba06b2b",
|
|
8
|
-
"name": "Luzern",
|
|
9
|
-
"country_code": "CH",
|
|
10
|
-
"rank": null,
|
|
11
|
-
"translated_names": [],
|
|
12
|
-
"mot": {
|
|
13
|
-
"bus": false,
|
|
14
|
-
"rail": true,
|
|
15
|
-
"tram": false,
|
|
16
|
-
"ferry": false,
|
|
17
|
-
"subway": false,
|
|
18
|
-
"gondola": false,
|
|
19
|
-
"cable_car": false,
|
|
20
|
-
"funicular": false
|
|
21
|
-
},
|
|
22
|
-
"platforms": {
|
|
23
|
-
"rail": [
|
|
24
|
-
"1",
|
|
25
|
-
"2",
|
|
26
|
-
"3",
|
|
27
|
-
"4",
|
|
28
|
-
"5",
|
|
29
|
-
"6",
|
|
30
|
-
"7",
|
|
31
|
-
"8",
|
|
32
|
-
"9",
|
|
33
|
-
"10",
|
|
34
|
-
"11",
|
|
35
|
-
"12",
|
|
36
|
-
"13",
|
|
37
|
-
"14",
|
|
38
|
-
"15"
|
|
39
|
-
]
|
|
40
|
-
},
|
|
41
|
-
"ifopt": null,
|
|
42
|
-
"ident_source": "sbb",
|
|
43
|
-
"id": "8505000",
|
|
44
|
-
"code": "LZ"
|
|
45
|
-
},
|
|
46
|
-
"geometry": { "type": "Point", "coordinates": [8.310183, 47.050178] }
|
|
47
|
-
}
|
|
48
|
-
]
|
|
49
|
-
}
|
package/ol/layers/Layer.test.js
DELETED
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import VectorLayer from 'ol/layer/Vector';
|
|
2
|
-
import VectorSource from 'ol/source/Vector';
|
|
3
|
-
import Map from 'ol/Map';
|
|
4
|
-
import Group from 'ol/layer/Group';
|
|
5
|
-
import Layer from './Layer';
|
|
6
|
-
|
|
7
|
-
let olLayer;
|
|
8
|
-
let map;
|
|
9
|
-
|
|
10
|
-
describe('Layer', () => {
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
map = new Map({});
|
|
13
|
-
olLayer = new VectorLayer({ source: new VectorSource() });
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
test('should initialize.', () => {
|
|
17
|
-
const layer = new Layer({ name: 'Layer', olLayer });
|
|
18
|
-
expect(layer).toBeInstanceOf(Layer);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
test('should be visible by default.', () => {
|
|
22
|
-
const layer = new Layer({ name: 'Layer', olLayer });
|
|
23
|
-
expect(layer.visible).toBe(true);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
test('should be invisible if defined.', () => {
|
|
27
|
-
const layer = new Layer({ name: 'Layer', visible: false, olLayer });
|
|
28
|
-
expect(layer.visible).toBe(false);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
test('should be invisible if set.', () => {
|
|
32
|
-
const layer = new Layer({ name: 'Layer', olLayer });
|
|
33
|
-
layer.setVisible(false);
|
|
34
|
-
expect(layer.visible).toBe(false);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
test('should visibility stay unchanged', () => {
|
|
38
|
-
const layer = new Layer({ name: 'Layer', visible: false, olLayer });
|
|
39
|
-
layer.setVisible(false);
|
|
40
|
-
expect(layer.visible).toBe(false);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
test('should return its name.', () => {
|
|
44
|
-
const layer = new Layer({ name: 'Layer', visible: false, olLayer });
|
|
45
|
-
expect(layer.name).toEqual('Layer');
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
test('should call terminate on initialization.', () => {
|
|
49
|
-
const layer = new Layer({ name: 'Layer', olLayer });
|
|
50
|
-
const spy = jest.spyOn(layer, 'terminate');
|
|
51
|
-
layer.init();
|
|
52
|
-
expect(spy).toHaveBeenCalledTimes(1);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
test('should remove the layer when we call terminate.', () => {
|
|
56
|
-
const layer = new Layer({ name: 'Layer', olLayer });
|
|
57
|
-
const spy = jest.spyOn(layer, 'terminate');
|
|
58
|
-
layer.init(map);
|
|
59
|
-
expect(spy).toHaveBeenCalledTimes(1);
|
|
60
|
-
layer.terminate(map);
|
|
61
|
-
expect(spy).toHaveBeenCalledTimes(2);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
test('should manage copyrights as string.', () => {
|
|
65
|
-
const spy = jest.spyOn(VectorSource.prototype, 'setAttributions');
|
|
66
|
-
const layer = new Layer({ name: 'Layer', copyrights: 'foo', olLayer });
|
|
67
|
-
layer.init(map);
|
|
68
|
-
expect(spy).toHaveBeenCalledWith(['foo']);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
test('should manage copyrights as array.', () => {
|
|
72
|
-
const spy = jest.spyOn(VectorSource.prototype, 'setAttributions');
|
|
73
|
-
const layer = new Layer({ name: 'Layer', copyrights: ['bar'], olLayer });
|
|
74
|
-
layer.init(map);
|
|
75
|
-
expect(spy).toHaveBeenCalledWith(['bar']);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
test('should set attributions for Group.', () => {
|
|
79
|
-
const spy = jest.spyOn(VectorSource.prototype, 'setAttributions');
|
|
80
|
-
const layer = new Layer({
|
|
81
|
-
name: 'Layer',
|
|
82
|
-
copyrights: ['bar'],
|
|
83
|
-
olLayer: new Group({ layers: [olLayer] }),
|
|
84
|
-
});
|
|
85
|
-
layer.init(map);
|
|
86
|
-
expect(spy).toHaveBeenCalledWith(['bar']);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
test('should listen for click/hover events when layer is visible by default then should not when hidden.', async () => {
|
|
90
|
-
global.console.error = jest.fn();
|
|
91
|
-
const layer = new Layer({ name: 'Layer', olLayer });
|
|
92
|
-
expect(layer.visible).toBe(true);
|
|
93
|
-
const spy = jest.fn();
|
|
94
|
-
const spy2 = jest.fn();
|
|
95
|
-
layer.init(map);
|
|
96
|
-
layer.onHover(spy);
|
|
97
|
-
layer.onClick(spy2);
|
|
98
|
-
expect(spy).toHaveBeenCalledTimes(0);
|
|
99
|
-
expect(spy2).toHaveBeenCalledTimes(0);
|
|
100
|
-
|
|
101
|
-
await map.dispatchEvent({ type: 'pointermove', map, coordinate: [0, 0] });
|
|
102
|
-
await map.dispatchEvent({ type: 'singleclick', map, coordinate: [0, 0] });
|
|
103
|
-
expect(spy).toHaveBeenCalledTimes(1);
|
|
104
|
-
expect(spy2).toHaveBeenCalledTimes(1);
|
|
105
|
-
spy.mockReset();
|
|
106
|
-
spy2.mockReset();
|
|
107
|
-
|
|
108
|
-
layer.setVisible(false);
|
|
109
|
-
await map.dispatchEvent({ type: 'pointermove', map, coordinate: [0, 0] });
|
|
110
|
-
await map.dispatchEvent({ type: 'singleclick', map, coordinate: [0, 0] });
|
|
111
|
-
expect(spy).toHaveBeenCalledTimes(0);
|
|
112
|
-
expect(spy2).toHaveBeenCalledTimes(0);
|
|
113
|
-
global.console.error.mockRestore();
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
test('should not listen for click/hover events when layer is not visible by default then should not when visible.', async () => {
|
|
117
|
-
global.console.error = jest.fn();
|
|
118
|
-
const layer = new Layer({ name: 'Layer', olLayer, visible: false });
|
|
119
|
-
expect(layer.visible).toBe(false);
|
|
120
|
-
const spy = jest.fn();
|
|
121
|
-
const spy2 = jest.fn();
|
|
122
|
-
layer.init(map);
|
|
123
|
-
layer.onHover(spy);
|
|
124
|
-
layer.onClick(spy2);
|
|
125
|
-
expect(spy).toHaveBeenCalledTimes(0);
|
|
126
|
-
expect(spy2).toHaveBeenCalledTimes(0);
|
|
127
|
-
|
|
128
|
-
await map.dispatchEvent({ type: 'pointermove', map, coordinate: [0, 0] });
|
|
129
|
-
await map.dispatchEvent({ type: 'singleclick', map, coordinate: [0, 0] });
|
|
130
|
-
expect(spy).toHaveBeenCalledTimes(0);
|
|
131
|
-
expect(spy2).toHaveBeenCalledTimes(0);
|
|
132
|
-
spy.mockReset();
|
|
133
|
-
spy2.mockReset();
|
|
134
|
-
|
|
135
|
-
layer.setVisible(true);
|
|
136
|
-
await map.dispatchEvent({ type: 'pointermove', map, coordinate: [0, 0] });
|
|
137
|
-
await map.dispatchEvent({ type: 'singleclick', map, coordinate: [0, 0] });
|
|
138
|
-
expect(spy).toHaveBeenCalledTimes(1);
|
|
139
|
-
expect(spy2).toHaveBeenCalledTimes(1);
|
|
140
|
-
global.console.error.mockRestore();
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
test('should not listen for click/hover events after layer.terminate()', async () => {
|
|
144
|
-
global.console.error = jest.fn();
|
|
145
|
-
const layer = new Layer({ name: 'Layer', olLayer, visible: true });
|
|
146
|
-
expect(layer.visible).toBe(true);
|
|
147
|
-
const spy = jest.fn();
|
|
148
|
-
const spy2 = jest.fn();
|
|
149
|
-
layer.init(map);
|
|
150
|
-
layer.onHover(spy);
|
|
151
|
-
layer.onClick(spy2);
|
|
152
|
-
expect(spy).toHaveBeenCalledTimes(0);
|
|
153
|
-
expect(spy2).toHaveBeenCalledTimes(0);
|
|
154
|
-
|
|
155
|
-
await map.dispatchEvent({
|
|
156
|
-
type: 'pointermove',
|
|
157
|
-
map,
|
|
158
|
-
coordinate: [0, 0],
|
|
159
|
-
});
|
|
160
|
-
await map.dispatchEvent({
|
|
161
|
-
type: 'singleclick',
|
|
162
|
-
map,
|
|
163
|
-
coordinate: [0, 0],
|
|
164
|
-
});
|
|
165
|
-
expect(spy).toHaveBeenCalledTimes(1);
|
|
166
|
-
expect(spy2).toHaveBeenCalledTimes(1);
|
|
167
|
-
spy.mockReset();
|
|
168
|
-
spy2.mockReset();
|
|
169
|
-
|
|
170
|
-
layer.terminate(map);
|
|
171
|
-
await map.dispatchEvent({
|
|
172
|
-
type: 'pointermove',
|
|
173
|
-
map,
|
|
174
|
-
coordinate: [0, 0],
|
|
175
|
-
});
|
|
176
|
-
await map.dispatchEvent({
|
|
177
|
-
type: 'singleclick',
|
|
178
|
-
map,
|
|
179
|
-
coordinate: [0, 0],
|
|
180
|
-
});
|
|
181
|
-
expect(spy).toHaveBeenCalledTimes(0);
|
|
182
|
-
expect(spy2).toHaveBeenCalledTimes(0);
|
|
183
|
-
global.console.error.mockRestore();
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
test('should clone', () => {
|
|
187
|
-
const layer = new Layer({
|
|
188
|
-
name: 'Layer',
|
|
189
|
-
copyrights: ['bar'],
|
|
190
|
-
olLayer: new Group({ layers: [olLayer] }),
|
|
191
|
-
});
|
|
192
|
-
const clone = layer.clone({ name: 'clone' });
|
|
193
|
-
expect(clone).not.toBe(layer);
|
|
194
|
-
expect(clone.name).toBe('clone');
|
|
195
|
-
expect(clone).toBeInstanceOf(Layer);
|
|
196
|
-
});
|
|
197
|
-
});
|
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
import OlMap from 'ol/Map';
|
|
2
|
-
import View from 'ol/View';
|
|
3
|
-
import gllib from 'mapbox-gl';
|
|
4
|
-
import MapboxLayer from './MapboxLayer';
|
|
5
|
-
|
|
6
|
-
let layer;
|
|
7
|
-
let map;
|
|
8
|
-
let consoleOutput;
|
|
9
|
-
const styleUrl = 'foo.com/styles';
|
|
10
|
-
|
|
11
|
-
describe('MapboxLayer', () => {
|
|
12
|
-
describe('without apiKey', () => {
|
|
13
|
-
beforeEach(() => {
|
|
14
|
-
// Mock console statement
|
|
15
|
-
consoleOutput = [];
|
|
16
|
-
// eslint-disable-next-line no-console
|
|
17
|
-
console.warn = (message) => consoleOutput.push(message);
|
|
18
|
-
layer = new MapboxLayer({
|
|
19
|
-
name: 'Layer',
|
|
20
|
-
url: styleUrl,
|
|
21
|
-
});
|
|
22
|
-
map = new OlMap({
|
|
23
|
-
target: document.createElement('div'),
|
|
24
|
-
view: new View({ center: [0, 0] }),
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
test('should be instanced.', () => {
|
|
29
|
-
expect(layer).toBeInstanceOf(MapboxLayer);
|
|
30
|
-
expect(layer.styleUrl).toBe(styleUrl);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
test('should not initalized mapbox map.', () => {
|
|
34
|
-
layer.init();
|
|
35
|
-
expect(layer.mbMap).toBe();
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
test('should initalized mapbox map and warn the user if there is no api key defined.', () => {
|
|
39
|
-
layer.init(map);
|
|
40
|
-
expect(layer.mbMap).toBeInstanceOf(gllib.Map);
|
|
41
|
-
expect(consoleOutput[0]).toBe(
|
|
42
|
-
'No apiKey is defined for request to foo.com/styles',
|
|
43
|
-
);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
test('should called terminate on initalization.', () => {
|
|
47
|
-
const spy = jest.spyOn(layer, 'terminate');
|
|
48
|
-
layer.init();
|
|
49
|
-
expect(spy).toHaveBeenCalledTimes(1);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
test('should clone', () => {
|
|
53
|
-
const clone = layer.clone({ name: 'clone' });
|
|
54
|
-
expect(clone).not.toBe(layer);
|
|
55
|
-
expect(clone.name).toBe('clone');
|
|
56
|
-
expect(clone).toBeInstanceOf(MapboxLayer);
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
describe('with apiKey', () => {
|
|
61
|
-
beforeEach(() => {
|
|
62
|
-
layer = new MapboxLayer({
|
|
63
|
-
name: 'Layer',
|
|
64
|
-
url: styleUrl,
|
|
65
|
-
apiKey: 'apiKey',
|
|
66
|
-
});
|
|
67
|
-
map = new OlMap({
|
|
68
|
-
target: document.createElement('div'),
|
|
69
|
-
view: new View({ center: [0, 0] }),
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
test('should be instanced with apiKey.', () => {
|
|
74
|
-
expect(layer).toBeInstanceOf(MapboxLayer);
|
|
75
|
-
expect(layer.styleUrl).toBe(styleUrl);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
test('should not initalized mapbox map.', () => {
|
|
79
|
-
layer.init();
|
|
80
|
-
expect(layer.mbMap).toBe();
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
test("should initalized mapbox map, with 'apiKey' prop", () => {
|
|
84
|
-
const layer1 = new MapboxLayer({
|
|
85
|
-
name: 'Layer',
|
|
86
|
-
url: styleUrl,
|
|
87
|
-
apiKey: 'apiKeyVal',
|
|
88
|
-
});
|
|
89
|
-
layer1.init(map);
|
|
90
|
-
expect(layer1.mbMap.options.style).toBe('foo.com/styles?key=apiKeyVal');
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
test("should initalized mapbox map, with 'apiKeyName' prop", () => {
|
|
94
|
-
const layer1 = new MapboxLayer({
|
|
95
|
-
name: 'Layer',
|
|
96
|
-
url: styleUrl,
|
|
97
|
-
apiKey: 'test',
|
|
98
|
-
apiKeyName: 'apiKey',
|
|
99
|
-
});
|
|
100
|
-
layer1.init(map);
|
|
101
|
-
expect(layer1.mbMap.options.style).toBe('foo.com/styles?apiKey=test');
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
describe('#getFeatureInfoAtCoordinate()', () => {
|
|
106
|
-
let layer1;
|
|
107
|
-
beforeEach(() => {
|
|
108
|
-
layer1 = new MapboxLayer({
|
|
109
|
-
name: 'Layer',
|
|
110
|
-
url: styleUrl,
|
|
111
|
-
apiKey: 'test',
|
|
112
|
-
apiKeyName: 'apiKey',
|
|
113
|
-
});
|
|
114
|
-
layer1.init(map);
|
|
115
|
-
layer1.mbMap.isStyleLoaded = jest.fn(() => true);
|
|
116
|
-
layer1.mbMap.getSource = jest.fn(() => true);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
afterEach(() => {
|
|
120
|
-
layer1.mbMap.getSource.mockRestore();
|
|
121
|
-
layer1.mbMap.isStyleLoaded.mockRestore();
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
test('should set the mapboxFeature as a property', (done) => {
|
|
125
|
-
const mapboxFeature = {
|
|
126
|
-
id: '2',
|
|
127
|
-
type: 'Feature',
|
|
128
|
-
properties: {
|
|
129
|
-
foo: 'bar',
|
|
130
|
-
},
|
|
131
|
-
source: 'barr',
|
|
132
|
-
sourceLayer: 'fooo',
|
|
133
|
-
};
|
|
134
|
-
layer1.mbMap.project = jest.fn((coord) => ({ x: coord[0], y: coord[1] }));
|
|
135
|
-
layer1.mbMap.queryRenderedFeatures = jest.fn(() => [mapboxFeature]);
|
|
136
|
-
layer1.getFeatureInfoAtCoordinate([0, 0], {}).then((featureInfo) => {
|
|
137
|
-
expect(featureInfo.features[0].get('mapboxFeature')).toBe(
|
|
138
|
-
mapboxFeature,
|
|
139
|
-
);
|
|
140
|
-
done();
|
|
141
|
-
});
|
|
142
|
-
layer1.mbMap.project.mockRestore();
|
|
143
|
-
layer1.mbMap.queryRenderedFeatures.mockRestore();
|
|
144
|
-
});
|
|
145
|
-
describe('should use hitTolerance property', () => {
|
|
146
|
-
beforeEach(() => {
|
|
147
|
-
layer1.mbMap.project = jest.fn((coord) => ({
|
|
148
|
-
x: coord[0],
|
|
149
|
-
y: coord[1],
|
|
150
|
-
}));
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
afterEach(() => {
|
|
154
|
-
layer1.mbMap.project.mockRestore();
|
|
155
|
-
layer1.mbMap.queryRenderedFeatures.mockRestore();
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
test('when hitTolerance is not set', (done) => {
|
|
159
|
-
layer1.mbMap.queryRenderedFeatures = jest.fn((pixelBounds) => {
|
|
160
|
-
// Use default hoitTolerance
|
|
161
|
-
expect(pixelBounds).toEqual([
|
|
162
|
-
{ x: -5, y: -5 },
|
|
163
|
-
{ x: 5, y: 5 },
|
|
164
|
-
]);
|
|
165
|
-
done();
|
|
166
|
-
return [];
|
|
167
|
-
});
|
|
168
|
-
layer1.getFeatureInfoAtCoordinate([0, 0], {});
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
test('when hitTolerance is set to 10', (done) => {
|
|
172
|
-
layer1.hitTolerance = 10;
|
|
173
|
-
layer1.mbMap.queryRenderedFeatures = jest.fn((pixelBounds) => {
|
|
174
|
-
// Use default hoitTolerance
|
|
175
|
-
expect(pixelBounds).toEqual([
|
|
176
|
-
{ x: -10, y: -10 },
|
|
177
|
-
{ x: 10, y: 10 },
|
|
178
|
-
]);
|
|
179
|
-
done();
|
|
180
|
-
return [];
|
|
181
|
-
});
|
|
182
|
-
layer1.getFeatureInfoAtCoordinate([0, 0], {});
|
|
183
|
-
});
|
|
184
|
-
});
|
|
185
|
-
});
|
|
186
|
-
});
|