mobility-toolbox-js 2.0.0-beta.30 → 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 (225) hide show
  1. package/api/RealtimeAPI.d.ts +268 -0
  2. package/api/RealtimeAPI.d.ts.map +1 -0
  3. package/api/RealtimeAPI.js +626 -343
  4. package/api/RoutingAPI.d.ts +33 -0
  5. package/api/RoutingAPI.d.ts.map +1 -0
  6. package/api/RoutingAPI.js +65 -15
  7. package/api/StopsAPI.d.ts +36 -0
  8. package/api/StopsAPI.d.ts.map +1 -0
  9. package/api/StopsAPI.js +70 -12
  10. package/api/index.d.ts +5 -0
  11. package/api/index.d.ts.map +1 -0
  12. package/api/index.js +10 -3
  13. package/api/typedefs.d.ts +105 -0
  14. package/api/typedefs.d.ts.map +1 -0
  15. package/api/typedefs.js +72 -0
  16. package/common/api/HttpAPI.d.ts +31 -0
  17. package/common/api/HttpAPI.d.ts.map +1 -0
  18. package/common/api/HttpAPI.js +82 -30
  19. package/common/api/WebSocketAPI.d.ts +95 -0
  20. package/common/api/WebSocketAPI.d.ts.map +1 -0
  21. package/common/api/WebSocketAPI.js +313 -168
  22. package/common/controls/Control.d.ts +74 -0
  23. package/common/controls/Control.d.ts.map +1 -0
  24. package/common/controls/Control.js +167 -78
  25. package/common/index.d.ts +3 -0
  26. package/common/index.d.ts.map +1 -0
  27. package/common/index.js +18 -2
  28. package/common/layers/Layer.d.ts +80 -0
  29. package/common/layers/Layer.d.ts.map +1 -0
  30. package/common/layers/Layer.js +251 -134
  31. package/common/mixins/CopyrightMixin.d.ts +22 -0
  32. package/common/mixins/CopyrightMixin.d.ts.map +1 -0
  33. package/common/mixins/CopyrightMixin.js +70 -22
  34. package/common/mixins/MapboxLayerMixin.d.ts +27 -0
  35. package/common/mixins/MapboxLayerMixin.d.ts.map +1 -0
  36. package/common/mixins/MapboxLayerMixin.js +240 -0
  37. package/common/mixins/RealtimeLayerMixin.d.ts +58 -0
  38. package/common/mixins/RealtimeLayerMixin.d.ts.map +1 -0
  39. package/common/mixins/RealtimeLayerMixin.js +698 -429
  40. package/common/mixins/StopFinderMixin.d.ts +40 -0
  41. package/common/mixins/StopFinderMixin.d.ts.map +1 -0
  42. package/common/mixins/StopFinderMixin.js +195 -107
  43. package/common/mixins/UserInteractionsLayerMixin.d.ts +42 -0
  44. package/common/mixins/UserInteractionsLayerMixin.d.ts.map +1 -0
  45. package/common/mixins/UserInteractionsLayerMixin.js +222 -121
  46. package/common/styles/index.d.ts +5 -0
  47. package/common/styles/index.d.ts.map +1 -0
  48. package/common/styles/index.js +24 -4
  49. package/common/styles/realtimeDefaultStyle.d.ts +15 -0
  50. package/common/styles/realtimeDefaultStyle.d.ts.map +1 -0
  51. package/common/styles/realtimeDefaultStyle.js +236 -190
  52. package/common/styles/realtimeDelayStyle.d.ts +11 -0
  53. package/common/styles/realtimeDelayStyle.d.ts.map +1 -0
  54. package/common/styles/realtimeDelayStyle.js +25 -7
  55. package/common/styles/realtimeSimpleStyle.d.ts +3 -0
  56. package/common/styles/realtimeSimpleStyle.d.ts.map +1 -0
  57. package/common/styles/realtimeSimpleStyle.js +23 -17
  58. package/common/typedefs.d.ts +50 -0
  59. package/common/typedefs.d.ts.map +1 -0
  60. package/common/typedefs.js +21 -0
  61. package/common/utils/cleanStopTime.d.ts +7 -0
  62. package/common/utils/cleanStopTime.d.ts.map +1 -0
  63. package/common/utils/cleanStopTime.js +28 -17
  64. package/common/utils/compareDepartures.d.ts +9 -0
  65. package/common/utils/compareDepartures.d.ts.map +1 -0
  66. package/common/utils/compareDepartures.js +34 -22
  67. package/common/utils/createCanvas.d.ts +9 -0
  68. package/common/utils/createCanvas.d.ts.map +1 -0
  69. package/common/utils/createCanvas.js +28 -16
  70. package/common/utils/createTrackerFilters.d.ts +12 -0
  71. package/common/utils/createTrackerFilters.d.ts.map +1 -0
  72. package/common/utils/createTrackerFilters.js +75 -54
  73. package/common/utils/getLayersAsFlatArray.d.ts +3 -0
  74. package/common/utils/getLayersAsFlatArray.d.ts.map +1 -0
  75. package/common/utils/getLayersAsFlatArray.js +15 -13
  76. package/common/utils/getMapboxMapCopyrights.d.ts +8 -0
  77. package/common/utils/getMapboxMapCopyrights.d.ts.map +1 -0
  78. package/common/utils/getMapboxMapCopyrights.js +24 -17
  79. package/common/utils/getMapboxRender.d.ts +5 -0
  80. package/common/utils/getMapboxRender.d.ts.map +1 -0
  81. package/common/utils/getMapboxRender.js +77 -0
  82. package/common/utils/getMaplibreRender.d.ts +5 -0
  83. package/common/utils/getMaplibreRender.d.ts.map +1 -0
  84. package/common/utils/getMaplibreRender.js +38 -0
  85. package/common/utils/getRealtimeModeSuffix.d.ts +8 -0
  86. package/common/utils/getRealtimeModeSuffix.d.ts.map +1 -0
  87. package/common/utils/getRealtimeModeSuffix.js +11 -2
  88. package/common/utils/getUrlWithParams.d.ts +9 -0
  89. package/common/utils/getUrlWithParams.d.ts.map +1 -0
  90. package/common/utils/getUrlWithParams.js +20 -10
  91. package/common/utils/getVehiclePosition.d.ts +14 -0
  92. package/common/utils/getVehiclePosition.d.ts.map +1 -0
  93. package/common/utils/getVehiclePosition.js +63 -39
  94. package/common/utils/index.d.ts +12 -0
  95. package/common/utils/index.d.ts.map +1 -0
  96. package/common/utils/index.js +37 -9
  97. package/common/utils/removeDuplicate.d.ts +10 -0
  98. package/common/utils/removeDuplicate.d.ts.map +1 -0
  99. package/common/utils/removeDuplicate.js +29 -7
  100. package/common/utils/renderTrajectories.d.ts +20 -0
  101. package/common/utils/renderTrajectories.d.ts.map +1 -0
  102. package/common/utils/renderTrajectories.js +111 -78
  103. package/common/utils/sortByDelay.d.ts +3 -0
  104. package/common/utils/sortByDelay.d.ts.map +1 -0
  105. package/common/utils/sortByDelay.js +21 -17
  106. package/common/utils/timeUtils.d.ts +5 -0
  107. package/common/utils/timeUtils.d.ts.map +1 -0
  108. package/common/utils/timeUtils.js +47 -18
  109. package/common/utils/trackerConfig.d.ts +24 -0
  110. package/common/utils/trackerConfig.d.ts.map +1 -0
  111. package/common/utils/trackerConfig.js +171 -118
  112. package/iife.d.ts +3 -0
  113. package/iife.d.ts.map +1 -0
  114. package/iife.js +7 -0
  115. package/index.d.ts +6 -0
  116. package/index.d.ts.map +1 -0
  117. package/index.js +10 -7
  118. package/mapbox/controls/CopyrightControl.d.ts +32 -0
  119. package/mapbox/controls/CopyrightControl.d.ts.map +1 -0
  120. package/mapbox/controls/CopyrightControl.js +72 -28
  121. package/mapbox/controls/index.d.ts +2 -0
  122. package/mapbox/controls/index.d.ts.map +1 -0
  123. package/mapbox/controls/index.js +6 -1
  124. package/mapbox/index.d.ts +5 -0
  125. package/mapbox/index.d.ts.map +1 -0
  126. package/mapbox/index.js +20 -4
  127. package/mapbox/layers/Layer.d.ts +47 -0
  128. package/mapbox/layers/Layer.d.ts.map +1 -0
  129. package/mapbox/layers/Layer.js +137 -54
  130. package/mapbox/layers/RealtimeLayer.d.ts +118 -0
  131. package/mapbox/layers/RealtimeLayer.d.ts.map +1 -0
  132. package/mapbox/layers/RealtimeLayer.js +310 -183
  133. package/mapbox/layers/index.d.ts +3 -0
  134. package/mapbox/layers/index.d.ts.map +1 -0
  135. package/mapbox/layers/index.js +7 -2
  136. package/mapbox/utils.d.ts +8 -0
  137. package/mapbox/utils.d.ts.map +1 -0
  138. package/mapbox/utils.js +54 -29
  139. package/mbt.js +2052 -2109
  140. package/mbt.js.map +3 -3
  141. package/mbt.min.js +18 -18
  142. package/mbt.min.js.map +3 -3
  143. package/ol/controls/CopyrightControl.d.ts +31 -0
  144. package/ol/controls/CopyrightControl.d.ts.map +1 -0
  145. package/ol/controls/CopyrightControl.js +89 -41
  146. package/ol/controls/RoutingControl.d.ts +180 -0
  147. package/ol/controls/RoutingControl.d.ts.map +1 -0
  148. package/ol/controls/RoutingControl.js +666 -371
  149. package/ol/controls/StopFinderControl.d.ts +32 -0
  150. package/ol/controls/StopFinderControl.d.ts.map +1 -0
  151. package/ol/controls/StopFinderControl.js +59 -10
  152. package/ol/controls/index.d.ts +4 -0
  153. package/ol/controls/index.d.ts.map +1 -0
  154. package/ol/controls/index.js +9 -3
  155. package/ol/index.d.ts +6 -0
  156. package/ol/index.d.ts.map +1 -0
  157. package/ol/index.js +21 -5
  158. package/ol/layers/Layer.d.ts +49 -0
  159. package/ol/layers/Layer.d.ts.map +1 -0
  160. package/ol/layers/Layer.js +178 -81
  161. package/ol/layers/MapboxLayer.d.ts +42 -0
  162. package/ol/layers/MapboxLayer.d.ts.map +1 -0
  163. package/ol/layers/MapboxLayer.js +131 -198
  164. package/ol/layers/MapboxStyleLayer.d.ts +146 -0
  165. package/ol/layers/MapboxStyleLayer.d.ts.map +1 -0
  166. package/ol/layers/MapboxStyleLayer.js +382 -186
  167. package/ol/layers/MaplibreLayer.d.ts +27 -0
  168. package/ol/layers/MaplibreLayer.d.ts.map +1 -0
  169. package/ol/layers/MaplibreLayer.js +67 -138
  170. package/ol/layers/RealtimeLayer.d.ts +119 -0
  171. package/ol/layers/RealtimeLayer.d.ts.map +1 -0
  172. package/ol/layers/RealtimeLayer.js +327 -184
  173. package/ol/layers/RoutingLayer.d.ts +24 -0
  174. package/ol/layers/RoutingLayer.d.ts.map +1 -0
  175. package/ol/layers/RoutingLayer.js +111 -56
  176. package/ol/layers/VectorLayer.d.ts +23 -0
  177. package/ol/layers/VectorLayer.d.ts.map +1 -0
  178. package/ol/layers/VectorLayer.js +71 -21
  179. package/ol/layers/WMSLayer.d.ts +38 -0
  180. package/ol/layers/WMSLayer.d.ts.map +1 -0
  181. package/ol/layers/WMSLayer.js +105 -37
  182. package/ol/layers/index.d.ts +9 -0
  183. package/ol/layers/index.d.ts.map +1 -0
  184. package/ol/layers/index.js +19 -8
  185. package/ol/styles/fullTrajectoryDelayStyle.d.ts +4 -0
  186. package/ol/styles/fullTrajectoryDelayStyle.d.ts.map +1 -0
  187. package/ol/styles/fullTrajectoryDelayStyle.js +32 -28
  188. package/ol/styles/fullTrajectoryStyle.d.ts +4 -0
  189. package/ol/styles/fullTrajectoryStyle.d.ts.map +1 -0
  190. package/ol/styles/fullTrajectoryStyle.js +44 -40
  191. package/ol/styles/index.d.ts +3 -0
  192. package/ol/styles/index.d.ts.map +1 -0
  193. package/ol/styles/index.js +7 -2
  194. package/package.json +14 -36
  195. package/setupTests.d.ts +2 -0
  196. package/setupTests.d.ts.map +1 -0
  197. package/setupTests.js +15 -0
  198. package/types/index.d.ts +7 -6
  199. package/types/routing.d.ts +25 -25
  200. package/types/stops.d.ts +19 -19
  201. package/api/RealtimeAPI.test.js +0 -67
  202. package/api/RoutingAPI.test.js +0 -25
  203. package/api/StopsAPI.test.js +0 -22
  204. package/common/api/HttpAPI.test.js +0 -50
  205. package/common/api/WebSocketAPI.test.js +0 -311
  206. package/common/controls/Control.test.js +0 -87
  207. package/common/layers/Layer.test.js +0 -134
  208. package/common/mixins/UserInteractionsLayerMixin.test.js +0 -199
  209. package/common/utils/createTrackerFilters.test.js +0 -79
  210. package/common/utils/getMapboxMapCopyrights.test.js +0 -40
  211. package/common/utils/removeDuplicate.test.js +0 -19
  212. package/common/utils/timeUtils.test.js +0 -10
  213. package/common/utils/trackerConfig.test.js +0 -23
  214. package/mapbox/layers/Layer.test.js +0 -182
  215. package/mapbox/layers/RealtimeLayer.test.js +0 -10
  216. package/ol/controls/CopyrightControl.test.js +0 -165
  217. package/ol/controls/RoutingControl.test.js +0 -146
  218. package/ol/controls/StopFinderControl.test.js +0 -48
  219. package/ol/layers/Layer.test.js +0 -175
  220. package/ol/layers/MapboxLayer.test.js +0 -160
  221. package/ol/layers/MapboxStyleLayer.test.js +0 -226
  222. package/ol/layers/RealtimeLayer.test.js +0 -67
  223. package/ol/layers/RoutingLayer.test.js +0 -39
  224. package/ol/layers/VectorLayer.test.js +0 -76
  225. package/ol/layers/WMSLayer.test.js +0 -57
@@ -1,204 +1,137 @@
1
- import { toLonLat } from "ol/proj";
2
- import { Map } from "mapbox-gl";
3
- import Source from "ol/source/Source";
4
- import OLLayer from "ol/layer/Layer";
5
- import GeoJSON from "ol/format/GeoJSON";
6
- import Layer from "./Layer";
7
- import { getMapboxMapCopyrights, getUrlWithParams } from "../../common/utils";
8
- export default class MapboxLayer extends Layer {
9
- constructor(options = {}) {
10
- const mbLayer = new OLLayer({
11
- source: new Source({}),
12
- render: (frameState) => {
13
- if (!this.map || !this.mbMap) {
14
- return null;
15
- }
16
- let changed = false;
17
- const canvas = this.mbMap.getCanvas();
18
- const { viewState } = frameState;
19
- const visible = this.olLayer.getVisible();
20
- if (this.renderState.visible !== visible) {
21
- canvas.style.display = visible ? "block" : "none";
22
- this.renderState.visible = visible;
23
- canvas.style.position = "absolute";
24
- }
25
- const opacity = this.olLayer.getOpacity();
26
- if (this.renderState.opacity !== opacity) {
27
- canvas.style.opacity = opacity;
28
- this.renderState.opacity = opacity;
29
- }
30
- const { rotation } = viewState;
31
- if (this.renderState.rotation !== rotation) {
32
- this.mbMap.rotateTo(-(rotation || 0) * 180 / Math.PI, {
33
- animate: false
34
- });
35
- changed = true;
36
- this.renderState.rotation = rotation;
37
- }
38
- if (this.renderState.zoom !== viewState.zoom || this.renderState.center[0] !== viewState.center[0] || this.renderState.center[1] !== viewState.center[1]) {
39
- this.mbMap.jumpTo({
40
- center: toLonLat(viewState.center),
41
- zoom: viewState.zoom - 1,
42
- animate: false
43
- });
44
- changed = true;
45
- this.renderState.zoom = viewState.zoom;
46
- this.renderState.center = viewState.center;
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];
47
23
  }
48
- const size = this.map.getSize();
49
- if (this.renderState.size[0] !== size[0] || this.renderState.size[1] !== size[1]) {
50
- changed = true;
51
- this.renderState.size = size;
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;
52
62
  }
53
- if (this.mbMap && this.mbMap.style && this.mbMap.isStyleLoaded() && changed) {
54
- try {
55
- if (this.mbMap._frame) {
56
- this.mbMap._frame.cancel();
57
- this.mbMap._frame = null;
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);
58
73
  }
59
- this.mbMap._render();
60
- } catch (err) {
61
- console.warn(err);
62
- }
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;
63
88
  }
64
- return this.mbMap.getContainer();
65
- }
66
- });
67
- super({
68
- ...options,
69
- olLayer: mbLayer
70
- });
71
- this.styleUrl = options.url;
72
- this.apiKey = options.apiKey;
73
- this.apiKeyName = options.apiKeyName || "key";
74
- this.updateAttribution = this.updateAttribution.bind(this);
75
- }
76
- attachToMap(map) {
77
- super.attachToMap(map);
78
- if (!this.map || this.mbMap) {
79
- return;
80
- }
81
- this.format = new GeoJSON({
82
- featureProjection: this.map.getView().getProjection()
83
- });
84
- this.loadMbMap();
85
- this.olListenersKeys.push(this.map.on("change:size", () => {
86
- try {
87
- if (this.mbMap) {
88
- this.mbMap.resize();
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
+ }
89
118
  }
90
- } catch (err) {
91
- console.warn(err);
92
- }
93
- }));
94
- }
95
- detachFromMap() {
96
- if (this.mbMap) {
97
- this.mbMap.off("idle", this.updateAttribution);
98
- this.mbMap.triggerRepaint = () => {
99
- };
100
- this.mbMap.remove();
101
- this.mbMap = null;
102
- }
103
- this.loaded = false;
104
- super.detachFromMap();
105
- }
106
- loadMbMap() {
107
- this.olListenersKeys.push(this.map.on("change:target", () => {
108
- this.loadMbMap();
109
- }));
110
- if (!this.map.getTargetElement()) {
111
- return;
112
- }
113
- if (!this.visible) {
114
- this.olListenersKeys.push(this.once("change:visible", () => {
115
- this.loadMbMap();
116
- }));
117
- return;
118
- }
119
- let [x, y] = this.map.getView().getCenter();
120
- if (!x || !y) {
121
- x = 0;
122
- y = 0;
123
- }
124
- const container = document.createElement("div");
125
- container.style.position = "absolute";
126
- container.style.width = "100%";
127
- container.style.height = "100%";
128
- if (!this.apiKey && !this.styleUrl.includes(this.apiKeyName)) {
129
- console.warn(`No apiKey is defined for request to ${this.styleUrl}`);
130
- }
131
- this.mbMap = new Map({
132
- style: getUrlWithParams(this.styleUrl, {
133
- [this.apiKeyName]: this.apiKey
134
- }).toString(),
135
- container,
136
- interactive: false,
137
- trackResize: false,
138
- attributionControl: false,
139
- ...this.options.mapOptions || {}
140
- });
141
- this.renderState = {
142
- center: [x, y],
143
- zoom: null,
144
- rotation: null,
145
- visible: null,
146
- opacity: null,
147
- size: [0, 0]
148
119
  };
149
- this.mbMap.once("load", () => {
150
- this.mbMap.resize();
151
- this.loaded = true;
152
- this.copyrights = getMapboxMapCopyrights(this.mbMap) || [];
153
- this.olLayer.getSource()?.setAttributions(this.copyrights);
154
- this.dispatchEvent({
155
- type: "load",
156
- target: this
157
- });
158
- });
159
- const mapboxCanvas = this.mbMap.getCanvas();
160
- if (mapboxCanvas) {
161
- if (this.options.tabIndex) {
162
- mapboxCanvas.setAttribute("tabindex", this.options.tabIndex);
163
- } else {
164
- mapboxCanvas.removeAttribute("tabindex");
165
- }
166
- }
167
- this.mbMap.on("idle", this.updateAttribution);
168
- }
169
- updateAttribution(evt) {
170
- const newAttributions = getMapboxMapCopyrights(evt.target) || [];
171
- if (this.copyrights.toString() !== newAttributions.toString()) {
172
- this.copyrights = newAttributions;
173
- this.olLayer.getSource()?.setAttributions(newAttributions);
174
- }
175
- }
176
- getFeatureInfoAtCoordinate(coordinate, options) {
177
- if (!options || !this.format || !this.mbMap || !this.mbMap.isStyleLoaded()) {
178
- return Promise.resolve({ coordinate, features: [], layer: this });
179
- }
180
- let pixel = coordinate && this.mbMap.project(toLonLat(coordinate));
181
- if (this.hitTolerance) {
182
- const { x, y } = pixel;
183
- pixel = [
184
- { x: x - this.hitTolerance, y: y - this.hitTolerance },
185
- { x: x + this.hitTolerance, y: y + this.hitTolerance }
186
- ];
187
- }
188
- const features = this.mbMap.queryRenderedFeatures(pixel, options).map((feature) => {
189
- const olFeature = this.format.readFeature(feature);
190
- if (olFeature) {
191
- olFeature.set("mapboxFeature", feature);
192
- }
193
- return olFeature;
194
- });
195
- return Promise.resolve({
196
- layer: this,
197
- features,
198
- coordinate
199
- });
200
- }
201
- clone(newOptions) {
202
- return new MapboxLayer({ ...this.options, ...newOptions });
203
- }
204
- }
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;
@@ -0,0 +1,146 @@
1
+ export default MapboxStyleLayer;
2
+ /**
3
+ * Layer for visualizing a specific set of layer from a MapboxLayer.
4
+ *
5
+ * @example
6
+ * import { MapboxLayer, MapboxStyleLayer } from 'mobility-toolbox-js/ol';
7
+ *
8
+ * const mapboxLayer = new MapboxLayer({
9
+ * url: 'https://maps.geops.io/styles/travic_v2/style.json?key=[yourApiKey]',
10
+ * });
11
+ *
12
+ * const layer = new MapboxStyleLayer({
13
+ * mapboxLayer: mapboxLayer,
14
+ * styleLayersFilter: () => {},
15
+ * });
16
+ *
17
+ * @classproperty {ol/Map~Map} map - The map where the layer is displayed.
18
+ * @extends {Layer}
19
+ */
20
+ declare class MapboxStyleLayer extends Layer {
21
+ /**
22
+ * Constructor.
23
+ *
24
+ * @param {Object} options
25
+ * @param {MapboxLayer} [options.mapboxLayer] The MapboxLayer to use.
26
+ * @param {Function} [options.styleLayersFilter] Filter function to decide which style layer to display.
27
+ */
28
+ constructor(options?: {
29
+ mapboxLayer?: MapboxLayer;
30
+ styleLayersFilter?: Function;
31
+ });
32
+ /**
33
+ * MapboxLayer provided for the style Layer.
34
+ * @type {MapboxLayer}
35
+ * @private
36
+ */
37
+ private mapboxLayer;
38
+ /**
39
+ * Define if the layer has data to display in the current mapbox layer.
40
+ */
41
+ disabled: boolean;
42
+ /**
43
+ * Function to filter features to be displayed.
44
+ * @type {function}
45
+ * @private
46
+ */
47
+ private styleLayersFilter;
48
+ /**
49
+ * Mapbox style layer id where to add the style layers.
50
+ * See [mapbox.map.addLayer](https://docs.mapbox.com/mapbox-gl-js/api/map/#map#addlayer) documentation.
51
+ * @type {String}
52
+ * @private
53
+ */
54
+ private beforeId;
55
+ /**
56
+ * Function to filter features for getFeatureInfoAtCoordinate method.
57
+ * @type {function}
58
+ * @private
59
+ */
60
+ private featureInfoFilter;
61
+ /**
62
+ * Function to query the rendered features.
63
+ * @type {function}
64
+ * @private
65
+ */
66
+ private queryRenderedLayersFilter;
67
+ /**
68
+ * Array of features to highlight.
69
+ * @type {Array<ol/Feature~Feature>}
70
+ * @private
71
+ */
72
+ private highlightedFeatures;
73
+ /**
74
+ * Array of selected features.
75
+ * @type {Array<ol/Feature~Feature>}
76
+ * @private
77
+ */
78
+ private selectedFeatures;
79
+ /**
80
+ * Array of mapbox style layers to add.
81
+ * @type {Array<mapboxgl.styleLayer>}
82
+ * @private
83
+ */
84
+ private styleLayers;
85
+ /** @ignore */
86
+ addStyleLayers(): void;
87
+ /**
88
+ * On Mapbox map load callback function. Add style layers and dynaimc filters.
89
+ * @ignore
90
+ */
91
+ onLoad(): void;
92
+ /** @private */
93
+ private addDynamicFilters;
94
+ /**
95
+ * Terminate the layer.
96
+ * @param {mapboxgl.Map} map the mapbox map.
97
+ * @override
98
+ */
99
+ override detachFromMap(map: mapboxgl.Map): void;
100
+ /** @ignore */
101
+ removeStyleLayers(): void;
102
+ /**
103
+ * Request feature information for a given coordinate.
104
+ * @param {ol/coordinate~Coordinate} coordinate Coordinate to request the information at.
105
+ * @return {Promise<FeatureInfo>} Promise with features, layer and coordinate.
106
+ */
107
+ getFeatureInfoAtCoordinate(coordinate: any): Promise<FeatureInfo>;
108
+ /**
109
+ * Set filter that determines which features should be rendered in a style layer.
110
+ * @param {mapboxgl.filter} filter Determines which features should be rendered in a style layer.
111
+ */
112
+ setFilter(filter: mapboxgl.filter): void;
113
+ /**
114
+ * Set if features are hovered or not.
115
+ * @param {Array<ol/Feature~Feature>} features
116
+ * @param {boolean} state Is the feature hovered
117
+ * @private
118
+ */
119
+ private setHoverState;
120
+ /**
121
+ * Select a list of features.
122
+ * @param {Array<ol/Feature~Feature>} [features=[]] Features to select.
123
+ * @private
124
+ */
125
+ private select;
126
+ /**
127
+ * Highlight a list of features.
128
+ * @param {Array<ol/Feature~Feature>} [features=[]] Features to highlight.
129
+ * @private
130
+ */
131
+ private highlight;
132
+ /**
133
+ * Apply visibility to style layers that fits the styleLayersFilter function.
134
+ * @param {Event} evt Layer's event that has called the function.
135
+ * @private
136
+ */
137
+ private applyLayoutVisibility;
138
+ /**
139
+ * Create a copy of the MapboxStyleLayer.
140
+ * @param {Object} newOptions Options to override.
141
+ * @return {MapboxStyleLayer} A MapboxStyleLayer.
142
+ */
143
+ clone(newOptions: any): MapboxStyleLayer;
144
+ }
145
+ import Layer from "./Layer";
146
+ //# sourceMappingURL=MapboxStyleLayer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MapboxStyleLayer.d.ts","sourceRoot":"","sources":["../../../src/ol/layers/MapboxStyleLayer.js"],"names":[],"mappings":";AAGA;;;;;;;;;;;;;;;;;GAiBG;AACH;IACE;;;;;;OAMG;IACH;QAHiC,WAAW;QACd,iBAAiB;OA4F9C;IAvFC;;;;OAIG;IACH,oBAAsC;IAEtC;;OAEG;IACH,kBAAqB;IAErB;;;;OAIG;IACH,0BAAkD;IAElD;;;;;OAKG;IACH,iBAAgC;IAEhC;;;;OAIG;IACH,0BAAoE;IAEpE;;;;OAIG;IACH,kCAAkE;IAElE;;;;OAIG;IACH,4BAA6B;IAE7B;;;;OAIG;IACH,yBAA0B;IAE1B;;;;OAIG;IACH,oBACyE;IAiG3E,cAAc;IACd,uBAcC;IAiBD;;;OAGG;IACH,eAaC;IAtIG,eAAe;IACf,0BAMC;IAgEL;;;;OAIG;IACH,gDAOC;IAmBD,cAAc;IACd,0BAYC;IAqBD;;;;OAIG;IACH,6CAFY,QAAQ,WAAW,CAAC,CAiC/B;IAED;;;OAGG;IACH,yCAYC;IAED;;;;;OAKG;IACH,sBA8BC;IAED;;;;OAIG;IACH,eAIC;IAED;;;;OAIG;IACH,kBAeC;IAED;;;;OAIG;IAEH,8BA8BC;IAED;;;;OAIG;IACH,wBAFY,gBAAgB,CAI3B;CACF"}