mobility-toolbox-js 2.0.0-beta.33 → 2.0.0-beta.36

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 (116) hide show
  1. package/api/RealtimeAPI.d.ts +6 -6
  2. package/api/RealtimeAPI.d.ts.map +1 -1
  3. package/api/RealtimeAPI.js +613 -0
  4. package/api/RoutingAPI.d.ts.map +1 -1
  5. package/api/RoutingAPI.js +35 -0
  6. package/api/StopsAPI.d.ts +1 -1
  7. package/api/StopsAPI.d.ts.map +1 -1
  8. package/api/StopsAPI.js +38 -0
  9. package/api/index.d.ts +3 -4
  10. package/api/index.d.ts.map +1 -1
  11. package/api/index.js +3 -0
  12. package/api/typedefs.js +73 -0
  13. package/common/api/HttpAPI.d.ts.map +1 -1
  14. package/common/api/HttpAPI.js +57 -0
  15. package/common/api/WebSocketAPI.d.ts +2 -2
  16. package/common/api/WebSocketAPI.d.ts.map +1 -1
  17. package/common/api/WebSocketAPI.js +290 -0
  18. package/common/controls/Control.d.ts +5 -5
  19. package/common/controls/Control.d.ts.map +1 -1
  20. package/common/controls/Control.js +137 -0
  21. package/common/index.js +2 -0
  22. package/common/layers/Layer.d.ts +11 -11
  23. package/common/layers/Layer.d.ts.map +1 -1
  24. package/common/layers/Layer.js +223 -0
  25. package/common/mixins/CopyrightMixin.js +43 -0
  26. package/common/mixins/MapboxLayerMixin.js +198 -0
  27. package/common/mixins/RealtimeLayerMixin.js +650 -0
  28. package/common/mixins/StopFinderMixin.d.ts +3 -3
  29. package/common/mixins/StopFinderMixin.d.ts.map +1 -1
  30. package/common/mixins/StopFinderMixin.js +156 -0
  31. package/common/mixins/UserInteractionsLayerMixin.js +192 -0
  32. package/common/styles/index.js +4 -0
  33. package/common/styles/realtimeDefaultStyle.js +239 -0
  34. package/common/styles/realtimeDelayStyle.js +13 -0
  35. package/common/styles/realtimeSimpleStyle.js +22 -0
  36. package/common/typedefs.js +22 -0
  37. package/common/utils/cleanStopTime.js +28 -0
  38. package/common/utils/compareDepartures.d.ts +1 -1
  39. package/common/utils/compareDepartures.d.ts.map +1 -1
  40. package/common/utils/compareDepartures.js +34 -0
  41. package/common/utils/createCanvas.js +27 -0
  42. package/common/utils/createTrackerFilters.d.ts +1 -1
  43. package/common/utils/createTrackerFilters.d.ts.map +1 -1
  44. package/common/utils/createTrackerFilters.js +67 -0
  45. package/common/utils/getLayersAsFlatArray.js +14 -0
  46. package/common/utils/getMapboxMapCopyrights.js +24 -0
  47. package/common/utils/getMapboxRender.js +74 -0
  48. package/common/utils/getMaplibreRender.js +35 -0
  49. package/common/utils/getRealtimeModeSuffix.js +7 -0
  50. package/common/utils/getUrlWithParams.js +18 -0
  51. package/common/utils/getVehiclePosition.js +63 -0
  52. package/common/utils/index.js +12 -0
  53. package/common/utils/removeDuplicate.d.ts +1 -1
  54. package/common/utils/removeDuplicate.d.ts.map +1 -1
  55. package/common/utils/removeDuplicate.js +15 -0
  56. package/common/utils/renderTrajectories.js +107 -0
  57. package/common/utils/sortByDelay.js +20 -0
  58. package/common/utils/timeUtils.js +39 -0
  59. package/common/utils/trackerConfig.js +170 -0
  60. package/iife.js +5 -0
  61. package/index.d.ts +4 -0
  62. package/index.js +10 -0
  63. package/mapbox/controls/CopyrightControl.d.ts +0 -1
  64. package/mapbox/controls/CopyrightControl.d.ts.map +1 -1
  65. package/mapbox/controls/CopyrightControl.js +53 -0
  66. package/mapbox/controls/index.js +2 -0
  67. package/mapbox/index.js +4 -0
  68. package/mapbox/layers/Layer.d.ts +1 -1
  69. package/mapbox/layers/Layer.d.ts.map +1 -1
  70. package/mapbox/layers/Layer.js +97 -0
  71. package/mapbox/layers/RealtimeLayer.d.ts +4 -4
  72. package/mapbox/layers/RealtimeLayer.d.ts.map +1 -1
  73. package/mapbox/layers/RealtimeLayer.js +270 -0
  74. package/mapbox/layers/index.js +2 -0
  75. package/mapbox/utils.js +43 -0
  76. package/mbt.js +6 -5
  77. package/mbt.js.map +2 -2
  78. package/mbt.min.js +2 -2
  79. package/mbt.min.js.map +2 -2
  80. package/ol/controls/CopyrightControl.js +69 -0
  81. package/ol/controls/RoutingControl.d.ts +6 -5
  82. package/ol/controls/RoutingControl.d.ts.map +1 -1
  83. package/ol/controls/RoutingControl.js +622 -0
  84. package/ol/controls/StopFinderControl.js +36 -0
  85. package/ol/controls/index.js +3 -0
  86. package/ol/index.js +5 -0
  87. package/ol/layers/Layer.d.ts +1 -1
  88. package/ol/layers/Layer.d.ts.map +1 -1
  89. package/ol/layers/Layer.js +148 -0
  90. package/ol/layers/MapboxLayer.d.ts +7 -7
  91. package/ol/layers/MapboxLayer.d.ts.map +1 -1
  92. package/ol/layers/MapboxLayer.js +101 -0
  93. package/ol/layers/MapboxStyleLayer.d.ts +3 -3
  94. package/ol/layers/MapboxStyleLayer.d.ts.map +1 -1
  95. package/ol/layers/MapboxStyleLayer.js +340 -0
  96. package/ol/layers/MaplibreLayer.d.ts +1 -1
  97. package/ol/layers/MaplibreLayer.d.ts.map +1 -1
  98. package/ol/layers/MaplibreLayer.js +35 -0
  99. package/ol/layers/RealtimeLayer.d.ts +2 -2
  100. package/ol/layers/RealtimeLayer.d.ts.map +1 -1
  101. package/ol/layers/RealtimeLayer.js +294 -0
  102. package/ol/layers/RoutingLayer.d.ts +2 -2
  103. package/ol/layers/RoutingLayer.d.ts.map +1 -1
  104. package/ol/layers/RoutingLayer.js +84 -0
  105. package/ol/layers/VectorLayer.d.ts +1 -1
  106. package/ol/layers/VectorLayer.d.ts.map +1 -1
  107. package/ol/layers/VectorLayer.js +38 -0
  108. package/ol/layers/WMSLayer.d.ts +1 -1
  109. package/ol/layers/WMSLayer.d.ts.map +1 -1
  110. package/ol/layers/WMSLayer.js +72 -0
  111. package/ol/layers/index.js +8 -0
  112. package/ol/styles/fullTrajectoryDelayStyle.js +33 -0
  113. package/ol/styles/fullTrajectoryStyle.js +44 -0
  114. package/ol/styles/index.js +2 -0
  115. package/package.json +2 -2
  116. package/setupTests.js +13 -0
@@ -0,0 +1,35 @@
1
+ import { Map } from 'maplibre-gl';
2
+ import Layer from './Layer';
3
+ import mixin from '../../common/mixins/MapboxLayerMixin';
4
+ import { getMaplibreRender } from '../../common/utils';
5
+ /**
6
+ * A class representing MaplibreLayer to display on BasicMap
7
+ *
8
+ * @example
9
+ * import { MaplibreLayer } from 'mobility-toolbox-js/ol';
10
+ *
11
+ * const layer = new MaplibreLayer({
12
+ * url: 'https://maps.geops.io/styles/travic_v2/style.json',
13
+ * apikey: 'yourApiKey',
14
+ * });
15
+ *
16
+ * @classproperty {ol/Map~Map} map - The map where the layer is displayed.
17
+ * @extends {Layer}
18
+ */
19
+ export default class MaplibreLayer extends mixin(Layer) {
20
+ getOlLayerRender() {
21
+ return getMaplibreRender(this);
22
+ }
23
+ // eslint-disable-next-line class-methods-use-this
24
+ getMapboxMapClass() {
25
+ return Map;
26
+ }
27
+ /**
28
+ * Create a copy of the MapboxLayer.
29
+ * @param {Object} newOptions Options to override
30
+ * @return {MapboxLayer} A MapboxLayer
31
+ */
32
+ clone(newOptions) {
33
+ return new MaplibreLayer(Object.assign(Object.assign({}, this.options), newOptions));
34
+ }
35
+ }
@@ -33,7 +33,7 @@ declare class RealtimeLayer extends Layer implements UserInteractionsLayerInterf
33
33
  /** @ignore */
34
34
  renderState: {
35
35
  center: number[];
36
- zoom: any;
36
+ zoom: null;
37
37
  rotation: number;
38
38
  };
39
39
  attachToMap(map: any): void;
@@ -113,7 +113,7 @@ declare class RealtimeLayer extends Layer implements UserInteractionsLayerInterf
113
113
  * @param {Object} newOptions Options to override
114
114
  * @return {RealtimeLayer} A RealtimeLayer
115
115
  */
116
- clone(newOptions: any): RealtimeLayer;
116
+ clone(newOptions: Object): RealtimeLayer;
117
117
  }
118
118
  import Layer from "./Layer";
119
119
  //# sourceMappingURL=RealtimeLayer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"RealtimeLayer.d.ts","sourceRoot":"","sources":["../../../src/ol/layers/RealtimeLayer.js"],"names":[],"mappings":";AAYA;;;;;;;;;;;;;;;;;GAiBG;AACH,qDAHgB,8BAA8B,EAC9B,sBAAsB;IAGpC;;;;;OAKG;IACH,sBA2FC;IApFC,cAAc;IACd,aAsEI;IApDQ,0BAA8C;IAI9C,mCAAuD;IAmDnE,iBAAmD;IAInD,cAAc;IACd;;;;MAIC;IAGH,4BAqBC;IANO,iBAAuB;IAgB/B;;;;OAIG;IACH,qDAYC;IAED;;;;OAIG;IACH,kCAHW,OAAO,QAiBjB;IAED;;;;OAIG;IACH,4CAuBC;IAPG,uBAAyC;IAS7C;;OAEG;IACH,0BAEC;IAED,+DAMC;IAED;;;;;OAKG;IACH,2BAaC;IAED;;;;;;OAMG;IAEH,2BAEC;IAED;;;;;OAKG;IACH,gCAKC;IAED;;;;;OAKG;IACH,gCAQC;IAED;;;;OAIG;IACH,wBAMC;IAED;;;;OAIG;IACH,gBAQC;IAED;;;OAGG;IACH,4BAiBC;IAED;;;;OAIG;IACH,wBAFY,aAAa,CAIxB;CACF"}
1
+ {"version":3,"file":"RealtimeLayer.d.ts","sourceRoot":"","sources":["../../../src/ol/layers/RealtimeLayer.js"],"names":[],"mappings":";AAYA;;;;;;;;;;;;;;;;;GAiBG;AACH,qDAHgB,8BAA8B,EAC9B,sBAAsB;IAGpC;;;;;OAKG;IACH,sBA2FC;IApFC,cAAc;IACd,aAsEI;IApDQ,0BAA8C;IAI9C,mCAAuD;IAmDnE,iBAAmD;IAInD,cAAc;IACd;;;;MAIC;IAGH,4BAqBC;IANO,iBAAuB;IAgB/B;;;;OAIG;IACH,qDAYC;IAED;;;;OAIG;IACH,kCAHW,OAAO,QAiBjB;IAED;;;;OAIG;IACH,4CAuBC;IAPG,uBAAyC;IAS7C;;OAEG;IACH,0BAEC;IAED,+DAMC;IAED;;;;;OAKG;IACH,2BAaC;IAED;;;;;;OAMG;IAEH,2BAEC;IAED;;;;;OAKG;IACH,gCAKC;IAED;;;;;OAKG;IACH,gCAQC;IAED;;;;OAIG;IACH,wBAMC;IAED;;;;OAIG;IACH,gBAQC;IAED;;;OAGG;IACH,4BAiBC;IAED;;;;OAIG;IACH,kBAHW,MAAM,GACL,aAAa,CAIxB;CACF"}
@@ -0,0 +1,294 @@
1
+ import GeoJSON from 'ol/format/GeoJSON';
2
+ import { Layer as OLLayer, Group, Vector as VectorLayer } from 'ol/layer';
3
+ import Source from 'ol/source/Source';
4
+ import { composeCssTransform } from 'ol/transform';
5
+ import { Vector as VectorSource } from 'ol/source';
6
+ import Layer from './Layer';
7
+ import mixin from '../../common/mixins/RealtimeLayerMixin';
8
+ import { fullTrajectoryStyle } from '../styles';
9
+ /** @private */
10
+ const format = new GeoJSON();
11
+ /**
12
+ * Responsible for loading and display data from a Realtime service.
13
+ *
14
+ * @example
15
+ * import { RealtimeLayer } from 'mobility-toolbox-js/ol';
16
+ *
17
+ * const layer = new RealtimeLayer({
18
+ * url: [yourUrl],
19
+ * apiKey: [yourApiKey],
20
+ * });
21
+ *
22
+ *
23
+ * @see <a href="/api/class/src/api/RealtimeAPI%20js~RealtimeAPI%20html">RealtimeAPI</a>
24
+ *
25
+ * @extends {Layer}
26
+ * @implements {UserInteractionsLayerInterface}
27
+ * @implements {RealtimeLayerInterface}
28
+ */
29
+ class RealtimeLayer extends mixin(Layer) {
30
+ /**
31
+ * Constructor.
32
+ *
33
+ * @param {Object} options
34
+ * @private
35
+ */
36
+ constructor(options = {}) {
37
+ // We use a group to be able to add custom vector layer in extended class.
38
+ // For example TrajservLayer use a vectorLayer to display the complete trajectory.
39
+ super(Object.assign({}, options));
40
+ /** @ignore */
41
+ this.olLayer =
42
+ options.olLayer ||
43
+ new Group({
44
+ layers: [
45
+ new VectorLayer({
46
+ source: new VectorSource({ features: [] }),
47
+ style: (feature, resolution) => {
48
+ return (options.fullTrajectoryStyle || fullTrajectoryStyle)(feature, resolution, this.styleOptions);
49
+ },
50
+ }),
51
+ new OLLayer({
52
+ source: new Source({}),
53
+ render: (frameState) => {
54
+ if (!this.container) {
55
+ this.container = document.createElement('div');
56
+ this.container.style.position = 'absolute';
57
+ this.container.style.width = '100%';
58
+ this.container.style.height = '100%';
59
+ this.transformContainer = document.createElement('div');
60
+ this.transformContainer.style.position = 'absolute';
61
+ this.transformContainer.style.width = '100%';
62
+ this.transformContainer.style.height = '100%';
63
+ this.container.appendChild(this.transformContainer);
64
+ this.canvas.style.position = 'absolute';
65
+ this.canvas.style.top = '0';
66
+ this.canvas.style.left = '0';
67
+ this.canvas.style.transformOrigin = 'top left';
68
+ this.transformContainer.appendChild(this.canvas);
69
+ }
70
+ if (this.renderedViewState) {
71
+ const { center, resolution, rotation } = frameState.viewState;
72
+ const { center: renderedCenter, resolution: renderedResolution, rotation: renderedRotation, } = this.renderedViewState;
73
+ if (renderedResolution / resolution >= 3) {
74
+ // Avoid having really big points when zooming fast.
75
+ const context = this.canvas.getContext('2d');
76
+ context.clearRect(0, 0, this.canvas.width, this.canvas.height);
77
+ }
78
+ else {
79
+ const pixelCenterRendered = this.map.getPixelFromCoordinate(renderedCenter);
80
+ const pixelCenter = this.map.getPixelFromCoordinate(center);
81
+ this.transformContainer.style.transform = composeCssTransform(pixelCenterRendered[0] - pixelCenter[0], pixelCenterRendered[1] - pixelCenter[1], renderedResolution / resolution, renderedResolution / resolution, rotation - renderedRotation, 0, 0);
82
+ }
83
+ }
84
+ return this.container;
85
+ },
86
+ }),
87
+ ],
88
+ });
89
+ // We store the layer used to highlight the full Trajectory
90
+ this.vectorLayer = this.olLayer.getLayers().item(0);
91
+ // Options the last render run did happen. If something changes
92
+ // we have to render again
93
+ /** @ignore */
94
+ this.renderState = {
95
+ center: [0, 0],
96
+ zoom: null,
97
+ rotation: 0,
98
+ };
99
+ }
100
+ attachToMap(map) {
101
+ super.attachToMap(map);
102
+ if (this.map) {
103
+ this.olListenersKeys.push(this.map.on(['moveend', 'change:target'], (evt) => {
104
+ const view = this.map.getView();
105
+ if (view.getAnimating() || view.getInteracting()) {
106
+ return;
107
+ }
108
+ const zoom = view.getZoom();
109
+ // Update the interval between render updates
110
+ if (this.currentZoom !== zoom) {
111
+ this.onZoomEnd(evt);
112
+ }
113
+ this.currentZoom = zoom;
114
+ this.onMoveEnd(evt);
115
+ }));
116
+ }
117
+ }
118
+ /**
119
+ * Destroy the container of the tracker.
120
+ */
121
+ detachFromMap() {
122
+ super.detachFromMap();
123
+ this.container = null;
124
+ }
125
+ /**
126
+ * Detect in the canvas if there is data to query at a specific coordinate.
127
+ * @param {ol/coordinate~Coordinate} coordinate The coordinate to test
128
+ * @returns
129
+ */
130
+ hasFeatureInfoAtCoordinate(coordinate) {
131
+ if (this.map && this.canvas) {
132
+ const context = this.canvas.getContext('2d');
133
+ const pixel = this.map.getPixelFromCoordinate(coordinate);
134
+ return !!context.getImageData(pixel[0] * this.pixelRatio, pixel[1] * this.pixelRatio, 1, 1).data[3];
135
+ }
136
+ return false;
137
+ }
138
+ /**
139
+ * Render the trajectories using current map's size, resolution and rotation.
140
+ * @param {boolean} noInterpolate if true, renders the vehicles without interpolating theirs positions.
141
+ * @overrides
142
+ */
143
+ renderTrajectories(noInterpolate) {
144
+ const view = this.map.getView();
145
+ super.renderTrajectories({
146
+ size: this.map.getSize(),
147
+ center: this.map.getView().getCenter(),
148
+ extent: view.calculateExtent(),
149
+ resolution: view.getResolution(),
150
+ rotation: view.getRotation(),
151
+ zoom: view.getZoom(),
152
+ pixelRatio: this.pixelRatio,
153
+ }, noInterpolate);
154
+ }
155
+ /**
156
+ * Launch renderTrajectories. it avoids duplicating code in renderTrajectories methhod.
157
+ * @private
158
+ * @override
159
+ */
160
+ renderTrajectoriesInternal(viewState, noInterpolate) {
161
+ if (!this.map) {
162
+ return false;
163
+ }
164
+ let isRendered = false;
165
+ const blockRendering = this.map.getView().getAnimating() || this.map.getView().getInteracting();
166
+ // Don't render the map when the map is animating or interacting.
167
+ isRendered = blockRendering
168
+ ? false
169
+ : super.renderTrajectoriesInternal(viewState, noInterpolate);
170
+ // We update the current render state.
171
+ if (isRendered) {
172
+ this.renderedViewState = Object.assign({}, viewState);
173
+ if (this.transformContainer) {
174
+ this.transformContainer.style.transform = '';
175
+ }
176
+ }
177
+ return isRendered;
178
+ }
179
+ /**
180
+ * Return the delay in ms before the next rendering.
181
+ */
182
+ getRefreshTimeInMs() {
183
+ return super.getRefreshTimeInMs(this.map.getView().getZoom());
184
+ }
185
+ getFeatureInfoAtCoordinate(coordinate, options = {}) {
186
+ const resolution = this.map.getView().getResolution();
187
+ return super.getFeatureInfoAtCoordinate(coordinate, Object.assign({ resolution }, options));
188
+ }
189
+ /**
190
+ * On move end we update the websocket with the new bbox.
191
+ *
192
+ * @private
193
+ * @override
194
+ */
195
+ onMoveEnd() {
196
+ if (this.visible && this.isUpdateBboxOnMoveEnd) {
197
+ this.setBbox();
198
+ }
199
+ if (this.visible &&
200
+ this.isUpdateBboxOnMoveEnd &&
201
+ this.userClickInteractions &&
202
+ this.selectedVehicleId) {
203
+ this.highlightTrajectory(this.selectedVehicleId);
204
+ }
205
+ }
206
+ /**
207
+ * Function called on moveend event only when the zoom has changed.
208
+ *
209
+ * @param {ol/MapEvent~MapEvent} evt Moveend event.
210
+ * @private
211
+ * @override
212
+ */
213
+ // eslint-disable-next-line no-unused-vars
214
+ onZoomEnd(evt) {
215
+ super.onZoomEnd(evt);
216
+ }
217
+ /**
218
+ * Update the cursor style when hovering a vehicle.
219
+ *
220
+ * @private
221
+ * @override
222
+ */
223
+ onFeatureHover(features, layer, coordinate) {
224
+ super.onFeatureHover(features, layer, coordinate);
225
+ this.map.getTargetElement().style.cursor = features.length
226
+ ? 'pointer'
227
+ : 'auto';
228
+ }
229
+ /**
230
+ * Display the complete trajectory of the vehicle.
231
+ *
232
+ * @private
233
+ * @override
234
+ */
235
+ onFeatureClick(features, layer, coordinate) {
236
+ super.onFeatureClick(features, layer, coordinate);
237
+ if (!features.length && this.vectorLayer) {
238
+ this.vectorLayer.getSource().clear();
239
+ }
240
+ if (this.selectedVehicleId) {
241
+ this.highlightTrajectory(this.selectedVehicleId);
242
+ }
243
+ }
244
+ /**
245
+ * Remove the trajectory form the list if necessary.
246
+ *
247
+ * @private
248
+ */
249
+ purgeTrajectory(trajectory, extent, zoom) {
250
+ return super.purgeTrajectory(trajectory, extent || this.map.getView().calculateExtent(), zoom || this.map.getView().getZoom());
251
+ }
252
+ /**
253
+ * Send the current bbox to the websocket
254
+ *
255
+ * @private
256
+ */
257
+ setBbox(extent, zoom) {
258
+ let newExtent = extent;
259
+ let newZoom = zoom;
260
+ if (!newExtent && this.isUpdateBboxOnMoveEnd) {
261
+ newExtent = extent || this.map.getView().calculateExtent();
262
+ newZoom = Math.floor(this.map.getView().getZoom());
263
+ }
264
+ super.setBbox(newExtent, newZoom);
265
+ }
266
+ /**
267
+ * Highlight the trajectory of journey.
268
+ * @private
269
+ */
270
+ highlightTrajectory(id) {
271
+ this.api
272
+ .getFullTrajectory(id, this.mode, this.generalizationLevel)
273
+ .then((fullTrajectory) => {
274
+ const vectorSource = this.vectorLayer.getSource();
275
+ vectorSource.clear();
276
+ if (!fullTrajectory ||
277
+ !fullTrajectory.features ||
278
+ !fullTrajectory.features.length) {
279
+ return;
280
+ }
281
+ const features = format.readFeatures(fullTrajectory);
282
+ this.vectorLayer.getSource().addFeatures(features);
283
+ });
284
+ }
285
+ /**
286
+ * Create a copy of the RealtimeLayer.
287
+ * @param {Object} newOptions Options to override
288
+ * @return {RealtimeLayer} A RealtimeLayer
289
+ */
290
+ clone(newOptions) {
291
+ return new RealtimeLayer(Object.assign(Object.assign({}, this.options), newOptions));
292
+ }
293
+ }
294
+ export default RealtimeLayer;
@@ -11,14 +11,14 @@ declare class RoutingLayer extends Layer {
11
11
  * @param {Object} [options]
12
12
  * @param {ol/style/Style~StyleLike} [options.style] Style to be used for routes, uses (ol/StyleLike) [https://openlayers.org/en/latest/apidoc/module-ol_style_Style.html#~StyleLike] instances
13
13
  */
14
- constructor(options?: any);
14
+ constructor(options?: Object | undefined);
15
15
  olLayer: any;
16
16
  /**
17
17
  * Create a copy of the RoutingLayer.
18
18
  * @param {Object} newOptions Options to override
19
19
  * @return {RoutingLayer} A RoutingLayer
20
20
  */
21
- clone(newOptions: any): RoutingLayer;
21
+ clone(newOptions: Object): RoutingLayer;
22
22
  }
23
23
  import Layer from "./Layer";
24
24
  //# sourceMappingURL=RoutingLayer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"RoutingLayer.d.ts","sourceRoot":"","sources":["../../../src/ol/layers/RoutingLayer.js"],"names":[],"mappings":";AA8DA;;;;;GAKG;AACH;IACE;;;;OAIG;IACH,2BASC;IANC,aAKI;IAGN;;;;OAIG;IACH,wBAFY,YAAY,CAIvB;CACF"}
1
+ {"version":3,"file":"RoutingLayer.d.ts","sourceRoot":"","sources":["../../../src/ol/layers/RoutingLayer.js"],"names":[],"mappings":";AA8DA;;;;;GAKG;AACH;IACE;;;;OAIG;IACH,0CASC;IANC,aAKI;IAGN;;;;OAIG;IACH,kBAHW,MAAM,GACL,YAAY,CAIvB;CACF"}
@@ -0,0 +1,84 @@
1
+ import { Circle, Fill, Stroke, Style } from 'ol/style';
2
+ import { Vector as VectorSource } from 'ol/source';
3
+ import { Vector } from 'ol/layer';
4
+ import Layer from './Layer';
5
+ /** @private */
6
+ const circleStyle = new Circle({
7
+ radius: 6,
8
+ fill: new Fill({
9
+ color: [255, 0, 0, 1],
10
+ }),
11
+ stroke: new Stroke({
12
+ color: [0, 0, 0, 1],
13
+ width: 1,
14
+ }),
15
+ });
16
+ /** @private */
17
+ const blackBorder = new Style({
18
+ stroke: new Stroke({
19
+ color: [0, 0, 0, 1],
20
+ width: 5,
21
+ }),
22
+ });
23
+ /** @private */
24
+ const redLine = new Style({
25
+ image: circleStyle,
26
+ stroke: new Stroke({
27
+ color: [255, 0, 0, 1],
28
+ width: 3,
29
+ }),
30
+ });
31
+ /** @private */
32
+ const dashedRedLine = new Style({
33
+ image: circleStyle,
34
+ stroke: new Stroke({
35
+ color: [255, 0, 0, 1],
36
+ width: 3,
37
+ lineDash: [1, 10],
38
+ }),
39
+ });
40
+ /** @private */
41
+ const defaultStyleFunction = (feature, resolution) => {
42
+ const minResolution = feature.get('minResolution');
43
+ const maxResolution = feature.get('maxResolution');
44
+ const inRange = resolution <= minResolution && resolution > maxResolution;
45
+ if (minResolution && maxResolution && !inRange) {
46
+ return null;
47
+ }
48
+ const mot = feature.get('mot');
49
+ if (mot !== 'foot') {
50
+ return [blackBorder, redLine];
51
+ }
52
+ return [dashedRedLine];
53
+ };
54
+ /**
55
+ * A class use to display vector data.
56
+ *
57
+ * @classproperty {ol/Map~Map} map - The map where the layer is displayed.
58
+ * @extends {Layer}
59
+ */
60
+ class RoutingLayer extends Layer {
61
+ /**
62
+ * Constructor.
63
+ * @param {Object} [options]
64
+ * @param {ol/style/Style~StyleLike} [options.style] Style to be used for routes, uses (ol/StyleLike) [https://openlayers.org/en/latest/apidoc/module-ol_style_Style.html#~StyleLike] instances
65
+ */
66
+ constructor(options = {}) {
67
+ super(options);
68
+ this.olLayer =
69
+ options.olLayer ||
70
+ new Vector({
71
+ source: new VectorSource(),
72
+ style: options.style || defaultStyleFunction,
73
+ });
74
+ }
75
+ /**
76
+ * Create a copy of the RoutingLayer.
77
+ * @param {Object} newOptions Options to override
78
+ * @return {RoutingLayer} A RoutingLayer
79
+ */
80
+ clone(newOptions) {
81
+ return new RoutingLayer(Object.assign(Object.assign({}, this.options), newOptions));
82
+ }
83
+ }
84
+ export default RoutingLayer;
@@ -17,7 +17,7 @@ declare class VectorLayer extends Layer {
17
17
  * @param {Object} newOptions Options to override
18
18
  * @return {VectorLayer} A VectorLayer
19
19
  */
20
- clone(newOptions: any): VectorLayer;
20
+ clone(newOptions: Object): VectorLayer;
21
21
  }
22
22
  import Layer from "./Layer";
23
23
  //# sourceMappingURL=VectorLayer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"VectorLayer.d.ts","sourceRoot":"","sources":["../../../src/ol/layers/VectorLayer.js"],"names":[],"mappings":";AAEA;;;;;GAKG;AACH;IACE;;;;OAIG;IACH,6CAFY,QAAQ,WAAW,CAAC,CAkB/B;IAED;;;;OAIG;IACH,wBAFY,WAAW,CAItB;CACF"}
1
+ {"version":3,"file":"VectorLayer.d.ts","sourceRoot":"","sources":["../../../src/ol/layers/VectorLayer.js"],"names":[],"mappings":";AAEA;;;;;GAKG;AACH;IACE;;;;OAIG;IACH,6CAFY,QAAQ,WAAW,CAAC,CAkB/B;IAED;;;;OAIG;IACH,kBAHW,MAAM,GACL,WAAW,CAItB;CACF"}
@@ -0,0 +1,38 @@
1
+ import Layer from './Layer';
2
+ /**
3
+ * A class use to display vector data.
4
+ *
5
+ * @classproperty {ol/Map~Map} map - The map where the layer is displayed.
6
+ * @extends {Layer}
7
+ */
8
+ class VectorLayer extends Layer {
9
+ /**
10
+ * Request feature information for a given coordinate.
11
+ * @param {ol/coordinate~Coordinate} coordinate the coordinate to request the information at.
12
+ * @return {Promise<FeatureInfo>} Promise with features, layer and coordinate.
13
+ */
14
+ getFeatureInfoAtCoordinate(coordinate) {
15
+ let features = [];
16
+ if (this.map) {
17
+ const pixel = this.map.getPixelFromCoordinate(coordinate);
18
+ features = this.map.getFeaturesAtPixel(pixel, {
19
+ layerFilter: (l) => l === this.olLayer,
20
+ hitTolerance: this.hitTolerance,
21
+ });
22
+ }
23
+ return Promise.resolve({
24
+ features,
25
+ layer: this,
26
+ coordinate,
27
+ });
28
+ }
29
+ /**
30
+ * Create a copy of the VectorLayer.
31
+ * @param {Object} newOptions Options to override
32
+ * @return {VectorLayer} A VectorLayer
33
+ */
34
+ clone(newOptions) {
35
+ return new VectorLayer(Object.assign(Object.assign({}, this.options), newOptions));
36
+ }
37
+ }
38
+ export default VectorLayer;
@@ -31,7 +31,7 @@ declare class WMSLayer extends Layer {
31
31
  * @param {Object} newOptions Options to override
32
32
  * @return {WMSLayer} A WMSLayer
33
33
  */
34
- clone(newOptions: any): WMSLayer;
34
+ clone(newOptions: Object): WMSLayer;
35
35
  }
36
36
  import Layer from "./Layer";
37
37
  import GeoJSON from "ol/format/GeoJSON";
@@ -1 +1 @@
1
- {"version":3,"file":"WMSLayer.d.ts","sourceRoot":"","sources":["../../../src/ol/layers/WMSLayer.js"],"names":[],"mappings":";AAGA;;;;;GAKG;AACH;IACE;;OAEG;IACH,0BAOC;IAJC,cAAc;IACd,iCAA4C;IAC5C,cAAc;IACd,gBAA2B;IAG7B;;;;OAIG;IACH,kCAaC;IAED;;;;OAIG;IACH,6CAFY,QAAQ,WAAW,CAAC,CAsB/B;IAED;;;;OAIG;IACH,wBAFY,QAAQ,CAInB;CACF"}
1
+ {"version":3,"file":"WMSLayer.d.ts","sourceRoot":"","sources":["../../../src/ol/layers/WMSLayer.js"],"names":[],"mappings":";AAGA;;;;;GAKG;AACH;IACE;;OAEG;IACH,0BAOC;IAJC,cAAc;IACd,iCAA4C;IAC5C,cAAc;IACd,gBAA2B;IAG7B;;;;OAIG;IACH,kCAaC;IAED;;;;OAIG;IACH,6CAFY,QAAQ,WAAW,CAAC,CAsB/B;IAED;;;;OAIG;IACH,kBAHW,MAAM,GACL,QAAQ,CAInB;CACF"}
@@ -0,0 +1,72 @@
1
+ import GeoJSON from 'ol/format/GeoJSON';
2
+ import Layer from './Layer';
3
+ /**
4
+ * Class use to display a WMS layer.
5
+ *
6
+ * @classproperty {ol/Map~Map} map - The map where the layer is displayed.
7
+ * @extends {Layer}
8
+ */
9
+ class WMSLayer extends Layer {
10
+ /**
11
+ * @override
12
+ */
13
+ constructor(options = {}) {
14
+ super(options);
15
+ /** @ignore */
16
+ this.abortController = new AbortController();
17
+ /** @ignore */
18
+ this.format = new GeoJSON();
19
+ }
20
+ /**
21
+ * Get features infos' Url.
22
+ * @param {ol/coordinate~Coordinate} coord
23
+ * @return {ol/layer/Layer~Layer}
24
+ */
25
+ getFeatureInfoUrl(coord) {
26
+ const projection = this.map.getView().getProjection();
27
+ const resolution = this.map.getView().getResolution();
28
+ if (this.olLayer.getSource().getFeatureInfoUrl) {
29
+ return this.olLayer
30
+ .getSource()
31
+ .getFeatureInfoUrl(coord, resolution, projection, {
32
+ info_format: 'application/json',
33
+ query_layers: this.olLayer.getSource().getParams().layers,
34
+ });
35
+ }
36
+ return false;
37
+ }
38
+ /**
39
+ * Request feature information for a given coordinate.
40
+ * @param {ol/coordinate~Coordinate} coordinate to request the information at.
41
+ * @return {Promise<FeatureInfo>} Promise with features, layer and coordinate.
42
+ */
43
+ getFeatureInfoAtCoordinate(coordinate) {
44
+ this.abortController.abort();
45
+ this.abortController = new AbortController();
46
+ const { signal } = this.abortController;
47
+ return fetch(this.getFeatureInfoUrl(coordinate), { signal })
48
+ .then((resp) => resp.json())
49
+ .then((r) => r.features)
50
+ .then((data) => ({
51
+ layer: this,
52
+ coordinate,
53
+ features: data.map((d) => this.format.readFeature(d)),
54
+ }))
55
+ .catch(() =>
56
+ // resolve an empty feature array something fails
57
+ Promise.resolve({
58
+ features: [],
59
+ coordinate,
60
+ layer: this,
61
+ }));
62
+ }
63
+ /**
64
+ * Create a copy of the WMSLayer.
65
+ * @param {Object} newOptions Options to override
66
+ * @return {WMSLayer} A WMSLayer
67
+ */
68
+ clone(newOptions) {
69
+ return new WMSLayer(Object.assign(Object.assign({}, this.options), newOptions));
70
+ }
71
+ }
72
+ export default WMSLayer;
@@ -0,0 +1,8 @@
1
+ export { default as Layer } from './Layer';
2
+ export { default as MapboxLayer } from './MapboxLayer';
3
+ export { default as MaplibreLayer } from './MaplibreLayer';
4
+ export { default as MapboxStyleLayer } from './MapboxStyleLayer';
5
+ export { default as RoutingLayer } from './RoutingLayer';
6
+ export { default as RealtimeLayer } from './RealtimeLayer';
7
+ export { default as VectorLayer } from './VectorLayer';
8
+ export { default as WMSLayer } from './WMSLayer';
@@ -0,0 +1,33 @@
1
+ import { Style, Fill, Stroke, Circle } from 'ol/style';
2
+ /** @private */
3
+ const stroke = new Style({
4
+ zIndex: 2,
5
+ image: new Circle({
6
+ radius: 5,
7
+ fill: new Fill({
8
+ color: '#000000',
9
+ }),
10
+ }),
11
+ stroke: new Stroke({
12
+ color: '#000000',
13
+ width: 6,
14
+ }),
15
+ });
16
+ /** @private */
17
+ const fill = new Style({
18
+ zIndex: 3,
19
+ image: new Circle({
20
+ radius: 4,
21
+ fill: new Fill({
22
+ color: '#a0a0a0',
23
+ }),
24
+ }),
25
+ stroke: new Stroke({
26
+ color: '#a0a0a0',
27
+ width: 4,
28
+ }),
29
+ });
30
+ const fullTrajectoryDelaystyle = () => {
31
+ return [stroke, fill];
32
+ };
33
+ export default fullTrajectoryDelaystyle;