mobility-toolbox-js 2.0.0-beta.33 → 2.0.0-beta.34

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.
Files changed (69) hide show
  1. package/api/RealtimeAPI.js +640 -0
  2. package/api/RoutingAPI.js +65 -0
  3. package/api/StopsAPI.js +70 -0
  4. package/api/index.js +10 -0
  5. package/api/typedefs.js +72 -0
  6. package/common/api/HttpAPI.d.ts +2 -2
  7. package/common/api/HttpAPI.d.ts.map +1 -1
  8. package/common/api/HttpAPI.js +84 -0
  9. package/common/api/WebSocketAPI.js +320 -0
  10. package/common/controls/Control.js +170 -0
  11. package/common/index.js +18 -0
  12. package/common/layers/Layer.js +257 -0
  13. package/common/mixins/CopyrightMixin.js +72 -0
  14. package/common/mixins/MapboxLayerMixin.js +240 -0
  15. package/common/mixins/RealtimeLayerMixin.js +705 -0
  16. package/common/mixins/StopFinderMixin.js +198 -0
  17. package/common/mixins/UserInteractionsLayerMixin.js +225 -0
  18. package/common/styles/index.js +24 -0
  19. package/common/styles/realtimeDefaultStyle.js +248 -0
  20. package/common/styles/realtimeDelayStyle.js +26 -0
  21. package/common/styles/realtimeSimpleStyle.js +24 -0
  22. package/common/typedefs.js +21 -0
  23. package/common/utils/cleanStopTime.js +30 -0
  24. package/common/utils/compareDepartures.js +37 -0
  25. package/common/utils/createCanvas.js +29 -0
  26. package/common/utils/createTrackerFilters.js +77 -0
  27. package/common/utils/getLayersAsFlatArray.js +16 -0
  28. package/common/utils/getMapboxMapCopyrights.js +26 -0
  29. package/common/utils/getMapboxRender.js +77 -0
  30. package/common/utils/getMaplibreRender.js +38 -0
  31. package/common/utils/getRealtimeModeSuffix.js +11 -0
  32. package/common/utils/getUrlWithParams.js +21 -0
  33. package/common/utils/getVehiclePosition.js +66 -0
  34. package/common/utils/index.js +37 -0
  35. package/common/utils/removeDuplicate.js +30 -0
  36. package/common/utils/renderTrajectories.js +119 -0
  37. package/common/utils/sortByDelay.js +22 -0
  38. package/common/utils/timeUtils.js +49 -0
  39. package/common/utils/trackerConfig.js +182 -0
  40. package/iife.js +7 -0
  41. package/index.js +11 -0
  42. package/mapbox/controls/CopyrightControl.js +73 -0
  43. package/mapbox/controls/index.js +6 -0
  44. package/mapbox/index.js +20 -0
  45. package/mapbox/layers/Layer.js +139 -0
  46. package/mapbox/layers/RealtimeLayer.js +312 -0
  47. package/mapbox/layers/index.js +7 -0
  48. package/mapbox/utils.js +57 -0
  49. package/mbt.js.map +2 -2
  50. package/mbt.min.js.map +2 -2
  51. package/ol/controls/CopyrightControl.js +90 -0
  52. package/ol/controls/RoutingControl.js +683 -0
  53. package/ol/controls/StopFinderControl.js +59 -0
  54. package/ol/controls/index.js +9 -0
  55. package/ol/index.js +21 -0
  56. package/ol/layers/Layer.js +180 -0
  57. package/ol/layers/MapboxLayer.js +137 -0
  58. package/ol/layers/MapboxStyleLayer.js +383 -0
  59. package/ol/layers/MaplibreLayer.js +69 -0
  60. package/ol/layers/RealtimeLayer.js +330 -0
  61. package/ol/layers/RoutingLayer.js +116 -0
  62. package/ol/layers/VectorLayer.js +72 -0
  63. package/ol/layers/WMSLayer.js +106 -0
  64. package/ol/layers/index.js +19 -0
  65. package/ol/styles/fullTrajectoryDelayStyle.js +35 -0
  66. package/ol/styles/fullTrajectoryStyle.js +46 -0
  67. package/ol/styles/index.js +7 -0
  68. package/package.json +1 -1
  69. package/setupTests.js +15 -0
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ var proj_1 = require("ol/proj");
19
+ var Control_1 = require("../../common/controls/Control");
20
+ var StopFinderMixin_1 = require("../../common/mixins/StopFinderMixin");
21
+ /**
22
+ * Search stations.
23
+ *
24
+ * @example
25
+ * import { Map } from 'ol';
26
+ * import { StopFinderControl } from 'mobility-toolbox-js/ol';
27
+ *
28
+ * const map = new Map({
29
+ * target: 'map',
30
+ * });
31
+ *
32
+ * const control = new StopFinderControl({
33
+ * apiKey: [yourApiKey]
34
+ * });
35
+ *
36
+ * control.attachToMap(map);
37
+ *
38
+ *
39
+ * @see <a href="/example/ol-search">Openlayers search example</a>
40
+ *
41
+ * @extends {Control}
42
+ * @implements {StopFinderInterface}
43
+ */
44
+ var StopFinderControl = /** @class */ (function (_super) {
45
+ __extends(StopFinderControl, _super);
46
+ function StopFinderControl() {
47
+ return _super !== null && _super.apply(this, arguments) || this;
48
+ }
49
+ /**
50
+ * @private
51
+ */
52
+ StopFinderControl.prototype.onSuggestionClick = function (_a) {
53
+ var geometry = _a.geometry;
54
+ var coord = (0, proj_1.fromLonLat)(geometry.coordinates);
55
+ this.map.getView().setCenter(coord);
56
+ };
57
+ return StopFinderControl;
58
+ }((0, StopFinderMixin_1.default)(Control_1.default)));
59
+ exports.default = StopFinderControl;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StopFinderControl = exports.RoutingControl = exports.CopyrightControl = void 0;
4
+ var CopyrightControl_1 = require("./CopyrightControl");
5
+ Object.defineProperty(exports, "CopyrightControl", { enumerable: true, get: function () { return CopyrightControl_1.default; } });
6
+ var RoutingControl_1 = require("./RoutingControl");
7
+ Object.defineProperty(exports, "RoutingControl", { enumerable: true, get: function () { return RoutingControl_1.default; } });
8
+ var StopFinderControl_1 = require("./StopFinderControl");
9
+ Object.defineProperty(exports, "StopFinderControl", { enumerable: true, get: function () { return StopFinderControl_1.default; } });
package/ol/index.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("../api"), exports);
18
+ __exportStar(require("../common"), exports);
19
+ __exportStar(require("./controls"), exports);
20
+ __exportStar(require("./layers"), exports);
21
+ __exportStar(require("./styles"), exports);
@@ -0,0 +1,180 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __assign = (this && this.__assign) || function () {
18
+ __assign = Object.assign || function(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
+ t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ var Observable_1 = require("ol/Observable");
30
+ var Layer_1 = require("../../common/layers/Layer");
31
+ var UserInteractionsLayerMixin_1 = require("../../common/mixins/UserInteractionsLayerMixin");
32
+ /**
33
+ * A class representing a layer to display on an OpenLayers map.
34
+ *
35
+ * @example
36
+ * import { Layer } from 'mobility-toolbox-js/ol';
37
+ *
38
+ * const layer = new Layer({
39
+ * olLayer: ...,
40
+ * });
41
+ *
42
+ * @see <a href="/example/ol-map">Map example</a>
43
+ *
44
+ * @classproperty {ol/Map~Map} map - The map where the layer is displayed.
45
+ * @extends {Layer}
46
+ */
47
+ var Layer = /** @class */ (function (_super) {
48
+ __extends(Layer, _super);
49
+ /**
50
+ * Constructor.
51
+ *
52
+ * @param {Object} options
53
+ * @param {ol/layer/Layer~Layer} options.olLayer The layer (required).
54
+ * @param {string} [options.name=uuid()] Layer name. Default use a generated uuid.
55
+ * @param {string} [options.key=uuid().toLowerCase()] Layer key, will use options.name.toLowerCase() if not specified.
56
+ * @param {string} [options.copyright=undefined] Copyright-Statement.
57
+ * @param {Array<Layer>} [options.children=[]] Sublayers.
58
+ * @param {Object} [options.properties={}] Application-specific layer properties.
59
+ * @param {boolean} [options.visible=true] If true this layer is the currently visible layer on the map.
60
+ */
61
+ function Layer(options) {
62
+ var _this = _super.call(this, options) || this;
63
+ if (_this.olLayer) {
64
+ _this.olLayer.setVisible(_this.visible);
65
+ }
66
+ return _this;
67
+ }
68
+ /**
69
+ * Define layer's properties.
70
+ *
71
+ * @ignore
72
+ */
73
+ Layer.prototype.defineProperties = function (options) {
74
+ _super.prototype.defineProperties.call(this, options);
75
+ Object.defineProperties(this, {
76
+ olLayer: { value: options.olLayer, writable: true },
77
+ olListenersKeys: {
78
+ value: [],
79
+ },
80
+ });
81
+ };
82
+ /**
83
+ * Initialize the layer and listen to feature clicks.
84
+ * @param {ol/Map~Map} map
85
+ */
86
+ Layer.prototype.attachToMap = function (map) {
87
+ var _this = this;
88
+ var _a, _b, _c, _d;
89
+ _super.prototype.attachToMap.call(this, map);
90
+ if (!this.map) {
91
+ return;
92
+ }
93
+ if (this.olLayer &&
94
+ !((_c = (_b = (_a = this.map) === null || _a === void 0 ? void 0 : _a.getLayers()) === null || _b === void 0 ? void 0 : _b.getArray()) === null || _c === void 0 ? void 0 : _c.includes(this.olLayer))) {
95
+ this.map.addLayer(this.olLayer);
96
+ }
97
+ this.olListenersKeys.push(this.on('change:visible', function () {
98
+ if (_this.olLayer) {
99
+ _this.olLayer.setVisible(_this.visible);
100
+ }
101
+ }));
102
+ this.olListenersKeys.push(this.map.getLayers().on('remove', function (evt) {
103
+ if (evt.element === _this.olLayer) {
104
+ _this.detachFromMap();
105
+ }
106
+ }));
107
+ this.toggleVisibleListeners();
108
+ this.olListenersKeys.push(this.on('change:visible', this.toggleVisibleListeners));
109
+ // We set the copyright to the source used by the layer.
110
+ if (this.copyrights && this.olLayer) {
111
+ var attributions_1 = this.copyrights || [];
112
+ if (this.olLayer.getLayers) {
113
+ this.olLayer
114
+ .getLayers()
115
+ .getArray()
116
+ .forEach(function (layer) {
117
+ var _a;
118
+ (_a = layer.getSource()) === null || _a === void 0 ? void 0 : _a.setAttributions(attributions_1);
119
+ });
120
+ }
121
+ else if (this.olLayer.getSource) {
122
+ (_d = this.olLayer.getSource()) === null || _d === void 0 ? void 0 : _d.setAttributions(attributions_1);
123
+ }
124
+ }
125
+ };
126
+ /**
127
+ * Terminate what was initialized in init function. Remove layer, events...
128
+ */
129
+ Layer.prototype.detachFromMap = function () {
130
+ var _a, _b, _c;
131
+ this.deactivateUserInteractions();
132
+ (0, Observable_1.unByKey)(this.olListenersKeys);
133
+ if (this.olLayer &&
134
+ ((_c = (_b = (_a = this.map) === null || _a === void 0 ? void 0 : _a.getLayers()) === null || _b === void 0 ? void 0 : _b.getArray()) === null || _c === void 0 ? void 0 : _c.includes(this.olLayer))) {
135
+ this.map.removeLayer(this.olLayer);
136
+ }
137
+ _super.prototype.detachFromMap.call(this);
138
+ };
139
+ Layer.prototype.activateUserInteractions = function () {
140
+ this.deactivateUserInteractions();
141
+ if (this.map &&
142
+ this.userInteractions &&
143
+ this.userClickInteractions &&
144
+ this.userClickCallbacks.length) {
145
+ this.singleClickListenerKey = this.map.on('singleclick', this.onUserClickCallback);
146
+ this.olListenersKeys.push(this.singleClickListenerKey);
147
+ }
148
+ if (this.map &&
149
+ this.userInteractions &&
150
+ this.userHoverInteractions &&
151
+ this.userHoverCallbacks.length) {
152
+ this.pointerMoveListenerKey = this.map.on('pointermove', this.onUserMoveCallback);
153
+ }
154
+ };
155
+ Layer.prototype.deactivateUserInteractions = function () {
156
+ (0, Observable_1.unByKey)([this.pointerMoveListenerKey, this.singleClickListenerKey]);
157
+ };
158
+ /**
159
+ * Toggle listeners needed when a layer is avisible or not.
160
+ * @private
161
+ */
162
+ Layer.prototype.toggleVisibleListeners = function () {
163
+ if (this.visible) {
164
+ this.activateUserInteractions();
165
+ }
166
+ else {
167
+ this.deactivateUserInteractions();
168
+ }
169
+ };
170
+ /**
171
+ * Create a copy of the Layer.
172
+ * @param {Object} newOptions Options to override
173
+ * @return {Layer} A Layer
174
+ */
175
+ Layer.prototype.clone = function (newOptions) {
176
+ return new Layer(__assign(__assign({}, this.options), newOptions));
177
+ };
178
+ return Layer;
179
+ }((0, UserInteractionsLayerMixin_1.default)(Layer_1.default)));
180
+ exports.default = Layer;
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __assign = (this && this.__assign) || function () {
18
+ __assign = Object.assign || function(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
+ t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ /* eslint-disable no-underscore-dangle */
30
+ var mapbox_gl_1 = require("mapbox-gl");
31
+ var Layer_1 = require("./Layer");
32
+ var MapboxLayerMixin_1 = require("../../common/mixins/MapboxLayerMixin");
33
+ var utils_1 = require("../../common/utils");
34
+ /**
35
+ * A class representing Mapboxlayer to display on BasicMap
36
+ *
37
+ * @example
38
+ * import { MapboxLayer } from 'mobility-toolbox-js/ol';
39
+ *
40
+ * const layer = new MapboxLayer({
41
+ * url: 'https://maps.geops.io/styles/travic_v2/style.json',
42
+ * apikey: 'yourApiKey',
43
+ * });
44
+ *
45
+ * @classproperty {ol/Map~Map} map - The map where the layer is displayed.
46
+ * @extends {Layer}
47
+ */
48
+ var MapboxLayer = /** @class */ (function (_super) {
49
+ __extends(MapboxLayer, _super);
50
+ function MapboxLayer() {
51
+ return _super !== null && _super.apply(this, arguments) || this;
52
+ }
53
+ /**
54
+ * Initialize the layer and listen to feature clicks.
55
+ * @param {ol/Map~Map} map
56
+ */
57
+ MapboxLayer.prototype.attachToMap = function (map) {
58
+ var _this = this;
59
+ _super.prototype.attachToMap.call(this, map);
60
+ if (!this.map || this.mbMap) {
61
+ return;
62
+ }
63
+ this.olListenersKeys.push(this.map.on('change:size', function () {
64
+ try {
65
+ if (_this.mbMap) {
66
+ _this.mbMap.resize();
67
+ }
68
+ }
69
+ catch (err) {
70
+ // ignore render errors
71
+ // eslint-disable-next-line no-console
72
+ console.warn(err);
73
+ }
74
+ }));
75
+ };
76
+ /**
77
+ * Create the mapbox map.
78
+ * @private
79
+ */
80
+ MapboxLayer.prototype.loadMbMap = function () {
81
+ var _this = this;
82
+ // If the map hasn't been resized, the center could be [NaN,NaN].
83
+ // We set default good value for the mapbox map, to avoid the app crashes.
84
+ var _a = this.map.getView().getCenter(), x = _a[0], y = _a[1];
85
+ if (!x || !y) {
86
+ x = 0;
87
+ y = 0;
88
+ }
89
+ // Options the last render run did happen. If something changes
90
+ // we have to render again
91
+ /** @ignore */
92
+ this.renderState = {
93
+ center: [x, y],
94
+ zoom: null,
95
+ rotation: null,
96
+ visible: null,
97
+ opacity: null,
98
+ size: [0, 0],
99
+ };
100
+ _super.prototype.loadMbMap.call(this);
101
+ this.mbMap.once('load', function () {
102
+ var _a;
103
+ _this.mbMap.resize();
104
+ /** @ignore */
105
+ _this.copyrights = (0, utils_1.getMapboxMapCopyrights)(_this.mbMap) || [];
106
+ (_a = _this.olLayer.getSource()) === null || _a === void 0 ? void 0 : _a.setAttributions(_this.copyrights);
107
+ });
108
+ var mapboxCanvas = this.mbMap.getCanvas();
109
+ if (mapboxCanvas) {
110
+ if (this.options.tabIndex) {
111
+ mapboxCanvas.setAttribute('tabindex', this.options.tabIndex);
112
+ }
113
+ else {
114
+ // With a tabIndex='-1' the mouse events works but the map is not focused when we click on it
115
+ // so we remove completely the tabIndex attribute.
116
+ mapboxCanvas.removeAttribute('tabindex');
117
+ }
118
+ }
119
+ };
120
+ MapboxLayer.prototype.getOlLayerRender = function () {
121
+ return (0, utils_1.getMapboxRender)(this);
122
+ };
123
+ // eslint-disable-next-line class-methods-use-this
124
+ MapboxLayer.prototype.getMapboxMapClass = function () {
125
+ return mapbox_gl_1.Map;
126
+ };
127
+ /**
128
+ * Create a copy of the MapboxLayer.
129
+ * @param {Object} newOptions Options to override
130
+ * @return {MapboxLayer} A MapboxLayer
131
+ */
132
+ MapboxLayer.prototype.clone = function (newOptions) {
133
+ return new MapboxLayer(__assign(__assign({}, this.options), newOptions));
134
+ };
135
+ return MapboxLayer;
136
+ }((0, MapboxLayerMixin_1.default)(Layer_1.default)));
137
+ exports.default = MapboxLayer;