mobility-toolbox-js 3.0.0-beta.3 → 3.0.0-beta.32

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 (125) hide show
  1. package/api/HttpAPI.d.ts +20 -0
  2. package/api/HttpAPI.js +0 -11
  3. package/api/RealtimeAPI.d.ts +404 -0
  4. package/api/RealtimeAPI.js +342 -276
  5. package/api/RoutingAPI.d.ts +47 -0
  6. package/api/RoutingAPI.js +17 -7
  7. package/api/StopsAPI.d.ts +44 -0
  8. package/api/StopsAPI.js +17 -11
  9. package/api/WebSocketAPI.d.ts +147 -0
  10. package/api/WebSocketAPI.js +164 -164
  11. package/api/index.d.ts +3 -0
  12. package/api/index.js +1 -1
  13. package/api/typedefs.d.ts +76 -0
  14. package/api/typedefs.js +27 -42
  15. package/common/controls/StopFinderControlCommon.d.ts +53 -0
  16. package/common/controls/StopFinderControlCommon.js +31 -31
  17. package/common/index.d.ts +2 -0
  18. package/common/index.js +1 -1
  19. package/common/mixins/RealtimeLayerMixin.d.ts +267 -0
  20. package/common/mixins/RealtimeLayerMixin.js +401 -393
  21. package/common/styles/index.d.ts +4 -0
  22. package/common/styles/realtimeDefaultStyle.d.ts +36 -0
  23. package/common/styles/realtimeDefaultStyle.js +6 -6
  24. package/common/styles/realtimeDelayStyle.d.ts +12 -0
  25. package/common/styles/realtimeHeadingStyle.d.ts +12 -0
  26. package/common/styles/realtimeHeadingStyle.js +5 -5
  27. package/common/styles/realtimeSimpleStyle.d.ts +4 -0
  28. package/common/typedefs.d.ts +219 -0
  29. package/common/typedefs.js +7 -1
  30. package/common/utils/compareDepartures.d.ts +10 -0
  31. package/common/utils/compareDepartures.js +2 -2
  32. package/common/utils/constants.d.ts +5 -0
  33. package/common/utils/createCanvas.d.ts +10 -0
  34. package/common/utils/createDefaultCopyrightElt.d.ts +5 -0
  35. package/common/utils/createDefaultStopFinderElt.d.ts +5 -0
  36. package/common/utils/createRealtimeFilters.d.ts +12 -0
  37. package/common/utils/debounceDeparturesMessages.d.ts +12 -0
  38. package/common/utils/debounceWebsocketMessages.d.ts +11 -0
  39. package/common/utils/getLayersAsFlatArray.d.ts +3 -0
  40. package/common/utils/getLayersAsFlatArray.js +5 -1
  41. package/common/utils/getMapGlCopyrights.d.ts +17 -0
  42. package/common/utils/getMapGlCopyrights.js +3 -3
  43. package/common/utils/getRealtimeModeSuffix.d.ts +10 -0
  44. package/common/utils/getRealtimeModeSuffix.js +1 -0
  45. package/common/utils/getUrlWithParams.d.ts +8 -0
  46. package/common/utils/getVehiclePosition.d.ts +17 -0
  47. package/common/utils/getVehiclePosition.js +9 -3
  48. package/common/utils/index.d.ts +16 -0
  49. package/common/utils/realtimeConfig.d.ts +64 -0
  50. package/common/utils/removeDuplicate.d.ts +9 -0
  51. package/common/utils/renderTrajectories.d.ts +16 -0
  52. package/common/utils/renderTrajectories.js +6 -6
  53. package/common/utils/sortAndFilterDepartures.d.ts +15 -0
  54. package/common/utils/sortAndFilterDepartures.js +1 -1
  55. package/common/utils/sortByDelay.d.ts +3 -0
  56. package/common/utils/sortByDelay.js +5 -1
  57. package/common/utils/timeUtils.d.ts +23 -0
  58. package/common/utils/toMercatorExtent.d.ts +5 -0
  59. package/iife.d.ts +2 -0
  60. package/index.d.ts +9 -0
  61. package/maplibre/controls/CopyrightControl.d.ts +35 -0
  62. package/maplibre/controls/index.d.ts +1 -0
  63. package/maplibre/index.d.ts +5 -0
  64. package/maplibre/layers/Layer.d.ts +28 -0
  65. package/maplibre/layers/Layer.js +1 -1
  66. package/maplibre/layers/RealtimeLayer.d.ts +181 -0
  67. package/maplibre/layers/RealtimeLayer.js +29 -5
  68. package/maplibre/layers/index.d.ts +2 -0
  69. package/maplibre/utils/getMercatorResolution.d.ts +7 -0
  70. package/maplibre/utils/getSourceCoordinates.d.ts +7 -0
  71. package/maplibre/utils/getSourceCoordinates.js +5 -5
  72. package/maplibre/utils/index.d.ts +2 -0
  73. package/mbt.js +39819 -32088
  74. package/mbt.js.map +4 -4
  75. package/mbt.min.js +61 -58
  76. package/mbt.min.js.map +4 -4
  77. package/ol/controls/CopyrightControl.d.ts +31 -0
  78. package/ol/controls/CopyrightControl.js +18 -8
  79. package/ol/controls/RoutingControl.d.ts +202 -0
  80. package/ol/controls/RoutingControl.js +220 -219
  81. package/ol/controls/StopFinderControl.d.ts +37 -0
  82. package/ol/controls/StopFinderControl.js +5 -2
  83. package/ol/controls/index.d.ts +3 -0
  84. package/ol/index.d.ts +7 -0
  85. package/ol/index.js +1 -0
  86. package/ol/layers/Layer.d.ts +103 -0
  87. package/ol/layers/Layer.js +38 -0
  88. package/ol/layers/MaplibreLayer.d.ts +167 -0
  89. package/ol/layers/MaplibreLayer.js +115 -27
  90. package/ol/layers/MaplibreStyleLayer.d.ts +237 -0
  91. package/ol/layers/MaplibreStyleLayer.js +315 -265
  92. package/ol/layers/RealtimeLayer.d.ts +283 -0
  93. package/ol/layers/RealtimeLayer.js +143 -128
  94. package/ol/layers/VectorLayer.d.ts +18 -0
  95. package/ol/layers/VectorLayer.js +32 -0
  96. package/ol/layers/index.d.ts +5 -0
  97. package/ol/layers/index.js +3 -0
  98. package/ol/mixins/MobilityLayerMixin.d.ts +96 -0
  99. package/ol/mixins/MobilityLayerMixin.js +1 -4
  100. package/ol/mixins/PropertiesLayerMixin.d.ts +136 -0
  101. package/ol/mixins/PropertiesLayerMixin.js +122 -140
  102. package/ol/mixins/index.d.ts +1 -0
  103. package/ol/mixins/index.js +2 -0
  104. package/ol/renderers/MaplibreLayerRenderer.d.ts +0 -0
  105. package/ol/renderers/MaplibreLayerRenderer.js +142 -114
  106. package/ol/renderers/MaplibreStyleLayerRenderer.d.ts +20 -0
  107. package/ol/renderers/MaplibreStyleLayerRenderer.js +20 -23
  108. package/ol/renderers/RealtimeLayerRenderer.d.ts +22 -0
  109. package/ol/renderers/RealtimeLayerRenderer.js +58 -53
  110. package/ol/styles/fullTrajectoryDelayStyle.d.ts +6 -0
  111. package/ol/styles/fullTrajectoryStyle.d.ts +5 -0
  112. package/ol/styles/index.d.ts +3 -0
  113. package/ol/styles/routingStyle.d.ts +4 -0
  114. package/ol/utils/getFeatureInfoAtCoordinate.d.ts +8 -0
  115. package/ol/utils/getFeatureInfoAtCoordinate.js +12 -18
  116. package/ol/utils/index.d.ts +1 -0
  117. package/package.json +31 -31
  118. package/setupTests.d.ts +1 -0
  119. package/setupTests.js +3 -4
  120. package/types/common.d.ts +55 -48
  121. package/types/index.d.ts +1 -1
  122. package/types/realtime.d.ts +91 -93
  123. package/types/routing.d.ts +60 -60
  124. package/types/stops.d.ts +62 -62
  125. package/ol/layers/MapGlLayer.js +0 -142
@@ -0,0 +1,18 @@
1
+ import { Coordinate } from 'ol/coordinate';
2
+ import { LayerGetFeatureInfoResponse } from '../../types';
3
+ import { MobilityLayerOptions } from '../mixins/MobilityLayerMixin';
4
+ import Layer from './Layer';
5
+ /**
6
+ * @deprecated
7
+ */
8
+ declare class VectorLayer extends Layer {
9
+ /**
10
+ * @deprecated
11
+ */
12
+ clone(newOptions: MobilityLayerOptions): VectorLayer;
13
+ /**
14
+ * @deprecated
15
+ */
16
+ getFeatureInfoAtCoordinate(coordinate: Coordinate): Promise<LayerGetFeatureInfoResponse>;
17
+ }
18
+ export default VectorLayer;
@@ -0,0 +1,32 @@
1
+ import Layer from './Layer';
2
+ /**
3
+ * @deprecated
4
+ */
5
+ class VectorLayer extends Layer {
6
+ /**
7
+ * @deprecated
8
+ */
9
+ clone(newOptions) {
10
+ return new VectorLayer(Object.assign(Object.assign({}, this.options), newOptions));
11
+ }
12
+ /**
13
+ * @deprecated
14
+ */
15
+ getFeatureInfoAtCoordinate(coordinate) {
16
+ let features = [];
17
+ if (this.map) {
18
+ const pixel = this.map.getPixelFromCoordinate(coordinate);
19
+ features =
20
+ this.map.getFeaturesAtPixel(pixel, {
21
+ hitTolerance: this.hitTolerance || 5,
22
+ layerFilter: (l) => l === this.olLayer,
23
+ }) || [];
24
+ }
25
+ return Promise.resolve({
26
+ coordinate,
27
+ features,
28
+ layer: this,
29
+ });
30
+ }
31
+ }
32
+ export default VectorLayer;
@@ -0,0 +1,5 @@
1
+ export { default as MaplibreLayer } from "./MaplibreLayer";
2
+ export { default as MaplibreStyleLayer } from "./MaplibreStyleLayer";
3
+ export { default as RealtimeLayer } from "./RealtimeLayer";
4
+ export { default as Layer } from "./Layer";
5
+ export { default as VectorLayer } from "./VectorLayer";
@@ -1,3 +1,6 @@
1
1
  export { default as MaplibreLayer } from './MaplibreLayer';
2
2
  export { default as MaplibreStyleLayer } from './MaplibreStyleLayer';
3
3
  export { default as RealtimeLayer } from './RealtimeLayer';
4
+ // Deprecated export
5
+ export { default as Layer } from './Layer';
6
+ export { default as VectorLayer } from './VectorLayer';
@@ -0,0 +1,96 @@
1
+ import { Layer } from 'ol/layer';
2
+ import { PropertiesLayerMixinOptions } from './PropertiesLayerMixin';
3
+ export type MobilityLayerOptions = PropertiesLayerMixinOptions & Record<string, any>;
4
+ type GConstructor<T = object> = new (...args: any[]) => T;
5
+ export type Layerable = GConstructor<Omit<Layer, keyof string>>;
6
+ declare function MobilityLayerMixin<TBase extends Layerable>(Base: TBase): {
7
+ new (...args: any[]): {
8
+ olEventsKeys: import("ol/events").EventsKey[];
9
+ options?: PropertiesLayerMixinOptions;
10
+ attachToMap(map: import("ol").Map): void;
11
+ detachFromMap(): void;
12
+ flat(): any[];
13
+ onChildrenChange(oldValue: Layer[]): void;
14
+ setMapInternal: ((map: import("ol").Map) => void) & ((map: import("ol").default | null) => void);
15
+ children: Layer<import("ol/source").Source, import("ol/renderer/Layer").default<any>>[];
16
+ get copyrights(): string;
17
+ set copyrights(newCopyrights: string | string[]);
18
+ disabled: boolean;
19
+ readonly group: string;
20
+ hitTolerance: number;
21
+ readonly key: string;
22
+ readonly map: import("ol").Map;
23
+ readonly name: string;
24
+ olLayer: Layer;
25
+ parent: Layer<import("ol/source").Source, import("ol/renderer/Layer").default<any>>;
26
+ visible: boolean;
27
+ on: import("ol/layer/Layer").LayerOnSignature<import("ol/events").EventsKey>;
28
+ once: import("ol/layer/Layer").LayerOnSignature<import("ol/events").EventsKey>;
29
+ un: import("ol/layer/Layer").LayerOnSignature<void>;
30
+ render: (frameState: import("ol/Map").FrameState | null, target: HTMLElement) => HTMLElement | null;
31
+ getSource: () => import("ol/source").Source | null;
32
+ getRenderSource: () => import("ol/source").Source | null;
33
+ getFeatures: (pixel: import("ol/pixel").Pixel) => Promise<Array<import("ol/Feature").FeatureLike>>;
34
+ getData: (pixel: import("ol/pixel").Pixel) => Uint8ClampedArray | Uint8Array | Float32Array | DataView | null;
35
+ isVisible: (view?: import("ol").View | import("ol/View").ViewStateLayerStateExtent | undefined) => boolean;
36
+ getAttributions: (view?: import("ol").View | import("ol/View").ViewStateLayerStateExtent | undefined) => Array<string>;
37
+ unrender: () => void;
38
+ getDeclutter: () => string;
39
+ renderDeclutter: (frameState: import("ol/Map").FrameState, layerState: import("ol/layer/Layer").State) => void;
40
+ renderDeferred: (frameState: import("ol/Map").FrameState) => void;
41
+ getMapInternal: () => import("ol").default | null;
42
+ setMap: (map: import("ol").default | null) => void;
43
+ setSource: (source: import("ol/source").Source | null) => void;
44
+ getRenderer: () => import("ol/renderer/Layer").default<any> | null;
45
+ hasRenderer: () => boolean;
46
+ getBackground: () => import("ol/layer/Base").BackgroundColor | false;
47
+ getClassName: () => string;
48
+ getLayerState: (managed?: boolean | undefined) => import("ol/layer/Layer").State;
49
+ getLayersArray: (array?: import("ol/layer/Layer").default<import("ol/source").default, import("ol/renderer/Layer").default<any>>[] | undefined) => Array<import("ol/layer/Layer").default>;
50
+ getLayerStatesArray: (states?: import("ol/layer/Layer").State[] | undefined) => Array<import("ol/layer/Layer").State>;
51
+ getExtent: () => import("ol/extent").Extent | undefined;
52
+ getMaxResolution: () => number;
53
+ getMinResolution: () => number;
54
+ getMinZoom: () => number;
55
+ getMaxZoom: () => number;
56
+ getOpacity: () => number;
57
+ getSourceState: () => import("ol/source/Source").State;
58
+ getVisible: () => boolean;
59
+ getZIndex: () => number | undefined;
60
+ setBackground: (background?: import("ol/layer/Base").BackgroundColor | undefined) => void;
61
+ setExtent: (extent: import("ol/extent").Extent | undefined) => void;
62
+ setMaxResolution: (maxResolution: number) => void;
63
+ setMinResolution: (minResolution: number) => void;
64
+ setMaxZoom: (maxZoom: number) => void;
65
+ setMinZoom: (minZoom: number) => void;
66
+ setOpacity: (opacity: number) => void;
67
+ setVisible: (visible: boolean) => void;
68
+ setZIndex: (zindex: number) => void;
69
+ get: (key: string) => any;
70
+ getKeys: () => Array<string>;
71
+ getProperties: () => {
72
+ [x: string]: any;
73
+ };
74
+ getPropertiesInternal: () => {
75
+ [x: string]: any;
76
+ } | null;
77
+ hasProperties: () => boolean;
78
+ notify: (key: string, oldValue: any) => void;
79
+ addChangeListener: (key: string, listener: import("ol/events").Listener) => void;
80
+ removeChangeListener: (key: string, listener: import("ol/events").Listener) => void;
81
+ set: (key: string, value: any, silent?: boolean | undefined) => void;
82
+ setProperties: (values: {
83
+ [x: string]: any;
84
+ }, silent?: boolean | undefined) => void;
85
+ unset: (key: string, silent?: boolean | undefined) => void;
86
+ changed: () => void;
87
+ getRevision: () => number;
88
+ addEventListener: (type: string, listener: import("ol/events").Listener) => void;
89
+ dispatchEvent: (event: import("ol/events/Event").default | string) => boolean | undefined;
90
+ getListeners: (type: string) => Array<import("ol/events").Listener> | undefined;
91
+ hasListener: (type?: string | undefined) => boolean;
92
+ removeEventListener: (type: string, listener: import("ol/events").Listener) => void;
93
+ dispose: () => void;
94
+ };
95
+ } & TBase;
96
+ export default MobilityLayerMixin;
@@ -1,9 +1,6 @@
1
1
  import PropertiesLayerMixin from './PropertiesLayerMixin';
2
2
  function MobilityLayerMixin(Base) {
3
- return class extends PropertiesLayerMixin(Base) {
4
- constructor(options = {}) {
5
- super(options);
6
- }
3
+ return class MobilityLayer extends PropertiesLayerMixin(Base) {
7
4
  };
8
5
  }
9
6
  export default MobilityLayerMixin;
@@ -0,0 +1,136 @@
1
+ import { Map } from 'ol';
2
+ import { EventsKey } from 'ol/events';
3
+ import { Layer } from 'ol/layer';
4
+ import type { Options } from 'ol/layer/Layer';
5
+ import type { Layerable } from './MobilityLayerMixin';
6
+ export type PropertiesLayerMixinOptions = Options & Record<string, any> & {
7
+ children?: any[];
8
+ copyrights?: string[];
9
+ disabled?: boolean;
10
+ group?: string;
11
+ hitTolerance?: number;
12
+ key?: string;
13
+ map?: Map;
14
+ name?: string;
15
+ properties?: Record<string, any>;
16
+ visible?: boolean;
17
+ };
18
+ /**
19
+ * This mixin adds some properties to access ol custom properties easily.
20
+ */
21
+ declare function PropertiesLayerMixin<TBase extends Layerable>(Base: TBase): {
22
+ new (...args: any[]): {
23
+ olEventsKeys: EventsKey[];
24
+ options?: PropertiesLayerMixinOptions;
25
+ /**
26
+ * Initialize the layer with the map passed in parameters.
27
+ *
28
+ * @param {ol/Map~Map} map A map.
29
+ */
30
+ attachToMap(map: Map): void;
31
+ /**
32
+ * Terminate what was initialized in init function. Remove layer, events...
33
+ */
34
+ detachFromMap(): void;
35
+ /**
36
+ * Return the an array containing all the descendants of the layer in a flat array. Including the current layer.
37
+ * @deprecated
38
+ */
39
+ flat(): any[];
40
+ /** @private */
41
+ onChildrenChange(oldValue: Layer[]): void;
42
+ setMapInternal(map: Map): void;
43
+ /** @deprecated */
44
+ children: Layer<import("ol/source").Source, import("ol/renderer/Layer").default<any>>[];
45
+ /** @deprecated */
46
+ get copyrights(): string;
47
+ /** @deprecated */
48
+ set copyrights(newCopyrights: string | string[]);
49
+ /** @deprecated */
50
+ disabled: boolean;
51
+ /** @deprecated */
52
+ /** @deprecated */
53
+ readonly group: string;
54
+ /** @deprecated */
55
+ hitTolerance: number;
56
+ readonly key: string;
57
+ readonly map: Map;
58
+ /** @deprecated */
59
+ readonly name: string;
60
+ /** @deprecated */
61
+ olLayer: Layer;
62
+ /** @deprecated */
63
+ /** @deprecated */
64
+ parent: Layer<import("ol/source").Source, import("ol/renderer/Layer").default<any>>;
65
+ /** @deprecated */
66
+ visible: boolean;
67
+ on: import("ol/layer/Layer").LayerOnSignature<import("ol/events").EventsKey>;
68
+ once: import("ol/layer/Layer").LayerOnSignature<import("ol/events").EventsKey>;
69
+ un: import("ol/layer/Layer").LayerOnSignature<void>;
70
+ render: (frameState: import("ol/Map").FrameState | null, target: HTMLElement) => HTMLElement | null;
71
+ getSource: () => import("ol/source").Source | null;
72
+ getRenderSource: () => import("ol/source").Source | null;
73
+ getFeatures: (pixel: import("ol/pixel").Pixel) => Promise<Array<import("ol/Feature").FeatureLike>>;
74
+ getData: (pixel: import("ol/pixel").Pixel) => Uint8ClampedArray | Uint8Array | Float32Array | DataView | null;
75
+ isVisible: (view?: import("ol").View | import("ol/View").ViewStateLayerStateExtent | undefined) => boolean;
76
+ getAttributions: (view?: import("ol").View | import("ol/View").ViewStateLayerStateExtent | undefined) => Array<string>;
77
+ unrender: () => void;
78
+ getDeclutter: () => string;
79
+ renderDeclutter: (frameState: import("ol/Map").FrameState, layerState: import("ol/layer/Layer").State) => void;
80
+ renderDeferred: (frameState: import("ol/Map").FrameState) => void;
81
+ getMapInternal: () => import("ol/Map").default | null;
82
+ setMap: (map: import("ol/Map").default | null) => void;
83
+ setSource: (source: import("ol/source").Source | null) => void;
84
+ getRenderer: () => import("ol/renderer/Layer").default<any> | null;
85
+ hasRenderer: () => boolean;
86
+ getBackground: () => import("ol/layer/Base").BackgroundColor | false;
87
+ getClassName: () => string;
88
+ getLayerState: (managed?: boolean | undefined) => import("ol/layer/Layer").State;
89
+ getLayersArray: (array?: import("ol/layer/Layer").default<import("ol/source").default, import("ol/renderer/Layer").default<any>>[] | undefined) => Array<import("ol/layer/Layer").default>;
90
+ getLayerStatesArray: (states?: import("ol/layer/Layer").State[] | undefined) => Array<import("ol/layer/Layer").State>;
91
+ getExtent: () => import("ol/extent").Extent | undefined;
92
+ getMaxResolution: () => number;
93
+ getMinResolution: () => number;
94
+ getMinZoom: () => number;
95
+ getMaxZoom: () => number;
96
+ getOpacity: () => number;
97
+ getSourceState: () => import("ol/source/Source").State;
98
+ getVisible: () => boolean;
99
+ getZIndex: () => number | undefined;
100
+ setBackground: (background?: import("ol/layer/Base").BackgroundColor | undefined) => void;
101
+ setExtent: (extent: import("ol/extent").Extent | undefined) => void;
102
+ setMaxResolution: (maxResolution: number) => void;
103
+ setMinResolution: (minResolution: number) => void;
104
+ setMaxZoom: (maxZoom: number) => void;
105
+ setMinZoom: (minZoom: number) => void;
106
+ setOpacity: (opacity: number) => void;
107
+ setVisible: (visible: boolean) => void;
108
+ setZIndex: (zindex: number) => void;
109
+ get: (key: string) => any;
110
+ getKeys: () => Array<string>;
111
+ getProperties: () => {
112
+ [x: string]: any;
113
+ };
114
+ getPropertiesInternal: () => {
115
+ [x: string]: any;
116
+ } | null;
117
+ hasProperties: () => boolean;
118
+ notify: (key: string, oldValue: any) => void;
119
+ addChangeListener: (key: string, listener: import("ol/events" /** @deprecated */).Listener) => void;
120
+ removeChangeListener: (key: string, listener: import("ol/events").Listener) => void;
121
+ set: (key: string, value: any, silent?: boolean | undefined) => void;
122
+ setProperties: (values: {
123
+ [x: string]: any;
124
+ }, silent?: boolean | undefined) => void;
125
+ unset: (key: string, silent?: boolean | undefined) => void;
126
+ changed: () => void;
127
+ getRevision: () => number;
128
+ addEventListener: (type: string, listener: import("ol/events").Listener) => void;
129
+ dispatchEvent: (event: import("ol/events/Event").default | string) => boolean | undefined;
130
+ getListeners: (type: string) => Array<import("ol/events").Listener> | undefined;
131
+ hasListener: (type?: string | undefined) => boolean;
132
+ removeEventListener: (type: string, listener: import("ol/events").Listener) => void;
133
+ dispose: () => void;
134
+ };
135
+ } & TBase;
136
+ export default PropertiesLayerMixin;
@@ -1,202 +1,184 @@
1
- import BaseEvent from 'ol/events/Event';
1
+ // eslint-disable-next-line max-classes-per-file
2
+ import debounce from 'lodash.debounce';
2
3
  import { getUid } from 'ol';
4
+ import { unByKey } from 'ol/Observable';
3
5
  import getLayersAsFlatArray from '../../common/utils/getLayersAsFlatArray';
6
+ let deprecated = () => { };
7
+ if (typeof window !== 'undefined' &&
8
+ new URLSearchParams(window.location.search).get('deprecated')) {
9
+ deprecated = debounce((message) => {
10
+ // eslint-disable-next-line no-console
11
+ console.warn(message);
12
+ }, 1000);
13
+ }
4
14
  /**
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.
15
+ * This mixin adds some properties to access ol custom properties easily.
7
16
  */
8
17
  function PropertiesLayerMixin(Base) {
9
- return class extends Base {
18
+ return class PropertiesLayer extends Base {
19
+ constructor(...args) {
20
+ const options = args[0];
21
+ super(options);
22
+ this.olEventsKeys = [];
23
+ this.options = {};
24
+ if (options.properties) {
25
+ deprecated("Deprecated. Don't use properties options. Pass the values directly in options object.");
26
+ this.setProperties(options.properties);
27
+ }
28
+ // Update parent property
29
+ this.on('propertychange', (evt) => {
30
+ if (evt.key === 'children') {
31
+ this.onChildrenChange(evt.oldValue);
32
+ }
33
+ });
34
+ this.options = options;
35
+ this.set('children', options.children || []); // Trigger the on children change event
36
+ }
37
+ /**
38
+ * Initialize the layer with the map passed in parameters.
39
+ *
40
+ * @param {ol/Map~Map} map A map.
41
+ */
42
+ attachToMap(map) {
43
+ // @ts-expect-error attachToMap not necessarily exists
44
+ (super.attachToMap || (() => { }))(map);
45
+ (this.get('children') || []).forEach((child) => {
46
+ map.addLayer(child);
47
+ });
48
+ }
49
+ /**
50
+ * Terminate what was initialized in init function. Remove layer, events...
51
+ */
52
+ detachFromMap() {
53
+ unByKey(this.olEventsKeys);
54
+ (this.get('children') || []).forEach((child) => {
55
+ this.map.removeLayer(child);
56
+ });
57
+ // @ts-expect-error detachToMap not necessarily exists
58
+ (super.detachFromMap || (() => { }))();
59
+ }
60
+ /**
61
+ * Return the an array containing all the descendants of the layer in a flat array. Including the current layer.
62
+ * @deprecated
63
+ */
64
+ flat() {
65
+ deprecated('Layer.flat is deprecated. Use getLayersAsFlatArray utils method instead.');
66
+ return getLayersAsFlatArray(this);
67
+ }
68
+ /** @private */
69
+ onChildrenChange(oldValue) {
70
+ // Set the parent property
71
+ (oldValue || []).forEach((child) => {
72
+ child.set('parent', undefined);
73
+ });
74
+ (this.get('children') || []).forEach((child) => {
75
+ child.set('parent', this);
76
+ });
77
+ }
78
+ // @ts-expect-error - this is a mixin
79
+ setMapInternal(map) {
80
+ if (map) {
81
+ super.setMapInternal(map);
82
+ this.attachToMap(map);
83
+ }
84
+ else {
85
+ this.detachFromMap();
86
+ super.setMapInternal(map);
87
+ }
88
+ }
89
+ /** @deprecated */
10
90
  get children() {
91
+ deprecated("Layer.children is deprecated. Use the Layer.get('children') method instead.");
11
92
  return this.get('children') || [];
12
93
  }
94
+ /** @deprecated */
13
95
  set children(newValue) {
96
+ deprecated("Layer.children is deprecated. Use the Layer.set('children', children) method instead.");
14
97
  this.set('children', newValue || []);
15
98
  }
99
+ /** @deprecated */
16
100
  get copyrights() {
17
- // eslint-disable-next-line no-console
18
- console.warn('Deprecated. Use the source object to get the attributions');
101
+ deprecated('Layer.copyrights is deprecated. Get the attributions from the source object');
19
102
  return this.get('copyrights');
20
103
  }
104
+ /** @deprecated */
21
105
  set copyrights(newCopyrights) {
22
- // eslint-disable-next-line no-console
23
- console.warn('Deprecated. Use the source object to set the attributions');
106
+ deprecated('Layer.copyrights is deprecated. Set the attributions to the source object.');
24
107
  const arrValue = newCopyrights && !Array.isArray(newCopyrights)
25
108
  ? [newCopyrights]
26
109
  : newCopyrights;
27
110
  this.set('copyrights', arrValue || []);
28
111
  }
112
+ /** @deprecated */
29
113
  get disabled() {
114
+ deprecated("Layer.disabled is deprecated. Use the Layer.get('disabled') method instead.");
30
115
  return this.get('disabled');
31
116
  }
117
+ /** @deprecated */
32
118
  set disabled(newValue) {
119
+ deprecated("Layer.disabled is deprecated. Use the Layer.set('disabled', newValue) method instead.");
33
120
  this.set('disabled', newValue);
34
121
  }
122
+ /** @deprecated */
123
+ /** @deprecated */
35
124
  get group() {
125
+ deprecated("Layer.group is deprecated. Use the Layer.get('group') method instead.");
36
126
  return this.get('group');
37
127
  }
128
+ /** @deprecated */
38
129
  get hitTolerance() {
39
- // eslint-disable-next-line no-console
40
- console.warn('Deprecated. Pass the pixelTolerance when you request the features.');
130
+ deprecated('Layer.hitTolerance is deprecated.Pass the hitTolerance when you request the features.');
41
131
  return this.get('hitTolerance') || 5;
42
132
  }
133
+ /** @deprecated */
134
+ set hitTolerance(newValue) {
135
+ deprecated('Layer.hitTolerance is deprecated.Pass the hitTolerance when you request the features.');
136
+ this.set('hitTolerance', newValue);
137
+ }
43
138
  get key() {
44
139
  return this.get('key') || this.get('name') || getUid(this);
45
140
  }
46
141
  get map() {
47
142
  return this.getMapInternal();
48
143
  }
144
+ /** @deprecated */
49
145
  get name() {
146
+ deprecated("Layer.name is deprecated. Use the Layer.get('name') method instead.");
50
147
  return this.get('name');
51
148
  }
149
+ /** @deprecated */
52
150
  get olLayer() {
53
- // eslint-disable-next-line no-console
54
- console.warn("Deprecated property: mobility-toolbox-js/ol layers inherits now from ol/layer/Layer class. This getter is only a redirect to the current 'this' object.");
151
+ deprecated("Layer.olLayer is deprecated. mobility-toolbox-js/ol layers inherits now from ol/layer/Layer class. This getter is only a redirect to the current 'this' object.");
55
152
  return this;
56
153
  }
57
154
  // eslint-disable-next-line class-methods-use-this
58
155
  set olLayer(newValue) {
59
- // eslint-disable-next-line no-console
60
- console.log('Deprecated property: mobility-toolbox-js/ol layers inherits now from ol/layer/Layer class. This setter has no effect.');
156
+ deprecated('Layer.olLayer is deprecated. mobility-toolbox-js/ol layers inherits now from ol/layer/Layer class. This setter has no effect.');
61
157
  }
158
+ /** @deprecated */
159
+ // get olListenersKeys(): EventsKey[] {
160
+ // return this.olEventsKeys;
161
+ // }
162
+ /** @deprecated */
62
163
  get parent() {
164
+ deprecated("Layer.parent is deprecated. Use the Layer.get('parent') method instead.");
63
165
  return this.get('parent');
64
166
  }
167
+ /** @deprecated */
65
168
  set parent(newValue) {
169
+ deprecated("Layer.parent is deprecated. Use the Layer.set('parent', parent) method instead.");
66
170
  this.set('parent', newValue);
67
171
  }
172
+ /** @deprecated */
68
173
  get visible() {
174
+ deprecated('Layer.visible is deprecated. Use the Layer.getVisible() method instead.');
69
175
  return this.getVisible();
70
176
  }
177
+ /** @deprecated */
71
178
  set visible(newValue) {
179
+ deprecated('Layer.visible is deprecated. Use the Layer.setVisible(newValue) method instead.');
72
180
  this.setVisible(newValue);
73
181
  }
74
- constructor(options) {
75
- var _a;
76
- super(options);
77
- this.options = {};
78
- this.olListenersKeys = [];
79
- if (options.properties) {
80
- // eslint-disable-next-line no-console
81
- console.warn("Deprecated. Don't use properties options. Pass the values directly in options object.");
82
- this.setProperties(options.properties);
83
- }
84
- (_a = this.olListenersKeys) === null || _a === void 0 ? void 0 : _a.push(
85
- // Update parent property
86
- this.on('propertychange', (evt) => {
87
- if (evt.key === 'children') {
88
- this.onChildrenChange(evt.oldValue);
89
- }
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
- }));
110
- this.options = options;
111
- this.children = options.children || []; // Trigger the on children change event
112
- }
113
- setMapInternal(map) {
114
- super.setMapInternal(map);
115
- if (map) {
116
- this.attachToMap(map);
117
- }
118
- else {
119
- this.detachFromMap();
120
- }
121
- }
122
- /** @private */
123
- onChildrenChange(oldValue) {
124
- // Set the parent property
125
- (oldValue || []).forEach((child) => {
126
- child.set('parent', undefined);
127
- });
128
- (this.children || []).forEach((child) => {
129
- child.set('parent', this);
130
- });
131
- }
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
- /**
173
- * Initialize the layer with the map passed in parameters.
174
- *
175
- * @param {ol/Map~Map} map A map.
176
- */
177
- attachToMap(map) {
178
- // @ts-ignore
179
- (super.attachToMap || (() => { }))(map);
180
- (this.get('children') || []).forEach((child) => {
181
- map.addLayer(child);
182
- });
183
- }
184
- /**
185
- * Terminate what was initialized in init function. Remove layer, events...
186
- */
187
- detachFromMap() {
188
- (this.get('children') || []).forEach((child) => {
189
- this.map.removeLayer(child);
190
- });
191
- // @ts-ignore
192
- (super.detachFromMap || (() => { }))(map);
193
- }
194
- /**
195
- * Return the an array containing all the descendants of the layer in a flat array. Including the current layer.
196
- */
197
- flat() {
198
- return getLayersAsFlatArray(this);
199
- }
200
182
  };
201
183
  }
202
184
  export default PropertiesLayerMixin;
@@ -0,0 +1 @@
1
+ export { default as MobilityLayerMixin } from './MobilityLayerMixin';
@@ -0,0 +1,2 @@
1
+ // eslint-disable-next-line import/prefer-default-export
2
+ export { default as MobilityLayerMixin } from './MobilityLayerMixin';
File without changes