mobility-toolbox-js 2.0.0-beta.1 → 2.0.0-beta.6
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/.babelrc +6 -0
- package/.esdoc.json +17 -0
- package/.eslintignore +1 -0
- package/.github/workflows/conventional-pr-title.yml +21 -0
- package/.github/workflows/cypress.yml +29 -0
- package/.github/workflows/nodejs.yml +28 -0
- package/.husky/commit-msg +4 -0
- package/.husky/post-checkout +4 -0
- package/.husky/post-merge +4 -0
- package/.husky/post-rebase +4 -0
- package/.husky/pre-commit +4 -0
- package/.neutrinorc.js +176 -0
- package/.nvmrc +1 -0
- package/CHANGELOG.md +10 -0
- package/LICENSE +21 -0
- package/Layer.js +2 -0
- package/Layer.js.map +7 -0
- package/README.md +7 -4
- package/__mocks__/mapbox-gl.js +81 -0
- package/__mocks__/maplibre-gl.js +81 -0
- package/commitlint.config.js +1 -0
- package/cypress/fixtures/example.json +5 -0
- package/cypress/integration/examples/api.spec.js +7 -0
- package/cypress/integration/examples/examples.spec.js +7 -0
- package/cypress/integration/examples/navigation.spec.js +29 -0
- package/cypress/plugins/index.js +21 -0
- package/cypress/support/commands.js +25 -0
- package/cypress/support/index.js +20 -0
- package/cypress.json +4 -0
- package/data/fetchRoute.json +292 -0
- package/data/fetchTrajectories.json +18 -0
- package/data/fetchTrajectoryById.json +3 -0
- package/data/fetchTrajectoryStations.json +18 -0
- package/data/stopsSearch.json +15 -0
- package/documentation.yml +4 -0
- package/esdoc/README.md +27 -0
- package/esdoc/plugins/MyPlugin.js +69 -0
- package/esdoc/plugins/dynamic-property-plugin/Plugin.js +50 -0
- package/esdoc/plugins/externals-plugin/Plugin.js +45 -0
- package/esdoc/plugins/externals-plugin/externals.js +96 -0
- package/global-setup.js +3 -0
- package/{ol/README.md → index.html} +0 -0
- package/indexweb.html +49 -0
- package/jest.config.js +5 -0
- package/package.json +34 -13
- package/pull_request_template.md +17 -0
- package/renovate.json +4 -0
- package/scripts/read-pkg-json.js +22 -0
- package/{api → src/api}/index.js +0 -1
- package/{api → src/api}/routing/RoutingAPI.js +0 -0
- package/{api → src/api}/routing/RoutingAPI.test.js +0 -0
- package/{api → src/api}/stops/StopsAPI.js +0 -0
- package/{api → src/api}/stops/StopsAPI.test.js +0 -0
- package/{api → src/api}/tralis/TralisAPI.js +1 -1
- package/{api → src/api}/tralis/TralisAPI.test.js +0 -0
- package/{api → src/api}/tralis/TralisAPIUtils.js +0 -0
- package/{api → src/api}/tralis/WebSocketConnector.js +0 -0
- package/{api → src/api}/tralis/WebSocketConnector.test.js +0 -0
- package/{api → src/api}/tralis/typedefs.js +0 -0
- 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 +93 -0
- package/{common → src/common}/Tracker.js +0 -0
- package/{common → src/common}/api/api.js +0 -0
- package/{common → src/common}/api/api.test.js +0 -0
- package/{common → src/common}/controls/Control.js +4 -1
- package/{common → src/common}/controls/Control.test.js +0 -0
- package/{common → src/common}/layers/Layer.js +18 -49
- package/{common → src/common}/layers/Layer.test.js +2 -106
- package/{common → src/common}/mixins/CopyrightMixin.js +0 -0
- package/{common → src/common}/mixins/SearchMixin.js +1 -1
- package/{common/mixins/TrackerLayerMixin.js → src/common/mixins/TralisLayerMixin.js} +380 -195
- package/src/common/styles/index.js +4 -0
- package/{common/utils/delayTrackerStyle.js → src/common/styles/trackerDefaultStyle.js} +8 -8
- package/src/common/styles/trackerDelayStyle.js +17 -0
- package/src/common/styles/trackerSimpleStyle.js +22 -0
- package/{common → src/common}/trackerConfig.js +0 -0
- package/{common → src/common}/trackerConfig.test.js +0 -13
- package/{common → src/common}/typedefs.js +0 -0
- package/{common → src/common}/utils/createTrackerFilters.js +0 -0
- package/{common → src/common}/utils/createTrackerFilters.test.js +0 -0
- package/{common → src/common}/utils/getMapboxMapCopyrights.js +1 -0
- package/{common → src/common}/utils/getMapboxMapCopyrights.test.js +0 -0
- package/{common → src/common}/utils/getMapboxStyleUrl.js +0 -0
- package/{common → src/common}/utils/getVehiclePosition.js +0 -0
- package/{common → src/common}/utils/index.js +2 -3
- package/{common → src/common}/utils/removeDuplicate.js +0 -0
- package/{common → src/common}/utils/removeDuplicate.test.js +0 -0
- package/src/common/utils/sortByDelay.js +23 -0
- package/{common → src/common}/utils/timeUtils.js +0 -0
- package/{common → src/common}/utils/timeUtils.test.js +0 -0
- package/src/doc/App.js +116 -0
- package/src/doc/App.scss +51 -0
- package/src/doc/_redirects +2 -0
- package/src/doc/components/CodeSandboxButton.js +103 -0
- package/src/doc/components/Documentation.js +40 -0
- package/src/doc/components/Esdoc/Anchor.js +57 -0
- package/src/doc/components/Esdoc/ClassDoc.js +272 -0
- package/src/doc/components/Esdoc/DeprecatedHTML.js +16 -0
- package/src/doc/components/Esdoc/DetailDocs.js +281 -0
- package/src/doc/components/Esdoc/DetailHTML.js +33 -0
- package/src/doc/components/Esdoc/DirectSubclassHTML.js +30 -0
- package/src/doc/components/Esdoc/DocBuilderUtils.js +694 -0
- package/src/doc/components/Esdoc/DocLinkHTML.js +62 -0
- package/src/doc/components/Esdoc/DocsLinkHTML.js +38 -0
- package/src/doc/components/Esdoc/Esdoc.js +63 -0
- package/src/doc/components/Esdoc/EsdocContent.js +51 -0
- package/src/doc/components/Esdoc/EsdocNavigation.js +13 -0
- package/src/doc/components/Esdoc/EsdocSearch.js +81 -0
- package/src/doc/components/Esdoc/ExperimentalHTML.js +17 -0
- package/src/doc/components/Esdoc/ExtendsChainHTML.js +32 -0
- package/src/doc/components/Esdoc/FileDocLinkHTML.js +60 -0
- package/src/doc/components/Esdoc/IdentifiersDoc.js +113 -0
- package/src/doc/components/Esdoc/IndirectSubclassHTML.js +30 -0
- package/src/doc/components/Esdoc/InheritedSummaryDoc.js +70 -0
- package/src/doc/components/Esdoc/InheritedSummaryHTML.js +38 -0
- package/src/doc/components/Esdoc/MixinClassesHTML.js +29 -0
- package/src/doc/components/Esdoc/NavDoc.js +112 -0
- package/src/doc/components/Esdoc/OverrideMethod.js +44 -0
- package/src/doc/components/Esdoc/OverrideMethodDescription.js +35 -0
- package/src/doc/components/Esdoc/Properties.js +89 -0
- package/src/doc/components/Esdoc/README.md +45 -0
- package/src/doc/components/Esdoc/SignatureHTML.js +123 -0
- package/src/doc/components/Esdoc/SingleDoc.js +31 -0
- package/src/doc/components/Esdoc/SummaryDoc.js +160 -0
- package/src/doc/components/Esdoc/SummaryHTML.js +96 -0
- package/src/doc/components/Esdoc/TypeDocLinkHTML.js +249 -0
- package/src/doc/components/Esdoc/css/identifiers.css +38 -0
- package/src/doc/components/Esdoc/css/search.css +76 -0
- package/src/doc/components/Esdoc/css/style.css +603 -0
- package/src/doc/components/Esdoc/index.js +7 -0
- package/src/doc/components/Example.js +153 -0
- package/src/doc/components/Examples.js +183 -0
- package/src/doc/components/Home.js +106 -0
- package/src/doc/components/TrackerExample.js +38 -0
- package/src/doc/components/esm.min.js +2 -0
- package/src/doc/components/examples/assets/tralis-live-map/index.js +11 -0
- package/src/doc/components/examples/assets/tralis-live-map/s1kreis.svg +105 -0
- package/src/doc/components/examples/assets/tralis-live-map/s20kreis.svg +101 -0
- package/src/doc/components/examples/assets/tralis-live-map/s2kreis.svg +95 -0
- package/src/doc/components/examples/assets/tralis-live-map/s3kreis.svg +95 -0
- package/src/doc/components/examples/assets/tralis-live-map/s4kreis.svg +95 -0
- package/src/doc/components/examples/assets/tralis-live-map/s6kreis.svg +95 -0
- package/src/doc/components/examples/assets/tralis-live-map/s7kreis.svg +95 -0
- package/src/doc/components/examples/assets/tralis-live-map/s8kreis.svg +93 -0
- package/src/doc/components/examples/assets/tralis-live-map/unknown.svg +107 -0
- package/src/doc/components/examples/mb-copyright.html +26 -0
- package/src/doc/components/examples/mb-copyright.js +37 -0
- package/src/doc/components/examples/mb-tracker.html +1 -0
- package/src/doc/components/examples/mb-tracker.js +39 -0
- package/src/doc/components/examples/mb-tracker.md +1 -0
- package/src/doc/components/examples/mb-tralis.html +1 -0
- package/src/doc/components/examples/mb-tralis.js +34 -0
- package/src/doc/components/examples/ol-copyright.html +26 -0
- package/src/doc/components/examples/ol-copyright.js +43 -0
- package/src/doc/components/examples/ol-mapbox-layer.html +1 -0
- package/src/doc/components/examples/ol-mapbox-layer.js +28 -0
- package/src/doc/components/examples/ol-mapbox-layer.md +0 -0
- package/src/doc/components/examples/ol-mapbox-style-layer.html +12 -0
- package/src/doc/components/examples/ol-mapbox-style-layer.js +44 -0
- package/src/doc/components/examples/ol-query.html +32 -0
- package/src/doc/components/examples/ol-query.js +83 -0
- package/src/doc/components/examples/ol-routing.html +26 -0
- package/src/doc/components/examples/ol-routing.js +59 -0
- package/src/doc/components/examples/ol-routing.md +1 -0
- package/src/doc/components/examples/ol-stop-finder.html +15 -0
- package/src/doc/components/examples/ol-stop-finder.js +31 -0
- package/src/doc/components/examples/ol-stop-finder.md +1 -0
- package/src/doc/components/examples/ol-tracker.html +1 -0
- package/src/doc/components/examples/ol-tracker.js +44 -0
- package/src/doc/components/examples/ol-tracker.md +1 -0
- package/src/doc/components/examples/ol-tralis.html +5 -0
- package/src/doc/components/examples/ol-tralis.js +57 -0
- package/src/doc/components/examples/tralis-live-map.html +1 -0
- package/src/doc/components/examples/tralis-live-map.js +51 -0
- package/src/doc/components/examples/tralis-live-map.md +3 -0
- package/src/doc/examples/assets/tralis-live-map/index.js +11 -0
- package/src/doc/examples/assets/tralis-live-map/s1kreis.svg +105 -0
- package/src/doc/examples/assets/tralis-live-map/s20kreis.svg +101 -0
- package/src/doc/examples/assets/tralis-live-map/s2kreis.svg +95 -0
- package/src/doc/examples/assets/tralis-live-map/s3kreis.svg +95 -0
- package/src/doc/examples/assets/tralis-live-map/s4kreis.svg +95 -0
- package/src/doc/examples/assets/tralis-live-map/s6kreis.svg +95 -0
- package/src/doc/examples/assets/tralis-live-map/s7kreis.svg +95 -0
- package/src/doc/examples/assets/tralis-live-map/s8kreis.svg +93 -0
- package/src/doc/examples/assets/tralis-live-map/unknown.svg +107 -0
- package/src/doc/examples/mb-copyright.html +26 -0
- package/src/doc/examples/mb-copyright.js +37 -0
- package/src/doc/examples/mb-tracker.html +1 -0
- package/src/doc/examples/mb-tracker.js +39 -0
- package/src/doc/examples/mb-tracker.md +1 -0
- package/src/doc/examples/mb-tralis.html +1 -0
- package/src/doc/examples/mb-tralis.js +34 -0
- package/src/doc/examples/ol-copyright.html +26 -0
- package/src/doc/examples/ol-copyright.js +43 -0
- package/src/doc/examples/ol-mapbox-layer.html +1 -0
- package/src/doc/examples/ol-mapbox-layer.js +28 -0
- package/src/doc/examples/ol-mapbox-layer.md +0 -0
- package/src/doc/examples/ol-mapbox-style-layer.html +12 -0
- package/src/doc/examples/ol-mapbox-style-layer.js +44 -0
- package/src/doc/examples/ol-query.html +32 -0
- package/src/doc/examples/ol-query.js +83 -0
- package/src/doc/examples/ol-routing.html +26 -0
- package/src/doc/examples/ol-routing.js +59 -0
- package/src/doc/examples/ol-routing.md +1 -0
- package/src/doc/examples/ol-stop-finder.html +15 -0
- package/src/doc/examples/ol-stop-finder.js +31 -0
- package/src/doc/examples/ol-stop-finder.md +1 -0
- package/src/doc/examples/ol-tracker.html +1 -0
- package/src/doc/examples/ol-tracker.js +44 -0
- package/src/doc/examples/ol-tracker.md +1 -0
- package/src/doc/examples/ol-tralis.html +5 -0
- package/src/doc/examples/ol-tralis.js +57 -0
- package/src/doc/examples/tralis-live-map.html +1 -0
- package/src/doc/examples/tralis-live-map.js +51 -0
- package/src/doc/examples/tralis-live-map.md +3 -0
- package/src/doc/examples.js +107 -0
- 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 +21 -0
- package/src/iife.js +7 -0
- package/{module.js → src/index.js} +3 -9
- package/{mapbox → src/mapbox}/controls/CopyrightControl.js +5 -1
- package/{mapbox → src/mapbox}/index.js +0 -2
- package/{mapbox → src/mapbox}/layers/Layer.js +0 -0
- package/{mapbox → src/mapbox}/layers/Layer.test.js +2 -2
- package/{mapbox/layers/TrackerLayer.js → src/mapbox/layers/TralisLayer.js} +71 -24
- package/src/mapbox/layers/TralisLayer.test.js +40 -0
- package/{mapbox → src/mapbox}/utils.js +0 -0
- package/src/ol/README.md +0 -0
- package/{ol → src/ol}/controls/CopyrightControl.js +4 -4
- package/{ol → src/ol}/controls/CopyrightControl.test.js +16 -16
- package/{ol → src/ol}/controls/RoutingControl.js +9 -7
- package/{ol → src/ol}/controls/RoutingControl.test.js +1 -1
- package/{ol → src/ol}/controls/StopFinderControl.js +8 -6
- package/{ol → src/ol}/controls/StopFinderControl.test.js +1 -1
- package/{ol → src/ol}/controls/snapshots/RoutingControlRouteGen10.json +0 -0
- package/{ol → src/ol}/controls/snapshots/RoutingControlRouteGen100.json +0 -0
- package/{ol → src/ol}/controls/snapshots/RoutingControlRouteGen30.json +0 -0
- package/{ol → src/ol}/controls/snapshots/RoutingControlRouteGen5.json +0 -0
- package/{ol → src/ol}/controls/snapshots/RoutingControlRouteOSM.json +0 -0
- package/{ol → src/ol}/controls/snapshots/RoutingControlStation1.json +0 -0
- package/{ol → src/ol}/controls/snapshots/RoutingControlStation2.json +0 -0
- package/{ol → src/ol}/index.js +3 -3
- package/{ol → src/ol}/layers/Layer.js +9 -0
- package/{ol → src/ol}/layers/Layer.test.js +22 -7
- package/{ol → src/ol}/layers/MapboxLayer.js +39 -44
- package/{ol → src/ol}/layers/MapboxLayer.test.js +5 -5
- package/{ol → src/ol}/layers/MapboxStyleLayer.js +0 -6
- package/{ol → src/ol}/layers/MapboxStyleLayer.test.js +22 -6
- package/src/ol/layers/MaplibreLayer.js +280 -0
- package/{ol → src/ol}/layers/RoutingLayer.js +0 -0
- package/{ol → src/ol}/layers/RoutingLayer.test.js +1 -1
- package/{ol/layers/TrackerLayer.js → src/ol/layers/TralisLayer.js} +96 -33
- package/{ol → src/ol}/layers/TralisLayer.test.js +1 -49
- package/{ol → src/ol}/layers/VectorLayer.js +0 -0
- package/{ol → src/ol}/layers/VectorLayer.test.js +1 -1
- package/{ol → src/ol}/layers/WMSLayer.js +0 -0
- package/{ol → src/ol}/layers/WMSLayer.test.js +6 -2
- package/src/ol/styles/fullTrajectoryDelayStyle.js +35 -0
- package/src/ol/styles/fullTrajectoryStyle.js +51 -0
- package/src/ol/styles/index.js +2 -0
- package/src/setupTests.js +15 -0
- package/webpack.config.js +6 -0
- package/api/trajserv/TrajservAPI.js +0 -71
- package/api/trajserv/TrajservAPI.test.js +0 -171
- package/api/trajserv/TrajservAPIUtils.js +0 -191
- package/api/trajserv/TrajservAPIUtils.test.js +0 -40
- package/api/trajserv/typedefs.js +0 -44
- package/common/mixins/MapMixin.js +0 -103
- package/common/mixins/TrajservLayerMixin.js +0 -544
- package/common/mixins/TralisLayerMixin.js +0 -402
- package/common/utils/simpleTrackerStyle.js +0 -18
- package/index.js +0 -2
- package/index.js.map +0 -1
- package/mapbox/Map.js +0 -87
- package/mapbox/layers/TrackerLayer.test.js +0 -68
- package/mapbox/layers/TrajservLayer.js +0 -114
- package/mapbox/layers/TrajservLayer.test.js +0 -90
- package/mapbox/layers/TralisLayer.js +0 -64
- package/ol/Map.js +0 -109
- package/ol/Map.test.js +0 -34
- package/ol/layers/TrackerLayer.test.js +0 -70
- package/ol/layers/TrajservLayer.js +0 -190
- package/ol/layers/TrajservLayer.test.js +0 -113
- package/ol/layers/TralisLayer.js +0 -177
|
@@ -1,24 +1,36 @@
|
|
|
1
|
+
import GeoJSON from 'ol/format/GeoJSON';
|
|
1
2
|
import { Layer as OLLayer, Group, Vector as VectorLayer } from 'ol/layer';
|
|
2
3
|
import Source from 'ol/source/Source';
|
|
3
4
|
import { composeCssTransform } from 'ol/transform';
|
|
4
5
|
import { Vector as VectorSource } from 'ol/source';
|
|
5
|
-
import mixin from '../../common/mixins/TrackerLayerMixin';
|
|
6
|
-
|
|
7
6
|
import Layer from './Layer';
|
|
7
|
+
import mixin from '../../common/mixins/TralisLayerMixin';
|
|
8
|
+
import { fullTrajectoryStyle } from '../styles';
|
|
9
|
+
|
|
10
|
+
const format = new GeoJSON();
|
|
8
11
|
|
|
9
12
|
/**
|
|
10
|
-
* Responsible for loading
|
|
13
|
+
* Responsible for loading and display data from a Tralis service.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* import { TralisLayer } from 'mobility-toolbox-js/ol';
|
|
17
|
+
*
|
|
18
|
+
* const layer = new TralisLayer({
|
|
19
|
+
* url: [yourUrl],
|
|
20
|
+
* apiKey: [yourApiKey],
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
*
|
|
24
|
+
* @see <a href="/api/class/src/api/tralis/TralisAPI%20js~TralisAPI%20html">TralisAPI</a>
|
|
11
25
|
*
|
|
12
|
-
* @classproperty {ol/Map~Map} map - The map where the layer is displayed.
|
|
13
26
|
* @extends {Layer}
|
|
14
|
-
* @implements {
|
|
27
|
+
* @implements {TralisLayerInterface}
|
|
15
28
|
*/
|
|
16
|
-
class
|
|
29
|
+
class TralisLayer extends mixin(Layer) {
|
|
17
30
|
/**
|
|
18
31
|
* Constructor.
|
|
19
32
|
*
|
|
20
33
|
* @param {Object} options
|
|
21
|
-
* @param {boolean} options.useDelayStyle Set the delay style.
|
|
22
34
|
* @private
|
|
23
35
|
*/
|
|
24
36
|
constructor(options = {}) {
|
|
@@ -35,6 +47,7 @@ class TrackerLayer extends mixin(Layer) {
|
|
|
35
47
|
layers: [
|
|
36
48
|
new VectorLayer({
|
|
37
49
|
source: new VectorSource({ features: [] }),
|
|
50
|
+
style: options.fullTrajectoryStyle || fullTrajectoryStyle,
|
|
38
51
|
}),
|
|
39
52
|
new OLLayer({
|
|
40
53
|
source: new Source({}),
|
|
@@ -111,7 +124,7 @@ class TrackerLayer extends mixin(Layer) {
|
|
|
111
124
|
super.init(map);
|
|
112
125
|
if (this.map) {
|
|
113
126
|
this.olListenersKeys.push(
|
|
114
|
-
this.map.on('moveend', (evt) => {
|
|
127
|
+
this.map.on(['moveend', 'change:target'], (evt) => {
|
|
115
128
|
const view = this.map.getView();
|
|
116
129
|
if (view.getAnimating() || view.getInteracting()) {
|
|
117
130
|
return;
|
|
@@ -211,23 +224,7 @@ class TrackerLayer extends mixin(Layer) {
|
|
|
211
224
|
return super.getRefreshTimeInMs(this.map.getView().getZoom());
|
|
212
225
|
}
|
|
213
226
|
|
|
214
|
-
/**
|
|
215
|
-
* Returns the vehicle which are at the given coordinates.
|
|
216
|
-
* Returns null when no vehicle is located at the given coordinates.
|
|
217
|
-
* @param {ol/coordinate~Coordinate} coordinate
|
|
218
|
-
* @param {number} nb Number of vehicles to return;
|
|
219
|
-
* @return {Array<ol/Feature~Feature>} Vehicle feature.
|
|
220
|
-
* @override
|
|
221
|
-
*/
|
|
222
|
-
getVehiclesAtCoordinate(coordinate, nb) {
|
|
223
|
-
const resolution = this.map.getView().getResolution();
|
|
224
|
-
return super.getVehiclesAtCoordinate(coordinate, resolution, nb);
|
|
225
|
-
}
|
|
226
|
-
|
|
227
227
|
getFeatureInfoAtCoordinate(coordinate, options = {}) {
|
|
228
|
-
if (!this.hasFeatureInfoAtCoordinate(coordinate)) {
|
|
229
|
-
return Promise.resolve({ features: [], layer: this, coordinate });
|
|
230
|
-
}
|
|
231
228
|
const resolution = this.map.getView().getResolution();
|
|
232
229
|
return super.getFeatureInfoAtCoordinate(coordinate, {
|
|
233
230
|
resolution,
|
|
@@ -236,14 +233,26 @@ class TrackerLayer extends mixin(Layer) {
|
|
|
236
233
|
}
|
|
237
234
|
|
|
238
235
|
/**
|
|
239
|
-
*
|
|
240
|
-
* To be defined in inherited classes
|
|
236
|
+
* On move end we update the websocket with the new bbox.
|
|
241
237
|
*
|
|
242
|
-
* @param {ol/MapEvent~MapEvent} evt Moveend event
|
|
238
|
+
* @param {ol/MapEvent~MapEvent} evt Moveend event
|
|
243
239
|
* @private
|
|
240
|
+
* @override
|
|
244
241
|
*/
|
|
245
|
-
|
|
246
|
-
|
|
242
|
+
onMoveEnd() {
|
|
243
|
+
if (this.visible && this.isUpdateBboxOnMoveEnd) {
|
|
244
|
+
this.setBbox();
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (
|
|
248
|
+
this.visible &&
|
|
249
|
+
this.isUpdateBboxOnMoveEnd &&
|
|
250
|
+
this.isClickActive &&
|
|
251
|
+
this.selectedVehicleId
|
|
252
|
+
) {
|
|
253
|
+
this.highlightTrajectory(this.selectedVehicleId);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
247
256
|
|
|
248
257
|
/**
|
|
249
258
|
* Function called on moveend event only when the zoom has changed.
|
|
@@ -281,16 +290,70 @@ class TrackerLayer extends mixin(Layer) {
|
|
|
281
290
|
if (!features.length && this.vectorLayer) {
|
|
282
291
|
this.vectorLayer.getSource().clear();
|
|
283
292
|
}
|
|
293
|
+
if (this.selectedVehicleId) {
|
|
294
|
+
this.highlightTrajectory(this.selectedVehicleId);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Remove the trajectory form the list if necessary.
|
|
300
|
+
*
|
|
301
|
+
* @private
|
|
302
|
+
*/
|
|
303
|
+
purgeTrajectory(trajectory, extent, zoom) {
|
|
304
|
+
return super.purgeTrajectory(
|
|
305
|
+
trajectory,
|
|
306
|
+
extent || this.map.getView().calculateExtent(),
|
|
307
|
+
zoom || this.map.getView().getZoom(),
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Send the current bbox to the websocket
|
|
313
|
+
*
|
|
314
|
+
* @private
|
|
315
|
+
*/
|
|
316
|
+
setBbox(extent, zoom) {
|
|
317
|
+
let newExtent = extent;
|
|
318
|
+
let newZoom = zoom;
|
|
319
|
+
if (!newExtent && this.isUpdateBboxOnMoveEnd) {
|
|
320
|
+
newExtent = extent || this.map.getView().calculateExtent();
|
|
321
|
+
newZoom = Math.floor(this.map.getView().getZoom());
|
|
322
|
+
}
|
|
323
|
+
super.setBbox(newExtent, newZoom);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Highlight the trajectory of journey.
|
|
328
|
+
* @private
|
|
329
|
+
*/
|
|
330
|
+
highlightTrajectory(id) {
|
|
331
|
+
this.api
|
|
332
|
+
.getFullTrajectory(id, this.mode, this.generalizationLevel)
|
|
333
|
+
.then((fullTrajectory) => {
|
|
334
|
+
const vectorSource = this.vectorLayer.getSource();
|
|
335
|
+
vectorSource.clear();
|
|
336
|
+
|
|
337
|
+
if (
|
|
338
|
+
!fullTrajectory ||
|
|
339
|
+
!fullTrajectory.features ||
|
|
340
|
+
!fullTrajectory.features.length
|
|
341
|
+
) {
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
const features = format.readFeatures(fullTrajectory);
|
|
345
|
+
this.vectorLayer.getSource().addFeatures(features);
|
|
346
|
+
});
|
|
284
347
|
}
|
|
285
348
|
|
|
286
349
|
/**
|
|
287
|
-
* Create a copy of the
|
|
350
|
+
* Create a copy of the TralisLayer.
|
|
288
351
|
* @param {Object} newOptions Options to override
|
|
289
|
-
* @return {
|
|
352
|
+
* @return {TralisLayer} A TralisLayer
|
|
290
353
|
*/
|
|
291
354
|
clone(newOptions) {
|
|
292
|
-
return new
|
|
355
|
+
return new TralisLayer({ ...this.options, ...newOptions });
|
|
293
356
|
}
|
|
294
357
|
}
|
|
295
358
|
|
|
296
|
-
export default
|
|
359
|
+
export default TralisLayer;
|
|
@@ -10,7 +10,7 @@ let onClick;
|
|
|
10
10
|
let olMap;
|
|
11
11
|
let server;
|
|
12
12
|
|
|
13
|
-
describe('
|
|
13
|
+
describe('TralisLayer', () => {
|
|
14
14
|
beforeEach(() => {
|
|
15
15
|
server = new WS('ws://localhost:1234');
|
|
16
16
|
global.fetch = fetch;
|
|
@@ -69,63 +69,17 @@ describe('TrajservLayer', () => {
|
|
|
69
69
|
sort: fn,
|
|
70
70
|
});
|
|
71
71
|
expect(laye).toBeInstanceOf(TralisLayer);
|
|
72
|
-
expect(laye.useDelayStyle).toBe(false);
|
|
73
72
|
expect(laye.sort).toBe(fn);
|
|
74
73
|
});
|
|
75
74
|
|
|
76
|
-
test.only('should set a default sort function if useDelayStyle is used.', () => {
|
|
77
|
-
const laye = new TralisLayer({
|
|
78
|
-
url: 'ws://localhost:1234',
|
|
79
|
-
apiKey: 'apiKey',
|
|
80
|
-
useDelayStyle: true,
|
|
81
|
-
});
|
|
82
|
-
expect(laye).toBeInstanceOf(TralisLayer);
|
|
83
|
-
expect(laye.useDelayStyle).toBe(true);
|
|
84
|
-
expect(laye.sort).toBeDefined();
|
|
85
|
-
const red = { properties: { delay: 1000000 } };
|
|
86
|
-
const yellow = { properties: { delay: 180000 } };
|
|
87
|
-
const green2 = { properties: { delay: 178990 } };
|
|
88
|
-
const green = { properties: { delay: 0 } };
|
|
89
|
-
const gray = { properties: { delay: null } };
|
|
90
|
-
const cancelled = { properties: { cancelled: true, delay: 3000000 } };
|
|
91
|
-
|
|
92
|
-
const trajectories = [gray, green, yellow, red, green2, cancelled];
|
|
93
|
-
trajectories.sort(laye.sort);
|
|
94
|
-
expect(trajectories).toEqual([red, yellow, cancelled, green2, green, gray]);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
test('should override the default sort function when useDelayStyle is used.', () => {
|
|
98
|
-
const laye = new TralisLayer({
|
|
99
|
-
url: 'ws://localhost:1234',
|
|
100
|
-
apiKey: 'apiKey',
|
|
101
|
-
useDelayStyle: true,
|
|
102
|
-
sort: () => -1, // reverse the array
|
|
103
|
-
});
|
|
104
|
-
expect(laye).toBeInstanceOf(TralisLayer);
|
|
105
|
-
expect(laye.useDelayStyle).toBe(true);
|
|
106
|
-
expect(laye.sort).toBeDefined();
|
|
107
|
-
const red = { delay: 1000000 };
|
|
108
|
-
const yellow = { delay: 180000 };
|
|
109
|
-
const green2 = { delay: 178990 };
|
|
110
|
-
const green = { delay: 0 };
|
|
111
|
-
const gray = { delay: null };
|
|
112
|
-
const cancelled = { cancelled: true, delay: 3000000 };
|
|
113
|
-
|
|
114
|
-
const trajectories = [gray, green, yellow, red, green2, cancelled];
|
|
115
|
-
trajectories.sort(laye.sort);
|
|
116
|
-
expect(trajectories).toEqual([cancelled, green2, red, yellow, green, gray]);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
75
|
test('should use filter function.', () => {
|
|
120
76
|
const fn = () => true;
|
|
121
77
|
const laye = new TralisLayer({
|
|
122
78
|
url: 'ws://localhost:1234',
|
|
123
79
|
apiKey: 'apiKey',
|
|
124
|
-
useDelayStyle: true,
|
|
125
80
|
filter: fn, // reverse the array
|
|
126
81
|
});
|
|
127
82
|
expect(laye).toBeInstanceOf(TralisLayer);
|
|
128
|
-
expect(laye.useDelayStyle).toBe(true);
|
|
129
83
|
expect(laye.filter).toBe(fn);
|
|
130
84
|
});
|
|
131
85
|
|
|
@@ -134,12 +88,10 @@ describe('TrajservLayer', () => {
|
|
|
134
88
|
const laye = new TralisLayer({
|
|
135
89
|
url: 'ws://localhost:1234',
|
|
136
90
|
apiKey: 'apiKey',
|
|
137
|
-
useDelayStyle: true,
|
|
138
91
|
filter: fn, // reverse the array
|
|
139
92
|
publishedLineName: '.*',
|
|
140
93
|
});
|
|
141
94
|
expect(laye).toBeInstanceOf(TralisLayer);
|
|
142
|
-
expect(laye.useDelayStyle).toBe(true);
|
|
143
95
|
expect(laye.filter).not.toBe(fn);
|
|
144
96
|
});
|
|
145
97
|
});
|
|
File without changes
|
|
@@ -3,7 +3,7 @@ import VectorSource from 'ol/source/Vector';
|
|
|
3
3
|
import View from 'ol/View';
|
|
4
4
|
import Feature from 'ol/Feature';
|
|
5
5
|
import Point from 'ol/geom/Point';
|
|
6
|
-
import Map from '
|
|
6
|
+
import Map from 'ol/Map';
|
|
7
7
|
import VectorLayer from './VectorLayer';
|
|
8
8
|
|
|
9
9
|
const feature1 = new Feature({
|
|
File without changes
|
|
@@ -3,7 +3,7 @@ import ImageLayer from 'ol/layer/Image';
|
|
|
3
3
|
import ImageWMS from 'ol/source/ImageWMS';
|
|
4
4
|
import fetch from 'jest-fetch-mock';
|
|
5
5
|
import qs from 'query-string';
|
|
6
|
-
import Map from '
|
|
6
|
+
import Map from 'ol/Map';
|
|
7
7
|
import WMSLayer from './WMSLayer';
|
|
8
8
|
|
|
9
9
|
describe('WMSLayer', () => {
|
|
@@ -23,11 +23,15 @@ describe('WMSLayer', () => {
|
|
|
23
23
|
}),
|
|
24
24
|
}),
|
|
25
25
|
});
|
|
26
|
-
|
|
26
|
+
layer.init(map);
|
|
27
27
|
fetch.mockResponseOnce(JSON.stringify({ features: [] }));
|
|
28
28
|
global.fetch = fetch;
|
|
29
29
|
});
|
|
30
30
|
|
|
31
|
+
afterEach(() => {
|
|
32
|
+
layer.terminate();
|
|
33
|
+
});
|
|
34
|
+
|
|
31
35
|
test('should initialize.', () => {
|
|
32
36
|
expect(layer).toBeInstanceOf(WMSLayer);
|
|
33
37
|
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Style, Fill, Stroke, Circle } from 'ol/style';
|
|
2
|
+
|
|
3
|
+
const stroke = new Style({
|
|
4
|
+
zIndex: 2,
|
|
5
|
+
image: new Circle({
|
|
6
|
+
radius: 5,
|
|
7
|
+
fill: new Fill({
|
|
8
|
+
color: '#000000',
|
|
9
|
+
}),
|
|
10
|
+
}),
|
|
11
|
+
stroke: new Stroke({
|
|
12
|
+
color: '#000000',
|
|
13
|
+
width: 6,
|
|
14
|
+
}),
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const fill = new Style({
|
|
18
|
+
zIndex: 3,
|
|
19
|
+
image: new Circle({
|
|
20
|
+
radius: 4,
|
|
21
|
+
fill: new Fill({
|
|
22
|
+
color: '#a0a0a0',
|
|
23
|
+
}),
|
|
24
|
+
}),
|
|
25
|
+
stroke: new Stroke({
|
|
26
|
+
color: '#a0a0a0',
|
|
27
|
+
width: 4,
|
|
28
|
+
}),
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const fullTrajectoryDelaystyle = () => {
|
|
32
|
+
return [stroke, fill];
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export default fullTrajectoryDelaystyle;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Style, Fill, Stroke, Circle } from 'ol/style';
|
|
2
|
+
import { getBgColor } from '../../common/trackerConfig';
|
|
3
|
+
|
|
4
|
+
const borderStyle = new Style({
|
|
5
|
+
zIndex: 2,
|
|
6
|
+
image: new Circle({
|
|
7
|
+
radius: 5,
|
|
8
|
+
fill: new Fill({
|
|
9
|
+
color: '#000000',
|
|
10
|
+
}),
|
|
11
|
+
}),
|
|
12
|
+
stroke: new Stroke({
|
|
13
|
+
color: '#000000',
|
|
14
|
+
width: 6,
|
|
15
|
+
}),
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const fullTrajectorystyle = (feature) => {
|
|
19
|
+
let lineColor = '#ffffff'; // white
|
|
20
|
+
|
|
21
|
+
const type = feature.get('type');
|
|
22
|
+
let stroke = feature.get('stroke');
|
|
23
|
+
|
|
24
|
+
if (stroke && stroke[0] !== '#') {
|
|
25
|
+
stroke = `#${stroke}`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
lineColor = stroke || getBgColor(type);
|
|
29
|
+
|
|
30
|
+
// Don't allow white lines, use red instead.
|
|
31
|
+
lineColor = /#ffffff/i.test(lineColor) ? '#ff0000' : lineColor;
|
|
32
|
+
|
|
33
|
+
const style = [
|
|
34
|
+
borderStyle,
|
|
35
|
+
new Style({
|
|
36
|
+
zIndex: 3,
|
|
37
|
+
image: new Circle({
|
|
38
|
+
radius: 4,
|
|
39
|
+
fill: new Fill({
|
|
40
|
+
color: lineColor,
|
|
41
|
+
}),
|
|
42
|
+
}),
|
|
43
|
+
stroke: new Stroke({
|
|
44
|
+
color: lineColor,
|
|
45
|
+
width: 4,
|
|
46
|
+
}),
|
|
47
|
+
}),
|
|
48
|
+
];
|
|
49
|
+
return style;
|
|
50
|
+
};
|
|
51
|
+
export default fullTrajectorystyle;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/* eslint-disable import/no-extraneous-dependencies */
|
|
2
|
+
import 'jest-canvas-mock';
|
|
3
|
+
import fetchTrajectoryByIdResponse from '../data/fetchTrajectoryById.json';
|
|
4
|
+
import fetchTrajectoriesResponse from '../data/fetchTrajectories.json';
|
|
5
|
+
import fetchTrajectoryStationsResponse from '../data/fetchTrajectoryStations.json';
|
|
6
|
+
import stopsSearchResponse from '../data/stopsSearch.json';
|
|
7
|
+
import fetchRouteResponse from '../data/fetchRoute.json';
|
|
8
|
+
|
|
9
|
+
global.fetchTrajectoryByIdResponse = fetchTrajectoryByIdResponse;
|
|
10
|
+
global.fetchTrajectoriesResponse = fetchTrajectoriesResponse;
|
|
11
|
+
global.fetchTrajectoryStationsResponse = fetchTrajectoryStationsResponse;
|
|
12
|
+
global.stopsSearchResponse = stopsSearchResponse;
|
|
13
|
+
global.fetchRouteResponse = fetchRouteResponse;
|
|
14
|
+
|
|
15
|
+
global.URL.createObjectURL = jest.fn(() => 'fooblob');
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// Whilst the configuration object can be modified here, the recommended way of making
|
|
2
|
+
// changes is via the presets' options or Neutrino's API in `.neutrinorc.js` instead.
|
|
3
|
+
// Neutrino's inspect feature can be used to view/export the generated configuration.
|
|
4
|
+
const neutrino = require('neutrino');
|
|
5
|
+
|
|
6
|
+
module.exports = neutrino().webpack();
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
translateTrajCollResponse,
|
|
3
|
-
translateTrajStationsResp,
|
|
4
|
-
} from './TrajservAPIUtils';
|
|
5
|
-
import API from '../../common/api/api';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Access to the [Realtime service](https://developer.geops.io/apis/5dcbd5c9a256d90001cf1360/).
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* import { TrajservAPI } from 'mobility-toolbox-js/api';
|
|
12
|
-
*
|
|
13
|
-
* const api = new TrajservAPI({
|
|
14
|
-
* url: 'https://api.geops.io/tracker/v1',
|
|
15
|
-
* apiKey: [yourApiKey]
|
|
16
|
-
* });
|
|
17
|
-
*
|
|
18
|
-
*/
|
|
19
|
-
class TrajservAPI extends API {
|
|
20
|
-
/**
|
|
21
|
-
* Constructor
|
|
22
|
-
*
|
|
23
|
-
* @param {Object} options Options.
|
|
24
|
-
* @param {string} [options.url='https://api.geops.io/tracker/v1'] Service url.
|
|
25
|
-
* @param {string} options.apiKey Access key for [geOps services](https://developer.geops.io/).
|
|
26
|
-
*/
|
|
27
|
-
constructor(options = {}) {
|
|
28
|
-
super({ url: 'https://api.geops.io/tracker/v1', ...options });
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Fetch a trajectory by id.
|
|
33
|
-
*
|
|
34
|
-
* @param {GetTrajectoryByIdParams} params Request parameters. See [Realtime service documentation](https://developer.geops.io/apis/5dcbd5c9a256d90001cf1360/#/default/get_trajectorybyid).
|
|
35
|
-
* @param {AbortController} abortController Abort controller used to cancel the request.
|
|
36
|
-
* @return {Promise<TrajservTrajectory>} A trajectory.
|
|
37
|
-
*/
|
|
38
|
-
fetchTrajectoryById(params, abortController = {}) {
|
|
39
|
-
return this.fetch(`/trajectorybyid`, params, {
|
|
40
|
-
signal: abortController.signal,
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Fetch trajectories.
|
|
46
|
-
*
|
|
47
|
-
* @param {GetTrajectoriesParams} params Request parameters. See [Realtime service documentation](https://developer.geops.io/apis/5dcbd5c9a256d90001cf1360/#/default/get_trajectory_collection).
|
|
48
|
-
* @param {AbortController} abortController Abort controller used to cancel the request.
|
|
49
|
-
* @return {Promise<Array<Trajectory>>} A list of trajectories.
|
|
50
|
-
*/
|
|
51
|
-
fetchTrajectories(params, abortController = {}) {
|
|
52
|
-
return this.fetch(`/trajectory_collection`, params, {
|
|
53
|
-
signal: abortController.signal,
|
|
54
|
-
}).then((data) => translateTrajCollResponse(data.features));
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Fetch stations informations about a trajectory.
|
|
59
|
-
*
|
|
60
|
-
* @param {GetTrajectoryStationsParams} params Request parameters. See [Realtime service documentation](https://developer.geops.io/apis/5dcbd5c9a256d90001cf1360/#/default/get_trajstations).
|
|
61
|
-
* @param {AbortController} abortController Abort controller used to cancel the request.
|
|
62
|
-
* @return {Promise<Array<TrajectoryStation>>} A list of stations.
|
|
63
|
-
*/
|
|
64
|
-
fetchTrajectoryStations(params, abortController = {}) {
|
|
65
|
-
return this.fetch(`/trajstations`, params, {
|
|
66
|
-
signal: abortController.signal,
|
|
67
|
-
}).then((data) => translateTrajStationsResp(data));
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export default TrajservAPI;
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import fetch from 'jest-fetch-mock';
|
|
2
|
-
import TrajservAPI from './TrajservAPI';
|
|
3
|
-
|
|
4
|
-
let api;
|
|
5
|
-
|
|
6
|
-
describe('TrajservAPI', () => {
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
global.fetch = fetch;
|
|
9
|
-
fetch.resetMocks();
|
|
10
|
-
|
|
11
|
-
api = new TrajservAPI({ apiKey: 'apiKey' });
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
describe('#fetchTrajectoryById', () => {
|
|
15
|
-
test('should success', () => {
|
|
16
|
-
fetch.mockResponseOnce(
|
|
17
|
-
JSON.stringify(global.fetchTrajectoryByIdResponse),
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
return api
|
|
21
|
-
.fetchTrajectoryById({
|
|
22
|
-
a: '1',
|
|
23
|
-
bbox: '917830.8141233932,5949421.787168904,926771.7516620635,5953300.375201735',
|
|
24
|
-
btime: '5:54:7.880',
|
|
25
|
-
cd: '1',
|
|
26
|
-
date: '20200701',
|
|
27
|
-
etime: '5:54:24.582',
|
|
28
|
-
fl: '1',
|
|
29
|
-
id: '16617:3',
|
|
30
|
-
nm: '1',
|
|
31
|
-
rid: '1',
|
|
32
|
-
s: '0',
|
|
33
|
-
time: '5:54:8.103',
|
|
34
|
-
z: '15.248670953423606',
|
|
35
|
-
})
|
|
36
|
-
.then((response) => {
|
|
37
|
-
// Correct url
|
|
38
|
-
expect(fetch.mock.calls[0][0]).toEqual(
|
|
39
|
-
'https://api.geops.io/tracker/v1/trajectorybyid?a=1&bbox=917830.8141233932%2C5949421.787168904%2C926771.7516620635%2C5953300.375201735&btime=5%3A54%3A7.880&cd=1&date=20200701&etime=5%3A54%3A24.582&fl=1&id=16617%3A3&key=apiKey&nm=1&rid=1&s=0&time=5%3A54%3A8.103&z=15.248670953423606',
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
// Correct search result
|
|
43
|
-
expect(response.rid).toEqual('21120.000011.101:1');
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
test('should trigger error message', () => {
|
|
48
|
-
// Mock console statement
|
|
49
|
-
const consoleOutput = [];
|
|
50
|
-
// eslint-disable-next-line no-console
|
|
51
|
-
console.warn = (message, err) =>
|
|
52
|
-
consoleOutput.push([message, err.toString()]);
|
|
53
|
-
|
|
54
|
-
fetch.mockResponseOnce('invalid json');
|
|
55
|
-
|
|
56
|
-
return api
|
|
57
|
-
.fetchTrajectoryById({
|
|
58
|
-
attr_det: '1',
|
|
59
|
-
bbox: '922972.5439121567,5951167.694705085,923812.5648796591,5951532.096677226',
|
|
60
|
-
btime: '5:18:31.766',
|
|
61
|
-
etime: '5:18:41.967',
|
|
62
|
-
date: '20200701',
|
|
63
|
-
rid: '1',
|
|
64
|
-
a: '1',
|
|
65
|
-
cd: '1',
|
|
66
|
-
nm: '1',
|
|
67
|
-
fl: '1',
|
|
68
|
-
s: '0',
|
|
69
|
-
z: '18.66059982835272',
|
|
70
|
-
})
|
|
71
|
-
.catch((err) => {
|
|
72
|
-
expect(err.name).toEqual('FetchError');
|
|
73
|
-
expect(err.message).toEqual(
|
|
74
|
-
'invalid json response body at reason: Unexpected token i in JSON at position 0',
|
|
75
|
-
);
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
describe('#fetchTrajectories', () => {
|
|
81
|
-
test('should success', () => {
|
|
82
|
-
fetch.mockResponseOnce(JSON.stringify(global.fetchTrajectoriesResponse));
|
|
83
|
-
|
|
84
|
-
return api
|
|
85
|
-
.fetchTrajectories({
|
|
86
|
-
attr_det: '1',
|
|
87
|
-
bbox: '922972.5439121567,5951167.694705085,923812.5648796591,5951532.096677226',
|
|
88
|
-
btime: '5:18:31.766',
|
|
89
|
-
etime: '5:18:41.967',
|
|
90
|
-
date: '20200701',
|
|
91
|
-
rid: '1',
|
|
92
|
-
a: '1',
|
|
93
|
-
cd: '1',
|
|
94
|
-
nm: '1',
|
|
95
|
-
fl: '1',
|
|
96
|
-
s: '0',
|
|
97
|
-
z: '18.66059982835272',
|
|
98
|
-
})
|
|
99
|
-
.then((features) => {
|
|
100
|
-
// Correct url
|
|
101
|
-
expect(fetch.mock.calls[0][0]).toEqual(
|
|
102
|
-
'https://api.geops.io/tracker/v1/trajectory_collection?a=1&attr_det=1&bbox=922972.5439121567%2C5951167.694705085%2C923812.5648796591%2C5951532.096677226&btime=5%3A18%3A31.766&cd=1&date=20200701&etime=5%3A18%3A41.967&fl=1&key=apiKey&nm=1&rid=1&s=0&z=18.66059982835272',
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
// Correct search result
|
|
106
|
-
expect(features[0].id).toEqual(4150092);
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
test('should display error message if the transformation fails', () => {
|
|
111
|
-
fetch.mockResponseOnce(JSON.stringify({ foo: 'bar' }));
|
|
112
|
-
|
|
113
|
-
return api
|
|
114
|
-
.fetchTrajectories({
|
|
115
|
-
attr_det: '1',
|
|
116
|
-
bbox: '922972.5439121567,5951167.694705085,923812.5648796591,5951532.096677226',
|
|
117
|
-
btime: '5:18:31.766',
|
|
118
|
-
etime: '5:18:41.967',
|
|
119
|
-
date: '20200701',
|
|
120
|
-
rid: '1',
|
|
121
|
-
a: '1',
|
|
122
|
-
cd: '1',
|
|
123
|
-
nm: '1',
|
|
124
|
-
fl: '1',
|
|
125
|
-
s: '0',
|
|
126
|
-
z: '18.66059982835272',
|
|
127
|
-
})
|
|
128
|
-
.catch((err) => {
|
|
129
|
-
expect(err.name).toEqual('TypeError');
|
|
130
|
-
expect(err.message).toEqual(
|
|
131
|
-
"Cannot read property 'length' of undefined",
|
|
132
|
-
);
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
describe('#fetchTrajectoryStations', () => {
|
|
138
|
-
test('should success', () => {
|
|
139
|
-
fetch.mockResponseOnce(
|
|
140
|
-
JSON.stringify(global.fetchTrajectoryStationsResponse),
|
|
141
|
-
);
|
|
142
|
-
|
|
143
|
-
return api
|
|
144
|
-
.fetchTrajectoryStations({
|
|
145
|
-
a: '1',
|
|
146
|
-
bbox: '1059098.4179109985,5917420.543096403,1063534.5137495932,5919344.9260996',
|
|
147
|
-
btime: '6:17:22.722',
|
|
148
|
-
cd: '1',
|
|
149
|
-
date: '20200701',
|
|
150
|
-
etime: '6:17:33.526',
|
|
151
|
-
fl: '1',
|
|
152
|
-
id: '1714251',
|
|
153
|
-
key: 'apiKey',
|
|
154
|
-
nm: '1',
|
|
155
|
-
rid: '1',
|
|
156
|
-
s: '0',
|
|
157
|
-
time: '6:17:23.34',
|
|
158
|
-
z: '16.259806538265146',
|
|
159
|
-
})
|
|
160
|
-
.then((response) => {
|
|
161
|
-
// Correct url
|
|
162
|
-
expect(fetch.mock.calls[0][0]).toEqual(
|
|
163
|
-
'https://api.geops.io/tracker/v1/trajstations?a=1&bbox=1059098.4179109985%2C5917420.543096403%2C1063534.5137495932%2C5919344.9260996&btime=6%3A17%3A22.722&cd=1&date=20200701&etime=6%3A17%3A33.526&fl=1&id=1714251&key=apiKey&nm=1&rid=1&s=0&time=6%3A17%3A23.34&z=16.259806538265146',
|
|
164
|
-
);
|
|
165
|
-
|
|
166
|
-
// Correct search result
|
|
167
|
-
expect(response.routeIdentifier).toEqual('01716.000072.001:1716');
|
|
168
|
-
});
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
});
|