mobility-toolbox-js 3.0.0-beta.7 → 3.0.0-beta.9

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 (88) hide show
  1. package/api/HttpAPI.d.ts +31 -0
  2. package/api/RealtimeAPI.d.ts +359 -0
  3. package/api/RealtimeAPI.js +96 -89
  4. package/api/RoutingAPI.d.ts +37 -0
  5. package/api/StopsAPI.d.ts +38 -0
  6. package/api/WebSocketAPI.d.ts +153 -0
  7. package/api/index.d.ts +3 -0
  8. package/api/typedefs.d.ts +178 -0
  9. package/common/controls/StopFinderControlCommon.d.ts +53 -0
  10. package/common/index.d.ts +2 -0
  11. package/common/mixins/RealtimeLayerMixin.d.ts +273 -0
  12. package/common/styles/index.d.ts +4 -0
  13. package/common/styles/realtimeDefaultStyle.d.ts +36 -0
  14. package/common/styles/realtimeDelayStyle.d.ts +12 -0
  15. package/common/styles/realtimeHeadingStyle.d.ts +12 -0
  16. package/common/styles/realtimeSimpleStyle.d.ts +4 -0
  17. package/common/typedefs.d.ts +212 -0
  18. package/common/utils/compareDepartures.d.ts +10 -0
  19. package/common/utils/constants.d.ts +5 -0
  20. package/common/utils/createCanvas.d.ts +10 -0
  21. package/common/utils/createDefaultCopyrightElt.d.ts +5 -0
  22. package/common/utils/createDefaultStopFinderElt.d.ts +5 -0
  23. package/common/utils/createRealtimeFilters.d.ts +12 -0
  24. package/common/utils/debounceDeparturesMessages.d.ts +12 -0
  25. package/common/utils/debounceWebsocketMessages.d.ts +11 -0
  26. package/common/utils/getLayersAsFlatArray.d.ts +3 -0
  27. package/common/utils/getLayersAsFlatArray.js +5 -1
  28. package/common/utils/getMapGlCopyrights.d.ts +17 -0
  29. package/common/utils/getRealtimeModeSuffix.d.ts +9 -0
  30. package/common/utils/getUrlWithParams.d.ts +8 -0
  31. package/common/utils/getVehiclePosition.d.ts +16 -0
  32. package/common/utils/index.d.ts +16 -0
  33. package/common/utils/realtimeConfig.d.ts +64 -0
  34. package/common/utils/removeDuplicate.d.ts +9 -0
  35. package/common/utils/renderTrajectories.d.ts +16 -0
  36. package/common/utils/sortAndFilterDepartures.d.ts +15 -0
  37. package/common/utils/sortByDelay.d.ts +3 -0
  38. package/common/utils/timeUtils.d.ts +23 -0
  39. package/common/utils/toMercatorExtent.d.ts +5 -0
  40. package/iife.d.ts +2 -0
  41. package/index.d.ts +9 -0
  42. package/maplibre/controls/CopyrightControl.d.ts +35 -0
  43. package/maplibre/controls/index.d.ts +1 -0
  44. package/maplibre/index.d.ts +5 -0
  45. package/maplibre/layers/Layer.d.ts +28 -0
  46. package/maplibre/layers/RealtimeLayer.d.ts +160 -0
  47. package/maplibre/layers/RealtimeLayer.js +2 -2
  48. package/maplibre/layers/index.d.ts +2 -0
  49. package/maplibre/utils/getMercatorResolution.d.ts +7 -0
  50. package/maplibre/utils/getSourceCoordinates.d.ts +7 -0
  51. package/maplibre/utils/index.d.ts +2 -0
  52. package/mbt.js +137 -114
  53. package/mbt.js.map +3 -3
  54. package/mbt.min.js +13 -13
  55. package/mbt.min.js.map +3 -3
  56. package/ol/controls/CopyrightControl.d.ts +31 -0
  57. package/ol/controls/CopyrightControl.js +18 -8
  58. package/ol/controls/RoutingControl.d.ts +209 -0
  59. package/ol/controls/RoutingControl.js +3 -0
  60. package/ol/controls/StopFinderControl.d.ts +37 -0
  61. package/ol/controls/StopFinderControl.js +3 -0
  62. package/ol/controls/index.d.ts +3 -0
  63. package/ol/index.d.ts +6 -0
  64. package/ol/layers/MapGlLayer.d.ts +144 -0
  65. package/ol/layers/MapGlLayer.js +3 -1
  66. package/ol/layers/MaplibreLayer.d.ts +63 -0
  67. package/ol/layers/MaplibreStyleLayer.d.ts +235 -0
  68. package/ol/layers/MaplibreStyleLayer.js +1 -1
  69. package/ol/layers/RealtimeLayer.d.ts +285 -0
  70. package/ol/layers/RealtimeLayer.js +13 -7
  71. package/ol/layers/index.d.ts +3 -0
  72. package/ol/mixins/MobilityLayerMixin.d.ts +98 -0
  73. package/ol/mixins/MobilityLayerMixin.js +1 -4
  74. package/ol/mixins/PropertiesLayerMixin.d.ts +127 -0
  75. package/ol/mixins/PropertiesLayerMixin.js +5 -4
  76. package/ol/renderers/MaplibreLayerRenderer.d.ts +20 -0
  77. package/ol/renderers/MaplibreStyleLayerRenderer.d.ts +20 -0
  78. package/ol/renderers/RealtimeLayerRenderer.d.ts +22 -0
  79. package/ol/renderers/RealtimeLayerRenderer.js +9 -9
  80. package/ol/styles/fullTrajectoryDelayStyle.d.ts +6 -0
  81. package/ol/styles/fullTrajectoryStyle.d.ts +5 -0
  82. package/ol/styles/index.d.ts +3 -0
  83. package/ol/styles/routingStyle.d.ts +4 -0
  84. package/ol/utils/getFeatureInfoAtCoordinate.d.ts +8 -0
  85. package/ol/utils/getFeatureInfoAtCoordinate.js +1 -1
  86. package/ol/utils/index.d.ts +1 -0
  87. package/package.json +1 -1
  88. package/setupTests.d.ts +1 -0
@@ -0,0 +1,31 @@
1
+ import { MapEvent } from 'ol';
2
+ import Control, { Options } from 'ol/control/Control';
3
+ export type CopyrightControlOptions = Options & {
4
+ className?: 'string';
5
+ format?: (copyrights: string[]) => string;
6
+ };
7
+ /**
8
+ * Display layer's copyrights.
9
+ *
10
+ * @example
11
+ * import { Map } from 'ol';
12
+ * import { CopyrightControl } from 'mobility-toolbox-js/ol';
13
+ *
14
+ * const map = new Map({
15
+ * target: 'map',
16
+ * });
17
+ *
18
+ * const control = new CopyrightControl();
19
+ * map.addControl(control);
20
+ *
21
+ *
22
+ * @see <a href="/example/ol-copyright">Openlayers copyright example</a>
23
+ *
24
+ * @extends {ol/control/Control}
25
+ */
26
+ declare class CopyrightControl extends Control {
27
+ format: (copyrights: string[]) => string;
28
+ constructor(options?: CopyrightControlOptions);
29
+ render({ frameState }: MapEvent): void;
30
+ }
31
+ export default CopyrightControl;
@@ -26,6 +26,11 @@ class CopyrightControl extends Control {
26
26
  const element = createDefaultCopyrightElement();
27
27
  element.className = options.className || 'mbt-copyright';
28
28
  super(Object.assign({ element }, options));
29
+ this.format =
30
+ options.format ||
31
+ ((copyrights) => {
32
+ return copyrights === null || copyrights === void 0 ? void 0 : copyrights.join(' | ');
33
+ });
29
34
  }
30
35
  render({ frameState }) {
31
36
  if (!frameState) {
@@ -35,18 +40,23 @@ class CopyrightControl extends Control {
35
40
  let copyrights = [];
36
41
  // This code loop comes mainly from ol.
37
42
  frameState === null || frameState === void 0 ? void 0 : frameState.layerStatesArray.forEach((layerState) => {
43
+ var _a;
38
44
  const { layer } = layerState;
39
- if (frameState &&
40
- inView(layerState, frameState.viewState) &&
41
- layer &&
42
- layer.getSource &&
43
- layer.getSource() &&
44
- layer.getSource().getAttributions()) {
45
- copyrights = copyrights.concat(layer.getSource().getAttributions()(frameState));
45
+ if (frameState && inView(layerState, frameState.viewState)) {
46
+ if ((_a = layer === null || layer === void 0 ? void 0 : layer.getSource()) === null || _a === void 0 ? void 0 : _a.getAttributions()) {
47
+ copyrights = copyrights.concat(layer.getSource().getAttributions()(frameState));
48
+ }
49
+ if (layer === null || layer === void 0 ? void 0 : layer.get('copyrights')) {
50
+ let copyProp = layer.get('copyrights');
51
+ copyProp = !Array.isArray(copyProp) ? [copyProp] : copyProp;
52
+ if (copyProp === null || copyProp === void 0 ? void 0 : copyProp.length) {
53
+ copyrights.push(...copyProp);
54
+ }
55
+ }
46
56
  }
47
57
  });
48
58
  const unique = removeDuplicate(copyrights) || [];
49
- this.element.innerHTML = unique.join(' | ');
59
+ this.element.innerHTML = this.format(unique);
50
60
  }
51
61
  }
52
62
  export default CopyrightControl;
@@ -0,0 +1,209 @@
1
+ import { Feature } from 'ol';
2
+ import type { Map, MapBrowserEvent } from 'ol';
3
+ import { Geometry, LineString, Point } from 'ol/geom';
4
+ import { Modify } from 'ol/interaction';
5
+ import { GeoJSON } from 'ol/format';
6
+ import type { Coordinate } from 'ol/coordinate';
7
+ import type { StyleLike } from 'ol/style/Style';
8
+ import { EventsKey } from 'ol/events';
9
+ import { ModifyEvent } from 'ol/interaction/Modify';
10
+ import VectorLayer from 'ol/layer/Vector';
11
+ import VectorSource from 'ol/source/Vector';
12
+ import Control, { Options } from 'ol/control/Control';
13
+ import { RoutingAPI } from '../../api';
14
+ import type { RoutingGraph, RoutingMot, RoutingParameters, RoutingViaPoint } from '../../types';
15
+ export type RoutingControlOptions = Options & {
16
+ apiKey?: string;
17
+ active?: boolean;
18
+ stopsApiKey?: string;
19
+ stopsApiUrl?: string;
20
+ routingLayer?: VectorLayer<VectorSource<Feature<Geometry>>>;
21
+ graphs?: RoutingGraph[];
22
+ mot?: string;
23
+ modify?: boolean;
24
+ routingApiParams?: RoutingParameters;
25
+ useRawViaPoints?: boolean;
26
+ snapToClosestStation?: boolean;
27
+ style?: StyleLike;
28
+ onRouteError?: () => void;
29
+ };
30
+ export type AbotControllersByGraph = {
31
+ [key: string]: AbortController;
32
+ };
33
+ /**
34
+ * Display a route of a specified mean of transport.
35
+ *
36
+ * @example
37
+ * import { Map } from 'ol';
38
+ * import { RoutingControl } from 'mobility-toolbox-js/ol';
39
+ *
40
+ * const map = new Map({
41
+ * target: 'map'
42
+ * });
43
+ *
44
+ * const control = new RoutingControl();
45
+ *
46
+ * control.attachToMap(map)
47
+ *
48
+ * @classproperty {string} apiKey - Key used for RoutingApi requests.
49
+ * @classproperty {string} stopsApiKey - Key used for Stop lookup requests (defaults to apiKey).
50
+ * @classproperty {string} stopsApiUrl - Url used for Stop lookup requests (defaults to https://api.geops.io/stops/v1/lookup/).
51
+ * @classproperty {Array.<Array<graph="osm", minZoom=0, maxZoom=99>>} graphs - Array of routing graphs and min/max zoom levels. If you use the control in combination with the [geOps Maps API](https://developer.geops.io/apis/maps/), you may want to use the optimal level of generalizations: "[['gen4', 0, 8], ['gen3', 8, 9], ['gen2', 9, 11], ['gen1', 11, 13], ['osm', 13, 99]]"
52
+ * @classproperty {string} mot - Mean of transport to be used for routing.
53
+ * @classproperty {object} routingApiParams - object of additional parameters to pass to the routing api request.
54
+ * @classproperty {object} snapToClosestStation - If true, the routing will snap the coordinate to the closest station. Default to false.
55
+ * @classproperty {boolean} useRawViaPoints - Experimental property. Wen true, it allows the user to add via points using different kind of string. See "via" parameter defined by the [geOps Routing API](https://developer.geops.io/apis/routing/). Default to false, only array of coordinates and station's id are supported as via points.
56
+ * @classproperty {VectorLayer} routingLayer - Layer for adding route features.
57
+ * @classproperty {function} onRouteError - Callback on error.
58
+ * @classproperty {boolean} loading - True if the control is requesting the backend.
59
+ * @see <a href="/example/ol-routing">Openlayers routing example</a>
60
+ *
61
+ * @extends {Control}
62
+ * @implements {RoutingInterface}
63
+ * @public
64
+ */
65
+ declare class RoutingControl extends Control {
66
+ map?: Map;
67
+ viaPoints: RoutingViaPoint[];
68
+ routingLayer?: VectorLayer<VectorSource<Feature<Geometry>>>;
69
+ graphs: RoutingGraph[];
70
+ routingApiParams?: RoutingParameters;
71
+ useRawViaPoints: boolean;
72
+ snapToClosestStation: boolean;
73
+ cacheStationData: {
74
+ [key: string]: Coordinate;
75
+ };
76
+ abortControllers: {
77
+ [key: string]: AbortController;
78
+ };
79
+ apiKey?: string;
80
+ stopsApiKey?: string;
81
+ segments: Feature<LineString>[];
82
+ stopsApiUrl?: string;
83
+ api?: RoutingAPI;
84
+ format: GeoJSON;
85
+ graphsResolutions?: [number, number][];
86
+ onRouteError: (error?: Error, control?: RoutingControl) => void;
87
+ onMapClickKey?: EventsKey;
88
+ modifyInteraction?: Modify;
89
+ initialRouteDrag?: {
90
+ viaPoint?: Feature<Point>;
91
+ oldRoute?: Feature<LineString>;
92
+ segmentIndex?: number;
93
+ };
94
+ get active(): boolean;
95
+ set active(newValue: boolean);
96
+ get loading(): boolean;
97
+ set loading(newValue: boolean);
98
+ get modify(): any;
99
+ set modify(newValue: any);
100
+ get mot(): RoutingMot;
101
+ set mot(newValue: RoutingMot);
102
+ constructor(options?: RoutingControlOptions);
103
+ /**
104
+ * Calculate at which resolutions corresponds each generalizations.
105
+ *
106
+ * @private
107
+ */
108
+ static getGraphsResolutions(graphs: RoutingGraph[], map: Map): [number, number][];
109
+ /**
110
+ * Activet7deactivate the control when activ eproperty changes
111
+ * @private
112
+ */
113
+ onActiveChange(): void;
114
+ /**
115
+ * Adds/Replaces a viaPoint to the viaPoints array and redraws route:
116
+ * Adds a viaPoint at end of array by default.
117
+ * If an index is passed a viaPoint is added at the specified index.
118
+ * If an index is passed and overwrite x is > 0, x viaPoints at the specified
119
+ * index are replaced with a single new viaPoint.
120
+ * @param {number[]|string} coordinates Array of coordinates
121
+ * @param {number} [index=-1] Integer representing the index of the added viaPoint. If not specified, the viaPoint is added at the end of the array.
122
+ * @param {number} [overwrite=0] Marks the number of viaPoints that are removed at the specified index on add.
123
+ * @public
124
+ */
125
+ addViaPoint(coordinatesOrString: RoutingViaPoint, index?: number, overwrite?: number): void;
126
+ /**
127
+ * Removes a viaPoint at the passed array index and redraws route
128
+ * By default the last viaPoint is removed.
129
+ * @param {number} index Integer representing the index of the viaPoint to delete.
130
+ * @public
131
+ */
132
+ removeViaPoint(index?: number): void;
133
+ /**
134
+ * Replaces the current viaPoints with a new coordinate array.
135
+ * @param {Array<Array<number>>} coordinateArray Array of nested coordinates
136
+ * @public
137
+ */
138
+ setViaPoints(coordinateArray: Coordinate[]): void;
139
+ /**
140
+ * Removes all viaPoints, clears the source and triggers a change event
141
+ * @public
142
+ */
143
+ reset(): void;
144
+ /**
145
+ * Aborts viapoint and route requests
146
+ * @private
147
+ */
148
+ abortRequests(): void;
149
+ /**
150
+ * Draws route on map using an array of coordinates:
151
+ * If a single coordinate is passed a single point feature is added to map.
152
+ * If two or more coordinates are passed a request to the RoutingAPI fetches
153
+ * the route using the passed coordinates and the current mot.
154
+ * @private
155
+ */
156
+ drawRoute(): Promise<void | Feature<Geometry>> | Promise<Feature<Geometry> | null> | Promise<(void | never[])[]> | null;
157
+ /**
158
+ * Draw a via point. This function can parse all the possibilitiies
159
+ *
160
+ * @private
161
+ */
162
+ drawViaPoint(viaPoint: RoutingViaPoint, idx: number, abortController: AbortController): Promise<void | Feature<Geometry>> | Promise<Feature<Geometry> | null>;
163
+ /**
164
+ * Used on click on map while control is active:
165
+ * By default adds a viaPoint to the end of array.
166
+ * If an existing viaPoint is clicked removes the clicked viaPoint.
167
+ * @private
168
+ */
169
+ onMapClick(evt: MapBrowserEvent<MouseEvent>): void;
170
+ /**
171
+ * Used on start of the modify interaction. Stores relevant data
172
+ * in this.initialRouteDrag object
173
+ * @private
174
+ */
175
+ onModifyStart(evt: ModifyEvent): void;
176
+ /**
177
+ * Used on end of the modify interaction. Resolves feature modification:
178
+ * Line drag creates new viaPoint at the final coordinate of drag.
179
+ * Point drag replaces old viaPoint.
180
+ * @private
181
+ */
182
+ onModifyEnd(evt: ModifyEvent): void | Promise<never>;
183
+ /**
184
+ * Define a default element.
185
+ *
186
+ * @private
187
+ */
188
+ createDefaultElement(): void;
189
+ /**
190
+ * Create the interaction used to modify vertexes of features.
191
+ * @private
192
+ */
193
+ createModifyInteraction(): void;
194
+ /**
195
+ * Add click listener to map.
196
+ * @private
197
+ */
198
+ addListeners(): void;
199
+ /**
200
+ * Remove click listener from map.
201
+ * @private
202
+ */
203
+ removeListeners(): void;
204
+ setMap(map: Map): void;
205
+ activate(): void;
206
+ deactivate(): void;
207
+ render(): void;
208
+ }
209
+ export default RoutingControl;
@@ -114,6 +114,9 @@ class RoutingControl extends Control {
114
114
  this.segments = [];
115
115
  this.format = new GeoJSON({ featureProjection: 'EPSG:3857' });
116
116
  this.initialRouteDrag = {};
117
+ if (!this.element) {
118
+ this.createDefaultElement();
119
+ }
117
120
  /** True if the control is requesting the backend. */
118
121
  this.loading = false;
119
122
  /** @private */
@@ -0,0 +1,37 @@
1
+ import { Feature } from 'geojson';
2
+ import Control, { Options } from 'ol/control/Control';
3
+ import StopFinderControlCommon from '../../common/controls/StopFinderControlCommon';
4
+ export type StopFinderControlOptions = Options & StopFinderControlCommon & {
5
+ className?: string;
6
+ };
7
+ /**
8
+ * Search stations.
9
+ *
10
+ * @example
11
+ * import { Map } from 'ol';
12
+ * import { StopFinderControl } from 'mobility-toolbox-js/ol';
13
+ *
14
+ * const map = new Map({
15
+ * target: 'map',
16
+ * });
17
+ *
18
+ * const control = new StopFinderControl({
19
+ * apiKey: [yourApiKey]
20
+ * });
21
+ *
22
+ * map.addControl(control);
23
+ *
24
+ *
25
+ * @see <a href="/example/ol-search">Openlayers search example</a>
26
+ * @public
27
+ */
28
+ declare class StopFinderControl extends Control {
29
+ controller: StopFinderControlCommon;
30
+ constructor(options: StopFinderControlOptions);
31
+ /**
32
+ * @private
33
+ */
34
+ onSuggestionClick(suggestion: Feature): void;
35
+ search(q: string, abortController: AbortController): Promise<void>;
36
+ }
37
+ export default StopFinderControl;
@@ -39,5 +39,8 @@ class StopFinderControl extends Control {
39
39
  const coord = fromLonLat(suggestion.geometry.coordinates);
40
40
  (_a = this.getMap()) === null || _a === void 0 ? void 0 : _a.getView().setCenter(coord);
41
41
  }
42
+ search(q, abortController) {
43
+ return this.controller.search(q, abortController);
44
+ }
42
45
  }
43
46
  export default StopFinderControl;
@@ -0,0 +1,3 @@
1
+ export { default as CopyrightControl } from "./CopyrightControl";
2
+ export { default as RoutingControl } from "./RoutingControl";
3
+ export { default as StopFinderControl } from "./StopFinderControl";
package/ol/index.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ export * from "../api";
2
+ export * from "../common";
3
+ export * from "./controls";
4
+ export * from "./layers";
5
+ export * from "./styles";
6
+ export * from "./utils";
@@ -0,0 +1,144 @@
1
+ import Source from 'ol/source/Source';
2
+ import OlMap from 'ol/Map';
3
+ import BaseEvent from 'ol/events/Event';
4
+ import Layer from 'ol/layer/Layer';
5
+ import { AnyMapGlMap } from '../../types';
6
+ import { MobilityLayerOptions } from '../mixins/MobilityLayerMixin';
7
+ export type MapGlLayerOptions = MobilityLayerOptions & {
8
+ apiKey?: string;
9
+ apiKeyName?: string;
10
+ style?: string | maplibregl.StyleSpecification;
11
+ url?: string;
12
+ mapOptions: maplibregl.MapOptions;
13
+ queryRenderedFeaturesOptions: maplibregl.QueryRenderedFeaturesOptions;
14
+ };
15
+ declare const MapGlLayer_base: {
16
+ new (...args: any[]): {
17
+ options?: import("../mixins/PropertiesLayerMixin").PropertiesLayerMixinOptions | undefined;
18
+ olListenersKeys: import("ol/events").EventsKey[];
19
+ children: Layer<Source, import("ol/renderer/Layer").default<any>>[];
20
+ get copyrights(): string;
21
+ set copyrights(newCopyrights: string | string[]);
22
+ disabled: boolean;
23
+ readonly group: string;
24
+ readonly hitTolerance: boolean;
25
+ readonly key: string;
26
+ readonly map: OlMap;
27
+ readonly name: string;
28
+ olLayer: Layer<Source, import("ol/renderer/Layer").default<any>>;
29
+ parent: Layer<Source, import("ol/renderer/Layer").default<any>>;
30
+ visible: boolean;
31
+ setMapInternal: ((map: OlMap) => void) & ((map: OlMap | null) => void);
32
+ onChildrenChange(oldValue: Layer<Source, import("ol/renderer/Layer").default<any>>[]): void;
33
+ attachToMap(map: OlMap): void;
34
+ detachFromMap(): void;
35
+ flat(): any[];
36
+ addEventListener: (type: string, listener: import("ol/events").Listener) => void;
37
+ removeEventListener: (type: string, listener: import("ol/events").Listener) => void;
38
+ on: import("ol/layer/Layer").LayerOnSignature<import("ol/events").EventsKey>;
39
+ render: (frameState: import("ol/Map").FrameState | null, target: HTMLElement) => HTMLElement | null;
40
+ once: import("ol/layer/Layer").LayerOnSignature<import("ol/events").EventsKey>;
41
+ un: import("ol/layer/Layer").LayerOnSignature<void>;
42
+ getSource: () => Source | null;
43
+ getRenderSource: () => Source | null;
44
+ getFeatures: (pixel: import("ol/pixel").Pixel) => Promise<import("ol/Feature").FeatureLike[]>;
45
+ getData: (pixel: import("ol/pixel").Pixel) => Float32Array | Uint8ClampedArray | Uint8Array | DataView | null;
46
+ isVisible: (view?: import("ol/View").default | import("ol/View").ViewStateLayerStateExtent | undefined) => boolean;
47
+ getAttributions: (view?: import("ol/View").default | import("ol/View").ViewStateLayerStateExtent | undefined) => string[];
48
+ unrender: () => void;
49
+ getDeclutter: () => string;
50
+ renderDeclutter: (frameState: import("ol/Map").FrameState, layerState: import("ol/layer/Layer").State) => void;
51
+ renderDeferred: (frameState: import("ol/Map").FrameState) => void;
52
+ getMapInternal: () => OlMap | null;
53
+ setMap: (map: OlMap | null) => void;
54
+ setSource: (source: Source | null) => void;
55
+ getRenderer: () => import("ol/renderer/Layer").default<any> | null;
56
+ hasRenderer: () => boolean;
57
+ getBackground: () => false | import("ol/layer/Base").BackgroundColor;
58
+ getClassName: () => string;
59
+ getLayerState: (managed?: boolean | undefined) => import("ol/layer/Layer").State;
60
+ getLayersArray: (array?: Layer<Source, import("ol/renderer/Layer").default<any>>[] | undefined) => Layer<Source, import("ol/renderer/Layer").default<any>>[];
61
+ getLayerStatesArray: (states?: import("ol/layer/Layer").State[] | undefined) => import("ol/layer/Layer").State[];
62
+ getExtent: () => import("ol/extent").Extent | undefined;
63
+ getMaxResolution: () => number;
64
+ getMinResolution: () => number;
65
+ getMinZoom: () => number;
66
+ getMaxZoom: () => number;
67
+ getOpacity: () => number;
68
+ getSourceState: () => import("ol/source/Source").State;
69
+ getVisible: () => boolean;
70
+ getZIndex: () => number | undefined;
71
+ setBackground: (background?: import("ol/layer/Base").BackgroundColor | undefined) => void;
72
+ setExtent: (extent: import("ol/extent").Extent | undefined) => void;
73
+ setMaxResolution: (maxResolution: number) => void;
74
+ setMinResolution: (minResolution: number) => void;
75
+ setMaxZoom: (maxZoom: number) => void;
76
+ setMinZoom: (minZoom: number) => void;
77
+ setOpacity: (opacity: number) => void;
78
+ setVisible: (visible: boolean) => void;
79
+ setZIndex: (zindex: number) => void;
80
+ get: (key: string) => any;
81
+ getKeys: () => string[];
82
+ getProperties: () => {
83
+ [x: string]: any;
84
+ };
85
+ getPropertiesInternal: () => {
86
+ [x: string]: any;
87
+ } | null;
88
+ hasProperties: () => boolean;
89
+ notify: (key: string, oldValue: any) => void;
90
+ addChangeListener: (key: string, listener: import("ol/events").Listener) => void;
91
+ removeChangeListener: (key: string, listener: import("ol/events").Listener) => void;
92
+ set: (key: string, value: any, silent?: boolean | undefined) => void;
93
+ setProperties: (values: {
94
+ [x: string]: any;
95
+ }, silent?: boolean | undefined) => void;
96
+ unset: (key: string, silent?: boolean | undefined) => void;
97
+ changed: () => void;
98
+ getRevision: () => number;
99
+ dispatchEvent: (event: string | BaseEvent) => boolean | undefined;
100
+ getListeners: (type: string) => import("ol/events").Listener[] | undefined;
101
+ hasListener: (type?: string | undefined) => boolean;
102
+ dispose: () => void;
103
+ };
104
+ } & typeof Layer;
105
+ /**
106
+ * Common class for Maplibre and Maplibre and potential other fork from Maplibre.
107
+ * It's used to share code between Maplibre and Maplibre layers without importing both libs.
108
+ * @private
109
+ */
110
+ declare class MapGlLayer extends MapGlLayer_base {
111
+ loaded: boolean;
112
+ mbMap?: AnyMapGlMap;
113
+ get apiKey(): string;
114
+ set apiKey(newValue: string);
115
+ get apiKeyName(): string;
116
+ set apiKeyName(newValue: string);
117
+ get style(): string;
118
+ set style(newValue: string);
119
+ get url(): string;
120
+ set url(newValue: string);
121
+ get queryRenderedFeaturesOptions(): maplibregl.QueryRenderedFeaturesOptions;
122
+ set queryRenderedFeaturesOptions(newValue: maplibregl.QueryRenderedFeaturesOptions);
123
+ constructor(options: MapGlLayerOptions);
124
+ /**
125
+ * Initialize the layer and listen to feature clicks.
126
+ * @param {ol/Map~Map} map
127
+ */
128
+ attachToMap(map: OlMap): void;
129
+ /**
130
+ * Terminate what was initialized in init function. Remove layer, events...
131
+ */
132
+ detachFromMap(): void;
133
+ /**
134
+ * Create the Maplibre map.
135
+ * @private
136
+ */
137
+ loadMbMap(): void;
138
+ getStyle(): string;
139
+ createMap(options: {
140
+ [id: string]: any;
141
+ }): AnyMapGlMap;
142
+ updateMbMap(): void;
143
+ }
144
+ export default MapGlLayer;
@@ -45,7 +45,9 @@ class MapGlLayer extends MobilityLayerMixin(Layer) {
45
45
  attributions: () => {
46
46
  return (this.mbMap && getMapGlCopyrights(this.mbMap)) || [];
47
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) || {})) }));
48
+ }), apiKeyName: 'key', style: 'travic_v2', url: 'https://maps.geops.io' }, (options || {})), {
49
+ // @ts-expect-error mapOptions must be saved by the mixin in this.options
50
+ 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
51
  }
50
52
  /**
51
53
  * Initialize the layer and listen to feature clicks.
@@ -0,0 +1,63 @@
1
+ import { Map, MapOptions } from 'maplibre-gl';
2
+ import MapGlLayer, { MapGlLayerOptions } from './MapGlLayer';
3
+ import MaplibreLayerRenderer from '../renderers/MaplibreLayerRenderer';
4
+ export type MaplibreLayerOptions = MapGlLayerOptions & {
5
+ mapOptions?: MapOptions;
6
+ };
7
+ /**
8
+ * This layer is meant to facilitate the use of the geOps Maps api in an OpenLayers map using Maplibre.
9
+ *
10
+ * @example
11
+ * import { MaplibreLayer } from 'mobility-toolbox-js/ol';
12
+ *
13
+ * const layer = new MaplibreLayer({
14
+ * apiKey: 'yourApiKey',
15
+ * // apiKeyName: 'key',
16
+ * // mapOptions: {
17
+ * // interactive: false,
18
+ * // trackResize: false,
19
+ * // attributionControl: false,
20
+ * // }
21
+ * // queryRenderedFeaturesOptions: {
22
+ * // layers: ['waters_lakes'], // map.getFeaturesAtPixel will only return lakes.
23
+ * // },
24
+ * // style: 'travic_v2',
25
+ * // url: 'https://maps.geops.io',
26
+ * });
27
+ *
28
+ * @classproperty {maplibregl.Map} maplibreMap - The Maplibre map object. Readonly.
29
+ * @classproperty {maplibregl.QueryRenderedFeaturesOptions} queryRenderedFeaturesOptions - Options used when we query features using map.getFeaturesAtPixel().
30
+ * @classproperty {string} style - geOps Maps api style.
31
+ * @extends {ol/layer/Layer~Layer}
32
+ * @public
33
+ */
34
+ export default class MaplibreLayer extends MapGlLayer {
35
+ options?: MaplibreLayerOptions;
36
+ /** @private */
37
+ get maplibreMap(): maplibregl.Map | undefined;
38
+ /**
39
+ * Constructor.
40
+ *
41
+ * @param {MaplibreLayerOptions} options
42
+ * @param {string} options.apiKey Access key for [geOps apis](https://developer.geops.io/).
43
+ * @param {string} [options.apiKeyName="key"] The geOps Maps api key name.
44
+ * @param {maplibregl.MapOptions} [options.mapOptions={ interactive: false, trackResize: false, attributionControl: false }] Maplibre map options.
45
+ * @param {string} [options.style="travic_v2"] The geOps Maps api style.
46
+ * @param {string} [options.url="https://maps.geops.io"] The geOps Maps api url.
47
+ */
48
+ constructor(options: MaplibreLayerOptions);
49
+ /**
50
+ * @private
51
+ */
52
+ createRenderer(): MaplibreLayerRenderer;
53
+ /**
54
+ * @private
55
+ */
56
+ createMap(options: MapOptions): Map;
57
+ /**
58
+ * Create a copy of the MaplibreLayer.
59
+ * @param {MaplibreLayerOptions} newOptions Options to override
60
+ * @return {MaplibreLayer} A MaplibreLayer layer
61
+ */
62
+ clone(newOptions: MaplibreLayerOptions): MaplibreLayer;
63
+ }