mobility-toolbox-js 3.0.0-beta.1 → 3.0.0-beta.11

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 (92) hide show
  1. package/api/HttpAPI.d.ts +20 -0
  2. package/api/HttpAPI.js +1 -11
  3. package/api/RealtimeAPI.d.ts +365 -0
  4. package/api/RealtimeAPI.js +101 -88
  5. package/api/RoutingAPI.d.ts +37 -0
  6. package/api/RoutingAPI.js +1 -1
  7. package/api/StopsAPI.d.ts +44 -0
  8. package/api/StopsAPI.js +15 -9
  9. package/api/WebSocketAPI.d.ts +153 -0
  10. package/api/index.d.ts +3 -0
  11. package/api/typedefs.d.ts +178 -0
  12. package/common/controls/StopFinderControlCommon.d.ts +53 -0
  13. package/common/index.d.ts +2 -0
  14. package/common/mixins/RealtimeLayerMixin.d.ts +273 -0
  15. package/common/styles/index.d.ts +4 -0
  16. package/common/styles/realtimeDefaultStyle.d.ts +36 -0
  17. package/common/styles/realtimeDelayStyle.d.ts +12 -0
  18. package/common/styles/realtimeHeadingStyle.d.ts +12 -0
  19. package/common/styles/realtimeSimpleStyle.d.ts +4 -0
  20. package/common/typedefs.d.ts +212 -0
  21. package/common/utils/compareDepartures.d.ts +10 -0
  22. package/common/utils/constants.d.ts +5 -0
  23. package/common/utils/createCanvas.d.ts +10 -0
  24. package/common/utils/createDefaultCopyrightElt.d.ts +5 -0
  25. package/common/utils/createDefaultStopFinderElt.d.ts +5 -0
  26. package/common/utils/createRealtimeFilters.d.ts +12 -0
  27. package/common/utils/debounceDeparturesMessages.d.ts +12 -0
  28. package/common/utils/debounceWebsocketMessages.d.ts +11 -0
  29. package/common/utils/getLayersAsFlatArray.d.ts +3 -0
  30. package/common/utils/getLayersAsFlatArray.js +5 -1
  31. package/common/utils/getMapGlCopyrights.d.ts +17 -0
  32. package/common/utils/getRealtimeModeSuffix.d.ts +9 -0
  33. package/common/utils/getUrlWithParams.d.ts +8 -0
  34. package/common/utils/getVehiclePosition.d.ts +16 -0
  35. package/common/utils/getVehiclePosition.js +3 -2
  36. package/common/utils/index.d.ts +16 -0
  37. package/common/utils/realtimeConfig.d.ts +64 -0
  38. package/common/utils/removeDuplicate.d.ts +9 -0
  39. package/common/utils/renderTrajectories.d.ts +16 -0
  40. package/common/utils/sortAndFilterDepartures.d.ts +15 -0
  41. package/common/utils/sortByDelay.d.ts +3 -0
  42. package/common/utils/timeUtils.d.ts +23 -0
  43. package/common/utils/toMercatorExtent.d.ts +5 -0
  44. package/iife.d.ts +2 -0
  45. package/index.d.ts +9 -0
  46. package/maplibre/controls/CopyrightControl.d.ts +35 -0
  47. package/maplibre/controls/index.d.ts +1 -0
  48. package/maplibre/index.d.ts +5 -0
  49. package/maplibre/layers/Layer.d.ts +28 -0
  50. package/maplibre/layers/RealtimeLayer.d.ts +160 -0
  51. package/maplibre/layers/RealtimeLayer.js +2 -2
  52. package/maplibre/layers/index.d.ts +2 -0
  53. package/maplibre/utils/getMercatorResolution.d.ts +7 -0
  54. package/maplibre/utils/getSourceCoordinates.d.ts +7 -0
  55. package/maplibre/utils/index.d.ts +2 -0
  56. package/mbt.js +5752 -6987
  57. package/mbt.js.map +4 -4
  58. package/mbt.min.js +55 -55
  59. package/mbt.min.js.map +4 -4
  60. package/ol/controls/CopyrightControl.d.ts +31 -0
  61. package/ol/controls/CopyrightControl.js +18 -8
  62. package/ol/controls/RoutingControl.d.ts +209 -0
  63. package/ol/controls/RoutingControl.js +4 -1
  64. package/ol/controls/StopFinderControl.d.ts +37 -0
  65. package/ol/controls/StopFinderControl.js +4 -1
  66. package/ol/controls/index.d.ts +3 -0
  67. package/ol/index.d.ts +6 -0
  68. package/ol/layers/MaplibreLayer.d.ts +183 -0
  69. package/ol/layers/MaplibreLayer.js +133 -10
  70. package/ol/layers/MaplibreStyleLayer.d.ts +241 -0
  71. package/ol/layers/MaplibreStyleLayer.js +61 -46
  72. package/ol/layers/RealtimeLayer.d.ts +285 -0
  73. package/ol/layers/RealtimeLayer.js +12 -6
  74. package/ol/layers/index.d.ts +3 -0
  75. package/ol/mixins/MobilityLayerMixin.d.ts +98 -0
  76. package/ol/mixins/MobilityLayerMixin.js +1 -4
  77. package/ol/mixins/PropertiesLayerMixin.d.ts +127 -0
  78. package/ol/mixins/PropertiesLayerMixin.js +6 -65
  79. package/ol/renderers/MaplibreLayerRenderer.d.ts +20 -0
  80. package/ol/renderers/MaplibreStyleLayerRenderer.d.ts +20 -0
  81. package/ol/renderers/RealtimeLayerRenderer.d.ts +22 -0
  82. package/ol/renderers/RealtimeLayerRenderer.js +9 -9
  83. package/ol/styles/fullTrajectoryDelayStyle.d.ts +6 -0
  84. package/ol/styles/fullTrajectoryStyle.d.ts +5 -0
  85. package/ol/styles/index.d.ts +3 -0
  86. package/ol/styles/routingStyle.d.ts +4 -0
  87. package/ol/utils/getFeatureInfoAtCoordinate.d.ts +8 -0
  88. package/ol/utils/getFeatureInfoAtCoordinate.js +2 -2
  89. package/ol/utils/index.d.ts +1 -0
  90. package/package.json +19 -21
  91. package/setupTests.d.ts +1 -0
  92. package/ol/layers/MapGlLayer.js +0 -142
@@ -1,12 +1,10 @@
1
- import BaseEvent from 'ol/events/Event';
2
1
  import { getUid } from 'ol';
3
2
  import getLayersAsFlatArray from '../../common/utils/getLayersAsFlatArray';
4
3
  /**
5
- * This mixin adds some properties to access some ol properties easily ansd also
6
- * the management of a hierarchy of layers using children, parent and group property.
4
+ * This mixin adds some properties to access ol custom properties easily.
7
5
  */
8
6
  function PropertiesLayerMixin(Base) {
9
- return class extends Base {
7
+ return class PropertiesLayer extends Base {
10
8
  get children() {
11
9
  return this.get('children') || [];
12
10
  }
@@ -71,8 +69,9 @@ function PropertiesLayerMixin(Base) {
71
69
  set visible(newValue) {
72
70
  this.setVisible(newValue);
73
71
  }
74
- constructor(options) {
72
+ constructor(...args) {
75
73
  var _a;
74
+ const options = args[0];
76
75
  super(options);
77
76
  this.options = {};
78
77
  this.olListenersKeys = [];
@@ -87,29 +86,11 @@ function PropertiesLayerMixin(Base) {
87
86
  if (evt.key === 'children') {
88
87
  this.onChildrenChange(evt.oldValue);
89
88
  }
90
- }),
91
- // Manage group visiblity
92
- this.on('change:visible', () => {
93
- this.onVisibleChange();
94
- }),
95
- // Listen for group visiblity change
96
- // if a layer from a group is newly visible we hide the others.
97
- // @ts-ignore
98
- this.on(`change:visible:group`, (evt) => {
99
- // We hide layer of the same group
100
- if (this.group === evt.target.group &&
101
- this !== evt.target &&
102
- this.visible) {
103
- this.visible = false;
104
- // Propagate event to parent
105
- }
106
- else if (this.children) {
107
- this.children.forEach((child) => child.dispatchEvent(evt));
108
- }
109
89
  }));
110
90
  this.options = options;
111
91
  this.children = options.children || []; // Trigger the on children change event
112
92
  }
93
+ // @ts-expect-error - this is a mixin
113
94
  setMapInternal(map) {
114
95
  super.setMapInternal(map);
115
96
  if (map) {
@@ -129,46 +110,6 @@ function PropertiesLayerMixin(Base) {
129
110
  child.set('parent', this);
130
111
  });
131
112
  }
132
- /** @private */
133
- onVisibleChange() {
134
- const parent = this.get('parent');
135
- const children = this.get('children') || [];
136
- if (this.getVisible()) {
137
- const group = this.get('group');
138
- // We make the parent visible
139
- if (parent) {
140
- parent.setVisible(true);
141
- }
142
- // If children doesn't contain any visible layers, we display all children.
143
- if (children && !children.some((child) => child.getVisible())) {
144
- children.forEach((child) => {
145
- child.setVisible(true);
146
- });
147
- }
148
- // Warn the same group that a new layer is visible
149
- if (parent && group) {
150
- // We search for the higher parent then it will dispatch to all the tree.
151
- let higherParent = parent;
152
- while (higherParent.get('parent')) {
153
- higherParent = higherParent.get('parent');
154
- }
155
- const evt = new BaseEvent(`change:visible:group`);
156
- evt.target = this;
157
- higherParent.dispatchEvent(evt);
158
- }
159
- }
160
- else {
161
- // We hide all the children
162
- children.forEach((child) => {
163
- child.setVisible(false);
164
- });
165
- // If the parent has no more visible child we also hide it.
166
- if ((parent === null || parent === void 0 ? void 0 : parent.getVisible()) &&
167
- !(parent === null || parent === void 0 ? void 0 : parent.get('children').find((child) => child.getVisible()))) {
168
- parent.setVisible(false);
169
- }
170
- }
171
- }
172
113
  /**
173
114
  * Initialize the layer with the map passed in parameters.
174
115
  *
@@ -189,7 +130,7 @@ function PropertiesLayerMixin(Base) {
189
130
  this.map.removeLayer(child);
190
131
  });
191
132
  // @ts-ignore
192
- (super.detachFromMap || (() => { }))(map);
133
+ (super.detachFromMap || (() => { }))();
193
134
  }
194
135
  /**
195
136
  * Return the an array containing all the descendants of the layer in a flat array. Including the current layer.
@@ -0,0 +1,20 @@
1
+ import { FrameState } from 'ol/Map';
2
+ import LayerRenderer from 'ol/renderer/Layer';
3
+ import { Coordinate } from 'ol/coordinate';
4
+ import { FeatureCallback } from 'ol/renderer/vector';
5
+ import { Feature } from 'ol';
6
+ import { Geometry } from 'ol/geom';
7
+ import { Pixel } from 'ol/pixel';
8
+ import type MaplibreLayer from '../layers/MaplibreLayer';
9
+ /**
10
+ * This class is a renderer for Maplibre Layer to be able to use the native ol
11
+ * functionnalities like map.getFeaturesAtPixel or map.hasFeatureAtPixel.
12
+ * @private
13
+ */
14
+ export default class MaplibreLayerRenderer extends LayerRenderer<MaplibreLayer> {
15
+ getFeaturesAtCoordinate(coordinate: Coordinate | undefined, hitTolerance?: number): Feature<Geometry>[];
16
+ prepareFrame(): boolean;
17
+ renderFrame(frameState: FrameState): HTMLElement | null;
18
+ getFeatures(pixel: Pixel): Promise<Feature<Geometry>[]>;
19
+ forEachFeatureAtCoordinate<Feature>(coordinate: Coordinate, frameState: FrameState, hitTolerance: number, callback: FeatureCallback<Feature>): Feature | undefined;
20
+ }
@@ -0,0 +1,20 @@
1
+ import { FrameState } from 'ol/Map';
2
+ import LayerRenderer from 'ol/renderer/Layer';
3
+ import { Coordinate } from 'ol/coordinate';
4
+ import { FeatureCallback } from 'ol/renderer/vector';
5
+ import { Feature } from 'ol';
6
+ import { Geometry } from 'ol/geom';
7
+ import { Pixel } from 'ol/pixel';
8
+ import type { MaplibreStyleLayer } from '../layers';
9
+ /**
10
+ * This class is a renderer for Maplibre Layer to be able to use the native ol
11
+ * functionnalities like map.getFeaturesAtPixel or map.hasFeatureAtPixel.
12
+ * @private
13
+ */
14
+ export default class MaplibreStyleLayerRenderer extends LayerRenderer<MaplibreStyleLayer> {
15
+ getFeaturesAtCoordinate(coordinate: Coordinate | undefined, hitTolerance?: number): Feature<Geometry>[];
16
+ prepareFrame(): boolean;
17
+ renderFrame(): null;
18
+ getFeatures(pixel: Pixel): Promise<Feature<Geometry>[]>;
19
+ forEachFeatureAtCoordinate<Feature>(coordinate: Coordinate, frameState: FrameState, hitTolerance: number, callback: FeatureCallback<Feature>): Feature | undefined;
20
+ }
@@ -0,0 +1,22 @@
1
+ import { FrameState } from 'ol/Map';
2
+ import { Coordinate } from 'ol/coordinate';
3
+ import { FeatureCallback } from 'ol/renderer/vector';
4
+ import { Feature } from 'ol';
5
+ import { Geometry } from 'ol/geom';
6
+ import { Pixel } from 'ol/pixel';
7
+ import CanvasLayerRenderer from 'ol/renderer/canvas/Layer';
8
+ import type RealtimeLayer from '../layers/RealtimeLayer';
9
+ /**
10
+ * This class is a renderer for Maplibre Layer to be able to use the native ol
11
+ * functionnalities like map.getFeaturesAtPixel or map.hasFeatureAtPixel.
12
+ * @private
13
+ */
14
+ export default class RealtimeLayerRenderer extends CanvasLayerRenderer<RealtimeLayer> {
15
+ private canvas;
16
+ prepareFrame(): boolean;
17
+ renderFrame(frameState: FrameState): HTMLElement;
18
+ getData(pixel: Pixel): Uint8ClampedArray | null;
19
+ getFeatures(pixel: Pixel): Promise<Feature<Geometry>[]>;
20
+ forEachFeatureAtCoordinate<Feature>(coordinate: Coordinate, frameState: FrameState, hitTolerance: number, callback: FeatureCallback<Feature>): Feature | undefined;
21
+ getFeaturesAtCoordinate(coordinate: Coordinate | undefined, hitTolerance?: number): Feature<Geometry>[];
22
+ }
@@ -16,7 +16,6 @@ export default class RealtimeLayerRenderer extends CanvasLayerRenderer {
16
16
  return true;
17
17
  }
18
18
  renderFrame(frameState) {
19
- var _a;
20
19
  const { canvas, renderedViewState } = this.getLayer();
21
20
  if (!this.container) {
22
21
  this.container = document.createElement('div');
@@ -24,7 +23,7 @@ export default class RealtimeLayerRenderer extends CanvasLayerRenderer {
24
23
  this.container.style.position = 'absolute';
25
24
  this.container.style.width = '100%';
26
25
  this.container.style.height = '100%';
27
- if (canvas) {
26
+ if (canvas instanceof HTMLCanvasElement) {
28
27
  canvas.style.position = 'absolute';
29
28
  canvas.style.top = '0';
30
29
  canvas.style.left = '0';
@@ -41,12 +40,12 @@ export default class RealtimeLayerRenderer extends CanvasLayerRenderer {
41
40
  context === null || context === void 0 ? void 0 : context.clearRect(0, 0, canvas === null || canvas === void 0 ? void 0 : canvas.width, canvas === null || canvas === void 0 ? void 0 : canvas.height);
42
41
  }
43
42
  else {
44
- const pixelCenterRendered = (_a = this.getLayer()
45
- .getMapInternal()) === null || _a === void 0 ? void 0 : _a.getPixelFromCoordinate(renderedCenter);
46
- const pixelCenter = this.getLayer()
47
- .getMapInternal()
48
- .getPixelFromCoordinate(center);
49
- this.container.style.transform = composeCssTransform(pixelCenterRendered[0] - pixelCenter[0], pixelCenterRendered[1] - pixelCenter[1], renderedResolution / resolution, renderedResolution / resolution, rotation - renderedRotation, 0, 0);
43
+ const map = this.getLayer().getMapInternal();
44
+ const pixelCenterRendered = map === null || map === void 0 ? void 0 : map.getPixelFromCoordinate(renderedCenter);
45
+ const pixelCenter = map === null || map === void 0 ? void 0 : map.getPixelFromCoordinate(center);
46
+ if (pixelCenterRendered && pixelCenter) {
47
+ this.container.style.transform = composeCssTransform(pixelCenterRendered[0] - pixelCenter[0], pixelCenterRendered[1] - pixelCenter[1], renderedResolution / resolution, renderedResolution / resolution, rotation - renderedRotation, 0, 0);
48
+ }
50
49
  }
51
50
  }
52
51
  return this.container;
@@ -83,12 +82,13 @@ export default class RealtimeLayerRenderer extends CanvasLayerRenderer {
83
82
  return features === null || features === void 0 ? void 0 : features[0];
84
83
  }
85
84
  getFeaturesAtCoordinate(coordinate, hitTolerance = 5) {
85
+ var _a;
86
86
  if (!coordinate) {
87
87
  return [];
88
88
  }
89
89
  const layer = this.getLayer();
90
90
  const map = layer.getMapInternal();
91
- const resolution = map.getView().getResolution();
91
+ const resolution = ((_a = map === null || map === void 0 ? void 0 : map.getView()) === null || _a === void 0 ? void 0 : _a.getResolution()) || 1;
92
92
  const nb = 10;
93
93
  const ext = buffer([...coordinate, ...coordinate], hitTolerance * resolution);
94
94
  let features = [];
@@ -0,0 +1,6 @@
1
+ import { Style } from 'ol/style';
2
+ /**
3
+ * @private
4
+ */
5
+ declare const fullTrajectoryDelaystyle: () => Style[];
6
+ export default fullTrajectoryDelaystyle;
@@ -0,0 +1,5 @@
1
+ import type { FeatureLike } from 'ol/Feature';
2
+ import { Style } from 'ol/style';
3
+ /** @private */
4
+ declare const fullTrajectorystyle: (feature: FeatureLike, resolution: number, options: any) => Style[];
5
+ export default fullTrajectorystyle;
@@ -0,0 +1,3 @@
1
+ export { default as fullTrajectoryStyle } from "./fullTrajectoryStyle";
2
+ export { default as fullTrajectoryDelayStyle } from "./fullTrajectoryDelayStyle";
3
+ export { default as routingStyle } from "./routingStyle";
@@ -0,0 +1,4 @@
1
+ import { StyleFunction } from 'ol/style/Style';
2
+ /** @private */
3
+ declare const routingStyle: StyleFunction;
4
+ export default routingStyle;
@@ -0,0 +1,8 @@
1
+ import type { Coordinate } from 'ol/coordinate';
2
+ import type { Layer } from 'ol/layer';
3
+ import { LayerGetFeatureInfoResponse } from '../../types';
4
+ /**
5
+ * @private
6
+ */
7
+ declare const getFeatureInfoAtCoordinate: (coordinate: Coordinate, layers: Layer[], hitTolerance?: number) => Promise<LayerGetFeatureInfoResponse[]>;
8
+ export default getFeatureInfoAtCoordinate;
@@ -36,7 +36,7 @@ let abortControllers = {};
36
36
  /**
37
37
  * @private
38
38
  */
39
- const getFeatureInfoAtCoordinate = (coordinate, layers, hitTolerance = 5) => __awaiter(void 0, void 0, void 0, function* () {
39
+ const getFeatureInfoAtCoordinate = (coordinate_1, layers_1, ...args_1) => __awaiter(void 0, [coordinate_1, layers_1, ...args_1], void 0, function* (coordinate, layers, hitTolerance = 5) {
40
40
  // Kill all previous requests
41
41
  Object.values(abortControllers).forEach((abortController) => {
42
42
  abortController === null || abortController === void 0 ? void 0 : abortController.abort();
@@ -63,7 +63,7 @@ const getFeatureInfoAtCoordinate = (coordinate, layers, hitTolerance = 5) => __a
63
63
  const source = layer === null || layer === void 0 ? void 0 : layer.getSource();
64
64
  // @ts-ignore
65
65
  if (source === null || source === void 0 ? void 0 : source.getFeatureInfoUrl) {
66
- const id = getUid(this);
66
+ const id = getUid(layer);
67
67
  // Abort and recreates one controller per layer
68
68
  (_c = abortControllers[id]) === null || _c === void 0 ? void 0 : _c.abort();
69
69
  abortControllers[id] = new AbortController();
@@ -0,0 +1 @@
1
+ export { default as getFeatureInfoAtCoordinate } from "./getFeatureInfoAtCoordinate";
package/package.json CHANGED
@@ -2,9 +2,8 @@
2
2
  "name": "mobility-toolbox-js",
3
3
  "license": "MIT",
4
4
  "description": "Toolbox for JavaScript applications in the domains of mobility and logistics.",
5
- "version": "3.0.0-beta.1",
5
+ "version": "3.0.0-beta.11",
6
6
  "homepage": "https://mobility-toolbox-js.geops.io/",
7
- "module": "index.js",
8
7
  "exports": {
9
8
  ".": "./index.js",
10
9
  "./api": "./api/index.js",
@@ -24,10 +23,10 @@
24
23
  "ol": ">=7"
25
24
  },
26
25
  "devDependencies": {
27
- "@babel/preset-env": "^7.24.0",
28
- "@babel/preset-typescript": "^7.23.3",
29
- "@commitlint/cli": "19.0.3",
30
- "@commitlint/config-conventional": "19.0.3",
26
+ "@babel/preset-env": "^7.24.5",
27
+ "@babel/preset-typescript": "^7.24.1",
28
+ "@commitlint/cli": "19.3.0",
29
+ "@commitlint/config-conventional": "19.2.2",
31
30
  "@types/geojson": "7946.0.14",
32
31
  "@types/lodash.debounce": "4.0.9",
33
32
  "@types/lodash.throttle": "4.1.9",
@@ -35,10 +34,10 @@
35
34
  "@types/offscreencanvas": "2019.7.3",
36
35
  "@types/topojson": "3.2.6",
37
36
  "@types/uuid": "9.0.8",
38
- "@typescript-eslint/eslint-plugin": "7.1.0",
39
- "@typescript-eslint/parser": "7.1.0",
40
- "cypress": "13.6.6",
41
- "esbuild": "0.20.1",
37
+ "@typescript-eslint/eslint-plugin": "7.8.0",
38
+ "@typescript-eslint/parser": "7.8.0",
39
+ "cypress": "13.8.1",
40
+ "esbuild": "0.21.1",
42
41
  "esdoc": "1.1.0",
43
42
  "esdoc-ecmascript-proposal-plugin": "1.0.0",
44
43
  "esdoc-publish-html-plugin": "1.1.2",
@@ -46,13 +45,13 @@
46
45
  "esdoc-typescript-plugin": "1.0.1",
47
46
  "eslint": "8.57.0",
48
47
  "eslint-config-airbnb": "19.0.4",
49
- "eslint-config-airbnb-typescript": "17.1.0",
48
+ "eslint-config-airbnb-typescript": "18.0.0",
50
49
  "eslint-config-prettier": "9.1.0",
51
- "eslint-plugin-cypress": "2.15.1",
50
+ "eslint-plugin-cypress": "3.2.0",
52
51
  "eslint-plugin-import": "2.29.1",
53
52
  "eslint-plugin-jsx-a11y": "6.8.0",
54
53
  "eslint-plugin-prettier": "5.1.3",
55
- "eslint-plugin-react": "7.33.2",
54
+ "eslint-plugin-react": "7.34.1",
56
55
  "fixpack": "4.0.0",
57
56
  "husky": "9.0.11",
58
57
  "is-ci": "3.0.1",
@@ -64,23 +63,22 @@
64
63
  "jest-transformer-svg": "2.0.2",
65
64
  "jest-websocket-mock": "2.5.0",
66
65
  "lint-staged": "15.2.2",
67
- "maplibre-gl": "4.0.2",
66
+ "maplibre-gl": "4.2.0",
68
67
  "mock-socket": "9.3.1",
69
- "next": "14.1.0",
68
+ "next": "14.2.3",
70
69
  "next-transpile-modules": "10.0.1",
71
- "ol": "9.0.0",
72
- "openapi-typescript": "6.7.4",
70
+ "ol": "9.1.0",
71
+ "openapi-typescript": "6.7.5",
73
72
  "prettier": "3.2.5",
74
73
  "raw-loader": "4.0.2",
75
74
  "sort-json": "2.0.1",
76
75
  "standard-version": "9.5.0",
77
76
  "start-server-and-test": "2.0.3",
78
- "stylelint": "16.2.1",
77
+ "stylelint": "16.5.0",
79
78
  "stylelint-config-recommended-scss": "14.0.0",
80
79
  "stylelint-config-standard": "36.0.0",
81
- "stylelint-scss": "6.1.0",
82
- "typedoc": "^0.25.9",
83
- "typescript": "5.3.3"
80
+ "stylelint-scss": "6.3.0",
81
+ "typescript": "5.4.5"
84
82
  },
85
83
  "scripts": {
86
84
  "apidoc": "esdoc && cp apidoc/index.json doc/src/components/Esdoc",
@@ -0,0 +1 @@
1
+ export {};
@@ -1,142 +0,0 @@
1
- import Source from 'ol/source/Source';
2
- import BaseEvent from 'ol/events/Event';
3
- import Layer from 'ol/layer/Layer';
4
- import debounce from 'lodash.debounce';
5
- import { getUrlWithParams, getMapGlCopyrights } from '../../common/utils';
6
- import MobilityLayerMixin from '../mixins/MobilityLayerMixin';
7
- /**
8
- * Common class for Maplibre and Maplibre and potential other fork from Maplibre.
9
- * It's used to share code between Maplibre and Maplibre layers without importing both libs.
10
- * @private
11
- */
12
- class MapGlLayer extends MobilityLayerMixin(Layer) {
13
- get apiKey() {
14
- return this.get('apiKey');
15
- }
16
- set apiKey(newValue) {
17
- this.set('apiKey', newValue);
18
- }
19
- get apiKeyName() {
20
- return this.get('apiKeyName');
21
- }
22
- set apiKeyName(newValue) {
23
- this.set('apiKeyName', newValue);
24
- }
25
- get style() {
26
- return this.get('style');
27
- }
28
- set style(newValue) {
29
- this.set('style', newValue);
30
- }
31
- get url() {
32
- return this.get('url');
33
- }
34
- set url(newValue) {
35
- this.set('url', newValue);
36
- }
37
- get queryRenderedFeaturesOptions() {
38
- return this.get('queryRenderedFeaturesOptions');
39
- }
40
- set queryRenderedFeaturesOptions(newValue) {
41
- this.set('queryRenderedFeaturesOptions', newValue);
42
- }
43
- constructor(options) {
44
- super(Object.assign(Object.assign({ source: new Source({
45
- attributions: () => {
46
- return (this.mbMap && getMapGlCopyrights(this.mbMap)) || [];
47
- },
48
- }), apiKeyName: 'key', style: 'travic_v2', url: 'https://maps.geops.io' }, (options || {})), { mapOptions: Object.assign({ interactive: false, trackResize: false, attributionControl: false }, ((options === null || options === void 0 ? void 0 : options.mapOptions) || {})), queryRenderedFeaturesOptions: Object.assign({}, ((options === null || options === void 0 ? void 0 : options.queryRenderedFeaturesOptions) || {})) }));
49
- }
50
- /**
51
- * Initialize the layer and listen to feature clicks.
52
- * @param {ol/Map~Map} map
53
- */
54
- attachToMap(map) {
55
- super.attachToMap(map);
56
- this.loadMbMap();
57
- const updateMbMapDebounced = debounce(this.updateMbMap.bind(this), 150);
58
- this.olListenersKeys.push(this.on('propertychange', (evt) => {
59
- if (/(apiKey|apiKeyName|url|style|)/.test(evt.key)) {
60
- updateMbMapDebounced();
61
- }
62
- }));
63
- }
64
- /**
65
- * Terminate what was initialized in init function. Remove layer, events...
66
- */
67
- detachFromMap() {
68
- if (this.mbMap) {
69
- // Some asynchrone repaints are triggered even if the mbMap has been removed,
70
- // to avoid display of errors we set an empty function.
71
- this.mbMap.triggerRepaint = () => { };
72
- this.mbMap.remove();
73
- this.mbMap = undefined;
74
- }
75
- this.loaded = false;
76
- super.detachFromMap();
77
- }
78
- /**
79
- * Create the Maplibre map.
80
- * @private
81
- */
82
- loadMbMap() {
83
- var _a, _b, _c;
84
- this.loaded = false;
85
- this.olListenersKeys.push(
86
- // @ts-ignore
87
- (_a = this.map) === null || _a === void 0 ? void 0 : _a.on('change:target', this.loadMbMap.bind(this)));
88
- if (!((_b = this.map) === null || _b === void 0 ? void 0 : _b.getTargetElement())) {
89
- return;
90
- }
91
- if (!this.visible) {
92
- // On next change of visibility we load the map
93
- this.olListenersKeys.push(
94
- // @ts-ignore
95
- this.once('change:visible', this.loadMbMap.bind(this)));
96
- return;
97
- }
98
- const container = document.createElement('div');
99
- container.style.position = 'absolute';
100
- container.style.width = '100%';
101
- container.style.height = '100%';
102
- /**
103
- * A Maplibre map
104
- * @type {maplibregl.Map}
105
- */
106
- this.mbMap = this.createMap(Object.assign({ style: this.getStyle() || { version: '8', sources: {}, layers: [] }, container }, (((_c = this.options) === null || _c === void 0 ? void 0 : _c.mapOptions) || {})));
107
- this.mbMap.on('sourcedata', () => {
108
- var _a;
109
- (_a = this.getSource()) === null || _a === void 0 ? void 0 : _a.refresh(); // Refresh attribution
110
- });
111
- this.mbMap.once('load', () => {
112
- this.loaded = true;
113
- this.dispatchEvent(new BaseEvent('load'));
114
- });
115
- }
116
- getStyle() {
117
- // If the style is a complete style object, use it directly.
118
- if (this.style &&
119
- typeof this.style === 'object' &&
120
- this.style.name &&
121
- this.style.version) {
122
- return this.style;
123
- }
124
- // If the url set is already a complete style url, use it directly.
125
- if (this.url.includes('style.json')) {
126
- return this.url;
127
- }
128
- /// Otherwise build the complete style url.
129
- return getUrlWithParams(`${this.url}/styles/${this.style}/style.json`, {
130
- [this.apiKeyName]: this.apiKey,
131
- }).toString();
132
- }
133
- // eslint-disable-next-line class-methods-use-this, @typescript-eslint/no-unused-vars
134
- createMap(options) {
135
- throw new Error('createMap must be implemented in child class');
136
- }
137
- updateMbMap() {
138
- var _a;
139
- (_a = this.mbMap) === null || _a === void 0 ? void 0 : _a.setStyle(this.getStyle(), { diff: false });
140
- }
141
- }
142
- export default MapGlLayer;