mobility-toolbox-js 2.0.0-beta.3 → 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.
- package/README.md +4 -1
- package/api/RealtimeAPI.d.ts +268 -0
- package/api/RealtimeAPI.d.ts.map +1 -0
- package/api/RoutingAPI.d.ts +33 -0
- package/api/RoutingAPI.d.ts.map +1 -0
- package/api/StopsAPI.d.ts +36 -0
- package/api/StopsAPI.d.ts.map +1 -0
- package/api/index.d.ts +5 -0
- package/api/index.d.ts.map +1 -0
- package/api/typedefs.d.ts +105 -0
- package/api/typedefs.d.ts.map +1 -0
- package/common/api/HttpAPI.d.ts +31 -0
- package/common/api/HttpAPI.d.ts.map +1 -0
- package/common/api/WebSocketAPI.d.ts +95 -0
- package/common/api/WebSocketAPI.d.ts.map +1 -0
- package/common/controls/Control.d.ts +74 -0
- package/common/controls/Control.d.ts.map +1 -0
- package/common/index.d.ts +3 -0
- package/common/index.d.ts.map +1 -0
- package/common/layers/Layer.d.ts +80 -0
- package/common/layers/Layer.d.ts.map +1 -0
- package/common/mixins/CopyrightMixin.d.ts +22 -0
- package/common/mixins/CopyrightMixin.d.ts.map +1 -0
- package/common/mixins/MapboxLayerMixin.d.ts +27 -0
- package/common/mixins/MapboxLayerMixin.d.ts.map +1 -0
- package/common/mixins/RealtimeLayerMixin.d.ts +58 -0
- package/common/mixins/RealtimeLayerMixin.d.ts.map +1 -0
- package/common/mixins/StopFinderMixin.d.ts +40 -0
- package/common/mixins/StopFinderMixin.d.ts.map +1 -0
- package/common/mixins/UserInteractionsLayerMixin.d.ts +42 -0
- package/common/mixins/UserInteractionsLayerMixin.d.ts.map +1 -0
- package/common/styles/index.d.ts +5 -0
- package/common/styles/index.d.ts.map +1 -0
- package/common/styles/realtimeDefaultStyle.d.ts +15 -0
- package/common/styles/realtimeDefaultStyle.d.ts.map +1 -0
- package/common/styles/{trackerDelayStyle.js → realtimeDelayStyle.d.ts} +3 -9
- package/common/styles/realtimeDelayStyle.d.ts.map +1 -0
- package/common/styles/realtimeSimpleStyle.d.ts +3 -0
- package/common/styles/realtimeSimpleStyle.d.ts.map +1 -0
- package/common/typedefs.d.ts +50 -0
- package/common/typedefs.d.ts.map +1 -0
- package/common/utils/cleanStopTime.d.ts +7 -0
- package/common/utils/cleanStopTime.d.ts.map +1 -0
- package/common/utils/compareDepartures.d.ts +9 -0
- package/common/utils/compareDepartures.d.ts.map +1 -0
- package/common/utils/createCanvas.d.ts +9 -0
- package/common/utils/createCanvas.d.ts.map +1 -0
- package/common/utils/createTrackerFilters.d.ts +12 -0
- package/common/utils/createTrackerFilters.d.ts.map +1 -0
- package/common/utils/getLayersAsFlatArray.d.ts +3 -0
- package/common/utils/getLayersAsFlatArray.d.ts.map +1 -0
- package/common/utils/getMapboxMapCopyrights.d.ts +8 -0
- package/common/utils/getMapboxMapCopyrights.d.ts.map +1 -0
- package/common/utils/getMapboxRender.d.ts +5 -0
- package/common/utils/getMapboxRender.d.ts.map +1 -0
- package/common/utils/getMaplibreRender.d.ts +5 -0
- package/common/utils/getMaplibreRender.d.ts.map +1 -0
- package/common/utils/getRealtimeModeSuffix.d.ts +8 -0
- package/common/utils/getRealtimeModeSuffix.d.ts.map +1 -0
- package/common/utils/getUrlWithParams.d.ts +9 -0
- package/common/utils/getUrlWithParams.d.ts.map +1 -0
- package/common/utils/getVehiclePosition.d.ts +14 -0
- package/common/utils/getVehiclePosition.d.ts.map +1 -0
- package/common/utils/index.d.ts +12 -0
- package/common/utils/index.d.ts.map +1 -0
- package/common/utils/removeDuplicate.d.ts +10 -0
- package/common/utils/removeDuplicate.d.ts.map +1 -0
- package/common/utils/renderTrajectories.d.ts +20 -0
- package/common/utils/renderTrajectories.d.ts.map +1 -0
- package/common/utils/sortByDelay.d.ts +3 -0
- package/common/utils/sortByDelay.d.ts.map +1 -0
- package/common/utils/timeUtils.d.ts +5 -0
- package/common/utils/timeUtils.d.ts.map +1 -0
- package/common/utils/trackerConfig.d.ts +24 -0
- package/common/utils/trackerConfig.d.ts.map +1 -0
- package/iife.d.ts +3 -0
- package/iife.d.ts.map +1 -0
- package/index.d.ts +6 -0
- package/index.d.ts.map +1 -0
- package/mapbox/controls/CopyrightControl.d.ts +32 -0
- package/mapbox/controls/CopyrightControl.d.ts.map +1 -0
- package/mapbox/controls/index.d.ts +2 -0
- package/mapbox/controls/index.d.ts.map +1 -0
- package/mapbox/index.d.ts +5 -0
- package/mapbox/index.d.ts.map +1 -0
- package/mapbox/layers/Layer.d.ts +47 -0
- package/mapbox/layers/Layer.d.ts.map +1 -0
- package/mapbox/layers/RealtimeLayer.d.ts +118 -0
- package/mapbox/layers/RealtimeLayer.d.ts.map +1 -0
- package/mapbox/layers/index.d.ts +3 -0
- package/mapbox/layers/index.d.ts.map +1 -0
- package/mapbox/utils.d.ts +8 -0
- package/mapbox/utils.d.ts.map +1 -0
- package/mbt.js +50042 -0
- package/mbt.js.map +7 -0
- package/mbt.min.js +1008 -0
- package/mbt.min.js.map +7 -0
- package/ol/controls/CopyrightControl.d.ts +31 -0
- package/ol/controls/CopyrightControl.d.ts.map +1 -0
- package/ol/controls/RoutingControl.d.ts +180 -0
- package/ol/controls/RoutingControl.d.ts.map +1 -0
- package/ol/controls/StopFinderControl.d.ts +32 -0
- package/ol/controls/StopFinderControl.d.ts.map +1 -0
- package/ol/controls/index.d.ts +4 -0
- package/ol/controls/index.d.ts.map +1 -0
- package/ol/index.d.ts +6 -0
- package/ol/index.d.ts.map +1 -0
- package/ol/layers/Layer.d.ts +49 -0
- package/ol/layers/Layer.d.ts.map +1 -0
- package/ol/layers/MapboxLayer.d.ts +42 -0
- package/ol/layers/MapboxLayer.d.ts.map +1 -0
- package/ol/layers/MapboxStyleLayer.d.ts +146 -0
- package/ol/layers/MapboxStyleLayer.d.ts.map +1 -0
- package/ol/layers/MaplibreLayer.d.ts +27 -0
- package/ol/layers/MaplibreLayer.d.ts.map +1 -0
- package/ol/layers/RealtimeLayer.d.ts +119 -0
- package/ol/layers/RealtimeLayer.d.ts.map +1 -0
- package/ol/layers/RoutingLayer.d.ts +24 -0
- package/ol/layers/RoutingLayer.d.ts.map +1 -0
- package/ol/layers/VectorLayer.d.ts +23 -0
- package/ol/layers/VectorLayer.d.ts.map +1 -0
- package/ol/layers/WMSLayer.d.ts +38 -0
- package/ol/layers/WMSLayer.d.ts.map +1 -0
- package/ol/layers/index.d.ts +9 -0
- package/ol/layers/index.d.ts.map +1 -0
- package/ol/styles/fullTrajectoryDelayStyle.d.ts +4 -0
- package/ol/styles/fullTrajectoryDelayStyle.d.ts.map +1 -0
- package/ol/styles/fullTrajectoryStyle.d.ts +4 -0
- package/ol/styles/fullTrajectoryStyle.d.ts.map +1 -0
- package/ol/styles/index.d.ts +3 -0
- package/ol/styles/index.d.ts.map +1 -0
- package/package.json +56 -95
- package/setupTests.d.ts +2 -0
- package/setupTests.d.ts.map +1 -0
- package/types/index.d.ts +10 -0
- package/types/realtime.d.ts +24 -0
- package/types/routing.d.ts +206 -0
- package/types/stops.d.ts +143 -0
- package/api/index.js +0 -3
- package/api/routing/RoutingAPI.js +0 -44
- package/api/routing/RoutingAPI.test.js +0 -41
- package/api/stops/StopsAPI.js +0 -41
- package/api/stops/StopsAPI.test.js +0 -34
- package/api/tralis/TralisAPI.js +0 -731
- package/api/tralis/TralisAPI.test.js +0 -75
- package/api/tralis/TralisAPIUtils.js +0 -73
- package/api/tralis/WebSocketConnector.js +0 -338
- package/api/tralis/WebSocketConnector.test.js +0 -356
- package/api/tralis/typedefs.js +0 -81
- package/common/Tracker.js +0 -197
- package/common/api/api.js +0 -64
- package/common/api/api.test.js +0 -68
- package/common/controls/Control.js +0 -146
- package/common/controls/Control.test.js +0 -98
- package/common/layers/Layer.js +0 -404
- package/common/layers/Layer.test.js +0 -585
- package/common/mixins/CopyrightMixin.js +0 -48
- package/common/mixins/SearchMixin.js +0 -176
- package/common/mixins/TralisLayerMixin.js +0 -930
- package/common/styles/index.js +0 -4
- package/common/styles/trackerDefaultStyle.js +0 -333
- package/common/styles/trackerSimpleStyle.js +0 -22
- package/common/trackerConfig.js +0 -190
- package/common/trackerConfig.test.js +0 -25
- package/common/typedefs.js +0 -23
- package/common/utils/createTrackerFilters.js +0 -87
- package/common/utils/createTrackerFilters.test.js +0 -95
- package/common/utils/getMapboxMapCopyrights.js +0 -32
- package/common/utils/getMapboxMapCopyrights.test.js +0 -47
- package/common/utils/getMapboxStyleUrl.js +0 -32
- package/common/utils/getVehiclePosition.js +0 -72
- package/common/utils/index.js +0 -6
- package/common/utils/removeDuplicate.js +0 -22
- package/common/utils/removeDuplicate.test.js +0 -22
- package/common/utils/sortByDelay.js +0 -23
- package/common/utils/timeUtils.js +0 -44
- package/common/utils/timeUtils.test.js +0 -16
- package/index.js +0 -2
- package/index.js.map +0 -1
- package/mapbox/controls/CopyrightControl.js +0 -58
- package/mapbox/index.js +0 -3
- package/mapbox/layers/Layer.js +0 -118
- package/mapbox/layers/Layer.test.js +0 -202
- package/mapbox/layers/TralisLayer.js +0 -329
- package/mapbox/layers/TralisLayer.test.js +0 -40
- package/mapbox/utils.js +0 -46
- package/module.js +0 -23
- package/ol/README.md +0 -0
- package/ol/controls/CopyrightControl.js +0 -80
- package/ol/controls/CopyrightControl.test.js +0 -211
- package/ol/controls/RoutingControl.js +0 -752
- package/ol/controls/RoutingControl.test.js +0 -216
- package/ol/controls/StopFinderControl.js +0 -38
- package/ol/controls/StopFinderControl.test.js +0 -59
- package/ol/controls/snapshots/RoutingControlRouteGen10.json +0 -58
- package/ol/controls/snapshots/RoutingControlRouteGen100.json +0 -292
- package/ol/controls/snapshots/RoutingControlRouteGen30.json +0 -69
- package/ol/controls/snapshots/RoutingControlRouteGen5.json +0 -58
- package/ol/controls/snapshots/RoutingControlRouteOSM.json +0 -759
- package/ol/controls/snapshots/RoutingControlStation1.json +0 -60
- package/ol/controls/snapshots/RoutingControlStation2.json +0 -49
- package/ol/index.js +0 -13
- package/ol/layers/Layer.js +0 -193
- package/ol/layers/Layer.test.js +0 -197
- package/ol/layers/MapboxLayer.js +0 -378
- package/ol/layers/MapboxLayer.test.js +0 -186
- package/ol/layers/MapboxStyleLayer.js +0 -417
- package/ol/layers/MapboxStyleLayer.test.js +0 -262
- package/ol/layers/MaplibreLayer.js +0 -280
- package/ol/layers/RoutingLayer.js +0 -91
- package/ol/layers/RoutingLayer.test.js +0 -49
- package/ol/layers/TralisLayer.js +0 -359
- package/ol/layers/TralisLayer.test.js +0 -97
- package/ol/layers/VectorLayer.js +0 -43
- package/ol/layers/VectorLayer.test.js +0 -98
- package/ol/layers/WMSLayer.js +0 -80
- package/ol/layers/WMSLayer.test.js +0 -84
- package/ol/styles/fullTrajectoryDelayStyle.js +0 -35
- package/ol/styles/fullTrajectoryStyle.js +0 -51
- package/ol/styles/index.js +0 -2
|
@@ -1,280 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-underscore-dangle */
|
|
2
|
-
import { toLonLat } from 'ol/proj';
|
|
3
|
-
import { Map } from 'maplibre-gl';
|
|
4
|
-
import Source from 'ol/source/Source';
|
|
5
|
-
import OLLayer from 'ol/layer/Layer';
|
|
6
|
-
import GeoJSON from 'ol/format/GeoJSON';
|
|
7
|
-
import { toDegrees } from 'ol/math';
|
|
8
|
-
import Layer from './Layer';
|
|
9
|
-
import { getMapboxMapCopyrights, getMapboxStyleUrl } from '../../common/utils';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* A class representing MaplibreLayer to display on BasicMap
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* import { MaplibreLayer } from 'mobility-toolbox-js/ol';
|
|
16
|
-
*
|
|
17
|
-
* const layer = new MaplibreLayer({
|
|
18
|
-
* url: 'https://maps.geops.io/styles/travic_v2/style.json',
|
|
19
|
-
* apikey: 'yourApiKey',
|
|
20
|
-
* });
|
|
21
|
-
*
|
|
22
|
-
* @classproperty {ol/Map~Map} map - The map where the layer is displayed.
|
|
23
|
-
* @extends {Layer}
|
|
24
|
-
*/
|
|
25
|
-
export default class MaplibreLayer extends Layer {
|
|
26
|
-
/**
|
|
27
|
-
* Constructor.
|
|
28
|
-
*
|
|
29
|
-
* @param {Object} options
|
|
30
|
-
* @param {boolean} [options.preserveDrawingBuffer=false] If true able to export the canvas.
|
|
31
|
-
* @param {number} [options.fadeDuration=300] Duration of the fade effect in ms.
|
|
32
|
-
*/
|
|
33
|
-
constructor(options = {}) {
|
|
34
|
-
const mbLayer = new OLLayer({
|
|
35
|
-
source: new Source({}),
|
|
36
|
-
render: (frameState) => {
|
|
37
|
-
if (!this.mbMap) {
|
|
38
|
-
// eslint-disable-next-line no-console
|
|
39
|
-
console.warn("Mapbox map doesn't exist.");
|
|
40
|
-
return null;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const canvas = this.mbMap.getCanvas();
|
|
44
|
-
const { viewState } = frameState;
|
|
45
|
-
|
|
46
|
-
const opacity = this.olLayer.getOpacity();
|
|
47
|
-
canvas.style.opacity = opacity;
|
|
48
|
-
|
|
49
|
-
// adjust view parameters in mapbox
|
|
50
|
-
this.mbMap.jumpTo({
|
|
51
|
-
center: toLonLat(viewState.center),
|
|
52
|
-
zoom: viewState.zoom - 1,
|
|
53
|
-
bearing: toDegrees(-viewState.rotation),
|
|
54
|
-
animate: false,
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
if (!canvas.isConnected) {
|
|
58
|
-
// The canvas is not connected to the DOM, request a map rendering at the next animation frame
|
|
59
|
-
// to set the canvas size.
|
|
60
|
-
this.map.render();
|
|
61
|
-
} else if (
|
|
62
|
-
canvas.width !== frameState.size[0] ||
|
|
63
|
-
canvas.height !== frameState.size[1]
|
|
64
|
-
) {
|
|
65
|
-
this.mbMap.resize();
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
this.mbMap.redraw();
|
|
69
|
-
|
|
70
|
-
return this.mbMap.getContainer();
|
|
71
|
-
},
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
super({
|
|
75
|
-
...options,
|
|
76
|
-
olLayer: mbLayer,
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Url of the mapbox style.
|
|
81
|
-
* @type {string}
|
|
82
|
-
* @private
|
|
83
|
-
*/
|
|
84
|
-
this.styleUrl = options.url;
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Api key for the url of the mapbox style.
|
|
88
|
-
* If set to false, the apiKey is not required.
|
|
89
|
-
* @type {string}
|
|
90
|
-
* @private
|
|
91
|
-
*/
|
|
92
|
-
this.apiKey = options.apiKey;
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Name of the apiKey to set in the url request.
|
|
96
|
-
* Default is 'key'.
|
|
97
|
-
* @type {string}
|
|
98
|
-
* @private
|
|
99
|
-
*/
|
|
100
|
-
this.apiKeyName = options.apiKeyName || 'key';
|
|
101
|
-
|
|
102
|
-
/** @ignore */
|
|
103
|
-
this.updateAttribution = this.updateAttribution.bind(this);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Initialize the layer and listen to feature clicks.
|
|
108
|
-
* @param {ol/Map~Map} map
|
|
109
|
-
*/
|
|
110
|
-
init(map) {
|
|
111
|
-
super.init(map);
|
|
112
|
-
|
|
113
|
-
if (!this.map) {
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* The feature format.
|
|
119
|
-
* @type {ol/format/GeoJSON}
|
|
120
|
-
*/
|
|
121
|
-
this.format = new GeoJSON({
|
|
122
|
-
featureProjection: this.map.getView().getProjection(),
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
this.loadMbMap();
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Terminate what was initialized in init function. Remove layer, events...
|
|
130
|
-
*/
|
|
131
|
-
terminate() {
|
|
132
|
-
if (this.mbMap) {
|
|
133
|
-
this.mbMap.off('idle', this.updateAttribution);
|
|
134
|
-
// Some asynchrone repaints are triggered even if the mbMap has been removed,
|
|
135
|
-
// to avoid display of errors we set an empty function.
|
|
136
|
-
this.mbMap.triggerRepaint = () => {};
|
|
137
|
-
this.mbMap.remove();
|
|
138
|
-
this.mbMap = null;
|
|
139
|
-
}
|
|
140
|
-
this.loaded = false;
|
|
141
|
-
super.terminate();
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Returns a style URL with apiKey & apiKeyName infos.
|
|
146
|
-
* @private
|
|
147
|
-
*/
|
|
148
|
-
createStyleUrl() {
|
|
149
|
-
return getMapboxStyleUrl(this.apiKey, this.apiKeyName, this.styleUrl);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Create the mapbox map.
|
|
154
|
-
* @private
|
|
155
|
-
*/
|
|
156
|
-
loadMbMap() {
|
|
157
|
-
this.olListenersKeys.push(
|
|
158
|
-
this.map.on('change:target', () => {
|
|
159
|
-
this.loadMbMap();
|
|
160
|
-
}),
|
|
161
|
-
);
|
|
162
|
-
|
|
163
|
-
if (!this.map.getTargetElement()) {
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
if (!this.visible) {
|
|
168
|
-
// On next change of visibility we load the map
|
|
169
|
-
this.olListenersKeys.push(
|
|
170
|
-
this.once('change:visible', () => {
|
|
171
|
-
this.loadMbMap();
|
|
172
|
-
}),
|
|
173
|
-
);
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
const container = document.createElement('div');
|
|
178
|
-
container.style.position = 'absolute';
|
|
179
|
-
container.style.width = '100%';
|
|
180
|
-
container.style.height = '100%';
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* A mapbox map
|
|
184
|
-
* @type {mapboxgl.Map}
|
|
185
|
-
*/
|
|
186
|
-
this.mbMap = new Map({
|
|
187
|
-
style: this.createStyleUrl(),
|
|
188
|
-
container,
|
|
189
|
-
interactive: false,
|
|
190
|
-
trackResize: false,
|
|
191
|
-
attributionControl: false,
|
|
192
|
-
...(this.options.mapOptions || {}),
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
this.mbMap.once('load', () => {
|
|
196
|
-
/**
|
|
197
|
-
* Is the map loaded.
|
|
198
|
-
* @type {boolean}
|
|
199
|
-
*/
|
|
200
|
-
this.loaded = true;
|
|
201
|
-
|
|
202
|
-
this.dispatchEvent({
|
|
203
|
-
type: 'load',
|
|
204
|
-
target: this,
|
|
205
|
-
});
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
this.mbMap.on('idle', this.updateAttribution);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* Update attributions of the source.
|
|
213
|
-
* @private
|
|
214
|
-
*/
|
|
215
|
-
updateAttribution(evt) {
|
|
216
|
-
const newAttributions = getMapboxMapCopyrights(evt.target) || [];
|
|
217
|
-
if (this.copyrights?.toString() !== newAttributions.toString()) {
|
|
218
|
-
this.copyrights = newAttributions;
|
|
219
|
-
this.olLayer.getSource().setAttributions(newAttributions);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* Request feature information for a given coordinate.
|
|
225
|
-
* @param {ol/coordinate~Coordinate} coordinate Coordinate to request the information at.
|
|
226
|
-
* @param {Object} options A [mapboxgl.Map#queryrenderedfeatures](https://docs.mapbox.com/mapbox-gl-js/api/map/#map#queryrenderedfeatures) options parameter.
|
|
227
|
-
* @return {Promise<FeatureInfo>} Promise with features, layer and coordinate. The original Mapbox feature is available as a property named 'mapboxFeature'.
|
|
228
|
-
*/
|
|
229
|
-
getFeatureInfoAtCoordinate(coordinate, options) {
|
|
230
|
-
// Ignore the getFeatureInfo until the mapbox map is loaded
|
|
231
|
-
if (
|
|
232
|
-
!options ||
|
|
233
|
-
!this.format ||
|
|
234
|
-
!this.mbMap ||
|
|
235
|
-
!this.mbMap.isStyleLoaded()
|
|
236
|
-
) {
|
|
237
|
-
return Promise.resolve({ coordinate, features: [], layer: this });
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
let pixel = coordinate && this.mbMap.project(toLonLat(coordinate));
|
|
241
|
-
|
|
242
|
-
if (this.hitTolerance) {
|
|
243
|
-
const { x, y } = pixel;
|
|
244
|
-
pixel = [
|
|
245
|
-
{ x: x - this.hitTolerance, y: y - this.hitTolerance },
|
|
246
|
-
{ x: x + this.hitTolerance, y: y + this.hitTolerance },
|
|
247
|
-
];
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
// At this point we get GeoJSON Mapbox feature, we transform it to an OpenLayers
|
|
251
|
-
// feature to be consistent with other layers.
|
|
252
|
-
const features = this.mbMap
|
|
253
|
-
.queryRenderedFeatures(pixel, options)
|
|
254
|
-
.map((feature) => {
|
|
255
|
-
const olFeature = this.format.readFeature(feature);
|
|
256
|
-
if (olFeature) {
|
|
257
|
-
// We save the original mapbox feature to avoid losing informations
|
|
258
|
-
// potentially needed for other functionnality like highlighting
|
|
259
|
-
// (id, layer id, source, sourceLayer ...)
|
|
260
|
-
olFeature.set('mapboxFeature', feature);
|
|
261
|
-
}
|
|
262
|
-
return olFeature;
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
return Promise.resolve({
|
|
266
|
-
layer: this,
|
|
267
|
-
features,
|
|
268
|
-
coordinate,
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
/**
|
|
273
|
-
* Create a copy of the MapboxLayer.
|
|
274
|
-
* @param {Object} newOptions Options to override
|
|
275
|
-
* @return {MapboxLayer} A MapboxLayer
|
|
276
|
-
*/
|
|
277
|
-
clone(newOptions) {
|
|
278
|
-
return new MaplibreLayer({ ...this.options, ...newOptions });
|
|
279
|
-
}
|
|
280
|
-
}
|
|
@@ -1,91 +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
|
-
|
|
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
|
-
|
|
17
|
-
const blackBorder = new Style({
|
|
18
|
-
stroke: new Stroke({
|
|
19
|
-
color: [0, 0, 0, 1],
|
|
20
|
-
width: 5,
|
|
21
|
-
}),
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
const redLine = new Style({
|
|
25
|
-
image: circleStyle,
|
|
26
|
-
stroke: new Stroke({
|
|
27
|
-
color: [255, 0, 0, 1],
|
|
28
|
-
width: 3,
|
|
29
|
-
}),
|
|
30
|
-
});
|
|
31
|
-
|
|
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
|
-
|
|
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
|
-
|
|
46
|
-
if (minResolution && maxResolution && !inRange) {
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
const mot = feature.get('mot');
|
|
50
|
-
|
|
51
|
-
if (mot !== 'foot') {
|
|
52
|
-
return [blackBorder, redLine];
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return [dashedRedLine];
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* A class use to display vector data.
|
|
60
|
-
*
|
|
61
|
-
* @classproperty {ol/Map~Map} map - The map where the layer is displayed.
|
|
62
|
-
* @extends {Layer}
|
|
63
|
-
*/
|
|
64
|
-
class RoutingLayer extends Layer {
|
|
65
|
-
/**
|
|
66
|
-
* Constructor.
|
|
67
|
-
* @param {Object} [options]
|
|
68
|
-
* @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
|
|
69
|
-
*/
|
|
70
|
-
constructor(options = {}) {
|
|
71
|
-
super(options);
|
|
72
|
-
|
|
73
|
-
this.olLayer =
|
|
74
|
-
options.olLayer ||
|
|
75
|
-
new Vector({
|
|
76
|
-
source: new VectorSource(),
|
|
77
|
-
style: options.style || defaultStyleFunction,
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Create a copy of the RoutingLayer.
|
|
83
|
-
* @param {Object} newOptions Options to override
|
|
84
|
-
* @return {RoutingLayer} A RoutingLayer
|
|
85
|
-
*/
|
|
86
|
-
clone(newOptions) {
|
|
87
|
-
return new RoutingLayer({ ...this.options, ...newOptions });
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export default RoutingLayer;
|
|
@@ -1,49 +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
|
-
|
|
6
|
-
let layer;
|
|
7
|
-
let onClick;
|
|
8
|
-
let olMap;
|
|
9
|
-
|
|
10
|
-
describe('RoutingLayer', () => {
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
global.fetch = fetch;
|
|
13
|
-
fetch.resetMocks();
|
|
14
|
-
|
|
15
|
-
onClick = jest.fn();
|
|
16
|
-
layer = new RoutingLayer({
|
|
17
|
-
onClick,
|
|
18
|
-
apiKey: 'apiKey',
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
olMap = new Map({
|
|
22
|
-
view: new View({
|
|
23
|
-
center: [831634, 5933959],
|
|
24
|
-
zoom: 9,
|
|
25
|
-
}),
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
test('should be instanced.', () => {
|
|
30
|
-
expect(layer).toBeInstanceOf(RoutingLayer);
|
|
31
|
-
expect(layer.clickCallbacks[0]).toBe(onClick);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
test('should called terminate on initalization.', () => {
|
|
35
|
-
const spy = jest.spyOn(layer, 'terminate');
|
|
36
|
-
|
|
37
|
-
fetch.mockResponseOnce(JSON.stringify(global.fetchTrajectoriesResponse));
|
|
38
|
-
|
|
39
|
-
layer.init(olMap);
|
|
40
|
-
expect(spy).toHaveBeenCalledTimes(1);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
test('should clone', () => {
|
|
44
|
-
const clone = layer.clone({ name: 'clone' });
|
|
45
|
-
expect(clone).not.toBe(layer);
|
|
46
|
-
expect(clone.name).toBe('clone');
|
|
47
|
-
expect(clone).toBeInstanceOf(RoutingLayer);
|
|
48
|
-
});
|
|
49
|
-
});
|