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
|
@@ -3,22 +3,36 @@ import { unByKey } from 'ol/Observable';
|
|
|
3
3
|
import { getWidth, getHeight } from 'ol/extent';
|
|
4
4
|
import transformRotate from '@turf/transform-rotate';
|
|
5
5
|
import { point } from '@turf/helpers';
|
|
6
|
+
import mixin from '../../common/mixins/TralisLayerMixin';
|
|
6
7
|
import Layer from './Layer';
|
|
7
|
-
import mixin from '../../common/mixins/TrackerLayerMixin';
|
|
8
8
|
import { getSourceCoordinates, getMercatorResolution } from '../utils';
|
|
9
|
+
|
|
9
10
|
/**
|
|
10
|
-
* Responsible for loading
|
|
11
|
+
* Responsible for loading and display data from a Tralis service.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* import { TralisLayer } from 'mobility-toolbox-js/mapbox';
|
|
15
|
+
*
|
|
16
|
+
* const layer = new TralisLayer({
|
|
17
|
+
* url: [yourUrl],
|
|
18
|
+
* apiKey: [yourApiKey],
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
*
|
|
22
|
+
* @see <a href="/api/class/src/api/tralis/TralisAPI%20js~TralisAPI%20html">TralisAPI</a>
|
|
11
23
|
*
|
|
12
|
-
* @classproperty {mapboxgl.Map} map - The map where the layer is displayed.
|
|
13
24
|
* @extends {Layer}
|
|
14
|
-
* @implements {
|
|
25
|
+
* @implements {TralisLayerInterface}
|
|
15
26
|
*/
|
|
16
|
-
class
|
|
27
|
+
class TralisLayer extends mixin(Layer) {
|
|
17
28
|
constructor(options = {}) {
|
|
18
29
|
super({
|
|
19
30
|
...options,
|
|
20
31
|
});
|
|
21
32
|
|
|
33
|
+
/** @ignore */
|
|
34
|
+
this.onLoad = this.onLoad.bind(this);
|
|
35
|
+
|
|
22
36
|
/** @ignore */
|
|
23
37
|
this.onMove = this.onMove.bind(this);
|
|
24
38
|
|
|
@@ -51,7 +65,7 @@ class TrackerLayer extends mixin(Layer) {
|
|
|
51
65
|
height: canvas.height / this.pixelRatio,
|
|
52
66
|
});
|
|
53
67
|
|
|
54
|
-
|
|
68
|
+
this.source = {
|
|
55
69
|
type: 'canvas',
|
|
56
70
|
canvas: this.tracker.canvas,
|
|
57
71
|
coordinates: getSourceCoordinates(map, this.pixelRatio),
|
|
@@ -74,8 +88,12 @@ class TrackerLayer extends mixin(Layer) {
|
|
|
74
88
|
'raster-resampling': 'nearest', // important otherwise it looks blurry
|
|
75
89
|
},
|
|
76
90
|
};
|
|
77
|
-
|
|
78
|
-
map.
|
|
91
|
+
|
|
92
|
+
if (map.isStyleLoaded()) {
|
|
93
|
+
this.onLoad();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
this.map.on('load', this.onLoad);
|
|
79
97
|
|
|
80
98
|
this.listeners = [this.on('change:visible', this.onVisibilityChange)];
|
|
81
99
|
}
|
|
@@ -85,6 +103,8 @@ class TrackerLayer extends mixin(Layer) {
|
|
|
85
103
|
*/
|
|
86
104
|
terminate() {
|
|
87
105
|
if (this.map) {
|
|
106
|
+
this.map.off('load', this.onLoad);
|
|
107
|
+
|
|
88
108
|
this.listeners.forEach((listener) => {
|
|
89
109
|
unByKey(listener);
|
|
90
110
|
});
|
|
@@ -127,6 +147,15 @@ class TrackerLayer extends mixin(Layer) {
|
|
|
127
147
|
}
|
|
128
148
|
}
|
|
129
149
|
|
|
150
|
+
onLoad() {
|
|
151
|
+
if (!this.map.getSource(this.key)) {
|
|
152
|
+
this.map.addSource(this.key, this.source);
|
|
153
|
+
}
|
|
154
|
+
if (!this.map.getLayer(this.key)) {
|
|
155
|
+
this.map.addLayer(this.layer, this.beforeId);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
130
159
|
/**
|
|
131
160
|
* Function triggered when the user click the map.
|
|
132
161
|
* @override
|
|
@@ -206,19 +235,6 @@ class TrackerLayer extends mixin(Layer) {
|
|
|
206
235
|
return super.getRefreshTimeInMs(this.map.getZoom());
|
|
207
236
|
}
|
|
208
237
|
|
|
209
|
-
/**
|
|
210
|
-
* Returns an array of vehicles located at the given coordinate.
|
|
211
|
-
*
|
|
212
|
-
* @param {Array<number>} coordinate
|
|
213
|
-
* @param {number} nb Number of vehicles to return;
|
|
214
|
-
* @return {Array<ol/Feature~Feature>} Array of vehicle.
|
|
215
|
-
* @override
|
|
216
|
-
*/
|
|
217
|
-
getVehiclesAtCoordinate(coordinate, nb) {
|
|
218
|
-
const resolution = getMercatorResolution(this.map);
|
|
219
|
-
return super.getVehiclesAtCoordinate(coordinate, resolution, nb);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
238
|
getFeatureInfoAtCoordinate(coordinate, options = {}) {
|
|
223
239
|
const resolution = getMercatorResolution(this.map);
|
|
224
240
|
return super.getFeatureInfoAtCoordinate(coordinate, {
|
|
@@ -241,6 +257,32 @@ class TrackerLayer extends mixin(Layer) {
|
|
|
241
257
|
// );
|
|
242
258
|
}
|
|
243
259
|
|
|
260
|
+
/**
|
|
261
|
+
* Remove the trajectory form the list if necessary.
|
|
262
|
+
*
|
|
263
|
+
* @private
|
|
264
|
+
*/
|
|
265
|
+
purgeTrajectory(trajectory, extent, zoom) {
|
|
266
|
+
return super.purgeTrajectory(
|
|
267
|
+
trajectory,
|
|
268
|
+
extent || this.getMercatorExtent(),
|
|
269
|
+
zoom || Math.floor(this.map.getZoom() + 1),
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Send the current bbox to the websocket
|
|
275
|
+
*/
|
|
276
|
+
setBbox(extent, zoom) {
|
|
277
|
+
let newExtent = extent;
|
|
278
|
+
let newZoom = zoom;
|
|
279
|
+
if (!newExtent && this.isUpdateBboxOnMoveEnd) {
|
|
280
|
+
newExtent = extent || this.getMercatorExtent();
|
|
281
|
+
newZoom = Math.floor(this.getOlZoom());
|
|
282
|
+
}
|
|
283
|
+
super.setBbox(newExtent, newZoom);
|
|
284
|
+
}
|
|
285
|
+
|
|
244
286
|
/**
|
|
245
287
|
* Callback on 'move' event.
|
|
246
288
|
*
|
|
@@ -256,13 +298,18 @@ class TrackerLayer extends mixin(Layer) {
|
|
|
256
298
|
}
|
|
257
299
|
|
|
258
300
|
/**
|
|
259
|
-
*
|
|
301
|
+
* Send the new BBOX to the websocket.
|
|
260
302
|
*
|
|
303
|
+
* @param {ol/MapEvent~MapEvent} evt Moveend event
|
|
261
304
|
* @private
|
|
305
|
+
* @override
|
|
262
306
|
*/
|
|
263
|
-
// eslint-disable-next-line class-methods-use-this
|
|
264
307
|
onMoveEnd() {
|
|
265
308
|
this.renderTrajectories();
|
|
309
|
+
|
|
310
|
+
if (this.visible && this.isUpdateBboxOnMoveEnd) {
|
|
311
|
+
this.setBbox();
|
|
312
|
+
}
|
|
266
313
|
}
|
|
267
314
|
|
|
268
315
|
/**
|
|
@@ -279,4 +326,4 @@ class TrackerLayer extends mixin(Layer) {
|
|
|
279
326
|
}
|
|
280
327
|
}
|
|
281
328
|
|
|
282
|
-
export default
|
|
329
|
+
export default TralisLayer;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import TralisLayer from './TralisLayer';
|
|
2
|
+
|
|
3
|
+
let layer;
|
|
4
|
+
let onClick;
|
|
5
|
+
|
|
6
|
+
describe('TralisLayer', () => {
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
onClick = jest.fn();
|
|
9
|
+
layer = new TralisLayer({
|
|
10
|
+
onClick,
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
test('should be instanced.', () => {
|
|
15
|
+
expect(layer).toBeInstanceOf(TralisLayer);
|
|
16
|
+
expect(layer.clickCallbacks[0]).toBe(onClick);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test('#onClick', () => {
|
|
20
|
+
const f = () => {};
|
|
21
|
+
layer.onClick(f);
|
|
22
|
+
expect(layer.clickCallbacks[1]).toBe(f);
|
|
23
|
+
expect(layer.clickCallbacks.length).toBe(2);
|
|
24
|
+
layer.onClick(f);
|
|
25
|
+
expect(layer.clickCallbacks.length).toBe(2);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('#unClick', () => {
|
|
29
|
+
const foo = () => {};
|
|
30
|
+
const bar = () => {};
|
|
31
|
+
layer.onClick(foo);
|
|
32
|
+
layer.onClick(bar);
|
|
33
|
+
expect(layer.clickCallbacks[1]).toBe(foo);
|
|
34
|
+
expect(layer.clickCallbacks[2]).toBe(bar);
|
|
35
|
+
expect(layer.clickCallbacks.length).toBe(3);
|
|
36
|
+
layer.unClick(foo);
|
|
37
|
+
expect(layer.clickCallbacks[1]).toBe(bar);
|
|
38
|
+
expect(layer.clickCallbacks.length).toBe(2);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
File without changes
|
package/src/ol/README.md
ADDED
|
File without changes
|
|
@@ -7,14 +7,14 @@ import removeDuplicate from '../../common/utils/removeDuplicate';
|
|
|
7
7
|
* Display layer's copyrights.
|
|
8
8
|
*
|
|
9
9
|
* @example
|
|
10
|
-
* import { Map
|
|
10
|
+
* import { Map } from 'ol';
|
|
11
|
+
* import { CopyrightControl } from 'mobility-toolbox-js/ol';
|
|
11
12
|
*
|
|
12
13
|
* const map = new Map({
|
|
13
14
|
* target: 'map',
|
|
14
|
-
* controls: [
|
|
15
|
-
* new CopyrightControl()
|
|
16
|
-
* ]
|
|
17
15
|
* });
|
|
16
|
+
* const control = new CopyrightControl();
|
|
17
|
+
* control.map = map
|
|
18
18
|
*
|
|
19
19
|
*
|
|
20
20
|
* @see <a href="/example/ol-copyright">Openlayers copyright example</a>
|
|
@@ -3,7 +3,7 @@ import Tile from 'ol/Tile';
|
|
|
3
3
|
import TileLayer from 'ol/layer/Tile';
|
|
4
4
|
import TileSource from 'ol/source/Tile';
|
|
5
5
|
import { createXYZ } from 'ol/tilegrid';
|
|
6
|
-
import Map from '
|
|
6
|
+
import { Map } from 'ol';
|
|
7
7
|
import Layer from '../layers/Layer';
|
|
8
8
|
import CopyrightControl from './CopyrightControl';
|
|
9
9
|
|
|
@@ -48,8 +48,8 @@ describe('CopyrightControl', () => {
|
|
|
48
48
|
center: [0, 0],
|
|
49
49
|
zoom: 0,
|
|
50
50
|
}),
|
|
51
|
-
layers: [getLayer(true, 'bar')],
|
|
52
51
|
});
|
|
52
|
+
getLayer(true, 'bar').init(map);
|
|
53
53
|
map.setSize([200, 200]);
|
|
54
54
|
map.renderSync();
|
|
55
55
|
});
|
|
@@ -70,7 +70,7 @@ describe('CopyrightControl', () => {
|
|
|
70
70
|
const control = new CopyrightControl();
|
|
71
71
|
control.map = map;
|
|
72
72
|
expect(control.element.innerHTML).toBe('');
|
|
73
|
-
|
|
73
|
+
getLayer('copyright').init(map);
|
|
74
74
|
map.renderSync();
|
|
75
75
|
expect(control.element.innerHTML).toBe('copyright');
|
|
76
76
|
});
|
|
@@ -79,7 +79,7 @@ describe('CopyrightControl', () => {
|
|
|
79
79
|
const control = new CopyrightControl();
|
|
80
80
|
control.map = map;
|
|
81
81
|
expect(control.element.innerHTML).toBe('');
|
|
82
|
-
|
|
82
|
+
getLayer(['copyright 1', 'copyright 2']).init(map);
|
|
83
83
|
map.renderSync();
|
|
84
84
|
expect(control.element.innerHTML).toBe('copyright 1 | copyright 2');
|
|
85
85
|
});
|
|
@@ -88,9 +88,9 @@ describe('CopyrightControl', () => {
|
|
|
88
88
|
const control = new CopyrightControl();
|
|
89
89
|
control.map = map;
|
|
90
90
|
expect(control.element.innerHTML).toBe('');
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
91
|
+
getLayer(['copyright 1', 'copyright 2']).init(map);
|
|
92
|
+
getLayer('copyright 1').init(map);
|
|
93
|
+
getLayer(['copyright 2']).init(map);
|
|
94
94
|
map.renderSync();
|
|
95
95
|
expect(control.element.innerHTML).toBe('copyright 1 | copyright 2');
|
|
96
96
|
});
|
|
@@ -100,9 +100,9 @@ describe('CopyrightControl', () => {
|
|
|
100
100
|
control.map = map;
|
|
101
101
|
expect(control.element.innerHTML).toBe('');
|
|
102
102
|
const layer1 = getLayer('copyright hidden', false);
|
|
103
|
+
layer1.init(map);
|
|
103
104
|
const layer2 = getLayer('copyright', true);
|
|
104
|
-
|
|
105
|
-
map.addLayer(layer2);
|
|
105
|
+
layer2.init(map);
|
|
106
106
|
map.renderSync();
|
|
107
107
|
expect(control.element.innerHTML).toBe('copyright');
|
|
108
108
|
|
|
@@ -115,7 +115,7 @@ describe('CopyrightControl', () => {
|
|
|
115
115
|
});
|
|
116
116
|
|
|
117
117
|
test('should activate the control on construction then deactivate it', () => {
|
|
118
|
-
|
|
118
|
+
getLayer('copyright 1').init(map);
|
|
119
119
|
const control = new CopyrightControl({ active: true });
|
|
120
120
|
control.map = map;
|
|
121
121
|
map.renderSync();
|
|
@@ -133,12 +133,12 @@ describe('CopyrightControl', () => {
|
|
|
133
133
|
});
|
|
134
134
|
|
|
135
135
|
test('should deactivate the control on constrcution then activate it', () => {
|
|
136
|
-
|
|
136
|
+
getLayer('copyright 1').init(map);
|
|
137
137
|
const control = new CopyrightControl({ active: false });
|
|
138
138
|
control.map = map;
|
|
139
139
|
map.renderSync();
|
|
140
140
|
|
|
141
|
-
expect(control.element.parentNode).toBe(map.
|
|
141
|
+
expect(control.element.parentNode).toBe(map.getTargetElement());
|
|
142
142
|
|
|
143
143
|
// Should be activated by default.
|
|
144
144
|
expect(control.active).toBe(false);
|
|
@@ -152,14 +152,14 @@ describe('CopyrightControl', () => {
|
|
|
152
152
|
});
|
|
153
153
|
|
|
154
154
|
test('should add copyrights in the map container element then remove it.', () => {
|
|
155
|
-
|
|
155
|
+
getLayer('copyright value').init(map);
|
|
156
156
|
map.renderSync();
|
|
157
157
|
|
|
158
158
|
const control = new CopyrightControl();
|
|
159
159
|
|
|
160
160
|
// Add control
|
|
161
161
|
control.map = map;
|
|
162
|
-
expect(control.element.parentNode).toBe(map.
|
|
162
|
+
expect(control.element.parentNode).toBe(map.getTargetElement());
|
|
163
163
|
|
|
164
164
|
// Remove control
|
|
165
165
|
control.map = null;
|
|
@@ -167,7 +167,7 @@ describe('CopyrightControl', () => {
|
|
|
167
167
|
});
|
|
168
168
|
|
|
169
169
|
test('should add copyrights in the target element then remove it.', () => {
|
|
170
|
-
|
|
170
|
+
getLayer(['copyright value']).init(map);
|
|
171
171
|
map.renderSync();
|
|
172
172
|
|
|
173
173
|
const target = document.createElement('div');
|
|
@@ -200,7 +200,7 @@ describe('CopyrightControl', () => {
|
|
|
200
200
|
},
|
|
201
201
|
});
|
|
202
202
|
control.map = map;
|
|
203
|
-
|
|
203
|
+
getLayer(['copyright 1', 'copyright 2', 'copyright 3']).init(map);
|
|
204
204
|
map.renderSync();
|
|
205
205
|
|
|
206
206
|
// Add control
|
|
@@ -45,15 +45,17 @@ const getFlatCoordinatesFromSegments = (segmentArray) => {
|
|
|
45
45
|
* Display a route of a specified mean of transport.
|
|
46
46
|
*
|
|
47
47
|
* @example
|
|
48
|
-
* import { Map
|
|
48
|
+
* import { Map } from 'ol';
|
|
49
|
+
* import { RoutingControl } from 'mobility-toolbox-js/ol';
|
|
49
50
|
*
|
|
50
51
|
* const map = new Map({
|
|
51
|
-
* target: 'map'
|
|
52
|
-
* controls: [
|
|
53
|
-
* new RoutingControl()
|
|
54
|
-
* ]
|
|
52
|
+
* target: 'map'
|
|
55
53
|
* });
|
|
56
54
|
*
|
|
55
|
+
* const control = new RoutingControl();
|
|
56
|
+
*
|
|
57
|
+
* control.map = map
|
|
58
|
+
*
|
|
57
59
|
* @classproperty {string} apiKey - Key used for RoutingApi requests.
|
|
58
60
|
* @classproperty {string} stopsApiKey - Key used for Stop lookup requests (defaults to apiKey).
|
|
59
61
|
* @classproperty {string} stopsApiUrl - Url used for Stop lookup requests (defaults to https://api.geops.io/stops/v1/lookup/).
|
|
@@ -724,7 +726,7 @@ class RoutingControl extends Control {
|
|
|
724
726
|
this.map.removeInteraction(this.modifyInteraction);
|
|
725
727
|
|
|
726
728
|
// Add modify interaction, RoutingLayer and listeners
|
|
727
|
-
this.
|
|
729
|
+
this.routingLayer.init(this.map);
|
|
728
730
|
this.map.addInteraction(this.modifyInteraction);
|
|
729
731
|
this.modifyInteraction.setActive(this.modify);
|
|
730
732
|
this.addListeners();
|
|
@@ -738,7 +740,7 @@ class RoutingControl extends Control {
|
|
|
738
740
|
deactivate() {
|
|
739
741
|
if (this.map) {
|
|
740
742
|
// Remove modify interaction, RoutingLayer, listeners and viaPoints
|
|
741
|
-
this.
|
|
743
|
+
this.routingLayer.terminate(this.map);
|
|
742
744
|
this.map.removeInteraction(this.modifyInteraction);
|
|
743
745
|
this.removeListeners();
|
|
744
746
|
this.reset();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fetch from 'jest-fetch-mock';
|
|
2
2
|
import View from 'ol/View';
|
|
3
3
|
import qs from 'query-string';
|
|
4
|
-
import Map from '
|
|
4
|
+
import Map from 'ol/Map';
|
|
5
5
|
import RoutingControl from './RoutingControl';
|
|
6
6
|
|
|
7
7
|
import RoutingControlStation1 from './snapshots/RoutingControlStation1.json';
|
|
@@ -6,17 +6,19 @@ import mixin from '../../common/mixins/SearchMixin';
|
|
|
6
6
|
* Search stations.
|
|
7
7
|
*
|
|
8
8
|
* @example
|
|
9
|
-
* import { Map
|
|
9
|
+
* import { Map } from 'ol';
|
|
10
|
+
* import { StopFinderControl } from 'mobility-toolbox-js/ol';
|
|
10
11
|
*
|
|
11
12
|
* const map = new Map({
|
|
12
13
|
* target: 'map',
|
|
13
|
-
* controls: [
|
|
14
|
-
* new StopFinderControl({
|
|
15
|
-
* apiKey: [yourApiKey]
|
|
16
|
-
* })
|
|
17
|
-
* ]
|
|
18
14
|
* });
|
|
19
15
|
*
|
|
16
|
+
* const control = new StopFinderControl({
|
|
17
|
+
* apiKey: [yourApiKey]
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* control.map = map;
|
|
21
|
+
*
|
|
20
22
|
*
|
|
21
23
|
* @see <a href="/example/ol-search">Openlayers search example</a>
|
|
22
24
|
*
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/{ol → src/ol}/index.js
RENAMED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
export { default as Map } from './Map';
|
|
2
1
|
export { default as Layer } from './layers/Layer';
|
|
3
2
|
export { default as MapboxLayer } from './layers/MapboxLayer';
|
|
3
|
+
export { default as MaplibreLayer } from './layers/MaplibreLayer';
|
|
4
4
|
export { default as MapboxStyleLayer } from './layers/MapboxStyleLayer';
|
|
5
5
|
export { default as RoutingLayer } from './layers/RoutingLayer';
|
|
6
|
-
export { default as TrackerLayer } from './layers/TrackerLayer';
|
|
7
|
-
export { default as TrajservLayer } from './layers/TrajservLayer';
|
|
8
6
|
export { default as TralisLayer } from './layers/TralisLayer';
|
|
9
7
|
export { default as VectorLayer } from './layers/VectorLayer';
|
|
10
8
|
export { default as WMSLayer } from './layers/WMSLayer';
|
|
11
9
|
export { default as CopyrightControl } from './controls/CopyrightControl';
|
|
12
10
|
export { default as RoutingControl } from './controls/RoutingControl';
|
|
13
11
|
export { default as StopFinderControl } from './controls/StopFinderControl';
|
|
12
|
+
export * from '../common/styles';
|
|
13
|
+
export * from './styles';
|
|
@@ -67,6 +67,10 @@ class Layer extends LayerCommon {
|
|
|
67
67
|
return;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
+
if (this.map && this.olLayer) {
|
|
71
|
+
this.map.addLayer(this.olLayer);
|
|
72
|
+
}
|
|
73
|
+
|
|
70
74
|
this.olListenersKeys.push(
|
|
71
75
|
this.map.getLayers().on('remove', (evt) => {
|
|
72
76
|
if (evt.element === this.olLayer) {
|
|
@@ -103,6 +107,11 @@ class Layer extends LayerCommon {
|
|
|
103
107
|
*/
|
|
104
108
|
terminate() {
|
|
105
109
|
unByKey(this.olListenersKeys);
|
|
110
|
+
|
|
111
|
+
if (this.map && this.olLayer) {
|
|
112
|
+
this.map.removeLayer(this.olLayer);
|
|
113
|
+
}
|
|
114
|
+
|
|
106
115
|
super.terminate();
|
|
107
116
|
}
|
|
108
117
|
|
|
@@ -52,13 +52,12 @@ describe('Layer', () => {
|
|
|
52
52
|
expect(spy).toHaveBeenCalledTimes(1);
|
|
53
53
|
});
|
|
54
54
|
|
|
55
|
-
test('should
|
|
55
|
+
test('should remove the layer when we call terminate.', () => {
|
|
56
56
|
const layer = new Layer({ name: 'Layer', olLayer });
|
|
57
57
|
const spy = jest.spyOn(layer, 'terminate');
|
|
58
58
|
layer.init(map);
|
|
59
|
-
map.addLayer(olLayer);
|
|
60
59
|
expect(spy).toHaveBeenCalledTimes(1);
|
|
61
|
-
|
|
60
|
+
layer.terminate(map);
|
|
62
61
|
expect(spy).toHaveBeenCalledTimes(2);
|
|
63
62
|
});
|
|
64
63
|
|
|
@@ -153,16 +152,32 @@ describe('Layer', () => {
|
|
|
153
152
|
expect(spy).toHaveBeenCalledTimes(0);
|
|
154
153
|
expect(spy2).toHaveBeenCalledTimes(0);
|
|
155
154
|
|
|
156
|
-
await map.dispatchEvent({
|
|
157
|
-
|
|
155
|
+
await map.dispatchEvent({
|
|
156
|
+
type: 'pointermove',
|
|
157
|
+
map,
|
|
158
|
+
coordinate: [0, 0],
|
|
159
|
+
});
|
|
160
|
+
await map.dispatchEvent({
|
|
161
|
+
type: 'singleclick',
|
|
162
|
+
map,
|
|
163
|
+
coordinate: [0, 0],
|
|
164
|
+
});
|
|
158
165
|
expect(spy).toHaveBeenCalledTimes(1);
|
|
159
166
|
expect(spy2).toHaveBeenCalledTimes(1);
|
|
160
167
|
spy.mockReset();
|
|
161
168
|
spy2.mockReset();
|
|
162
169
|
|
|
163
170
|
layer.terminate(map);
|
|
164
|
-
await map.dispatchEvent({
|
|
165
|
-
|
|
171
|
+
await map.dispatchEvent({
|
|
172
|
+
type: 'pointermove',
|
|
173
|
+
map,
|
|
174
|
+
coordinate: [0, 0],
|
|
175
|
+
});
|
|
176
|
+
await map.dispatchEvent({
|
|
177
|
+
type: 'singleclick',
|
|
178
|
+
map,
|
|
179
|
+
coordinate: [0, 0],
|
|
180
|
+
});
|
|
166
181
|
expect(spy).toHaveBeenCalledTimes(0);
|
|
167
182
|
expect(spy2).toHaveBeenCalledTimes(0);
|
|
168
183
|
global.console.error.mockRestore();
|