mobility-toolbox-js 3.0.1-beta.0 → 3.0.1-beta.2

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 (78) hide show
  1. package/README.md +11 -3
  2. package/api/HttpAPI.js +1 -3
  3. package/api/RealtimeAPI.d.ts +47 -47
  4. package/api/RealtimeAPI.js +74 -74
  5. package/api/WebSocketAPI.js +0 -1
  6. package/common/controls/StopFinderControlCommon.d.ts +1 -1
  7. package/common/controls/StopFinderControlCommon.js +1 -1
  8. package/common/styles/realtimeDefaultStyle.js +0 -5
  9. package/common/styles/realtimeHeadingStyle.js +0 -5
  10. package/common/styles/realtimeSimpleStyle.d.ts +0 -1
  11. package/common/styles/realtimeSimpleStyle.js +0 -1
  12. package/common/typedefs.d.ts +0 -117
  13. package/common/typedefs.js +0 -31
  14. package/common/utils/RealtimeEngine.d.ts +214 -0
  15. package/common/utils/RealtimeEngine.js +554 -0
  16. package/common/utils/getLayersAsFlatArray.d.ts +0 -1
  17. package/common/utils/getLayersAsFlatArray.js +0 -1
  18. package/common/utils/getVehiclePosition.js +1 -4
  19. package/common/utils/realtimeConfig.d.ts +1 -1
  20. package/common/utils/realtimeConfig.js +0 -1
  21. package/common/utils/renderTrajectories.d.ts +1 -0
  22. package/common/utils/renderTrajectories.js +1 -0
  23. package/common/utils/sortAndFilterDepartures.d.ts +1 -0
  24. package/common/utils/sortAndFilterDepartures.js +1 -0
  25. package/maplibre/controls/CopyrightControl.d.ts +9 -6
  26. package/maplibre/controls/CopyrightControl.js +11 -8
  27. package/maplibre/layers/Layer.d.ts +7 -6
  28. package/maplibre/layers/Layer.js +1 -2
  29. package/maplibre/layers/RealtimeLayer.d.ts +54 -111
  30. package/maplibre/layers/RealtimeLayer.js +126 -114
  31. package/maplibre/utils/getSourceCoordinates.d.ts +1 -0
  32. package/maplibre/utils/getSourceCoordinates.js +5 -4
  33. package/mbt.js +6960 -14605
  34. package/mbt.js.map +4 -4
  35. package/mbt.min.js +68 -71
  36. package/mbt.min.js.map +4 -4
  37. package/ol/controls/CopyrightControl.d.ts +13 -5
  38. package/ol/controls/CopyrightControl.js +13 -5
  39. package/ol/controls/RoutingControl.d.ts +29 -18
  40. package/ol/controls/RoutingControl.js +44 -56
  41. package/ol/controls/StopFinderControl.d.ts +21 -2
  42. package/ol/controls/StopFinderControl.js +22 -3
  43. package/ol/index.d.ts +0 -1
  44. package/ol/index.js +0 -1
  45. package/ol/layers/Layer.d.ts +17 -92
  46. package/ol/layers/Layer.js +17 -3
  47. package/ol/layers/MaplibreLayer.d.ts +47 -114
  48. package/ol/layers/MaplibreLayer.js +102 -46
  49. package/ol/layers/MaplibreStyleLayer.d.ts +67 -147
  50. package/ol/layers/MaplibreStyleLayer.js +170 -123
  51. package/ol/layers/RealtimeLayer.d.ts +85 -218
  52. package/ol/layers/RealtimeLayer.js +170 -181
  53. package/ol/layers/VectorLayer.d.ts +1 -2
  54. package/ol/layers/VectorLayer.js +7 -6
  55. package/ol/renderers/MaplibreLayerRenderer.d.ts +9 -0
  56. package/ol/renderers/MaplibreLayerRenderer.js +35 -137
  57. package/ol/renderers/MaplibreStyleLayerRenderer.js +2 -2
  58. package/ol/renderers/RealtimeLayerRenderer.d.ts +1 -1
  59. package/ol/renderers/RealtimeLayerRenderer.js +6 -31
  60. package/ol/styles/fullTrajectoryDelayStyle.js +5 -7
  61. package/ol/styles/fullTrajectoryStyle.d.ts +1 -2
  62. package/ol/styles/fullTrajectoryStyle.js +5 -7
  63. package/ol/styles/routingStyle.d.ts +0 -1
  64. package/ol/styles/routingStyle.js +13 -10
  65. package/ol/utils/defineDeprecatedProperties.d.ts +10 -0
  66. package/ol/utils/defineDeprecatedProperties.js +180 -0
  67. package/package.json +40 -39
  68. package/setupTests.js +14 -0
  69. package/types/common.d.ts +4 -27
  70. package/types/realtime.d.ts +7 -2
  71. package/common/mixins/RealtimeLayerMixin.d.ts +0 -267
  72. package/common/mixins/RealtimeLayerMixin.js +0 -751
  73. package/ol/mixins/MobilityLayerMixin.d.ts +0 -96
  74. package/ol/mixins/MobilityLayerMixin.js +0 -6
  75. package/ol/mixins/PropertiesLayerMixin.d.ts +0 -136
  76. package/ol/mixins/PropertiesLayerMixin.js +0 -178
  77. package/ol/mixins/index.d.ts +0 -1
  78. package/ol/mixins/index.js +0 -2
@@ -1,142 +1,40 @@
1
- "use strict";
2
- // /* eslint-disable no-underscore-dangle */
3
- // import { FrameState } from 'ol/Map';
4
- // import { toDegrees } from 'ol/math';
5
- // import { toLonLat } from 'ol/proj';
6
- // import LayerRenderer from 'ol/renderer/Layer';
7
- // import GeoJSON from 'ol/format/GeoJSON';
8
- // import { Coordinate } from 'ol/coordinate';
9
- // import { FeatureCallback } from 'ol/renderer/vector';
10
- // import { Feature } from 'ol';
11
- // import { Geometry } from 'ol/geom';
12
- // import { Pixel } from 'ol/pixel';
13
- // import { Map } from 'maplibre-gl';
14
- // import { VECTOR_TILE_FEATURE_PROPERTY } from '../../common';
15
- // import type MaplibreLayer from '../layers/MaplibreLayer';
1
+ import { MapLibreLayerRenderer } from '@geoblocks/ol-maplibre-layer/lib';
16
2
  // /**
17
- // * @private
18
- // */
19
- // const formats: {
20
- // [key: string]: GeoJSON;
21
- // } = {
22
- // 'EPSG:3857': new GeoJSON({
23
- // featureProjection: 'EPSG:3857',
24
- // }),
25
- // };
26
- // /**
27
- // * This class is a renderer for Maplibre Layer to be able to use the native ol
3
+ // * This class is usea renderer for Maplibre Layer to be able to use the native ol
28
4
  // * functionnalities like map.getFeaturesAtPixel or map.hasFeatureAtPixel.
29
5
  // * @private
30
6
  // */
31
7
  // // @ts-expect-error
32
- // export default class MaplibreLayerRenderer extends LayerRenderer<MaplibreLayer> {
33
- // getFeaturesAtCoordinate(
34
- // coordinate: Coordinate | undefined,
35
- // hitTolerance: number = 5,
36
- // ): Feature<Geometry>[] {
37
- // if (!coordinate) {
38
- // return [];
39
- // }
40
- // const layer = this.getLayer();
41
- // const map = layer.getMapInternal();
42
- // const { mbMap } = layer;
43
- // const projection =
44
- // map?.getView()?.getProjection()?.getCode() || 'EPSG:3857';
45
- // let features: Feature[] = [];
46
- // if (!formats[projection]) {
47
- // formats[projection] = new GeoJSON({
48
- // featureProjection: projection,
49
- // });
50
- // }
51
- // if (mbMap?.isStyleLoaded()) {
52
- // const pixel =
53
- // coordinate && mbMap.project(toLonLat(coordinate) as [number, number]);
54
- // if (pixel?.x && pixel?.y) {
55
- // let pixels: [[number, number], [number, number]] | [number, number] = [
56
- // pixel.x,
57
- // pixel.y,
58
- // ];
59
- // if (hitTolerance) {
60
- // const [x, y] = pixels as [number, number];
61
- // pixels = [
62
- // [x - hitTolerance, y - hitTolerance],
63
- // [x + hitTolerance, y + hitTolerance],
64
- // ];
65
- // }
66
- // // At this point we get GeoJSON Maplibre feature, we transform it to an OpenLayers
67
- // // feature to be consistent with other layers.
68
- // features = (mbMap as Map)
69
- // .queryRenderedFeatures(
70
- // pixels,
71
- // layer.queryRenderedFeaturesOptions || {},
72
- // )
73
- // .map((feature) => {
74
- // const olFeature = formats[projection].readFeature(
75
- // feature,
76
- // ) as Feature;
77
- // if (olFeature) {
78
- // // We save the original Maplibre feature to avoid losing informations
79
- // // potentially needed for other functionnality like highlighting
80
- // // (id, layer id, source, sourceLayer ...)
81
- // // @ts-expect-error
82
- // olFeature.set(VECTOR_TILE_FEATURE_PROPERTY, feature);
83
- // }
84
- // return olFeature;
85
- // });
86
- // }
87
- // }
88
- // return features;
89
- // }
90
- // // eslint-disable-next-line class-methods-use-this
91
- // override prepareFrame() {
92
- // return true;
93
- // }
94
- // override renderFrame(frameState: FrameState) {
95
- // const layer = this.getLayer();
96
- // const { map, mbMap } = layer;
97
- // if (!layer || !map || !mbMap) {
98
- // return null;
99
- // }
100
- // const canvas = mbMap.getCanvas();
101
- // const { viewState } = frameState;
102
- // const opacity = layer.getOpacity() || 1;
103
- // canvas.style.opacity = `${opacity}`;
104
- // // adjust view parameters in Maplibre
105
- // mbMap.jumpTo({
106
- // center: toLonLat(viewState.center) as [number, number],
107
- // zoom: viewState.zoom - 1,
108
- // bearing: toDegrees(-viewState.rotation),
109
- // });
110
- // if (!canvas.isConnected) {
111
- // // The canvas is not connected to the DOM, request a map rendering at the next animation frame
112
- // // to set the canvas size.
113
- // map.render();
114
- // } else if (
115
- // canvas.width !== frameState.size[0] ||
116
- // canvas.height !== frameState.size[1]
117
- // ) {
118
- // mbMap.resize();
119
- // }
120
- // mbMap.redraw();
121
- // return mbMap.getContainer();
122
- // }
123
- // override getFeatures(pixel: Pixel) {
124
- // const coordinate = this.getLayer()
125
- // ?.getMapInternal()
126
- // ?.getCoordinateFromPixel(pixel);
127
- // return Promise.resolve(this.getFeaturesAtCoordinate(coordinate));
128
- // }
129
- // override forEachFeatureAtCoordinate<Feature>(
130
- // coordinate: Coordinate,
131
- // frameState: FrameState,
132
- // hitTolerance: number,
133
- // callback: FeatureCallback<Feature>,
134
- // ): Feature | undefined {
135
- // const features = this.getFeaturesAtCoordinate(coordinate, hitTolerance);
136
- // features.forEach((feature) => {
137
- // // @ts-expect-error
138
- // callback(feature, this.layer_, feature.getGeometry());
139
- // });
140
- // return features?.[0] as Feature;
141
- // }
142
- // }
8
+ export default class MaplibreLayerRenderer extends MapLibreLayerRenderer {
9
+ constructor(layer) {
10
+ super(layer);
11
+ this.ignoreNextRender = false;
12
+ this.setIsReady = this.setIsReady.bind(this);
13
+ this.ignoreNextRender = false;
14
+ }
15
+ renderFrame(frameState) {
16
+ var _a, _b, _c;
17
+ (_b = (_a = this.getLayer()) === null || _a === void 0 ? void 0 : _a.mapLibreMap) === null || _b === void 0 ? void 0 : _b.off('idle', this.setIsReady);
18
+ const mapLibreMap = (_c = this.getLayer()) === null || _c === void 0 ? void 0 : _c.mapLibreMap;
19
+ mapLibreMap === null || mapLibreMap === void 0 ? void 0 : mapLibreMap.off('idle', this.setIsReady);
20
+ if (this.ignoreNextRender) {
21
+ this.ignoreNextRender = false;
22
+ const container = mapLibreMap === null || mapLibreMap === void 0 ? void 0 : mapLibreMap.getContainer();
23
+ if (container) {
24
+ return container;
25
+ }
26
+ }
27
+ this.ready = false;
28
+ const container = super.renderFrame(frameState);
29
+ // Mark the renderer as ready when the map is idle
30
+ mapLibreMap === null || mapLibreMap === void 0 ? void 0 : mapLibreMap.once('idle', this.setIsReady);
31
+ return container;
32
+ }
33
+ setIsReady() {
34
+ if (!this.ready) {
35
+ this.ready = true;
36
+ this.ignoreNextRender = true;
37
+ this.getLayer().changed();
38
+ }
39
+ }
40
+ }
@@ -19,7 +19,7 @@ export default class MaplibreStyleLayerRenderer extends LayerRenderer {
19
19
  forEachFeatureAtCoordinate(coordinate, frameState, hitTolerance, callback) {
20
20
  const features = this.getFeaturesAtCoordinate(coordinate, hitTolerance);
21
21
  features.forEach((feature) => {
22
- // @ts-expect-error
22
+ // @ts-expect-error improve ts types
23
23
  callback(feature, this.layer_, feature.getGeometry());
24
24
  });
25
25
  return features === null || features === void 0 ? void 0 : features[0];
@@ -36,7 +36,7 @@ export default class MaplibreStyleLayerRenderer extends LayerRenderer {
36
36
  }
37
37
  const layer = this.getLayer();
38
38
  const map = layer.getMapInternal();
39
- const { mapLibreMap } = layer.maplibreLayer;
39
+ const mapLibreMap = layer.maplibreLayer.mapLibreMap;
40
40
  const projection = ((_b = (_a = map === null || map === void 0 ? void 0 : map.getView()) === null || _a === void 0 ? void 0 : _a.getProjection()) === null || _b === void 0 ? void 0 : _b.getCode()) || 'EPSG:3857';
41
41
  let features = [];
42
42
  if (!formats[projection]) {
@@ -14,7 +14,7 @@ import type RealtimeLayer from '../layers/RealtimeLayer';
14
14
  export default class RealtimeLayerRenderer extends CanvasLayerRenderer<RealtimeLayer> {
15
15
  private canvas;
16
16
  forEachFeatureAtCoordinate<Feature>(coordinate: Coordinate, frameState: FrameState, hitTolerance: number, callback: FeatureCallback<Feature>): Feature | undefined;
17
- getData(pixel: Pixel): Uint8ClampedArray | null;
17
+ getData(pixel: Pixel): Uint8ClampedArray<ArrayBufferLike> | null;
18
18
  getFeatures(pixel: Pixel): Promise<Feature<Geometry>[]>;
19
19
  getFeaturesAtCoordinate(coordinate: Coordinate | undefined, hitTolerance?: number): Feature<Geometry>[];
20
20
  prepareFrame(): boolean;
@@ -1,20 +1,17 @@
1
- import { buffer, containsCoordinate } from 'ol/extent';
2
1
  import GeoJSON from 'ol/format/GeoJSON';
3
2
  import CanvasLayerRenderer from 'ol/renderer/canvas/Layer';
4
3
  import { composeCssTransform } from 'ol/transform';
5
- /** @private */
6
4
  const format = new GeoJSON();
7
5
  /**
8
6
  * This class is a renderer for Maplibre Layer to be able to use the native ol
9
7
  * functionnalities like map.getFeaturesAtPixel or map.hasFeatureAtPixel.
10
8
  * @private
11
9
  */
12
- // @ts-expect-error
13
10
  export default class RealtimeLayerRenderer extends CanvasLayerRenderer {
14
11
  forEachFeatureAtCoordinate(coordinate, frameState, hitTolerance, callback) {
15
12
  const features = this.getFeaturesAtCoordinate(coordinate, hitTolerance);
16
13
  features.forEach((feature) => {
17
- // @ts-expect-error
14
+ // @ts-expect-error defintion to fix
18
15
  callback(feature, this.layer_, feature.getGeometry());
19
16
  });
20
17
  return features === null || features === void 0 ? void 0 : features[0];
@@ -43,37 +40,15 @@ export default class RealtimeLayerRenderer extends CanvasLayerRenderer {
43
40
  return Promise.resolve(this.getFeaturesAtCoordinate(coordinate));
44
41
  }
45
42
  getFeaturesAtCoordinate(coordinate, hitTolerance = 5) {
46
- var _a;
47
43
  if (!coordinate) {
48
44
  return [];
49
45
  }
50
46
  const layer = this.getLayer();
51
- const map = layer.getMapInternal();
52
- const resolution = ((_a = map === null || map === void 0 ? void 0 : map.getView()) === null || _a === void 0 ? void 0 : _a.getResolution()) || 1;
53
- const nb = 10;
54
- const ext = buffer([...coordinate, ...coordinate], hitTolerance * resolution);
55
- let features = [];
56
- let trajectories = Object.values(layer.trajectories || {});
57
- if (layer.sort) {
58
- // @ts-expect-error
59
- trajectories = trajectories.sort(this.sort);
60
- }
61
- const vehicles = [];
62
- for (let i = 0; i < trajectories.length; i += 1) {
63
- const trajectory = trajectories[i];
64
- if (
65
- // @ts-expect-error coordinate is added by the RealtimeLayer
66
- trajectory.properties.coordinate &&
67
- // @ts-expect-error coordinate is added by the RealtimeLayer
68
- containsCoordinate(ext, trajectory.properties.coordinate)) {
69
- vehicles.push(trajectories[i]);
70
- }
71
- if (vehicles.length === nb) {
72
- break;
73
- }
74
- }
75
- features = vehicles.map((vehicle) => format.readFeature(vehicle));
76
- return features;
47
+ const featureCollection = layer.engine.getVehiclesAtCoordinate(coordinate, {
48
+ hitTolerance,
49
+ nb: layer.maxNbFeaturesRequested,
50
+ });
51
+ return format.readFeatures(featureCollection);
77
52
  }
78
53
  // eslint-disable-next-line class-methods-use-this
79
54
  prepareFrame() {
@@ -1,31 +1,29 @@
1
- import { Style, Fill, Stroke, Circle } from 'ol/style';
2
- /** @private */
1
+ import { Circle, Fill, Stroke, Style } from 'ol/style';
3
2
  const stroke = new Style({
4
- zIndex: 2,
5
3
  image: new Circle({
6
- radius: 5,
7
4
  fill: new Fill({
8
5
  color: '#000000',
9
6
  }),
7
+ radius: 5,
10
8
  }),
11
9
  stroke: new Stroke({
12
10
  color: '#000000',
13
11
  width: 6,
14
12
  }),
13
+ zIndex: 2,
15
14
  });
16
- /** @private */
17
15
  const fill = new Style({
18
- zIndex: 3,
19
16
  image: new Circle({
20
- radius: 4,
21
17
  fill: new Fill({
22
18
  color: '#a0a0a0',
23
19
  }),
20
+ radius: 4,
24
21
  }),
25
22
  stroke: new Stroke({
26
23
  color: '#a0a0a0',
27
24
  width: 4,
28
25
  }),
26
+ zIndex: 3,
29
27
  });
30
28
  /**
31
29
  * @private
@@ -1,5 +1,4 @@
1
- import type { FeatureLike } from 'ol/Feature';
2
1
  import { Style } from 'ol/style';
3
- /** @private */
2
+ import type { FeatureLike } from 'ol/Feature';
4
3
  declare const fullTrajectorystyle: (feature: FeatureLike, resolution: number, options: any) => Style[];
5
4
  export default fullTrajectorystyle;
@@ -1,19 +1,17 @@
1
- import { Style, Fill, Stroke, Circle } from 'ol/style';
2
- /** @private */
1
+ import { Circle, Fill, Stroke, Style } from 'ol/style';
3
2
  const borderStyle = new Style({
4
- zIndex: 2,
5
3
  image: new Circle({
6
- radius: 5,
7
4
  fill: new Fill({
8
5
  color: '#000000',
9
6
  }),
7
+ radius: 5,
10
8
  }),
11
9
  stroke: new Stroke({
12
10
  color: '#000000',
13
11
  width: 6,
14
12
  }),
13
+ zIndex: 2,
15
14
  });
16
- /** @private */
17
15
  const fullTrajectorystyle = (feature, resolution, options) => {
18
16
  let lineColor = '#ffffff'; // white
19
17
  const type = feature.get('type');
@@ -27,17 +25,17 @@ const fullTrajectorystyle = (feature, resolution, options) => {
27
25
  const style = [
28
26
  borderStyle,
29
27
  new Style({
30
- zIndex: 3,
31
28
  image: new Circle({
32
- radius: 4,
33
29
  fill: new Fill({
34
30
  color: lineColor,
35
31
  }),
32
+ radius: 4,
36
33
  }),
37
34
  stroke: new Stroke({
38
35
  color: lineColor,
39
36
  width: 4,
40
37
  }),
38
+ zIndex: 3,
41
39
  }),
42
40
  ];
43
41
  return style;
@@ -1,4 +1,3 @@
1
1
  import { StyleFunction } from 'ol/style/Style';
2
- /** @private */
3
2
  declare const routingStyle: StyleFunction;
4
3
  export default routingStyle;
@@ -1,24 +1,21 @@
1
1
  import { Circle, Fill, Stroke } from 'ol/style';
2
2
  import Style from 'ol/style/Style';
3
- /** @private */
4
3
  const circleStyle = new Circle({
5
- radius: 6,
6
4
  fill: new Fill({
7
5
  color: [255, 0, 0, 1],
8
6
  }),
7
+ radius: 6,
9
8
  stroke: new Stroke({
10
9
  color: [0, 0, 0, 1],
11
10
  width: 1,
12
11
  }),
13
12
  });
14
- /** @private */
15
13
  const blackBorder = new Style({
16
14
  stroke: new Stroke({
17
15
  color: [0, 0, 0, 1],
18
16
  width: 5,
19
17
  }),
20
18
  });
21
- /** @private */
22
19
  const redLine = new Style({
23
20
  image: circleStyle,
24
21
  stroke: new Stroke({
@@ -26,27 +23,33 @@ const redLine = new Style({
26
23
  width: 3,
27
24
  }),
28
25
  });
29
- /** @private */
30
26
  const dashedRedLine = new Style({
31
27
  image: circleStyle,
32
28
  stroke: new Stroke({
33
29
  color: [255, 0, 0, 1],
34
- width: 3,
35
30
  lineDash: [1, 10],
31
+ width: 3,
36
32
  }),
37
33
  });
38
- /** @private */
39
34
  const routingStyle = (feature, resolution) => {
35
+ var _a;
40
36
  const minResolution = feature.get('minResolution');
41
37
  const maxResolution = feature.get('maxResolution');
42
38
  const inRange = resolution <= minResolution && resolution > maxResolution;
43
39
  if (minResolution && maxResolution && !inRange) {
44
40
  return [];
45
41
  }
42
+ const zIndex = ((_a = feature === null || feature === void 0 ? void 0 : feature.getGeometry()) === null || _a === void 0 ? void 0 : _a.getType()) === 'Point' ? 100 : 0;
43
+ let styles = [blackBorder, redLine];
46
44
  const mot = feature.get('mot');
47
- if (mot !== 'foot') {
48
- return [blackBorder, redLine];
45
+ if (mot === 'foot') {
46
+ styles = [dashedRedLine];
49
47
  }
50
- return [dashedRedLine];
48
+ styles = styles.map((style) => {
49
+ const tmp = style.clone();
50
+ tmp.setZIndex(zIndex);
51
+ return tmp;
52
+ });
53
+ return styles;
51
54
  };
52
55
  export default routingStyle;
@@ -0,0 +1,10 @@
1
+ import { Layer } from 'ol/layer';
2
+ import { MobilityLayerOptions } from '../layers/Layer';
3
+ /**
4
+ * obj function defines properties taht were used in mbt v2.
5
+ * They are all marked als deprecated.
6
+ * @param obj
7
+ * @returns
8
+ */
9
+ declare const defineDeprecatedProperties: (obj: Layer, options: MobilityLayerOptions) => void;
10
+ export default defineDeprecatedProperties;
@@ -0,0 +1,180 @@
1
+ import debounce from 'lodash.debounce';
2
+ let deprecated = () => { };
3
+ if (typeof window !== 'undefined' &&
4
+ new URLSearchParams(window.location.search).get('deprecated')) {
5
+ deprecated = debounce((message) => {
6
+ // eslint-disable-next-line no-console
7
+ console.warn(message);
8
+ }, 1000);
9
+ }
10
+ const onChildrenChange = (layer, oldValue) => {
11
+ // Set the parent property
12
+ (oldValue || []).forEach((child) => {
13
+ child.set('parent', undefined);
14
+ });
15
+ (layer.get('children') || []).forEach((child) => {
16
+ child.set('parent', this);
17
+ });
18
+ };
19
+ /**
20
+ * obj function defines properties taht were used in mbt v2.
21
+ * They are all marked als deprecated.
22
+ * @param obj
23
+ * @returns
24
+ */
25
+ const defineDeprecatedProperties = (obj, options) => {
26
+ if (options.properties) {
27
+ deprecated("Deprecated. Don't use properties options. Pass the values directly in options object.");
28
+ obj.setProperties(options.properties);
29
+ }
30
+ // Update parent property
31
+ obj.on('propertychange', (evt) => {
32
+ if (evt.key === 'children') {
33
+ onChildrenChange(evt.target, evt.oldValue);
34
+ }
35
+ if (evt.key === 'map') {
36
+ const map = evt.target.get(evt.key);
37
+ if (map) {
38
+ (evt.target.get('children') || []).forEach((child) => {
39
+ map.addLayer(child);
40
+ });
41
+ }
42
+ else if (evt.oldValue) {
43
+ (evt.target.get('children') || []).forEach((child) => {
44
+ evt.oldValue.removeLayer(child);
45
+ });
46
+ }
47
+ }
48
+ });
49
+ // Save options for cloning
50
+ obj.set('options', options);
51
+ obj.set('children', options.children || []); // Trigger the on children change event
52
+ Object.defineProperties(obj, {
53
+ children: {
54
+ /** @deprecated */
55
+ get: () => {
56
+ deprecated("Layer.children is deprecated. Use the Layer.get('children') method instead.");
57
+ return obj.get('children') || [];
58
+ },
59
+ /** @deprecated */
60
+ set: (newValue) => {
61
+ deprecated("Layer.children is deprecated. Use the Layer.set('children', children) method instead.");
62
+ obj.set('children', newValue || []);
63
+ },
64
+ },
65
+ copyrights: {
66
+ /** @deprecated */
67
+ get: () => {
68
+ deprecated('Layer.copyrights is deprecated. Get the attributions from the source object');
69
+ return obj.get('copyrights');
70
+ },
71
+ /** @deprecated */
72
+ set: (newCopyrights) => {
73
+ deprecated('Layer.copyrights is deprecated. Set the attributions to the source object.');
74
+ const arrValue = newCopyrights && !Array.isArray(newCopyrights)
75
+ ? [newCopyrights]
76
+ : newCopyrights;
77
+ obj.set('copyrights', arrValue || []);
78
+ },
79
+ },
80
+ disabled: {
81
+ /** @deprecated */
82
+ get() {
83
+ deprecated("Layer.disabled is deprecated. Use the Layer.get('disabled') method instead.");
84
+ return obj.get('disabled');
85
+ },
86
+ /** @deprecated */
87
+ set(newValue) {
88
+ deprecated("Layer.disabled is deprecated. Use the Layer.set('disabled', newValue) method instead.");
89
+ obj.set('disabled', newValue);
90
+ },
91
+ },
92
+ group: {
93
+ /** @deprecated */
94
+ get() {
95
+ deprecated("Layer.group is deprecated. Use the Layer.get('group') method instead.");
96
+ return obj.get('group');
97
+ },
98
+ },
99
+ hitTolerance: {
100
+ /** @deprecated */
101
+ get() {
102
+ deprecated('Layer.hitTolerance is deprecated. Pass the hitTolerance when you request the features.');
103
+ return obj.get('hitTolerance') || 5;
104
+ },
105
+ /** @deprecated */
106
+ set(newValue) {
107
+ deprecated('Layer.hitTolerance is deprecated. Pass the hitTolerance when you request the features.');
108
+ obj.set('hitTolerance', newValue);
109
+ },
110
+ },
111
+ key: {
112
+ /** @deprecated */
113
+ get() {
114
+ deprecated('Layer.key is deprecated. Use the Layer.get("key") method instead.');
115
+ return obj.get('key') || obj.get('name');
116
+ },
117
+ },
118
+ map: {
119
+ /** @deprecated */
120
+ get() {
121
+ deprecated('Layer.map is deprecated. Use the Layer.get("map") method instead.');
122
+ return obj.getMapInternal();
123
+ },
124
+ },
125
+ name: {
126
+ /** @deprecated */
127
+ get() {
128
+ deprecated("Layer.name is deprecated. Use the Layer.get('name') method instead.");
129
+ return obj.get('name');
130
+ },
131
+ },
132
+ olLayer: {
133
+ /** @deprecated */
134
+ get() {
135
+ deprecated("Layer.olLayer is deprecated. mobility-toolbox-js/ol layers inherits now from ol/layer/Layer class. obj getter is only a redirect to the current 'this' object.");
136
+ return obj;
137
+ },
138
+ /** @deprecated */
139
+ set() {
140
+ deprecated('Layer.olLayer is deprecated. mobility-toolbox-js/ol layers inherits now from ol/layer/Layer class. obj setter has no effect.');
141
+ },
142
+ },
143
+ options: {
144
+ /** @deprecated */
145
+ get() {
146
+ deprecated('Layer.options is deprecated. Use the Layer.get("options") method instead.');
147
+ return obj.get('options');
148
+ },
149
+ set(newValue) {
150
+ deprecated('Layer.options is deprecated. Use the Layer.set("options", newValue) method instead.');
151
+ return obj.set('options', newValue);
152
+ },
153
+ },
154
+ parent: {
155
+ /** @deprecated */
156
+ get() {
157
+ deprecated("Layer.parent is deprecated. Use the Layer.get('parent') method instead.");
158
+ return obj.get('parent');
159
+ },
160
+ /** @deprecated */
161
+ set(newValue) {
162
+ deprecated("Layer.parent is deprecated. Use the Layer.set('parent', parent) method instead.");
163
+ obj.set('parent', newValue);
164
+ },
165
+ },
166
+ visible: {
167
+ /** @deprecated */
168
+ get() {
169
+ deprecated('Layer.visible is deprecated. Use the Layer.getVisible() method instead.');
170
+ return obj.getVisible();
171
+ },
172
+ /** @deprecated */
173
+ set(newValue) {
174
+ deprecated('Layer.visible is deprecated. Use the Layer.setVisible(newValue) method instead.');
175
+ obj.setVisible(newValue);
176
+ },
177
+ },
178
+ });
179
+ };
180
+ export default defineDeprecatedProperties;