mobility-toolbox-js 2.0.0 → 2.0.1-beta.13
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/RoutingAPI.js +15 -0
- package/api/RoutingAPI.test.js +25 -0
- package/api/StopsAPI.js +12 -0
- package/api/StopsAPI.test.js +22 -0
- package/api/TralisAPI.js +359 -0
- package/api/TralisAPI.test.js +67 -0
- package/api/{tralis/TralisAPIUtils.js → TralisAPIUtils.js} +2 -32
- package/api/index.js +3 -3
- package/{ol/README.md → api/typedefs.js} +0 -0
- package/common/Tracker.js +14 -118
- package/common/api/HttpAPI.js +30 -0
- package/common/api/HttpAPI.test.js +50 -0
- package/common/api/WebSocketAPI.js +175 -0
- package/{api/tralis/WebSocketConnector.test.js → common/api/WebSocketAPI.test.js} +100 -145
- package/common/controls/Control.js +26 -91
- package/common/controls/Control.test.js +32 -43
- package/common/index.js +4 -0
- package/common/layers/Layer.js +53 -244
- package/common/layers/Layer.test.js +185 -244
- package/common/mixins/CopyrightMixin.js +20 -44
- package/common/mixins/SearchMixin.js +100 -166
- package/common/mixins/TralisLayerMixin.js +443 -894
- package/common/styles/index.js +4 -4
- package/common/styles/trackerDefaultStyle.js +39 -175
- package/common/styles/trackerDelayStyle.js +2 -11
- package/common/styles/trackerSimpleStyle.js +4 -8
- package/common/trackerConfig.js +61 -99
- package/common/trackerConfig.test.js +15 -17
- package/common/typedefs.js +0 -23
- package/common/utils/createTrackerFilters.js +10 -41
- package/common/utils/createTrackerFilters.test.js +40 -56
- package/common/utils/getMapboxMapCopyrights.js +3 -16
- package/common/utils/getMapboxMapCopyrights.test.js +32 -39
- package/common/utils/getMapboxStyleUrl.js +3 -13
- package/common/utils/getVehiclePosition.js +3 -33
- package/common/utils/index.js +5 -6
- package/common/utils/removeDuplicate.js +3 -17
- package/common/utils/removeDuplicate.test.js +17 -20
- package/common/utils/sortByDelay.js +2 -7
- package/common/utils/timeUtils.js +8 -32
- package/common/utils/timeUtils.test.js +7 -13
- package/index.js +8 -2
- package/mapbox/controls/CopyrightControl.js +9 -38
- package/mapbox/controls/index.js +1 -0
- package/mapbox/index.js +4 -3
- package/mapbox/layers/Layer.js +15 -76
- package/mapbox/layers/Layer.test.js +81 -101
- package/mapbox/layers/TralisLayer.js +46 -193
- package/mapbox/layers/TralisLayer.test.js +12 -14
- package/mapbox/layers/index.js +2 -0
- package/mapbox/utils.js +7 -21
- package/mbt.js +50444 -0
- package/mbt.js.map +7 -0
- package/mbt.min.js +1005 -0
- package/mbt.min.js.map +7 -0
- package/ol/controls/CopyrightControl.js +8 -46
- package/ol/controls/CopyrightControl.test.js +75 -121
- package/ol/controls/RoutingControl.js +167 -532
- package/ol/controls/RoutingControl.test.js +99 -164
- package/ol/controls/StopFinderControl.js +3 -31
- package/ol/controls/StopFinderControl.test.js +18 -29
- package/ol/controls/index.js +3 -0
- package/ol/index.js +5 -13
- package/ol/layers/Layer.js +23 -128
- package/ol/layers/Layer.test.js +79 -102
- package/ol/layers/MapboxLayer.js +62 -237
- package/ol/layers/MapboxLayer.test.js +58 -84
- package/ol/layers/MapboxStyleLayer.js +38 -268
- package/ol/layers/MapboxStyleLayer.test.js +97 -128
- package/ol/layers/MaplibreLayer.js +46 -187
- package/ol/layers/RoutingLayer.js +21 -51
- package/ol/layers/RoutingLayer.test.js +15 -24
- package/ol/layers/TralisLayer.js +102 -276
- package/ol/layers/TralisLayer.test.js +32 -50
- package/ol/layers/VectorLayer.js +3 -24
- package/ol/layers/VectorLayer.test.js +34 -45
- package/ol/layers/WMSLayer.js +15 -57
- package/ol/layers/WMSLayer.test.js +35 -43
- package/ol/layers/index.js +8 -0
- package/ol/styles/fullTrajectoryDelayStyle.js +11 -15
- package/ol/styles/fullTrajectoryStyle.js +17 -25
- package/ol/styles/index.js +2 -2
- package/package.json +35 -62
- 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/WebSocketConnector.js +0 -338
- package/api/tralis/typedefs.js +0 -81
- package/common/api/api.js +0 -64
- package/common/api/api.test.js +0 -68
- package/index.js.map +0 -1
- package/module.js +0 -23
- 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
|
@@ -1,80 +1,42 @@
|
|
|
1
|
-
import { inView } from
|
|
2
|
-
import Control from
|
|
3
|
-
import mixin from
|
|
4
|
-
import removeDuplicate from
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Display layer's copyrights.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* import { Map } from 'ol';
|
|
11
|
-
* import { CopyrightControl } from 'mobility-toolbox-js/ol';
|
|
12
|
-
*
|
|
13
|
-
* const map = new Map({
|
|
14
|
-
* target: 'map',
|
|
15
|
-
* });
|
|
16
|
-
* const control = new CopyrightControl();
|
|
17
|
-
* control.map = map
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* @see <a href="/example/ol-copyright">Openlayers copyright example</a>
|
|
21
|
-
*
|
|
22
|
-
* @extends {Control}
|
|
23
|
-
* @implements {CopyrightInterface}
|
|
24
|
-
*/
|
|
1
|
+
import { inView } from "ol/layer/Layer";
|
|
2
|
+
import Control from "../../common/controls/Control";
|
|
3
|
+
import mixin from "../../common/mixins/CopyrightMixin";
|
|
4
|
+
import removeDuplicate from "../../common/utils/removeDuplicate";
|
|
25
5
|
class CopyrightControl extends mixin(Control) {
|
|
26
6
|
constructor(options) {
|
|
27
7
|
super(options);
|
|
28
8
|
this.onPostRender = this.onPostRender.bind(this);
|
|
29
9
|
}
|
|
30
|
-
|
|
31
10
|
getCopyrights() {
|
|
32
11
|
if (!this.frameState) {
|
|
33
12
|
return [];
|
|
34
13
|
}
|
|
35
14
|
let copyrights = [];
|
|
36
|
-
|
|
37
|
-
// This code loop comes mainly from ol.
|
|
38
15
|
this.frameState.layerStatesArray.forEach((layerState) => {
|
|
39
16
|
const { layer } = layerState;
|
|
40
|
-
if (
|
|
41
|
-
|
|
42
|
-
layer &&
|
|
43
|
-
layer.getSource &&
|
|
44
|
-
layer.getSource() &&
|
|
45
|
-
layer.getSource().getAttributions()
|
|
46
|
-
) {
|
|
47
|
-
copyrights = copyrights.concat(
|
|
48
|
-
layer.getSource().getAttributions()(this.frameState),
|
|
49
|
-
);
|
|
17
|
+
if (inView(layerState, this.frameState.viewState) && layer && layer.getSource && layer.getSource() && layer.getSource().getAttributions()) {
|
|
18
|
+
copyrights = copyrights.concat(layer.getSource().getAttributions()(this.frameState));
|
|
50
19
|
}
|
|
51
20
|
});
|
|
52
21
|
return removeDuplicate(copyrights);
|
|
53
22
|
}
|
|
54
|
-
|
|
55
23
|
activate() {
|
|
56
24
|
super.activate();
|
|
57
25
|
if (this.map) {
|
|
58
|
-
this.map.on(
|
|
26
|
+
this.map.on("postrender", this.onPostRender);
|
|
59
27
|
}
|
|
60
28
|
}
|
|
61
|
-
|
|
62
29
|
deactivate() {
|
|
63
30
|
if (this.map) {
|
|
64
|
-
this.map.un(
|
|
31
|
+
this.map.un("postrender", this.onPostRender);
|
|
65
32
|
}
|
|
66
33
|
super.deactivate();
|
|
67
34
|
}
|
|
68
|
-
|
|
69
35
|
onPostRender(evt) {
|
|
70
36
|
if (this.map && this.element) {
|
|
71
|
-
/**
|
|
72
|
-
* @ignore
|
|
73
|
-
*/
|
|
74
37
|
this.frameState = evt.frameState;
|
|
75
38
|
this.render();
|
|
76
39
|
}
|
|
77
40
|
}
|
|
78
41
|
}
|
|
79
|
-
|
|
80
42
|
export default CopyrightControl;
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import View from
|
|
2
|
-
import Tile from
|
|
3
|
-
import TileLayer from
|
|
4
|
-
import TileSource from
|
|
5
|
-
import { createXYZ } from
|
|
6
|
-
import { Map } from
|
|
7
|
-
import Layer from
|
|
8
|
-
import CopyrightControl from
|
|
9
|
-
|
|
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";
|
|
10
9
|
const tileLoadFunction = () => {
|
|
11
|
-
const tile = new Tile([0, 0, -1], 2
|
|
10
|
+
const tile = new Tile([0, 0, -1], 2);
|
|
12
11
|
tile.getImage = () => {
|
|
13
12
|
const image = new Image();
|
|
14
13
|
image.width = 256;
|
|
@@ -17,195 +16,150 @@ const tileLoadFunction = () => {
|
|
|
17
16
|
};
|
|
18
17
|
return tile;
|
|
19
18
|
};
|
|
20
|
-
|
|
21
19
|
const getOLTileLayer = () => {
|
|
22
20
|
const layer = new TileLayer({
|
|
23
21
|
source: new TileSource({
|
|
24
|
-
projection:
|
|
25
|
-
tileGrid: createXYZ()
|
|
26
|
-
})
|
|
22
|
+
projection: "EPSG:3857",
|
|
23
|
+
tileGrid: createXYZ()
|
|
24
|
+
})
|
|
27
25
|
});
|
|
28
26
|
layer.getSource().getTile = tileLoadFunction;
|
|
29
27
|
return layer;
|
|
30
28
|
};
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
describe('CopyrightControl', () => {
|
|
29
|
+
const getLayer = (copyrights, visible = true) => new Layer({
|
|
30
|
+
visible,
|
|
31
|
+
copyrights,
|
|
32
|
+
olLayer: getOLTileLayer()
|
|
33
|
+
});
|
|
34
|
+
describe("CopyrightControl", () => {
|
|
40
35
|
let map;
|
|
41
|
-
|
|
42
36
|
beforeEach(() => {
|
|
43
|
-
const target = document.createElement(
|
|
37
|
+
const target = document.createElement("div");
|
|
44
38
|
document.body.appendChild(target);
|
|
45
39
|
map = new Map({
|
|
46
40
|
target,
|
|
47
41
|
view: new View({
|
|
48
42
|
center: [0, 0],
|
|
49
|
-
zoom: 0
|
|
50
|
-
})
|
|
43
|
+
zoom: 0
|
|
44
|
+
})
|
|
51
45
|
});
|
|
52
|
-
getLayer(true,
|
|
46
|
+
getLayer(true, "bar").attachToMap(map);
|
|
53
47
|
map.setSize([200, 200]);
|
|
54
48
|
map.renderSync();
|
|
55
49
|
});
|
|
56
|
-
|
|
57
50
|
afterEach(() => {
|
|
58
51
|
if (map) {
|
|
59
52
|
map.setTarget(null);
|
|
60
53
|
map = null;
|
|
61
54
|
}
|
|
62
55
|
});
|
|
63
|
-
|
|
64
|
-
test('should be activate by default', () => {
|
|
56
|
+
test("should be activate by default", () => {
|
|
65
57
|
const control = new CopyrightControl();
|
|
66
58
|
expect(control.active).toBe(true);
|
|
67
59
|
});
|
|
68
|
-
|
|
69
|
-
test('renders a string copyright', () => {
|
|
60
|
+
test("renders a string copyright", () => {
|
|
70
61
|
const control = new CopyrightControl();
|
|
71
|
-
control.map
|
|
72
|
-
expect(control.element.innerHTML).toBe(
|
|
73
|
-
getLayer(
|
|
62
|
+
control.attachToMap(map);
|
|
63
|
+
expect(control.element.innerHTML).toBe("");
|
|
64
|
+
getLayer("copyright").attachToMap(map);
|
|
74
65
|
map.renderSync();
|
|
75
|
-
expect(control.element.innerHTML).toBe(
|
|
66
|
+
expect(control.element.innerHTML).toBe("copyright");
|
|
76
67
|
});
|
|
77
|
-
|
|
78
|
-
test('renders an array of copyrights', () => {
|
|
68
|
+
test("renders an array of copyrights", () => {
|
|
79
69
|
const control = new CopyrightControl();
|
|
80
|
-
control.map
|
|
81
|
-
expect(control.element.innerHTML).toBe(
|
|
82
|
-
getLayer([
|
|
70
|
+
control.attachToMap(map);
|
|
71
|
+
expect(control.element.innerHTML).toBe("");
|
|
72
|
+
getLayer(["copyright 1", "copyright 2"]).attachToMap(map);
|
|
83
73
|
map.renderSync();
|
|
84
|
-
expect(control.element.innerHTML).toBe(
|
|
74
|
+
expect(control.element.innerHTML).toBe("copyright 1 | copyright 2");
|
|
85
75
|
});
|
|
86
|
-
|
|
87
|
-
test('renders unique copyrights', () => {
|
|
76
|
+
test("renders unique copyrights", () => {
|
|
88
77
|
const control = new CopyrightControl();
|
|
89
|
-
control.map
|
|
90
|
-
expect(control.element.innerHTML).toBe(
|
|
91
|
-
getLayer([
|
|
92
|
-
getLayer(
|
|
93
|
-
getLayer([
|
|
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);
|
|
94
83
|
map.renderSync();
|
|
95
|
-
expect(control.element.innerHTML).toBe(
|
|
84
|
+
expect(control.element.innerHTML).toBe("copyright 1 | copyright 2");
|
|
96
85
|
});
|
|
97
|
-
|
|
98
86
|
test("doesn't render copyright of an hidden layer", () => {
|
|
99
87
|
const control = new CopyrightControl();
|
|
100
|
-
control.map
|
|
101
|
-
expect(control.element.innerHTML).toBe(
|
|
102
|
-
const layer1 = getLayer(
|
|
103
|
-
layer1.
|
|
104
|
-
const layer2 = getLayer(
|
|
105
|
-
layer2.
|
|
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);
|
|
106
94
|
map.renderSync();
|
|
107
|
-
expect(control.element.innerHTML).toBe(
|
|
108
|
-
|
|
109
|
-
// the we update visibility of both layers
|
|
95
|
+
expect(control.element.innerHTML).toBe("copyright");
|
|
110
96
|
layer1.setVisible(true);
|
|
111
97
|
map.renderSync();
|
|
112
98
|
layer2.setVisible(false);
|
|
113
99
|
map.renderSync();
|
|
114
|
-
expect(control.element.innerHTML).toBe(
|
|
100
|
+
expect(control.element.innerHTML).toBe("copyright hidden");
|
|
115
101
|
});
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
getLayer('copyright 1').init(map);
|
|
102
|
+
test("should activate the control on construction then deactivate it", () => {
|
|
103
|
+
getLayer("copyright 1").attachToMap(map);
|
|
119
104
|
const control = new CopyrightControl({ active: true });
|
|
120
|
-
control.map
|
|
105
|
+
control.attachToMap(map);
|
|
121
106
|
map.renderSync();
|
|
122
|
-
|
|
123
107
|
expect(control.element.parentNode).toBe(map.getTargetElement());
|
|
124
|
-
|
|
125
|
-
// Should be activated by default.
|
|
126
108
|
expect(control.active).toBe(true);
|
|
127
|
-
expect(control.element.innerHTML).toBe(
|
|
128
|
-
|
|
129
|
-
// on deactivation
|
|
109
|
+
expect(control.element.innerHTML).toBe("copyright 1");
|
|
130
110
|
control.active = false;
|
|
131
111
|
map.renderSync();
|
|
132
|
-
expect(control.element.innerHTML).toBe(
|
|
112
|
+
expect(control.element.innerHTML).toBe("");
|
|
133
113
|
});
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
getLayer('copyright 1').init(map);
|
|
114
|
+
test("should deactivate the control on constrcution then activate it", () => {
|
|
115
|
+
getLayer("copyright 1").attachToMap(map);
|
|
137
116
|
const control = new CopyrightControl({ active: false });
|
|
138
|
-
control.map
|
|
117
|
+
control.attachToMap(map);
|
|
139
118
|
map.renderSync();
|
|
140
|
-
|
|
141
119
|
expect(control.element.parentNode).toBe(map.getTargetElement());
|
|
142
|
-
|
|
143
|
-
// Should be activated by default.
|
|
144
120
|
expect(control.active).toBe(false);
|
|
145
121
|
map.renderSync();
|
|
146
|
-
expect(control.element.innerHTML).toBe(
|
|
147
|
-
|
|
148
|
-
// on deactivation
|
|
122
|
+
expect(control.element.innerHTML).toBe("");
|
|
149
123
|
control.active = true;
|
|
150
124
|
map.renderSync();
|
|
151
|
-
expect(control.element.innerHTML).toBe(
|
|
125
|
+
expect(control.element.innerHTML).toBe("copyright 1");
|
|
152
126
|
});
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
getLayer('copyright value').init(map);
|
|
127
|
+
test("should add copyrights in the map container element then remove it.", () => {
|
|
128
|
+
getLayer("copyright value").attachToMap(map);
|
|
156
129
|
map.renderSync();
|
|
157
|
-
|
|
158
130
|
const control = new CopyrightControl();
|
|
159
|
-
|
|
160
|
-
// Add control
|
|
161
|
-
control.map = map;
|
|
131
|
+
control.attachToMap(map);
|
|
162
132
|
expect(control.element.parentNode).toBe(map.getTargetElement());
|
|
163
|
-
|
|
164
|
-
// Remove control
|
|
165
|
-
control.map = null;
|
|
133
|
+
control.detachFromMap();
|
|
166
134
|
expect(control.element.parentNode).toBe(null);
|
|
167
135
|
});
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
getLayer(['copyright value']).init(map);
|
|
136
|
+
test("should add copyrights in the target element then remove it.", () => {
|
|
137
|
+
getLayer(["copyright value"]).attachToMap(map);
|
|
171
138
|
map.renderSync();
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
target.setAttribute('id', 'copyright');
|
|
139
|
+
const target = document.createElement("div");
|
|
140
|
+
target.setAttribute("id", "copyright");
|
|
175
141
|
document.body.appendChild(target);
|
|
176
|
-
|
|
177
142
|
const control = new CopyrightControl({
|
|
178
|
-
target: document.getElementById(
|
|
143
|
+
target: document.getElementById("copyright")
|
|
179
144
|
});
|
|
180
|
-
|
|
181
|
-
// Add control
|
|
182
|
-
control.map = map;
|
|
145
|
+
control.attachToMap(map);
|
|
183
146
|
expect(control.element.parentNode).toBe(target);
|
|
184
|
-
|
|
185
|
-
// Remove control
|
|
186
|
-
control.map = null;
|
|
147
|
+
control.detachFromMap();
|
|
187
148
|
expect(control.element.parentNode).toBe(null);
|
|
188
149
|
});
|
|
189
|
-
|
|
190
|
-
test('renders custom copyrights with the render method ', () => {
|
|
150
|
+
test("renders custom copyrights with the render method ", () => {
|
|
191
151
|
const control = new CopyrightControl({
|
|
192
152
|
active: true,
|
|
193
153
|
render() {
|
|
194
154
|
if (!this.element) {
|
|
195
155
|
return;
|
|
196
156
|
}
|
|
197
|
-
this.element.innerHTML = this.active
|
|
198
|
-
|
|
199
|
-
: '';
|
|
200
|
-
},
|
|
157
|
+
this.element.innerHTML = this.active ? this.getCopyrights().join(", ") : "";
|
|
158
|
+
}
|
|
201
159
|
});
|
|
202
|
-
control.map
|
|
203
|
-
getLayer([
|
|
160
|
+
control.attachToMap(map);
|
|
161
|
+
getLayer(["copyright 1", "copyright 2", "copyright 3"]).attachToMap(map);
|
|
204
162
|
map.renderSync();
|
|
205
|
-
|
|
206
|
-
// Add control
|
|
207
|
-
expect(control.element.innerHTML).toBe(
|
|
208
|
-
'copyright 1, copyright 2, copyright 3',
|
|
209
|
-
);
|
|
163
|
+
expect(control.element.innerHTML).toBe("copyright 1, copyright 2, copyright 3");
|
|
210
164
|
});
|
|
211
165
|
});
|