mobility-toolbox-js 3.0.0-beta.2 → 3.0.0-beta.20

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 +344 -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 +16 -10
  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 +22160 -14512
  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 +4 -1
  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 +101 -0
  87. package/ol/layers/Layer.js +17 -0
  88. package/ol/layers/MaplibreLayer.d.ts +160 -0
  89. package/ol/layers/MaplibreLayer.js +88 -24
  90. package/ol/layers/MaplibreStyleLayer.d.ts +242 -0
  91. package/ol/layers/MaplibreStyleLayer.js +291 -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 +31 -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 +98 -0
  99. package/ol/mixins/MobilityLayerMixin.js +1 -4
  100. package/ol/mixins/PropertiesLayerMixin.d.ts +135 -0
  101. package/ol/mixins/PropertiesLayerMixin.js +108 -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,101 @@
1
+ import OLLayer from 'ol/layer/Layer';
2
+ import { MobilityLayerOptions } from '../mixins/MobilityLayerMixin';
3
+ declare const Layer_base: {
4
+ new (...args: any[]): {
5
+ olEventsKeys: import("ol/events").EventsKey[];
6
+ options?: import("../mixins/PropertiesLayerMixin").PropertiesLayerMixinOptions;
7
+ attachToMap(map: import("ol").Map): void;
8
+ detachFromMap(): void;
9
+ flat(): any[];
10
+ onChildrenChange(oldValue: OLLayer[]): void;
11
+ setMapInternal: ((map: import("ol").Map) => void) & ((map: import("ol").default | null) => void);
12
+ children: OLLayer<import("ol/source").Source, import("ol/renderer/Layer").default<any>>[];
13
+ get copyrights(): string;
14
+ set copyrights(newCopyrights: string | string[]);
15
+ disabled: boolean;
16
+ readonly group: string;
17
+ readonly hitTolerance: number;
18
+ readonly key: string;
19
+ readonly map: import("ol").Map;
20
+ readonly name: string;
21
+ olLayer: OLLayer;
22
+ parent: OLLayer<import("ol/source").Source, import("ol/renderer/Layer").default<any>>;
23
+ visible: boolean;
24
+ on: import("ol/layer/Layer").LayerOnSignature<import("ol/events").EventsKey>;
25
+ once: import("ol/layer/Layer").LayerOnSignature<import("ol/events").EventsKey>;
26
+ un: import("ol/layer/Layer").LayerOnSignature<void>;
27
+ render: (frameState: import("ol/Map").FrameState | null, target: HTMLElement) => HTMLElement | null;
28
+ getSource: () => import("ol/source").Source | null;
29
+ getRenderSource: () => import("ol/source").Source | null;
30
+ getFeatures: (pixel: import("ol/pixel").Pixel) => Promise<Array<import("ol/Feature").FeatureLike>>;
31
+ getData: (pixel: import("ol/pixel").Pixel) => Uint8ClampedArray | Uint8Array | Float32Array | DataView | null;
32
+ isVisible: (view?: import("ol").View | import("ol/View").ViewStateLayerStateExtent | undefined) => boolean;
33
+ getAttributions: (view?: import("ol").View | import("ol/View").ViewStateLayerStateExtent | undefined) => Array<string>;
34
+ unrender: () => void;
35
+ getDeclutter: () => string;
36
+ renderDeclutter: (frameState: import("ol/Map").FrameState, layerState: import("ol/layer/Layer").State) => void;
37
+ renderDeferred: (frameState: import("ol/Map").FrameState) => void;
38
+ getMapInternal: () => import("ol").default | null;
39
+ setMap: (map: import("ol").default | null) => void;
40
+ setSource: (source: import("ol/source").Source | null) => void;
41
+ getRenderer: () => import("ol/renderer/Layer").default<any> | null;
42
+ hasRenderer: () => boolean;
43
+ getBackground: () => import("ol/layer/Base").BackgroundColor | false;
44
+ getClassName: () => string;
45
+ getLayerState: (managed?: boolean | undefined) => import("ol/layer/Layer").State;
46
+ getLayersArray: (array?: import("ol/layer/Layer").default<import("ol/source").default, import("ol/renderer/Layer").default<any>>[] | undefined) => Array<import("ol/layer/Layer").default>;
47
+ getLayerStatesArray: (states?: import("ol/layer/Layer").State[] | undefined) => Array<import("ol/layer/Layer").State>;
48
+ getExtent: () => import("ol/extent").Extent | undefined;
49
+ getMaxResolution: () => number;
50
+ getMinResolution: () => number;
51
+ getMinZoom: () => number;
52
+ getMaxZoom: () => number;
53
+ getOpacity: () => number;
54
+ getSourceState: () => import("ol/source/Source").State;
55
+ getVisible: () => boolean;
56
+ getZIndex: () => number | undefined;
57
+ setBackground: (background?: import("ol/layer/Base").BackgroundColor | undefined) => void;
58
+ setExtent: (extent: import("ol/extent").Extent | undefined) => void;
59
+ setMaxResolution: (maxResolution: number) => void;
60
+ setMinResolution: (minResolution: number) => void;
61
+ setMaxZoom: (maxZoom: number) => void;
62
+ setMinZoom: (minZoom: number) => void;
63
+ setOpacity: (opacity: number) => void;
64
+ setVisible: (visible: boolean) => void;
65
+ setZIndex: (zindex: number) => void;
66
+ get: (key: string) => any;
67
+ getKeys: () => Array<string>;
68
+ getProperties: () => {
69
+ [x: string]: any;
70
+ };
71
+ getPropertiesInternal: () => {
72
+ [x: string]: any;
73
+ } | null;
74
+ hasProperties: () => boolean;
75
+ notify: (key: string, oldValue: any) => void;
76
+ addChangeListener: (key: string, listener: import("ol/events").Listener) => void;
77
+ removeChangeListener: (key: string, listener: import("ol/events").Listener) => void;
78
+ set: (key: string, value: any, silent?: boolean | undefined) => void;
79
+ setProperties: (values: {
80
+ [x: string]: any;
81
+ }, silent?: boolean | undefined) => void;
82
+ unset: (key: string, silent?: boolean | undefined) => void;
83
+ changed: () => void;
84
+ getRevision: () => number;
85
+ addEventListener: (type: string, listener: import("ol/events").Listener) => void;
86
+ dispatchEvent: (event: import("ol/events/Event").default | string) => boolean | undefined;
87
+ getListeners: (type: string) => Array<import("ol/events").Listener> | undefined;
88
+ hasListener: (type?: string | undefined) => boolean;
89
+ removeEventListener: (type: string, listener: import("ol/events").Listener) => void;
90
+ dispose: () => void;
91
+ };
92
+ } & typeof OLLayer;
93
+ /**
94
+ * An OpenLayers layer here only for backward compatibility v2.
95
+ * @deprecated
96
+ */
97
+ declare class Layer extends Layer_base {
98
+ constructor(options: MobilityLayerOptions);
99
+ clone(newOptions: MobilityLayerOptions): Layer;
100
+ }
101
+ export default Layer;
@@ -0,0 +1,17 @@
1
+ import OLLayer from 'ol/layer/Layer';
2
+ import MobilityLayerMixin from '../mixins/MobilityLayerMixin';
3
+ /**
4
+ * An OpenLayers layer here only for backward compatibility v2.
5
+ * @deprecated
6
+ */
7
+ class Layer extends MobilityLayerMixin(OLLayer) {
8
+ constructor(options) {
9
+ super(options);
10
+ // eslint-disable-next-line no-console
11
+ console.warn('Layer is deprecated. Use an OpenLayers Layer instead.');
12
+ }
13
+ clone(newOptions) {
14
+ return new Layer(Object.assign(Object.assign({}, (this.options || {})), (newOptions || {})));
15
+ }
16
+ }
17
+ export default Layer;
@@ -0,0 +1,160 @@
1
+ import OlMap from 'ol/Map';
2
+ import { MapLibreLayer } from '@geoblocks/ol-maplibre-layer';
3
+ import type { MapLibreLayerOptions, MapLibreOptions } from '@geoblocks/ol-maplibre-layer/lib/types/MapLibreLayer';
4
+ import { MobilityLayerOptions } from '../mixins/MobilityLayerMixin';
5
+ export type MaplibreLayerOptions = MobilityLayerOptions & MapLibreLayerOptions & {
6
+ apiKey?: string;
7
+ apiKeyName?: string;
8
+ style?: null | string | maplibregl.StyleSpecification;
9
+ url?: string;
10
+ mapLibreOptions?: MapLibreOptions;
11
+ };
12
+ declare const MaplibreLayer_base: {
13
+ new (...args: any[]): {
14
+ olEventsKeys: import("ol/events").EventsKey[];
15
+ options?: import("../mixins/PropertiesLayerMixin").PropertiesLayerMixinOptions;
16
+ attachToMap(map: OlMap): void;
17
+ detachFromMap(): void;
18
+ flat(): any[];
19
+ onChildrenChange(oldValue: import("ol/layer").Layer[]): void;
20
+ setMapInternal: ((map: OlMap) => void) & ((map: import("ol/Map").default | null) => void);
21
+ children: import("ol/layer").Layer<import("ol/source").Source, import("ol/renderer/Layer").default<any>>[];
22
+ get copyrights(): string;
23
+ set copyrights(newCopyrights: string | string[]);
24
+ disabled: boolean;
25
+ readonly group: string;
26
+ readonly hitTolerance: number;
27
+ readonly key: string;
28
+ readonly map: OlMap;
29
+ readonly name: string;
30
+ olLayer: import("ol/layer").Layer;
31
+ parent: import("ol/layer").Layer<import("ol/source").Source, import("ol/renderer/Layer").default<any>>;
32
+ visible: boolean;
33
+ on: import("ol/layer/Layer").LayerOnSignature<import("ol/events").EventsKey>;
34
+ once: import("ol/layer/Layer").LayerOnSignature<import("ol/events").EventsKey>;
35
+ un: import("ol/layer/Layer").LayerOnSignature<void>;
36
+ render: (frameState: import("ol/Map").FrameState | null, target: HTMLElement) => HTMLElement | null;
37
+ getSource: () => import("ol/source").Source | null;
38
+ getRenderSource: () => import("ol/source").Source | null;
39
+ getFeatures: (pixel: import("ol/pixel").Pixel) => Promise<Array<import("ol/Feature").FeatureLike>>;
40
+ getData: (pixel: import("ol/pixel").Pixel) => Uint8ClampedArray | Uint8Array | Float32Array | DataView | null;
41
+ isVisible: (view?: import("ol").View | import("ol/View").ViewStateLayerStateExtent | undefined) => boolean;
42
+ getAttributions: (view?: import("ol").View | import("ol/View").ViewStateLayerStateExtent | undefined) => Array<string>;
43
+ unrender: () => void;
44
+ getDeclutter: () => string;
45
+ renderDeclutter: (frameState: import("ol/Map").FrameState, layerState: import("ol/layer/Layer").State) => void;
46
+ renderDeferred: (frameState: import("ol/Map").FrameState) => void;
47
+ getMapInternal: () => import("ol/Map").default | null;
48
+ setMap: (map: import("ol/Map").default | null) => void;
49
+ setSource: (source: import("ol/source").Source | null) => void;
50
+ getRenderer: () => import("ol/renderer/Layer").default<any> | null;
51
+ hasRenderer: () => boolean;
52
+ getBackground: () => import("ol/layer/Base").BackgroundColor | false;
53
+ getClassName: () => string;
54
+ getLayerState: (managed?: boolean | undefined) => import("ol/layer/Layer").State;
55
+ getLayersArray: (array?: import("ol/layer").default<import("ol/source").default, import("ol/renderer/Layer").default<any>>[] | undefined) => Array<import("ol/layer").default>;
56
+ getLayerStatesArray: (states?: import("ol/layer/Layer").State[] | undefined) => Array<import("ol/layer/Layer").State>;
57
+ getExtent: () => import("ol/extent").Extent | undefined;
58
+ getMaxResolution: () => number;
59
+ getMinResolution: () => number;
60
+ getMinZoom: () => number;
61
+ getMaxZoom: () => number;
62
+ getOpacity: () => number;
63
+ getSourceState: () => import("ol/source/Source").State;
64
+ getVisible: () => boolean;
65
+ getZIndex: () => number | undefined;
66
+ setBackground: (background?: import("ol/layer/Base").BackgroundColor | undefined) => void;
67
+ setExtent: (extent: import("ol/extent").Extent | undefined) => void;
68
+ setMaxResolution: (maxResolution: number) => void;
69
+ setMinResolution: (minResolution: number) => void;
70
+ setMaxZoom: (maxZoom: number) => void;
71
+ setMinZoom: (minZoom: number) => void;
72
+ setOpacity: (opacity: number) => void;
73
+ setVisible: (visible: boolean) => void;
74
+ setZIndex: (zindex: number) => void;
75
+ get: (key: string) => any;
76
+ getKeys: () => Array<string>;
77
+ getProperties: () => {
78
+ [x: string]: any;
79
+ };
80
+ getPropertiesInternal: () => {
81
+ [x: string]: any;
82
+ } | null;
83
+ hasProperties: () => boolean;
84
+ notify: (key: string, oldValue: any) => void;
85
+ addChangeListener: (key: string, listener: import("ol/events").Listener) => void;
86
+ removeChangeListener: (key: string, listener: import("ol/events").Listener) => void;
87
+ set: (key: string, value: any, silent?: boolean | undefined) => void;
88
+ setProperties: (values: {
89
+ [x: string]: any;
90
+ }, silent?: boolean | undefined) => void;
91
+ unset: (key: string, silent?: boolean | undefined) => void;
92
+ changed: () => void;
93
+ getRevision: () => number;
94
+ addEventListener: (type: string, listener: import("ol/events").Listener) => void;
95
+ dispatchEvent: (event: import("ol/events/Event").default | string) => boolean | undefined;
96
+ getListeners: (type: string) => Array<import("ol/events").Listener> | undefined;
97
+ hasListener: (type?: string | undefined) => boolean;
98
+ removeEventListener: (type: string, listener: import("ol/events").Listener) => void;
99
+ dispose: () => void;
100
+ };
101
+ } & typeof MapLibreLayer;
102
+ /**
103
+ * An OpenLayers layer able to display data from the [geOps Maps API](https://developer.geops.io/apis/maps).
104
+ *
105
+ * @example
106
+ * import { MaplibreLayer } from 'mobility-toolbox-js/ol';
107
+ *
108
+ * const layer = new MaplibreLayer({
109
+ * apiKey: 'yourApiKey',
110
+ * // apiKeyName: 'key',
111
+ * // mapLibreOptions: {
112
+ * // interactive: false,
113
+ * // trackResize: false,
114
+ * // attributionControl: false,
115
+ * // }
116
+ * // queryRenderedFeaturesOptions: {
117
+ * // layers: ['waters_lakes'], // map.getFeaturesAtPixel will only return lakes.
118
+ * // },
119
+ * // style: 'travic_v2',
120
+ * // url: 'https://maps.geops.io',
121
+ * });
122
+ *
123
+ * @classproperty {maplibregl.Map} mapLibreMap - The Maplibre map object. Readonly.
124
+ * @classproperty {string} style - geOps Maps api style.
125
+ * @extends {ol/layer/Layer~Layer}
126
+ * @public
127
+ */
128
+ declare class MaplibreLayer extends MaplibreLayer_base {
129
+ get mbMap(): maplibregl.Map | undefined;
130
+ get maplibreMap(): maplibregl.Map | undefined;
131
+ get style(): string;
132
+ set style(newValue: string);
133
+ get url(): string;
134
+ set url(newValue: string);
135
+ /**
136
+ * Constructor.
137
+ *
138
+ * @param {MaplibreLayerOptions} options
139
+ * @param {string} options.apiKey Access key for [geOps apis](https://developer.geops.io/).
140
+ * @param {string} [options.apiKeyName="key"] The geOps Maps API key name.
141
+ * @param {maplibregl.MapOptions} [options.mapLibreOptions={ interactive: false, trackResize: false, attributionControl: false }] Maplibre map options.
142
+ * @param {string} [options.style="travic_v2"] The geOps Maps API style.
143
+ * @param {string} [options.url="https://maps.geops.io"] The geOps Maps API url.
144
+ */
145
+ constructor(options: MaplibreLayerOptions);
146
+ /**
147
+ * Initialize the layer and listen to feature clicks.
148
+ * @param {ol/Map~Map} map
149
+ */
150
+ attachToMap(map: OlMap): void;
151
+ getStyle(): string;
152
+ updateMaplibreMap(): void;
153
+ /**
154
+ * Create a copy of the MaplibreLayer.
155
+ * @param {MaplibreLayerOptions} newOptions Options to override
156
+ * @return {MaplibreLayer} A MaplibreLayer layer
157
+ */
158
+ clone(newOptions: MaplibreLayerOptions): MaplibreLayer;
159
+ }
160
+ export default MaplibreLayer;
@@ -1,8 +1,14 @@
1
- import { Map } from 'maplibre-gl';
2
- import MapGlLayer from './MapGlLayer';
3
- import MaplibreLayerRenderer from '../renderers/MaplibreLayerRenderer';
1
+ import debounce from 'lodash.debounce';
2
+ import { MapLibreLayer } from '@geoblocks/ol-maplibre-layer';
3
+ import { getUrlWithParams } from '../../common/utils';
4
+ import MobilityLayerMixin from '../mixins/MobilityLayerMixin';
5
+ const buildStyleUrl = (url, style, apiKey, apiKeyName) => {
6
+ return getUrlWithParams(`${url}/styles/${style}/style.json`, {
7
+ [apiKeyName]: apiKey,
8
+ }).toString();
9
+ };
4
10
  /**
5
- * This layer is meant to facilitate the use of the geOps Maps api in an OpenLayers map using Maplibre.
11
+ * An OpenLayers layer able to display data from the [geOps Maps API](https://developer.geops.io/apis/maps).
6
12
  *
7
13
  * @example
8
14
  * import { MaplibreLayer } from 'mobility-toolbox-js/ol';
@@ -10,7 +16,7 @@ import MaplibreLayerRenderer from '../renderers/MaplibreLayerRenderer';
10
16
  * const layer = new MaplibreLayer({
11
17
  * apiKey: 'yourApiKey',
12
18
  * // apiKeyName: 'key',
13
- * // mapOptions: {
19
+ * // mapLibreOptions: {
14
20
  * // interactive: false,
15
21
  * // trackResize: false,
16
22
  * // attributionControl: false,
@@ -22,42 +28,99 @@ import MaplibreLayerRenderer from '../renderers/MaplibreLayerRenderer';
22
28
  * // url: 'https://maps.geops.io',
23
29
  * });
24
30
  *
25
- * @classproperty {maplibregl.Map} maplibreMap - The Maplibre map object. Readonly.
26
- * @classproperty {maplibregl.QueryRenderedFeaturesOptions} queryRenderedFeaturesOptions - Options used when we query features using map.getFeaturesAtPixel().
31
+ * @classproperty {maplibregl.Map} mapLibreMap - The Maplibre map object. Readonly.
27
32
  * @classproperty {string} style - geOps Maps api style.
28
33
  * @extends {ol/layer/Layer~Layer}
29
34
  * @public
30
35
  */
31
- export default class MaplibreLayer extends MapGlLayer {
32
- /** @private */
36
+ class MaplibreLayer extends MobilityLayerMixin(MapLibreLayer) {
37
+ get mbMap() {
38
+ // eslint-disable-next-line no-console
39
+ console.warn('MaplibreLayer.mbMap is deprecated. Use layer.maplibreMap.');
40
+ return this.maplibreMap;
41
+ }
33
42
  get maplibreMap() {
34
- return this.mbMap;
43
+ // eslint-disable-next-line no-console
44
+ console.warn('MaplibreLayer.maplibreMap is deprecated. Use layer.mapLibreMap.');
45
+ return this.mapLibreMap;
46
+ }
47
+ // get queryRenderedFeaturesOptions(): maplibregl.QueryRenderedFeaturesOptions {
48
+ // return this.get('queryRenderedFeaturesOptions');
49
+ // }
50
+ // set queryRenderedFeaturesOptions(
51
+ // newValue: maplibregl.QueryRenderedFeaturesOptions,
52
+ // ) {
53
+ // this.set('queryRenderedFeaturesOptions', newValue);
54
+ // }
55
+ get style() {
56
+ return this.get('style');
57
+ }
58
+ set style(newValue) {
59
+ this.set('style', newValue);
60
+ }
61
+ get url() {
62
+ return this.get('url');
63
+ }
64
+ set url(newValue) {
65
+ this.set('url', newValue);
35
66
  }
36
67
  /**
37
68
  * Constructor.
38
69
  *
39
70
  * @param {MaplibreLayerOptions} options
40
71
  * @param {string} options.apiKey Access key for [geOps apis](https://developer.geops.io/).
41
- * @param {string} [options.apiKeyName="key"] The geOps Maps api key name.
42
- * @param {maplibregl.MapOptions} [options.mapOptions={ interactive: false, trackResize: false, attributionControl: false }] Maplibre map options.
43
- * @param {string} [options.style="travic_v2"] The geOps Maps api style.
44
- * @param {string} [options.url="https://maps.geops.io"] The geOps Maps api url.
72
+ * @param {string} [options.apiKeyName="key"] The geOps Maps API key name.
73
+ * @param {maplibregl.MapOptions} [options.mapLibreOptions={ interactive: false, trackResize: false, attributionControl: false }] Maplibre map options.
74
+ * @param {string} [options.style="travic_v2"] The geOps Maps API style.
75
+ * @param {string} [options.url="https://maps.geops.io"] The geOps Maps API url.
45
76
  */
46
77
  constructor(options) {
47
- super(Object.assign({}, options));
78
+ const newOptions = Object.assign(Object.assign({ apiKeyName: 'key', style: 'travic_v2', url: 'https://maps.geops.io' }, (options || {})), { mapLibreOptions: Object.assign({}, (options.mapLibreOptions || {})) });
79
+ if (!newOptions.mapLibreOptions.style &&
80
+ newOptions.apiKey &&
81
+ newOptions.style &&
82
+ typeof newOptions.style === 'string') {
83
+ newOptions.mapLibreOptions.style = buildStyleUrl(newOptions.url, newOptions.style, newOptions.apiKey, newOptions.apiKeyName);
84
+ }
85
+ super(newOptions);
48
86
  }
49
87
  /**
50
- * @private
88
+ * Initialize the layer and listen to feature clicks.
89
+ * @param {ol/Map~Map} map
51
90
  */
52
- createRenderer() {
53
- return new MaplibreLayerRenderer(this);
91
+ attachToMap(map) {
92
+ super.attachToMap(map);
93
+ const updateMaplibreMapDebounced = debounce(this.updateMaplibreMap.bind(this), 150);
94
+ this.olEventsKeys.push(this.on('propertychange', (evt) => {
95
+ if (/(url|style)/.test(evt.key)) {
96
+ updateMaplibreMapDebounced();
97
+ }
98
+ }));
54
99
  }
55
- /**
56
- * @private
57
- */
58
- // eslint-disable-next-line class-methods-use-this
59
- createMap(options) {
60
- return new Map(options);
100
+ getStyle() {
101
+ // If the style is a complete style object, use it directly.
102
+ if (this.style &&
103
+ typeof this.style === 'object' &&
104
+ this.style.name &&
105
+ this.style.version) {
106
+ return this.style;
107
+ }
108
+ // If the url set is already a complete style url, use it directly.
109
+ if (this.url.includes('style.json')) {
110
+ return this.url;
111
+ }
112
+ /// Otherwise build the complete style url.
113
+ return buildStyleUrl(this.url, this.style, this.get('apiKey'), this.get('apiKeyName'));
114
+ }
115
+ updateMaplibreMap() {
116
+ var _a;
117
+ try {
118
+ (_a = this.mapLibreMap) === null || _a === void 0 ? void 0 : _a.setStyle(this.getStyle(), { diff: false });
119
+ }
120
+ catch (e) {
121
+ // eslint-disable-next-line no-console
122
+ console.error('Error while updating MaplibreMap', e);
123
+ }
61
124
  }
62
125
  /**
63
126
  * Create a copy of the MaplibreLayer.
@@ -68,3 +131,4 @@ export default class MaplibreLayer extends MapGlLayer {
68
131
  return new MaplibreLayer(Object.assign(Object.assign({}, (this.options || {})), (newOptions || {})));
69
132
  }
70
133
  }
134
+ export default MaplibreLayer;