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

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 (210) hide show
  1. package/api/RealtimeAPI.d.ts +268 -0
  2. package/api/RealtimeAPI.d.ts.map +1 -0
  3. package/api/RoutingAPI.d.ts +33 -0
  4. package/api/RoutingAPI.d.ts.map +1 -0
  5. package/api/StopsAPI.d.ts +36 -0
  6. package/api/StopsAPI.d.ts.map +1 -0
  7. package/api/index.d.ts +5 -0
  8. package/api/index.d.ts.map +1 -0
  9. package/api/typedefs.d.ts +105 -0
  10. package/api/typedefs.d.ts.map +1 -0
  11. package/common/api/HttpAPI.d.ts +31 -0
  12. package/common/api/HttpAPI.d.ts.map +1 -0
  13. package/common/api/WebSocketAPI.d.ts +95 -0
  14. package/common/api/WebSocketAPI.d.ts.map +1 -0
  15. package/common/controls/Control.d.ts +74 -0
  16. package/common/controls/Control.d.ts.map +1 -0
  17. package/common/{index.js → index.d.ts} +1 -0
  18. package/common/index.d.ts.map +1 -0
  19. package/common/layers/Layer.d.ts +80 -0
  20. package/common/layers/Layer.d.ts.map +1 -0
  21. package/common/mixins/CopyrightMixin.d.ts +22 -0
  22. package/common/mixins/CopyrightMixin.d.ts.map +1 -0
  23. package/common/mixins/MapboxLayerMixin.d.ts +27 -0
  24. package/common/mixins/MapboxLayerMixin.d.ts.map +1 -0
  25. package/common/mixins/RealtimeLayerMixin.d.ts +58 -0
  26. package/common/mixins/RealtimeLayerMixin.d.ts.map +1 -0
  27. package/common/mixins/StopFinderMixin.d.ts +40 -0
  28. package/common/mixins/StopFinderMixin.d.ts.map +1 -0
  29. package/common/mixins/UserInteractionsLayerMixin.d.ts +42 -0
  30. package/common/mixins/UserInteractionsLayerMixin.d.ts.map +1 -0
  31. package/common/styles/{index.js → index.d.ts} +1 -0
  32. package/common/styles/index.d.ts.map +1 -0
  33. package/common/styles/realtimeDefaultStyle.d.ts +15 -0
  34. package/common/styles/realtimeDefaultStyle.d.ts.map +1 -0
  35. package/common/styles/realtimeDelayStyle.d.ts +11 -0
  36. package/common/styles/realtimeDelayStyle.d.ts.map +1 -0
  37. package/common/styles/realtimeSimpleStyle.d.ts +3 -0
  38. package/common/styles/realtimeSimpleStyle.d.ts.map +1 -0
  39. package/common/typedefs.d.ts +50 -0
  40. package/common/typedefs.d.ts.map +1 -0
  41. package/common/utils/cleanStopTime.d.ts +7 -0
  42. package/common/utils/cleanStopTime.d.ts.map +1 -0
  43. package/common/utils/compareDepartures.d.ts +9 -0
  44. package/common/utils/compareDepartures.d.ts.map +1 -0
  45. package/common/utils/createCanvas.d.ts +9 -0
  46. package/common/utils/createCanvas.d.ts.map +1 -0
  47. package/common/utils/createTrackerFilters.d.ts +12 -0
  48. package/common/utils/createTrackerFilters.d.ts.map +1 -0
  49. package/common/utils/getLayersAsFlatArray.d.ts +3 -0
  50. package/common/utils/getLayersAsFlatArray.d.ts.map +1 -0
  51. package/common/utils/getMapboxMapCopyrights.d.ts +8 -0
  52. package/common/utils/getMapboxMapCopyrights.d.ts.map +1 -0
  53. package/common/utils/getMapboxRender.d.ts +5 -0
  54. package/common/utils/getMapboxRender.d.ts.map +1 -0
  55. package/common/utils/getMaplibreRender.d.ts +5 -0
  56. package/common/utils/getMaplibreRender.d.ts.map +1 -0
  57. package/common/utils/getRealtimeModeSuffix.d.ts +8 -0
  58. package/common/utils/getRealtimeModeSuffix.d.ts.map +1 -0
  59. package/common/utils/getUrlWithParams.d.ts +9 -0
  60. package/common/utils/getUrlWithParams.d.ts.map +1 -0
  61. package/common/utils/getVehiclePosition.d.ts +14 -0
  62. package/common/utils/getVehiclePosition.d.ts.map +1 -0
  63. package/common/utils/{index.js → index.d.ts} +3 -0
  64. package/common/utils/index.d.ts.map +1 -0
  65. package/common/utils/removeDuplicate.d.ts +10 -0
  66. package/common/utils/removeDuplicate.d.ts.map +1 -0
  67. package/common/utils/renderTrajectories.d.ts +20 -0
  68. package/common/utils/renderTrajectories.d.ts.map +1 -0
  69. package/common/utils/sortByDelay.d.ts +3 -0
  70. package/common/utils/sortByDelay.d.ts.map +1 -0
  71. package/common/utils/timeUtils.d.ts +5 -0
  72. package/common/utils/timeUtils.d.ts.map +1 -0
  73. package/common/utils/trackerConfig.d.ts +24 -0
  74. package/common/utils/trackerConfig.d.ts.map +1 -0
  75. package/iife.d.ts +3 -0
  76. package/iife.d.ts.map +1 -0
  77. package/index.d.ts +6 -0
  78. package/index.d.ts.map +1 -0
  79. package/mapbox/controls/CopyrightControl.d.ts +32 -0
  80. package/mapbox/controls/CopyrightControl.d.ts.map +1 -0
  81. package/mapbox/controls/{index.js → index.d.ts} +1 -0
  82. package/mapbox/controls/index.d.ts.map +1 -0
  83. package/mapbox/{index.js → index.d.ts} +1 -0
  84. package/mapbox/index.d.ts.map +1 -0
  85. package/mapbox/layers/Layer.d.ts +47 -0
  86. package/mapbox/layers/Layer.d.ts.map +1 -0
  87. package/mapbox/layers/RealtimeLayer.d.ts +118 -0
  88. package/mapbox/layers/RealtimeLayer.d.ts.map +1 -0
  89. package/mapbox/layers/{index.js → index.d.ts} +1 -0
  90. package/mapbox/layers/index.d.ts.map +1 -0
  91. package/mapbox/utils.d.ts +8 -0
  92. package/mapbox/utils.d.ts.map +1 -0
  93. package/mbt.js +2049 -2106
  94. package/mbt.js.map +3 -3
  95. package/mbt.min.js +18 -18
  96. package/mbt.min.js.map +3 -3
  97. package/ol/controls/CopyrightControl.d.ts +31 -0
  98. package/ol/controls/CopyrightControl.d.ts.map +1 -0
  99. package/ol/controls/RoutingControl.d.ts +180 -0
  100. package/ol/controls/RoutingControl.d.ts.map +1 -0
  101. package/ol/controls/StopFinderControl.d.ts +32 -0
  102. package/ol/controls/StopFinderControl.d.ts.map +1 -0
  103. package/ol/controls/{index.js → index.d.ts} +1 -0
  104. package/ol/controls/index.d.ts.map +1 -0
  105. package/ol/{index.js → index.d.ts} +1 -0
  106. package/ol/index.d.ts.map +1 -0
  107. package/ol/layers/Layer.d.ts +49 -0
  108. package/ol/layers/Layer.d.ts.map +1 -0
  109. package/ol/layers/MapboxLayer.d.ts +42 -0
  110. package/ol/layers/MapboxLayer.d.ts.map +1 -0
  111. package/ol/layers/MapboxStyleLayer.d.ts +146 -0
  112. package/ol/layers/MapboxStyleLayer.d.ts.map +1 -0
  113. package/ol/layers/MaplibreLayer.d.ts +27 -0
  114. package/ol/layers/MaplibreLayer.d.ts.map +1 -0
  115. package/ol/layers/RealtimeLayer.d.ts +119 -0
  116. package/ol/layers/RealtimeLayer.d.ts.map +1 -0
  117. package/ol/layers/RoutingLayer.d.ts +24 -0
  118. package/ol/layers/RoutingLayer.d.ts.map +1 -0
  119. package/ol/layers/VectorLayer.d.ts +23 -0
  120. package/ol/layers/VectorLayer.d.ts.map +1 -0
  121. package/ol/layers/WMSLayer.d.ts +38 -0
  122. package/ol/layers/WMSLayer.d.ts.map +1 -0
  123. package/ol/layers/{index.js → index.d.ts} +1 -0
  124. package/ol/layers/index.d.ts.map +1 -0
  125. package/ol/styles/fullTrajectoryDelayStyle.d.ts +4 -0
  126. package/ol/styles/fullTrajectoryDelayStyle.d.ts.map +1 -0
  127. package/ol/styles/fullTrajectoryStyle.d.ts +4 -0
  128. package/ol/styles/fullTrajectoryStyle.d.ts.map +1 -0
  129. package/ol/styles/{index.js → index.d.ts} +1 -0
  130. package/ol/styles/index.d.ts.map +1 -0
  131. package/package.json +14 -36
  132. package/setupTests.d.ts +2 -0
  133. package/setupTests.d.ts.map +1 -0
  134. package/types/index.d.ts +7 -6
  135. package/types/routing.d.ts +25 -25
  136. package/types/stops.d.ts +19 -19
  137. package/api/RealtimeAPI.js +0 -357
  138. package/api/RealtimeAPI.test.js +0 -67
  139. package/api/RoutingAPI.js +0 -15
  140. package/api/RoutingAPI.test.js +0 -25
  141. package/api/StopsAPI.js +0 -12
  142. package/api/StopsAPI.test.js +0 -22
  143. package/api/index.js +0 -3
  144. package/api/typedefs.js +0 -0
  145. package/common/api/HttpAPI.js +0 -32
  146. package/common/api/HttpAPI.test.js +0 -50
  147. package/common/api/WebSocketAPI.js +0 -175
  148. package/common/api/WebSocketAPI.test.js +0 -311
  149. package/common/controls/Control.js +0 -81
  150. package/common/controls/Control.test.js +0 -87
  151. package/common/layers/Layer.js +0 -140
  152. package/common/layers/Layer.test.js +0 -134
  153. package/common/mixins/CopyrightMixin.js +0 -24
  154. package/common/mixins/RealtimeLayerMixin.js +0 -436
  155. package/common/mixins/StopFinderMixin.js +0 -110
  156. package/common/mixins/UserInteractionsLayerMixin.js +0 -124
  157. package/common/mixins/UserInteractionsLayerMixin.test.js +0 -199
  158. package/common/styles/realtimeDefaultStyle.js +0 -202
  159. package/common/styles/realtimeDelayStyle.js +0 -8
  160. package/common/styles/realtimeSimpleStyle.js +0 -18
  161. package/common/typedefs.js +0 -0
  162. package/common/utils/cleanStopTime.js +0 -19
  163. package/common/utils/compareDepartures.js +0 -25
  164. package/common/utils/createCanvas.js +0 -17
  165. package/common/utils/createTrackerFilters.js +0 -56
  166. package/common/utils/createTrackerFilters.test.js +0 -79
  167. package/common/utils/getLayersAsFlatArray.js +0 -14
  168. package/common/utils/getMapboxMapCopyrights.js +0 -19
  169. package/common/utils/getMapboxMapCopyrights.test.js +0 -40
  170. package/common/utils/getRealtimeModeSuffix.js +0 -2
  171. package/common/utils/getUrlWithParams.js +0 -11
  172. package/common/utils/getVehiclePosition.js +0 -42
  173. package/common/utils/removeDuplicate.js +0 -8
  174. package/common/utils/removeDuplicate.test.js +0 -19
  175. package/common/utils/renderTrajectories.js +0 -86
  176. package/common/utils/sortByDelay.js +0 -18
  177. package/common/utils/timeUtils.js +0 -20
  178. package/common/utils/timeUtils.test.js +0 -10
  179. package/common/utils/trackerConfig.js +0 -129
  180. package/common/utils/trackerConfig.test.js +0 -23
  181. package/index.js +0 -8
  182. package/mapbox/controls/CopyrightControl.js +0 -29
  183. package/mapbox/layers/Layer.js +0 -56
  184. package/mapbox/layers/Layer.test.js +0 -182
  185. package/mapbox/layers/RealtimeLayer.js +0 -185
  186. package/mapbox/layers/RealtimeLayer.test.js +0 -10
  187. package/mapbox/utils.js +0 -32
  188. package/ol/controls/CopyrightControl.js +0 -42
  189. package/ol/controls/CopyrightControl.test.js +0 -165
  190. package/ol/controls/RoutingControl.js +0 -388
  191. package/ol/controls/RoutingControl.test.js +0 -146
  192. package/ol/controls/StopFinderControl.js +0 -10
  193. package/ol/controls/StopFinderControl.test.js +0 -48
  194. package/ol/layers/Layer.js +0 -83
  195. package/ol/layers/Layer.test.js +0 -175
  196. package/ol/layers/MapboxLayer.js +0 -204
  197. package/ol/layers/MapboxLayer.test.js +0 -160
  198. package/ol/layers/MapboxStyleLayer.js +0 -187
  199. package/ol/layers/MapboxStyleLayer.test.js +0 -226
  200. package/ol/layers/MaplibreLayer.js +0 -140
  201. package/ol/layers/RealtimeLayer.js +0 -187
  202. package/ol/layers/RealtimeLayer.test.js +0 -67
  203. package/ol/layers/RoutingLayer.js +0 -61
  204. package/ol/layers/RoutingLayer.test.js +0 -39
  205. package/ol/layers/VectorLayer.js +0 -22
  206. package/ol/layers/VectorLayer.test.js +0 -76
  207. package/ol/layers/WMSLayer.js +0 -38
  208. package/ol/layers/WMSLayer.test.js +0 -57
  209. package/ol/styles/fullTrajectoryDelayStyle.js +0 -31
  210. package/ol/styles/fullTrajectoryStyle.js +0 -42
@@ -1,187 +0,0 @@
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
- const format = new GeoJSON();
10
- class RealtimeLayer extends mixin(Layer) {
11
- constructor(options = {}) {
12
- super({
13
- ...options
14
- });
15
- this.olLayer = options.olLayer || new Group({
16
- layers: [
17
- new VectorLayer({
18
- source: new VectorSource({ features: [] }),
19
- style: (feature, resolution) => {
20
- return (options.fullTrajectoryStyle || fullTrajectoryStyle)(feature, resolution, this.styleOptions);
21
- }
22
- }),
23
- new OLLayer({
24
- source: new Source({}),
25
- render: (frameState) => {
26
- if (!this.container) {
27
- this.container = document.createElement("div");
28
- this.container.style.position = "absolute";
29
- this.container.style.width = "100%";
30
- this.container.style.height = "100%";
31
- this.transformContainer = document.createElement("div");
32
- this.transformContainer.style.position = "absolute";
33
- this.transformContainer.style.width = "100%";
34
- this.transformContainer.style.height = "100%";
35
- this.container.appendChild(this.transformContainer);
36
- this.canvas.style.position = "absolute";
37
- this.canvas.style.top = "0";
38
- this.canvas.style.left = "0";
39
- this.canvas.style.transformOrigin = "top left";
40
- this.transformContainer.appendChild(this.canvas);
41
- }
42
- if (this.renderedViewState) {
43
- const { center, resolution, rotation } = frameState.viewState;
44
- const {
45
- center: renderedCenter,
46
- resolution: renderedResolution,
47
- rotation: renderedRotation
48
- } = this.renderedViewState;
49
- if (renderedResolution / resolution >= 3) {
50
- const context = this.canvas.getContext("2d");
51
- context.clearRect(0, 0, this.canvas.width, this.canvas.height);
52
- } else {
53
- const pixelCenterRendered = this.map.getPixelFromCoordinate(renderedCenter);
54
- const pixelCenter = this.map.getPixelFromCoordinate(center);
55
- this.transformContainer.style.transform = composeCssTransform(pixelCenterRendered[0] - pixelCenter[0], pixelCenterRendered[1] - pixelCenter[1], renderedResolution / resolution, renderedResolution / resolution, rotation - renderedRotation, 0, 0);
56
- }
57
- }
58
- return this.container;
59
- }
60
- })
61
- ]
62
- });
63
- this.vectorLayer = this.olLayer.getLayers().item(0);
64
- this.renderState = {
65
- center: [0, 0],
66
- zoom: null,
67
- rotation: 0
68
- };
69
- }
70
- attachToMap(map) {
71
- super.attachToMap(map);
72
- if (this.map) {
73
- this.olListenersKeys.push(this.map.on(["moveend", "change:target"], (evt) => {
74
- const view = this.map.getView();
75
- if (view.getAnimating() || view.getInteracting()) {
76
- return;
77
- }
78
- const zoom = view.getZoom();
79
- if (this.currentZoom !== zoom) {
80
- this.onZoomEnd(evt);
81
- }
82
- this.currentZoom = zoom;
83
- this.onMoveEnd(evt);
84
- }));
85
- }
86
- }
87
- detachFromMap() {
88
- super.detachFromMap();
89
- this.container = null;
90
- }
91
- hasFeatureInfoAtCoordinate(coordinate) {
92
- if (this.map && this.canvas) {
93
- const context = this.canvas.getContext("2d");
94
- const pixel = this.map.getPixelFromCoordinate(coordinate);
95
- return !!context.getImageData(pixel[0] * this.pixelRatio, pixel[1] * this.pixelRatio, 1, 1).data[3];
96
- }
97
- return false;
98
- }
99
- renderTrajectories(noInterpolate) {
100
- const view = this.map.getView();
101
- super.renderTrajectories({
102
- size: this.map.getSize(),
103
- center: this.map.getView().getCenter(),
104
- extent: view.calculateExtent(),
105
- resolution: view.getResolution(),
106
- rotation: view.getRotation(),
107
- zoom: view.getZoom(),
108
- pixelRatio: this.pixelRatio
109
- }, noInterpolate);
110
- }
111
- renderTrajectoriesInternal(viewState, noInterpolate) {
112
- if (!this.map) {
113
- return false;
114
- }
115
- let isRendered = false;
116
- const blockRendering = this.map.getView().getAnimating() || this.map.getView().getInteracting();
117
- isRendered = blockRendering ? false : super.renderTrajectoriesInternal(viewState, noInterpolate);
118
- if (isRendered) {
119
- this.renderedViewState = { ...viewState };
120
- if (this.transformContainer) {
121
- this.transformContainer.style.transform = "";
122
- }
123
- }
124
- return isRendered;
125
- }
126
- getRefreshTimeInMs() {
127
- return super.getRefreshTimeInMs(this.map.getView().getZoom());
128
- }
129
- getFeatureInfoAtCoordinate(coordinate, options = {}) {
130
- const resolution = this.map.getView().getResolution();
131
- return super.getFeatureInfoAtCoordinate(coordinate, {
132
- resolution,
133
- ...options
134
- });
135
- }
136
- onMoveEnd() {
137
- if (this.visible && this.isUpdateBboxOnMoveEnd) {
138
- this.setBbox();
139
- }
140
- if (this.visible && this.isUpdateBboxOnMoveEnd && this.userClickInteractions && this.selectedVehicleId) {
141
- this.highlightTrajectory(this.selectedVehicleId);
142
- }
143
- }
144
- onZoomEnd(evt) {
145
- super.onZoomEnd(evt);
146
- }
147
- onFeatureHover(features, layer, coordinate) {
148
- super.onFeatureHover(features, layer, coordinate);
149
- this.map.getTargetElement().style.cursor = features.length ? "pointer" : "auto";
150
- }
151
- onFeatureClick(features, layer, coordinate) {
152
- super.onFeatureClick(features, layer, coordinate);
153
- if (!features.length && this.vectorLayer) {
154
- this.vectorLayer.getSource().clear();
155
- }
156
- if (this.selectedVehicleId) {
157
- this.highlightTrajectory(this.selectedVehicleId);
158
- }
159
- }
160
- purgeTrajectory(trajectory, extent, zoom) {
161
- return super.purgeTrajectory(trajectory, extent || this.map.getView().calculateExtent(), zoom || this.map.getView().getZoom());
162
- }
163
- setBbox(extent, zoom) {
164
- let newExtent = extent;
165
- let newZoom = zoom;
166
- if (!newExtent && this.isUpdateBboxOnMoveEnd) {
167
- newExtent = extent || this.map.getView().calculateExtent();
168
- newZoom = Math.floor(this.map.getView().getZoom());
169
- }
170
- super.setBbox(newExtent, newZoom);
171
- }
172
- highlightTrajectory(id) {
173
- this.api.getFullTrajectory(id, this.mode, this.generalizationLevel).then((fullTrajectory) => {
174
- const vectorSource = this.vectorLayer.getSource();
175
- vectorSource.clear();
176
- if (!fullTrajectory || !fullTrajectory.features || !fullTrajectory.features.length) {
177
- return;
178
- }
179
- const features = format.readFeatures(fullTrajectory);
180
- this.vectorLayer.getSource().addFeatures(features);
181
- });
182
- }
183
- clone(newOptions) {
184
- return new RealtimeLayer({ ...this.options, ...newOptions });
185
- }
186
- }
187
- export default RealtimeLayer;
@@ -1,67 +0,0 @@
1
- import fetch from "jest-fetch-mock";
2
- import Map from "ol/Map";
3
- import View from "ol/View";
4
- import WS from "jest-websocket-mock";
5
- import RealtimeLayer from "./RealtimeLayer";
6
- let layer;
7
- let onClick;
8
- let olMap;
9
- let server;
10
- describe("RealtimeLayer", () => {
11
- beforeEach(() => {
12
- server = new WS("ws://localhost:1234");
13
- global.fetch = fetch;
14
- fetch.resetMocks();
15
- onClick = jest.fn();
16
- layer = new RealtimeLayer({
17
- url: "ws://localhost:1234",
18
- apiKey: "apiKey",
19
- onClick
20
- });
21
- olMap = new Map({
22
- view: new View({
23
- center: [831634, 5933959],
24
- zoom: 9
25
- })
26
- });
27
- });
28
- afterEach(() => {
29
- server.close();
30
- WS.clean();
31
- });
32
- test("should be instanced.", () => {
33
- expect(layer).toBeInstanceOf(RealtimeLayer);
34
- });
35
- test("should called terminate on initalization.", () => {
36
- const spy = jest.spyOn(layer, "detachFromMap");
37
- fetch.mockResponseOnce(JSON.stringify(global.fetchTrajectoriesResponse));
38
- layer.attachToMap(olMap);
39
- expect(spy).toHaveBeenCalledTimes(1);
40
- });
41
- test("should clone", () => {
42
- const clone = layer.clone({ name: "clone" });
43
- expect(clone).not.toBe(layer);
44
- expect(clone.name).toBe("clone");
45
- expect(clone).toBeInstanceOf(RealtimeLayer);
46
- });
47
- test("should use the sort function.", () => {
48
- const fn = () => true;
49
- const laye = new RealtimeLayer({
50
- url: "ws://localhost:1234",
51
- apiKey: "apiKey",
52
- sort: fn
53
- });
54
- expect(laye).toBeInstanceOf(RealtimeLayer);
55
- expect(laye.sort).toBe(fn);
56
- });
57
- test("should use filter function.", () => {
58
- const fn = () => true;
59
- const laye = new RealtimeLayer({
60
- url: "ws://localhost:1234",
61
- apiKey: "apiKey",
62
- filter: fn
63
- });
64
- expect(laye).toBeInstanceOf(RealtimeLayer);
65
- expect(laye.filter).toBe(fn);
66
- });
67
- });
@@ -1,61 +0,0 @@
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
- const circleStyle = new Circle({
6
- radius: 6,
7
- fill: new Fill({
8
- color: [255, 0, 0, 1]
9
- }),
10
- stroke: new Stroke({
11
- color: [0, 0, 0, 1],
12
- width: 1
13
- })
14
- });
15
- const blackBorder = new Style({
16
- stroke: new Stroke({
17
- color: [0, 0, 0, 1],
18
- width: 5
19
- })
20
- });
21
- const redLine = new Style({
22
- image: circleStyle,
23
- stroke: new Stroke({
24
- color: [255, 0, 0, 1],
25
- width: 3
26
- })
27
- });
28
- const dashedRedLine = new Style({
29
- image: circleStyle,
30
- stroke: new Stroke({
31
- color: [255, 0, 0, 1],
32
- width: 3,
33
- lineDash: [1, 10]
34
- })
35
- });
36
- const defaultStyleFunction = (feature, resolution) => {
37
- const minResolution = feature.get("minResolution");
38
- const maxResolution = feature.get("maxResolution");
39
- const inRange = resolution <= minResolution && resolution > maxResolution;
40
- if (minResolution && maxResolution && !inRange) {
41
- return null;
42
- }
43
- const mot = feature.get("mot");
44
- if (mot !== "foot") {
45
- return [blackBorder, redLine];
46
- }
47
- return [dashedRedLine];
48
- };
49
- class RoutingLayer extends Layer {
50
- constructor(options = {}) {
51
- super(options);
52
- this.olLayer = options.olLayer || new Vector({
53
- source: new VectorSource(),
54
- style: options.style || defaultStyleFunction
55
- });
56
- }
57
- clone(newOptions) {
58
- return new RoutingLayer({ ...this.options, ...newOptions });
59
- }
60
- }
61
- export default RoutingLayer;
@@ -1,39 +0,0 @@
1
- import fetch from "jest-fetch-mock";
2
- import Map from "ol/Map";
3
- import View from "ol/View";
4
- import RoutingLayer from "./RoutingLayer";
5
- let layer;
6
- let onClick;
7
- let olMap;
8
- describe("RoutingLayer", () => {
9
- beforeEach(() => {
10
- global.fetch = fetch;
11
- fetch.resetMocks();
12
- onClick = jest.fn();
13
- layer = new RoutingLayer({
14
- onClick,
15
- apiKey: "apiKey"
16
- });
17
- olMap = new Map({
18
- view: new View({
19
- center: [831634, 5933959],
20
- zoom: 9
21
- })
22
- });
23
- });
24
- test("should be instanced.", () => {
25
- expect(layer).toBeInstanceOf(RoutingLayer);
26
- });
27
- test("should called terminate on initalization.", () => {
28
- const spy = jest.spyOn(layer, "detachFromMap");
29
- fetch.mockResponseOnce(JSON.stringify(global.fetchTrajectoriesResponse));
30
- layer.attachToMap(olMap);
31
- expect(spy).toHaveBeenCalledTimes(1);
32
- });
33
- test("should clone", () => {
34
- const clone = layer.clone({ name: "clone" });
35
- expect(clone).not.toBe(layer);
36
- expect(clone.name).toBe("clone");
37
- expect(clone).toBeInstanceOf(RoutingLayer);
38
- });
39
- });
@@ -1,22 +0,0 @@
1
- import Layer from "./Layer";
2
- class VectorLayer extends Layer {
3
- getFeatureInfoAtCoordinate(coordinate) {
4
- let features = [];
5
- if (this.map) {
6
- const pixel = this.map.getPixelFromCoordinate(coordinate);
7
- features = this.map.getFeaturesAtPixel(pixel, {
8
- layerFilter: (l) => l === this.olLayer,
9
- hitTolerance: this.hitTolerance
10
- });
11
- }
12
- return Promise.resolve({
13
- features,
14
- layer: this,
15
- coordinate
16
- });
17
- }
18
- clone(newOptions) {
19
- return new VectorLayer({ ...this.options, ...newOptions });
20
- }
21
- }
22
- export default VectorLayer;
@@ -1,76 +0,0 @@
1
- import OLVectorLayer from "ol/layer/Vector";
2
- import VectorSource from "ol/source/Vector";
3
- import View from "ol/View";
4
- import Feature from "ol/Feature";
5
- import Point from "ol/geom/Point";
6
- import Map from "ol/Map";
7
- import VectorLayer from "./VectorLayer";
8
- const feature1 = new Feature({
9
- attribute: "bar",
10
- geometry: new Point([500, 500])
11
- });
12
- const olLayer = new OLVectorLayer({
13
- source: new VectorSource({
14
- features: [
15
- feature1,
16
- new Feature({
17
- attribute: "foo",
18
- geometry: new Point([50, 50])
19
- })
20
- ]
21
- })
22
- });
23
- let layer;
24
- let map;
25
- let onClick;
26
- describe("VectorLayer", () => {
27
- beforeEach(() => {
28
- onClick = jest.fn();
29
- layer = new VectorLayer({
30
- name: "Layer",
31
- olLayer,
32
- onClick
33
- });
34
- map = new Map({
35
- view: new View({ resolution: 5 }),
36
- target: document.body
37
- });
38
- });
39
- test("should be instanced.", () => {
40
- expect(layer).toBeInstanceOf(VectorLayer);
41
- expect(layer.hitTolerance).toBe(5);
42
- });
43
- test("should called terminate on initalization.", () => {
44
- const spy = jest.spyOn(layer, "detachFromMap");
45
- layer.attachToMap();
46
- expect(spy).toHaveBeenCalledTimes(1);
47
- });
48
- test("should call getFeatureInfoAtCoordinate on click then the callback", async () => {
49
- const coordinate = [500, 500];
50
- const px = [10, 10];
51
- const features = [feature1];
52
- const evt = { type: "singleclick", map, coordinate };
53
- const spy = jest.spyOn(layer, "getFeatureInfoAtCoordinate");
54
- const spy2 = jest.spyOn(map, "getPixelFromCoordinate").mockReturnValue(px);
55
- const spy3 = jest.spyOn(map, "getFeaturesAtPixel").mockReturnValue(features);
56
- layer.attachToMap(map);
57
- expect(onClick).toHaveBeenCalledTimes(0);
58
- await map.dispatchEvent(evt);
59
- expect(spy).toHaveBeenCalledTimes(1);
60
- expect(spy).toHaveBeenCalledWith(coordinate);
61
- expect(spy2).toHaveBeenCalledTimes(1);
62
- expect(spy2).toHaveBeenCalledWith(coordinate);
63
- expect(spy3).toHaveBeenCalledTimes(1);
64
- expect(spy3.mock.calls[0][0]).toBe(px);
65
- expect(spy3.mock.calls[0][1].layerFilter(layer.olLayer)).toBe(true);
66
- expect(spy3.mock.calls[0][1].layerFilter({})).toBe(false);
67
- expect(onClick).toHaveBeenCalledTimes(1);
68
- expect(onClick).toHaveBeenCalledWith(features, layer, coordinate);
69
- });
70
- test("should clone", () => {
71
- const clone = layer.clone({ name: "clone" });
72
- expect(clone).not.toBe(layer);
73
- expect(clone.name).toBe("clone");
74
- expect(clone).toBeInstanceOf(VectorLayer);
75
- });
76
- });
@@ -1,38 +0,0 @@
1
- import GeoJSON from "ol/format/GeoJSON";
2
- import Layer from "./Layer";
3
- class WMSLayer extends Layer {
4
- constructor(options = {}) {
5
- super(options);
6
- this.abortController = new AbortController();
7
- this.format = new GeoJSON();
8
- }
9
- getFeatureInfoUrl(coord) {
10
- const projection = this.map.getView().getProjection();
11
- const resolution = this.map.getView().getResolution();
12
- if (this.olLayer.getSource().getFeatureInfoUrl) {
13
- return this.olLayer.getSource().getFeatureInfoUrl(coord, resolution, projection, {
14
- info_format: "application/json",
15
- query_layers: this.olLayer.getSource().getParams().layers
16
- });
17
- }
18
- return false;
19
- }
20
- getFeatureInfoAtCoordinate(coordinate) {
21
- this.abortController.abort();
22
- this.abortController = new AbortController();
23
- const { signal } = this.abortController;
24
- return fetch(this.getFeatureInfoUrl(coordinate), { signal }).then((resp) => resp.json()).then((r) => r.features).then((data) => ({
25
- layer: this,
26
- coordinate,
27
- features: data.map((d) => this.format.readFeature(d))
28
- })).catch(() => Promise.resolve({
29
- features: [],
30
- coordinate,
31
- layer: this
32
- }));
33
- }
34
- clone(newOptions) {
35
- return new WMSLayer({ ...this.options, ...newOptions });
36
- }
37
- }
38
- export default WMSLayer;
@@ -1,57 +0,0 @@
1
- import OLView from "ol/View";
2
- import ImageLayer from "ol/layer/Image";
3
- import ImageWMS from "ol/source/ImageWMS";
4
- import fetch from "jest-fetch-mock";
5
- import Map from "ol/Map";
6
- import WMSLayer from "./WMSLayer";
7
- describe("WMSLayer", () => {
8
- let map;
9
- let layer;
10
- beforeEach(() => {
11
- map = new Map({
12
- view: new OLView({ resolution: 5 }),
13
- target: document.body
14
- });
15
- layer = new WMSLayer({
16
- olLayer: new ImageLayer({
17
- source: new ImageWMS({
18
- url: "http://dummy",
19
- params: { LAYERS: "layers" }
20
- })
21
- })
22
- });
23
- layer.attachToMap(map);
24
- fetch.mockResponseOnce(JSON.stringify({ features: [] }));
25
- global.fetch = fetch;
26
- });
27
- afterEach(() => {
28
- layer.detachFromMap();
29
- });
30
- test("should initialize.", () => {
31
- expect(layer).toBeInstanceOf(WMSLayer);
32
- });
33
- test("should called terminate on initalization.", () => {
34
- const spy = jest.spyOn(layer, "detachFromMap");
35
- layer.attachToMap();
36
- expect(spy).toHaveBeenCalledTimes(1);
37
- });
38
- test("should return a promise resolving features.", async () => {
39
- const data = await layer.getFeatureInfoAtCoordinate([50, 50]);
40
- const params = new URL(fetch.mock.calls[0][0]).searchParams;
41
- expect(params.get("REQUEST")).toBe("GetFeatureInfo");
42
- expect(params.get("I")).toBe("50");
43
- expect(params.get("J")).toBe("50");
44
- expect(data.features).toEqual([]);
45
- });
46
- test("should return a layer instance and a coordinate.", async () => {
47
- const data = await layer.getFeatureInfoAtCoordinate([50, 50]);
48
- expect(data.coordinate).toEqual([50, 50]);
49
- expect(data.layer).toBeInstanceOf(WMSLayer);
50
- });
51
- test("should clone", () => {
52
- const clone = layer.clone({ name: "clone" });
53
- expect(clone).not.toBe(layer);
54
- expect(clone.name).toBe("clone");
55
- expect(clone).toBeInstanceOf(WMSLayer);
56
- });
57
- });
@@ -1,31 +0,0 @@
1
- import { Style, Fill, Stroke, Circle } from "ol/style";
2
- const stroke = new Style({
3
- zIndex: 2,
4
- image: new Circle({
5
- radius: 5,
6
- fill: new Fill({
7
- color: "#000000"
8
- })
9
- }),
10
- stroke: new Stroke({
11
- color: "#000000",
12
- width: 6
13
- })
14
- });
15
- const fill = new Style({
16
- zIndex: 3,
17
- image: new Circle({
18
- radius: 4,
19
- fill: new Fill({
20
- color: "#a0a0a0"
21
- })
22
- }),
23
- stroke: new Stroke({
24
- color: "#a0a0a0",
25
- width: 4
26
- })
27
- });
28
- const fullTrajectoryDelaystyle = () => {
29
- return [stroke, fill];
30
- };
31
- export default fullTrajectoryDelaystyle;
@@ -1,42 +0,0 @@
1
- import { Style, Fill, Stroke, Circle } from "ol/style";
2
- const borderStyle = new Style({
3
- zIndex: 2,
4
- image: new Circle({
5
- radius: 5,
6
- fill: new Fill({
7
- color: "#000000"
8
- })
9
- }),
10
- stroke: new Stroke({
11
- color: "#000000",
12
- width: 6
13
- })
14
- });
15
- const fullTrajectorystyle = (feature, resolution, options) => {
16
- let lineColor = "#ffffff";
17
- const type = feature.get("type");
18
- let stroke = feature.get("stroke");
19
- if (stroke && stroke[0] !== "#") {
20
- stroke = `#${stroke}`;
21
- }
22
- lineColor = stroke || options?.getBgColor(type);
23
- lineColor = /#ffffff/i.test(lineColor) ? "#ff0000" : lineColor;
24
- const style = [
25
- borderStyle,
26
- new Style({
27
- zIndex: 3,
28
- image: new Circle({
29
- radius: 4,
30
- fill: new Fill({
31
- color: lineColor
32
- })
33
- }),
34
- stroke: new Stroke({
35
- color: lineColor,
36
- width: 4
37
- })
38
- })
39
- ];
40
- return style;
41
- };
42
- export default fullTrajectorystyle;