mobility-toolbox-js 2.0.0-beta.8 → 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/{src/api/tralis → api}/TralisAPIUtils.js +2 -32
- package/api/index.js +3 -0
- package/{index.html → api/typedefs.js} +0 -0
- package/common/Tracker.js +93 -0
- package/common/api/HttpAPI.js +30 -0
- package/common/api/HttpAPI.test.js +50 -0
- package/common/api/WebSocketAPI.js +175 -0
- package/{src/api/tralis/WebSocketConnector.test.js → common/api/WebSocketAPI.test.js} +100 -145
- package/common/controls/Control.js +81 -0
- package/{src/common → common}/controls/Control.test.js +32 -43
- package/common/index.js +4 -0
- package/common/layers/Layer.js +213 -0
- package/{src/common → common}/layers/Layer.test.js +185 -244
- package/common/mixins/CopyrightMixin.js +24 -0
- package/common/mixins/SearchMixin.js +110 -0
- package/common/mixins/TralisLayerMixin.js +479 -0
- package/common/styles/index.js +4 -0
- package/{src/common → common}/styles/trackerDefaultStyle.js +39 -175
- package/common/styles/trackerDelayStyle.js +8 -0
- package/{src/common → common}/styles/trackerSimpleStyle.js +4 -8
- package/{src/common → common}/trackerConfig.js +61 -99
- package/common/trackerConfig.test.js +23 -0
- package/{src/doc/examples/ol-mapbox-layer.md → common/typedefs.js} +0 -0
- package/common/utils/createTrackerFilters.js +56 -0
- package/common/utils/createTrackerFilters.test.js +79 -0
- package/{src/common → common}/utils/getMapboxMapCopyrights.js +3 -16
- package/common/utils/getMapboxMapCopyrights.test.js +40 -0
- package/{src/common → common}/utils/getMapboxStyleUrl.js +3 -13
- package/{src/common → common}/utils/getVehiclePosition.js +3 -33
- package/common/utils/index.js +5 -0
- package/common/utils/removeDuplicate.js +8 -0
- package/common/utils/removeDuplicate.test.js +19 -0
- package/{src/common → common}/utils/sortByDelay.js +2 -7
- package/common/utils/timeUtils.js +20 -0
- package/common/utils/timeUtils.test.js +10 -0
- package/index.js +8 -0
- package/mapbox/controls/CopyrightControl.js +29 -0
- package/mapbox/controls/index.js +1 -0
- package/mapbox/index.js +4 -0
- package/mapbox/layers/Layer.js +57 -0
- package/mapbox/layers/Layer.test.js +182 -0
- package/mapbox/layers/TralisLayer.js +182 -0
- package/{src/mapbox → mapbox}/layers/TralisLayer.test.js +12 -14
- package/mapbox/layers/index.js +2 -0
- package/{src/mapbox → 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 +42 -0
- package/ol/controls/CopyrightControl.test.js +165 -0
- package/ol/controls/RoutingControl.js +387 -0
- package/ol/controls/RoutingControl.test.js +151 -0
- package/ol/controls/StopFinderControl.js +10 -0
- package/ol/controls/StopFinderControl.test.js +48 -0
- package/ol/controls/index.js +3 -0
- package/ol/index.js +5 -0
- package/ol/layers/Layer.js +88 -0
- package/ol/layers/Layer.test.js +174 -0
- package/ol/layers/MapboxLayer.js +203 -0
- package/{src/ol → ol}/layers/MapboxLayer.test.js +58 -84
- package/ol/layers/MapboxStyleLayer.js +187 -0
- package/{src/ol → ol}/layers/MapboxStyleLayer.test.js +97 -128
- package/ol/layers/MaplibreLayer.js +139 -0
- package/ol/layers/RoutingLayer.js +61 -0
- package/{src/ol → ol}/layers/RoutingLayer.test.js +15 -24
- package/ol/layers/TralisLayer.js +185 -0
- package/ol/layers/TralisLayer.test.js +79 -0
- package/ol/layers/VectorLayer.js +22 -0
- package/{src/ol → ol}/layers/VectorLayer.test.js +34 -45
- package/ol/layers/WMSLayer.js +38 -0
- package/ol/layers/WMSLayer.test.js +76 -0
- package/ol/layers/index.js +8 -0
- package/{src/ol → ol}/styles/fullTrajectoryDelayStyle.js +11 -15
- package/ol/styles/fullTrajectoryStyle.js +43 -0
- package/ol/styles/index.js +2 -0
- package/package.json +34 -74
- package/.babelrc +0 -6
- package/.esdoc.json +0 -17
- package/.eslintignore +0 -1
- package/.github/workflows/conventional-pr-title.yml +0 -21
- package/.github/workflows/cypress.yml +0 -29
- package/.github/workflows/nodejs.yml +0 -28
- package/.husky/commit-msg +0 -4
- package/.husky/post-checkout +0 -4
- package/.husky/post-merge +0 -4
- package/.husky/post-rebase +0 -4
- package/.husky/pre-commit +0 -4
- package/.neutrinorc.js +0 -176
- package/.nvmrc +0 -1
- package/CHANGELOG.md +0 -10
- package/LICENSE +0 -21
- package/__mocks__/mapbox-gl.js +0 -81
- package/__mocks__/maplibre-gl.js +0 -81
- package/commitlint.config.js +0 -1
- package/cypress/fixtures/example.json +0 -5
- package/cypress/integration/examples/api.spec.js +0 -7
- package/cypress/integration/examples/examples.spec.js +0 -7
- package/cypress/integration/examples/navigation.spec.js +0 -29
- package/cypress/plugins/index.js +0 -21
- package/cypress/support/commands.js +0 -25
- package/cypress/support/index.js +0 -20
- package/cypress.json +0 -4
- package/data/fetchRoute.json +0 -292
- package/data/fetchTrajectories.json +0 -18
- package/data/fetchTrajectoryById.json +0 -3
- package/data/fetchTrajectoryStations.json +0 -18
- package/data/stopsSearch.json +0 -15
- package/documentation.yml +0 -4
- package/esdoc/README.md +0 -27
- package/esdoc/plugins/MyPlugin.js +0 -69
- package/esdoc/plugins/dynamic-property-plugin/Plugin.js +0 -50
- package/esdoc/plugins/externals-plugin/Plugin.js +0 -45
- package/esdoc/plugins/externals-plugin/externals.js +0 -96
- package/global-setup.js +0 -3
- package/indexweb.html +0 -49
- package/jest.config.js +0 -5
- package/pull_request_template.md +0 -17
- package/renovate.json +0 -4
- package/scripts/read-pkg-json.js +0 -22
- package/src/api/index.js +0 -3
- package/src/api/routing/RoutingAPI.js +0 -44
- package/src/api/routing/RoutingAPI.test.js +0 -41
- package/src/api/stops/StopsAPI.js +0 -41
- package/src/api/stops/StopsAPI.test.js +0 -34
- package/src/api/tralis/TralisAPI.js +0 -731
- package/src/api/tralis/TralisAPI.test.js +0 -75
- package/src/api/tralis/WebSocketConnector.js +0 -338
- package/src/api/tralis/typedefs.js +0 -81
- package/src/assets/Lato-Black.ttf +0 -0
- package/src/assets/Lato-BlackItalic.ttf +0 -0
- package/src/assets/Lato-Bold.ttf +0 -0
- package/src/assets/Lato-BoldItalic.ttf +0 -0
- package/src/assets/Lato-Italic.ttf +0 -0
- package/src/assets/Lato-Light.ttf +0 -0
- package/src/assets/Lato-LightItalic.ttf +0 -0
- package/src/assets/Lato-Regular.ttf +0 -0
- package/src/assets/Lato-Thin.ttf +0 -0
- package/src/assets/Lato-ThinItalic.ttf +0 -0
- package/src/assets/OFL.txt +0 -93
- package/src/common/Tracker.js +0 -197
- package/src/common/api/api.js +0 -64
- package/src/common/api/api.test.js +0 -68
- package/src/common/controls/Control.js +0 -146
- package/src/common/index.js +0 -5
- package/src/common/layers/Layer.js +0 -404
- package/src/common/mixins/CopyrightMixin.js +0 -48
- package/src/common/mixins/SearchMixin.js +0 -176
- package/src/common/mixins/TralisLayerMixin.js +0 -930
- package/src/common/styles/index.js +0 -4
- package/src/common/styles/trackerDelayStyle.js +0 -17
- package/src/common/trackerConfig.test.js +0 -25
- package/src/common/typedefs.js +0 -23
- package/src/common/utils/createTrackerFilters.js +0 -87
- package/src/common/utils/createTrackerFilters.test.js +0 -95
- package/src/common/utils/getMapboxMapCopyrights.test.js +0 -47
- package/src/common/utils/index.js +0 -5
- package/src/common/utils/removeDuplicate.js +0 -22
- package/src/common/utils/removeDuplicate.test.js +0 -22
- package/src/common/utils/timeUtils.js +0 -44
- package/src/common/utils/timeUtils.test.js +0 -16
- package/src/doc/App.js +0 -116
- package/src/doc/App.scss +0 -51
- package/src/doc/_redirects +0 -2
- package/src/doc/components/CodeSandboxButton.js +0 -103
- package/src/doc/components/Documentation.js +0 -40
- package/src/doc/components/Esdoc/Anchor.js +0 -57
- package/src/doc/components/Esdoc/ClassDoc.js +0 -272
- package/src/doc/components/Esdoc/DeprecatedHTML.js +0 -16
- package/src/doc/components/Esdoc/DetailDocs.js +0 -281
- package/src/doc/components/Esdoc/DetailHTML.js +0 -33
- package/src/doc/components/Esdoc/DirectSubclassHTML.js +0 -30
- package/src/doc/components/Esdoc/DocBuilderUtils.js +0 -694
- package/src/doc/components/Esdoc/DocLinkHTML.js +0 -62
- package/src/doc/components/Esdoc/DocsLinkHTML.js +0 -38
- package/src/doc/components/Esdoc/Esdoc.js +0 -63
- package/src/doc/components/Esdoc/EsdocContent.js +0 -51
- package/src/doc/components/Esdoc/EsdocNavigation.js +0 -13
- package/src/doc/components/Esdoc/EsdocSearch.js +0 -81
- package/src/doc/components/Esdoc/ExperimentalHTML.js +0 -17
- package/src/doc/components/Esdoc/ExtendsChainHTML.js +0 -32
- package/src/doc/components/Esdoc/FileDocLinkHTML.js +0 -60
- package/src/doc/components/Esdoc/IdentifiersDoc.js +0 -113
- package/src/doc/components/Esdoc/IndirectSubclassHTML.js +0 -30
- package/src/doc/components/Esdoc/InheritedSummaryDoc.js +0 -70
- package/src/doc/components/Esdoc/InheritedSummaryHTML.js +0 -38
- package/src/doc/components/Esdoc/MixinClassesHTML.js +0 -29
- package/src/doc/components/Esdoc/NavDoc.js +0 -112
- package/src/doc/components/Esdoc/OverrideMethod.js +0 -44
- package/src/doc/components/Esdoc/OverrideMethodDescription.js +0 -35
- package/src/doc/components/Esdoc/Properties.js +0 -89
- package/src/doc/components/Esdoc/README.md +0 -45
- package/src/doc/components/Esdoc/SignatureHTML.js +0 -123
- package/src/doc/components/Esdoc/SingleDoc.js +0 -31
- package/src/doc/components/Esdoc/SummaryDoc.js +0 -160
- package/src/doc/components/Esdoc/SummaryHTML.js +0 -96
- package/src/doc/components/Esdoc/TypeDocLinkHTML.js +0 -249
- package/src/doc/components/Esdoc/css/identifiers.css +0 -38
- package/src/doc/components/Esdoc/css/search.css +0 -76
- package/src/doc/components/Esdoc/css/style.css +0 -603
- package/src/doc/components/Esdoc/index.js +0 -7
- package/src/doc/components/Example.js +0 -153
- package/src/doc/components/Examples.js +0 -183
- package/src/doc/components/Home.js +0 -106
- package/src/doc/components/TrackerExample.js +0 -38
- package/src/doc/examples/assets/tralis-live-map/index.js +0 -11
- package/src/doc/examples/assets/tralis-live-map/s1kreis.svg +0 -105
- package/src/doc/examples/assets/tralis-live-map/s20kreis.svg +0 -101
- package/src/doc/examples/assets/tralis-live-map/s2kreis.svg +0 -95
- package/src/doc/examples/assets/tralis-live-map/s3kreis.svg +0 -95
- package/src/doc/examples/assets/tralis-live-map/s4kreis.svg +0 -95
- package/src/doc/examples/assets/tralis-live-map/s6kreis.svg +0 -95
- package/src/doc/examples/assets/tralis-live-map/s7kreis.svg +0 -95
- package/src/doc/examples/assets/tralis-live-map/s8kreis.svg +0 -93
- package/src/doc/examples/assets/tralis-live-map/unknown.svg +0 -107
- package/src/doc/examples/mb-copyright.html +0 -26
- package/src/doc/examples/mb-copyright.js +0 -37
- package/src/doc/examples/mb-tracker.html +0 -1
- package/src/doc/examples/mb-tracker.js +0 -39
- package/src/doc/examples/mb-tracker.md +0 -1
- package/src/doc/examples/mb-tralis.html +0 -1
- package/src/doc/examples/mb-tralis.js +0 -34
- package/src/doc/examples/ol-copyright.html +0 -26
- package/src/doc/examples/ol-copyright.js +0 -43
- package/src/doc/examples/ol-mapbox-layer.html +0 -1
- package/src/doc/examples/ol-mapbox-layer.js +0 -28
- package/src/doc/examples/ol-mapbox-style-layer.html +0 -12
- package/src/doc/examples/ol-mapbox-style-layer.js +0 -44
- package/src/doc/examples/ol-query.html +0 -32
- package/src/doc/examples/ol-query.js +0 -83
- package/src/doc/examples/ol-routing.html +0 -26
- package/src/doc/examples/ol-routing.js +0 -59
- package/src/doc/examples/ol-routing.md +0 -1
- package/src/doc/examples/ol-stop-finder.html +0 -15
- package/src/doc/examples/ol-stop-finder.js +0 -31
- package/src/doc/examples/ol-stop-finder.md +0 -1
- package/src/doc/examples/ol-tracker.html +0 -1
- package/src/doc/examples/ol-tracker.js +0 -44
- package/src/doc/examples/ol-tracker.md +0 -1
- package/src/doc/examples/ol-tralis.html +0 -5
- package/src/doc/examples/ol-tralis.js +0 -57
- package/src/doc/examples/tralis-live-map.html +0 -1
- package/src/doc/examples/tralis-live-map.js +0 -51
- package/src/doc/examples/tralis-live-map.md +0 -3
- package/src/doc/examples.js +0 -107
- package/src/doc/img/examples/live_tracker_mb.jpg +0 -0
- package/src/doc/img/examples/live_tracker_munich.jpg +0 -0
- package/src/doc/img/examples/live_tracker_ol.jpg +0 -0
- package/src/doc/img/examples/mapbox.jpg +0 -0
- package/src/doc/img/examples/mapbox_style.jpg +0 -0
- package/src/doc/img/examples/ol-copyright.png +0 -0
- package/src/doc/img/examples/query_objects.jpg +0 -0
- package/src/doc/img/examples/routing.jpg +0 -0
- package/src/doc/img/examples/simple_map.jpg +0 -0
- package/src/doc/img/examples/stops.jpg +0 -0
- package/src/doc/img/favico.ico +0 -0
- package/src/doc/index.js +0 -21
- package/src/iife.js +0 -7
- package/src/index.js +0 -10
- package/src/mapbox/controls/CopyrightControl.js +0 -58
- package/src/mapbox/controls/index.js +0 -2
- package/src/mapbox/index.js +0 -4
- package/src/mapbox/layers/Layer.js +0 -118
- package/src/mapbox/layers/Layer.test.js +0 -202
- package/src/mapbox/layers/TralisLayer.js +0 -329
- package/src/mapbox/layers/index.js +0 -2
- package/src/ol/README.md +0 -0
- package/src/ol/controls/CopyrightControl.js +0 -80
- package/src/ol/controls/CopyrightControl.test.js +0 -211
- package/src/ol/controls/RoutingControl.js +0 -752
- package/src/ol/controls/RoutingControl.test.js +0 -216
- package/src/ol/controls/StopFinderControl.js +0 -38
- package/src/ol/controls/StopFinderControl.test.js +0 -59
- package/src/ol/controls/index.js +0 -3
- package/src/ol/controls/snapshots/RoutingControlRouteGen10.json +0 -58
- package/src/ol/controls/snapshots/RoutingControlRouteGen100.json +0 -292
- package/src/ol/controls/snapshots/RoutingControlRouteGen30.json +0 -69
- package/src/ol/controls/snapshots/RoutingControlRouteGen5.json +0 -58
- package/src/ol/controls/snapshots/RoutingControlRouteOSM.json +0 -759
- package/src/ol/controls/snapshots/RoutingControlStation1.json +0 -60
- package/src/ol/controls/snapshots/RoutingControlStation2.json +0 -49
- package/src/ol/index.js +0 -5
- package/src/ol/layers/Layer.js +0 -193
- package/src/ol/layers/Layer.test.js +0 -197
- package/src/ol/layers/MapboxLayer.js +0 -378
- package/src/ol/layers/MapboxStyleLayer.js +0 -417
- package/src/ol/layers/MaplibreLayer.js +0 -280
- package/src/ol/layers/RoutingLayer.js +0 -91
- package/src/ol/layers/TralisLayer.js +0 -359
- package/src/ol/layers/TralisLayer.test.js +0 -97
- package/src/ol/layers/VectorLayer.js +0 -43
- package/src/ol/layers/WMSLayer.js +0 -80
- package/src/ol/layers/WMSLayer.test.js +0 -84
- package/src/ol/layers/index.js +0 -8
- package/src/ol/styles/fullTrajectoryStyle.js +0 -51
- package/src/ol/styles/index.js +0 -2
- package/src/setupTests.js +0 -15
- package/webpack.config.js +0 -6
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
const createFilters = (line, route, operator, regexLine) => {
|
|
2
|
+
const filterList = [];
|
|
3
|
+
if (!line && !route && !operator && !regexLine) {
|
|
4
|
+
return null;
|
|
5
|
+
}
|
|
6
|
+
if (regexLine) {
|
|
7
|
+
const regexLineList = typeof regexLine === "string" ? [regexLine] : regexLine;
|
|
8
|
+
const lineFilter = (item) => {
|
|
9
|
+
const name = item.properties.name || item.properties.line && item.properties.line.name || "";
|
|
10
|
+
if (!name) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
return regexLineList.some((regexStr) => new RegExp(regexStr, "i").test(name));
|
|
14
|
+
};
|
|
15
|
+
filterList.push(lineFilter);
|
|
16
|
+
}
|
|
17
|
+
if (line) {
|
|
18
|
+
const lineFiltersList = typeof line === "string" ? line.split(",") : line;
|
|
19
|
+
const lineList = lineFiltersList.map((l) => l.replace(/\s+/g, "").toUpperCase());
|
|
20
|
+
const lineFilter = (item) => {
|
|
21
|
+
const { line: linee, name } = item.properties;
|
|
22
|
+
const lineName = (name || linee && linee.name || "").toUpperCase();
|
|
23
|
+
if (!lineName) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
return lineList.includes(lineName);
|
|
27
|
+
};
|
|
28
|
+
filterList.push(lineFilter);
|
|
29
|
+
}
|
|
30
|
+
if (route) {
|
|
31
|
+
const routes = typeof route === "string" ? route.split(",") : route;
|
|
32
|
+
const routeList = routes.map((item) => parseInt(item, 10));
|
|
33
|
+
const routeFilter = (item) => {
|
|
34
|
+
const routeId = parseInt(item.properties.routeIdentifier.split(".")[0], 10);
|
|
35
|
+
return routeList.includes(routeId);
|
|
36
|
+
};
|
|
37
|
+
filterList.push(routeFilter);
|
|
38
|
+
}
|
|
39
|
+
if (operator) {
|
|
40
|
+
const operatorList = typeof operator === "string" ? [operator] : operator;
|
|
41
|
+
const operatorFilter = (item) => operatorList.some((op) => new RegExp(op, "i").test(item.properties.operator));
|
|
42
|
+
filterList.push(operatorFilter);
|
|
43
|
+
}
|
|
44
|
+
if (!filterList.length) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
return (t) => {
|
|
48
|
+
for (let i = 0; i < filterList.length; i += 1) {
|
|
49
|
+
if (!filterList[i](t)) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return true;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
export default createFilters;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import createTrackerFilters from "./createTrackerFilters";
|
|
2
|
+
const u1 = {
|
|
3
|
+
properties: {
|
|
4
|
+
routeIdentifier: "001.000827.004:7",
|
|
5
|
+
operator: "FoO",
|
|
6
|
+
line: {
|
|
7
|
+
name: "U1"
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
const ireta = {
|
|
12
|
+
properties: {
|
|
13
|
+
routeIdentifier: "0022.000827.004:7",
|
|
14
|
+
operator: "BAR",
|
|
15
|
+
line: {
|
|
16
|
+
name: "IRETA"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
const arb = {
|
|
21
|
+
properties: {
|
|
22
|
+
routeIdentifier: "00333.000827.004:7",
|
|
23
|
+
operator: "qux",
|
|
24
|
+
line: {
|
|
25
|
+
name: "ARB"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const trajectories = [u1, ireta, arb];
|
|
30
|
+
describe("#createTrackerFilter()", () => {
|
|
31
|
+
test("returns null", () => {
|
|
32
|
+
const filterFunc = createTrackerFilters();
|
|
33
|
+
expect(filterFunc).toBe(null);
|
|
34
|
+
});
|
|
35
|
+
describe("using line", () => {
|
|
36
|
+
test("as string", () => {
|
|
37
|
+
const filterFunc = createTrackerFilters("u1,foo");
|
|
38
|
+
expect(trajectories.filter(filterFunc)).toEqual([u1]);
|
|
39
|
+
});
|
|
40
|
+
test("as array of string", () => {
|
|
41
|
+
const filterFunc = createTrackerFilters(["u1", "foo", "IRETA"]);
|
|
42
|
+
expect(trajectories.filter(filterFunc)).toEqual([u1, ireta]);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
describe("using route identifier", () => {
|
|
46
|
+
test("as string", () => {
|
|
47
|
+
const filterFunc = createTrackerFilters(null, "1,foo");
|
|
48
|
+
expect(trajectories.filter(filterFunc)).toEqual([u1]);
|
|
49
|
+
});
|
|
50
|
+
test("as array of string", () => {
|
|
51
|
+
const filterFunc = createTrackerFilters(null, ["22", "foo", "1"]);
|
|
52
|
+
expect(trajectories.filter(filterFunc)).toEqual([u1, ireta]);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
describe("using operator", () => {
|
|
56
|
+
test("as string", () => {
|
|
57
|
+
const filterFunc = createTrackerFilters(null, null, "foo");
|
|
58
|
+
expect(trajectories.filter(filterFunc)).toEqual([u1]);
|
|
59
|
+
});
|
|
60
|
+
test("as array of string", () => {
|
|
61
|
+
const filterFunc = createTrackerFilters(null, null, ["bar", "foo", "1"]);
|
|
62
|
+
expect(trajectories.filter(filterFunc)).toEqual([u1, ireta]);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
describe("using regexLine", () => {
|
|
66
|
+
test("as string", () => {
|
|
67
|
+
const filterFunc = createTrackerFilters(null, null, null, "^(S|R$|RE|PE|D|IRE|RB|TER)");
|
|
68
|
+
expect(trajectories.filter(filterFunc)).toEqual([ireta]);
|
|
69
|
+
});
|
|
70
|
+
test("as array of string", () => {
|
|
71
|
+
const filterFunc = createTrackerFilters(null, null, null, [
|
|
72
|
+
"^IR",
|
|
73
|
+
"^ARB$",
|
|
74
|
+
"foo"
|
|
75
|
+
]);
|
|
76
|
+
expect(trajectories.filter(filterFunc)).toEqual([ireta, arb]);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
});
|
|
@@ -1,32 +1,19 @@
|
|
|
1
|
-
import removeDuplicate from
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Return the copyright a Mapbox map.
|
|
5
|
-
* @param {mapboxgl.Map} map A Mapbox map
|
|
6
|
-
* @ignore
|
|
7
|
-
*/
|
|
1
|
+
import removeDuplicate from "./removeDuplicate";
|
|
8
2
|
const getMapboxMapCopyrights = (map) => {
|
|
9
3
|
if (!map || !map.style) {
|
|
10
4
|
return [];
|
|
11
5
|
}
|
|
12
6
|
const { sourceCaches } = map.style;
|
|
13
7
|
let copyrights = [];
|
|
14
|
-
|
|
15
8
|
Object.values(sourceCaches).forEach((sourceCache) => {
|
|
16
9
|
if (sourceCache.used) {
|
|
17
10
|
const source = sourceCache.getSource();
|
|
18
|
-
const attribution =
|
|
19
|
-
source.attribution || (source.options && source.options.attribution);
|
|
20
|
-
|
|
11
|
+
const attribution = source.attribution || source.options && source.options.attribution;
|
|
21
12
|
if (attribution) {
|
|
22
|
-
copyrights = copyrights.concat(
|
|
23
|
-
attribution.replace(/©/g, '©').split(/(<a.*?<\/a>)/),
|
|
24
|
-
);
|
|
13
|
+
copyrights = copyrights.concat(attribution.replace(/©/g, "\xA9").split(/(<a.*?<\/a>)/));
|
|
25
14
|
}
|
|
26
15
|
}
|
|
27
16
|
});
|
|
28
|
-
|
|
29
17
|
return removeDuplicate(copyrights);
|
|
30
18
|
};
|
|
31
|
-
|
|
32
19
|
export default getMapboxMapCopyrights;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import getMapboxMapCopyrights from "./getMapboxMapCopyrights";
|
|
2
|
+
describe("getMapboxMapCopyrights()", () => {
|
|
3
|
+
test("returns an empty array if map is not defined", () => {
|
|
4
|
+
expect(getMapboxMapCopyrights().length).toBe(0);
|
|
5
|
+
});
|
|
6
|
+
test("returns an empty array if map.style is not defined", () => {
|
|
7
|
+
expect(getMapboxMapCopyrights({}).length).toBe(0);
|
|
8
|
+
});
|
|
9
|
+
test("returns non depluicated copyrights in an array", () => {
|
|
10
|
+
expect(getMapboxMapCopyrights({
|
|
11
|
+
style: {
|
|
12
|
+
sourceCaches: {
|
|
13
|
+
used: {
|
|
14
|
+
used: true,
|
|
15
|
+
getSource() {
|
|
16
|
+
return {
|
|
17
|
+
attribution: '<a href="https://www.openmaptiles.org/" target="_blank">\xA9 OpenMapTiles</a> <a href="https://www.openstreetmap.org/about/" target="_blank">© OpenStreetMap contributors</a>'
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"not used": {
|
|
22
|
+
used: false
|
|
23
|
+
},
|
|
24
|
+
"also used": {
|
|
25
|
+
used: true,
|
|
26
|
+
getSource() {
|
|
27
|
+
return {
|
|
28
|
+
attribution: '<a href="https://www.openmaptiles.org/" target="_blank">© OpenMapTiles</a> <a href="https://www.imagico.de/" target="_blank">© imagico</a>'
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
})).toEqual([
|
|
35
|
+
'<a href="https://www.openmaptiles.org/" target="_blank">\xA9 OpenMapTiles</a>',
|
|
36
|
+
'<a href="https://www.openstreetmap.org/about/" target="_blank">\xA9 OpenStreetMap contributors</a>',
|
|
37
|
+
'<a href="https://www.imagico.de/" target="_blank">\xA9 imagico</a>'
|
|
38
|
+
]);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
import qs from
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Return the styleUrl with apiKey parameters set.
|
|
5
|
-
* @param {string} apiKey apiKey value for the mapbox request.
|
|
6
|
-
* @param {string} apiKeyName parameter name for apiKey in the mapbox request.
|
|
7
|
-
* @param {string} styleUrl mapbox styleUrl value.
|
|
8
|
-
* @ignore
|
|
9
|
-
*/
|
|
1
|
+
import qs from "query-string";
|
|
10
2
|
const getMapboxStyleUrl = (apiKey, apiKeyName, styleUrl) => {
|
|
11
3
|
if (apiKey === false) {
|
|
12
4
|
return styleUrl;
|
|
@@ -16,7 +8,6 @@ const getMapboxStyleUrl = (apiKey, apiKeyName, styleUrl) => {
|
|
|
16
8
|
return styleUrl;
|
|
17
9
|
}
|
|
18
10
|
if (!apiKey) {
|
|
19
|
-
// eslint-disable-next-line no-console
|
|
20
11
|
console.warn(`No apiKey is defined for request to ${styleUrl}`);
|
|
21
12
|
return null;
|
|
22
13
|
}
|
|
@@ -24,9 +15,8 @@ const getMapboxStyleUrl = (apiKey, apiKeyName, styleUrl) => {
|
|
|
24
15
|
...parsedStyle,
|
|
25
16
|
query: {
|
|
26
17
|
...parsedStyle.query,
|
|
27
|
-
[apiKeyName]: apiKey
|
|
28
|
-
}
|
|
18
|
+
[apiKeyName]: apiKey
|
|
19
|
+
}
|
|
29
20
|
});
|
|
30
21
|
};
|
|
31
|
-
|
|
32
22
|
export default getMapboxStyleUrl;
|
|
@@ -1,23 +1,12 @@
|
|
|
1
|
-
import GeomType from
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Interpolate or not the vehicle position from a trajectory at a specific date.
|
|
5
|
-
*
|
|
6
|
-
* @param {number} now Current date to interpolate a position with. In ms.
|
|
7
|
-
* @param {TralisTrajectory} trajectory The trajectory to interpolate.
|
|
8
|
-
* @param {boolean} noInterpolate If true, the vehicle position is not interpolated on each render but only once.
|
|
9
|
-
* @returns
|
|
10
|
-
*/
|
|
1
|
+
import GeomType from "ol/geom/GeometryType";
|
|
11
2
|
const getVehiclePosition = (now, trajectory, noInterpolate) => {
|
|
12
3
|
const {
|
|
13
4
|
time_intervals: timeIntervals,
|
|
14
5
|
olGeometry: geometry,
|
|
15
|
-
coordinate
|
|
6
|
+
coordinate
|
|
16
7
|
} = trajectory.properties;
|
|
17
|
-
|
|
18
8
|
let coord;
|
|
19
9
|
let rotation;
|
|
20
|
-
|
|
21
10
|
if (noInterpolate && coordinate) {
|
|
22
11
|
coord = coordinate;
|
|
23
12
|
} else if (geometry.getType() === GeomType.POINT) {
|
|
@@ -26,30 +15,17 @@ const getVehiclePosition = (now, trajectory, noInterpolate) => {
|
|
|
26
15
|
const intervals = timeIntervals || [[]];
|
|
27
16
|
const firstInterval = intervals[0];
|
|
28
17
|
const lastInterval = intervals[intervals.length - 1];
|
|
29
|
-
|
|
30
|
-
// Between the last time interval of a trajectory event and the beginning
|
|
31
|
-
// of the new trajectory event, there is few seconds, can be 6 to 30
|
|
32
|
-
// seconds (that's why the vehicle jumps sometimes).
|
|
33
|
-
// So we make the choice here to display the last (or the first) position
|
|
34
|
-
// of an trajectory event instead of removing them, if the current date is
|
|
35
|
-
// outside the time intervals we display the vehicle at the last (or first) position known.
|
|
36
18
|
if (now < firstInterval[0]) {
|
|
37
|
-
// Display first position known.
|
|
38
19
|
[, , rotation] = firstInterval;
|
|
39
20
|
coord = geometry.getFirstCoordinate();
|
|
40
21
|
} else if (now > lastInterval[0]) {
|
|
41
|
-
// Display last position known.
|
|
42
22
|
[, , rotation] = lastInterval;
|
|
43
23
|
coord = geometry.getLastCoordinate();
|
|
44
24
|
} else {
|
|
45
|
-
// Interpolate position using time intervals.
|
|
46
25
|
for (let j = 0; j < intervals.length - 1; j += 1) {
|
|
47
|
-
// Rotation only available in tralis layer.
|
|
48
26
|
const [start, startFrac] = intervals[j];
|
|
49
27
|
const [end, endFrac] = intervals[j + 1];
|
|
50
|
-
|
|
51
28
|
if (start <= now && now <= end) {
|
|
52
|
-
// interpolate position inside the time interval.
|
|
53
29
|
const timeFrac = Math.min((now - start) / (end - start), 1);
|
|
54
30
|
const geomFrac = timeFrac * (endFrac - startFrac) + startFrac;
|
|
55
31
|
coord = geometry.getCoordinateAt(geomFrac);
|
|
@@ -59,14 +35,8 @@ const getVehiclePosition = (now, trajectory, noInterpolate) => {
|
|
|
59
35
|
}
|
|
60
36
|
}
|
|
61
37
|
} else {
|
|
62
|
-
|
|
63
|
-
console.error(
|
|
64
|
-
'This geometry type is not supported. Only Point or LineString are. Current geometry: ',
|
|
65
|
-
geometry,
|
|
66
|
-
);
|
|
38
|
+
console.error("This geometry type is not supported. Only Point or LineString are. Current geometry: ", geometry);
|
|
67
39
|
}
|
|
68
|
-
|
|
69
40
|
return { coord, rotation };
|
|
70
41
|
};
|
|
71
|
-
|
|
72
42
|
export default getVehiclePosition;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { default as getMapboxStyleUrl } from "./getMapboxStyleUrl";
|
|
2
|
+
export { default as getMapboxMapCopyrights } from "./getMapboxMapCopyrights";
|
|
3
|
+
export { default as removeDuplicate } from "./removeDuplicate";
|
|
4
|
+
export * from "./timeUtils";
|
|
5
|
+
export { default as sortByDelay } from "./sortByDelay";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const removeDuplicate = (array) => {
|
|
2
|
+
const arrWithoutEmptyValues = array.filter((val) => val !== void 0 && val !== null && val.trim && val.trim());
|
|
3
|
+
const lowerCasesValues = arrWithoutEmptyValues.map((str) => str.toLowerCase());
|
|
4
|
+
const uniqueLowerCaseValues = [...new Set(lowerCasesValues)];
|
|
5
|
+
const uniqueValues = uniqueLowerCaseValues.map((uniqueStr) => arrWithoutEmptyValues.find((str) => str.toLowerCase() === uniqueStr));
|
|
6
|
+
return uniqueValues;
|
|
7
|
+
};
|
|
8
|
+
export default removeDuplicate;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import removeDuplicate from "./removeDuplicate";
|
|
2
|
+
describe("removeDuplicate()", () => {
|
|
3
|
+
test("removes duplicates", () => {
|
|
4
|
+
expect(removeDuplicate([
|
|
5
|
+
"a",
|
|
6
|
+
" ",
|
|
7
|
+
" ",
|
|
8
|
+
"b",
|
|
9
|
+
"a",
|
|
10
|
+
void 0,
|
|
11
|
+
null,
|
|
12
|
+
"A",
|
|
13
|
+
0,
|
|
14
|
+
"c",
|
|
15
|
+
"b",
|
|
16
|
+
"B"
|
|
17
|
+
])).toEqual(["a", "b", "c"]);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
@@ -1,23 +1,18 @@
|
|
|
1
1
|
const sortByDelay = (traj1, traj2) => {
|
|
2
2
|
const props1 = traj1.properties;
|
|
3
3
|
const props2 = traj2.properties;
|
|
4
|
-
|
|
5
4
|
if (props1.delay === null && props2.delay !== null) {
|
|
6
5
|
return 1;
|
|
7
6
|
}
|
|
8
7
|
if (props2.delay === null && props1.delay !== null) {
|
|
9
8
|
return -1;
|
|
10
9
|
}
|
|
11
|
-
|
|
12
|
-
// We put cancelled train inbetween green and yellow trains
|
|
13
|
-
// >=180000ms corresponds to yellow train
|
|
14
10
|
if (props1.cancelled && !props2.cancelled) {
|
|
15
|
-
return props2.delay <
|
|
11
|
+
return props2.delay < 18e4 ? -1 : 1;
|
|
16
12
|
}
|
|
17
13
|
if (props2.cancelled && !props1.cancelled) {
|
|
18
|
-
return props1.delay <
|
|
14
|
+
return props1.delay < 18e4 ? 1 : -1;
|
|
19
15
|
}
|
|
20
16
|
return props2.delay - props1.delay;
|
|
21
17
|
};
|
|
22
|
-
|
|
23
18
|
export default sortByDelay;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export const getUTCDateString = (now = new Date()) => {
|
|
2
|
+
let month = (now.getUTCMonth() + 1).toString();
|
|
3
|
+
month = month.length === 1 ? `0${month}` : month;
|
|
4
|
+
let day = now.getUTCDate().toString();
|
|
5
|
+
day = day.length === 1 ? `0${day}` : day;
|
|
6
|
+
return [now.getUTCFullYear(), month, day].join("");
|
|
7
|
+
};
|
|
8
|
+
export const getUTCTimeString = (date) => [
|
|
9
|
+
date.getUTCHours(),
|
|
10
|
+
date.getUTCMinutes(),
|
|
11
|
+
`${date.getUTCSeconds()}.${date.getUTCMilliseconds()}`
|
|
12
|
+
].join(":");
|
|
13
|
+
export const pad = (integer) => integer < 10 ? `0${integer}` : integer;
|
|
14
|
+
export const getHoursAndMinutes = (timeInMs) => {
|
|
15
|
+
if (!timeInMs || timeInMs <= 0) {
|
|
16
|
+
return "";
|
|
17
|
+
}
|
|
18
|
+
const date = new Date(timeInMs);
|
|
19
|
+
return `${pad(date.getHours())}:${pad(date.getMinutes())}`;
|
|
20
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { getUTCDateString, getUTCTimeString } from "./timeUtils";
|
|
2
|
+
describe("timeUtils", () => {
|
|
3
|
+
test("getUTCDateString should be correct.", () => {
|
|
4
|
+
expect(getUTCDateString(new Date(2020, 5, 30))).toBe("20200630");
|
|
5
|
+
expect(getUTCDateString(new Date("January 1, 2021 00:15:30 GMT+2:00"))).toBe("20201231");
|
|
6
|
+
});
|
|
7
|
+
test("getUTCTimeString should be correct.", () => {
|
|
8
|
+
expect(getUTCTimeString(new Date(2020, 5, 30, 11, 5, 1, 123))).toBe("11:5:1.123");
|
|
9
|
+
});
|
|
10
|
+
});
|
package/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import Control from "../../common/controls/Control";
|
|
2
|
+
import mixin from "../../common/mixins/CopyrightMixin";
|
|
3
|
+
import { getMapboxMapCopyrights } from "../../common/utils";
|
|
4
|
+
class CopyrightControl extends mixin(Control) {
|
|
5
|
+
constructor(options) {
|
|
6
|
+
super(options);
|
|
7
|
+
this.render = this.render.bind(this);
|
|
8
|
+
}
|
|
9
|
+
activate() {
|
|
10
|
+
super.activate();
|
|
11
|
+
if (this.map) {
|
|
12
|
+
this.map.on("sourcedata", this.render);
|
|
13
|
+
this.map.on("styledata", this.render);
|
|
14
|
+
this.map.on("idle", this.render);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
deactivate() {
|
|
18
|
+
if (this.map) {
|
|
19
|
+
this.map.off("sourcedata", this.render);
|
|
20
|
+
this.map.off("styledata", this.render);
|
|
21
|
+
this.map.off("idle", this.render);
|
|
22
|
+
}
|
|
23
|
+
super.deactivate();
|
|
24
|
+
}
|
|
25
|
+
getCopyrights() {
|
|
26
|
+
return getMapboxMapCopyrights(this.map);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export default CopyrightControl;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as CopyrightControl } from "./CopyrightControl";
|
package/mapbox/index.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { unByKey } from "ol/Observable";
|
|
2
|
+
import { transformExtent } from "ol/proj";
|
|
3
|
+
import LayerCommon from "../../common/layers/Layer";
|
|
4
|
+
class Layer extends LayerCommon {
|
|
5
|
+
attachToMap(map) {
|
|
6
|
+
super.attachToMap(map);
|
|
7
|
+
if (!this.map) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
if (this.isClickActive || this.isHoverActive) {
|
|
11
|
+
this.toggleVisibleListeners();
|
|
12
|
+
this.onChangeVisibleKey = this.on("change:visible", this.toggleVisibleListeners);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
detachFromMap(map) {
|
|
16
|
+
if (this.map) {
|
|
17
|
+
this.map.off("mousemove", this.onUserMoveCallback);
|
|
18
|
+
this.map.off("click", this.onUserClickCallback);
|
|
19
|
+
unByKey(this.onChangeVisibleKey);
|
|
20
|
+
}
|
|
21
|
+
super.detachFromMap(map);
|
|
22
|
+
}
|
|
23
|
+
onUserClickCallback(evt) {
|
|
24
|
+
super.onUserClickCallback({ coordinate: evt.lngLat.toArray(), ...evt });
|
|
25
|
+
}
|
|
26
|
+
onUserMoveCallback(evt) {
|
|
27
|
+
super.onUserMoveCallback({ coordinate: evt.lngLat.toArray(), ...evt });
|
|
28
|
+
}
|
|
29
|
+
toggleVisibleListeners() {
|
|
30
|
+
if (this.visible) {
|
|
31
|
+
if (this.isClickActive) {
|
|
32
|
+
this.map.on("click", this.onUserClickCallback);
|
|
33
|
+
}
|
|
34
|
+
if (this.isHoverActive) {
|
|
35
|
+
this.map.on("mousemove", this.onUserMoveCallback);
|
|
36
|
+
}
|
|
37
|
+
} else {
|
|
38
|
+
if (this.isClickActive) {
|
|
39
|
+
this.map.off("click", this.onUserClickCallback);
|
|
40
|
+
}
|
|
41
|
+
if (this.isHoverActive) {
|
|
42
|
+
this.map.off("mousemove", this.onUserMoveCallback);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
getMercatorExtent() {
|
|
47
|
+
const bounds = this.map.getBounds().toArray();
|
|
48
|
+
return transformExtent([...bounds[0], ...bounds[1]], "EPSG:4326", "EPSG:3857");
|
|
49
|
+
}
|
|
50
|
+
getOlZoom() {
|
|
51
|
+
return this.map.getZoom() + 1;
|
|
52
|
+
}
|
|
53
|
+
clone(newOptions) {
|
|
54
|
+
return new Layer({ ...this.options, ...newOptions });
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export default Layer;
|