mobility-toolbox-js 2.0.0-beta.1 → 2.0.0
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 +7 -4
- package/api/index.js +0 -1
- package/api/tralis/TralisAPI.js +1 -1
- package/common/controls/Control.js +4 -1
- package/common/layers/Layer.js +18 -49
- package/common/layers/Layer.test.js +2 -106
- package/common/mixins/SearchMixin.js +1 -1
- package/common/mixins/TralisLayerMixin.js +549 -21
- package/common/styles/index.js +4 -0
- package/common/{utils/delayTrackerStyle.js → styles/trackerDefaultStyle.js} +8 -8
- package/common/styles/trackerDelayStyle.js +17 -0
- package/common/styles/trackerSimpleStyle.js +22 -0
- package/common/trackerConfig.test.js +0 -13
- package/common/utils/getMapboxMapCopyrights.js +1 -0
- package/common/utils/index.js +2 -3
- package/common/utils/sortByDelay.js +23 -0
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/mapbox/controls/CopyrightControl.js +5 -1
- package/mapbox/index.js +0 -2
- package/mapbox/layers/Layer.test.js +2 -2
- package/mapbox/layers/TralisLayer.js +270 -5
- package/mapbox/layers/TralisLayer.test.js +40 -0
- package/module.js +1 -9
- package/ol/controls/CopyrightControl.js +4 -4
- package/ol/controls/CopyrightControl.test.js +16 -16
- package/ol/controls/RoutingControl.js +9 -7
- package/ol/controls/RoutingControl.test.js +1 -1
- package/ol/controls/StopFinderControl.js +8 -6
- package/ol/controls/StopFinderControl.test.js +1 -1
- package/ol/index.js +3 -3
- package/ol/layers/Layer.js +9 -0
- package/ol/layers/Layer.test.js +22 -7
- package/ol/layers/MapboxLayer.js +39 -44
- package/ol/layers/MapboxLayer.test.js +5 -5
- package/ol/layers/MapboxStyleLayer.js +0 -6
- package/ol/layers/MapboxStyleLayer.test.js +22 -6
- package/ol/layers/MaplibreLayer.js +280 -0
- package/ol/layers/RoutingLayer.test.js +1 -1
- package/ol/layers/TralisLayer.js +258 -76
- package/ol/layers/TralisLayer.test.js +1 -49
- package/ol/layers/VectorLayer.test.js +1 -1
- package/ol/layers/WMSLayer.test.js +6 -2
- package/ol/styles/fullTrajectoryDelayStyle.js +35 -0
- package/ol/styles/fullTrajectoryStyle.js +51 -0
- package/ol/styles/index.js +2 -0
- package/package.json +16 -8
- package/api/trajserv/TrajservAPI.js +0 -71
- package/api/trajserv/TrajservAPI.test.js +0 -171
- package/api/trajserv/TrajservAPIUtils.js +0 -191
- package/api/trajserv/TrajservAPIUtils.test.js +0 -40
- package/api/trajserv/typedefs.js +0 -44
- package/common/mixins/MapMixin.js +0 -103
- package/common/mixins/TrackerLayerMixin.js +0 -745
- package/common/mixins/TrajservLayerMixin.js +0 -544
- package/common/utils/simpleTrackerStyle.js +0 -18
- package/mapbox/Map.js +0 -87
- package/mapbox/layers/TrackerLayer.js +0 -282
- package/mapbox/layers/TrackerLayer.test.js +0 -68
- package/mapbox/layers/TrajservLayer.js +0 -114
- package/mapbox/layers/TrajservLayer.test.js +0 -90
- package/ol/Map.js +0 -109
- package/ol/Map.test.js +0 -34
- package/ol/layers/TrackerLayer.js +0 -296
- package/ol/layers/TrackerLayer.test.js +0 -70
- package/ol/layers/TrajservLayer.js +0 -190
- package/ol/layers/TrajservLayer.test.js +0 -113
|
@@ -6,7 +6,8 @@ import { getMapboxMapCopyrights } from '../../common/utils';
|
|
|
6
6
|
* Display layer's copyrights.
|
|
7
7
|
*
|
|
8
8
|
* @example
|
|
9
|
-
* import { Map
|
|
9
|
+
* import { Map } from 'mapbox-gl';
|
|
10
|
+
* import { CopyrightControl } from 'mobility-toolbox-js/mapbox';
|
|
10
11
|
*
|
|
11
12
|
* const map = new Map({
|
|
12
13
|
* container: 'map',
|
|
@@ -16,6 +17,9 @@ import { getMapboxMapCopyrights } from '../../common/utils';
|
|
|
16
17
|
* ]
|
|
17
18
|
* });
|
|
18
19
|
*
|
|
20
|
+
* const control = new CopyrightControl();
|
|
21
|
+
* control.map = map;
|
|
22
|
+
*
|
|
19
23
|
*
|
|
20
24
|
* @see <a href="/example/mb-copyright">Mapbox copyright example</a>
|
|
21
25
|
*
|
package/mapbox/index.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
// eslint-disable-next-line import/prefer-default-export
|
|
2
|
-
export { default as Map } from './Map';
|
|
3
2
|
export { default as TralisLayer } from './layers/TralisLayer';
|
|
4
|
-
export { default as TrajservLayer } from './layers/TrajservLayer';
|
|
5
3
|
export { default as CopyrightControl } from './controls/CopyrightControl';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Map } from 'maplibre-gl';
|
|
2
2
|
import { toLonLat } from 'ol/proj';
|
|
3
3
|
import Layer from './Layer';
|
|
4
4
|
|
|
@@ -16,7 +16,7 @@ describe('Layer', () => {
|
|
|
16
16
|
style.height = '400px';
|
|
17
17
|
mapElement.setAttribute('id', 'map');
|
|
18
18
|
document.body.appendChild(mapElement);
|
|
19
|
-
map = new
|
|
19
|
+
map = new Map({
|
|
20
20
|
container: document.getElementById('map'),
|
|
21
21
|
style: `path/to/style`,
|
|
22
22
|
center: toLonLat([831634, 5933959]),
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { fromLonLat } from 'ol/proj';
|
|
2
|
+
import { unByKey } from 'ol/Observable';
|
|
3
|
+
import { getWidth, getHeight } from 'ol/extent';
|
|
4
|
+
import transformRotate from '@turf/transform-rotate';
|
|
5
|
+
import { point } from '@turf/helpers';
|
|
2
6
|
import mixin from '../../common/mixins/TralisLayerMixin';
|
|
7
|
+
import Layer from './Layer';
|
|
8
|
+
import { getSourceCoordinates, getMercatorResolution } from '../utils';
|
|
3
9
|
|
|
4
10
|
/**
|
|
5
11
|
* Responsible for loading and display data from a Tralis service.
|
|
@@ -15,10 +21,242 @@ import mixin from '../../common/mixins/TralisLayerMixin';
|
|
|
15
21
|
*
|
|
16
22
|
* @see <a href="/api/class/src/api/tralis/TralisAPI%20js~TralisAPI%20html">TralisAPI</a>
|
|
17
23
|
*
|
|
18
|
-
* @extends {
|
|
24
|
+
* @extends {Layer}
|
|
19
25
|
* @implements {TralisLayerInterface}
|
|
20
26
|
*/
|
|
21
|
-
class TralisLayer extends mixin(
|
|
27
|
+
class TralisLayer extends mixin(Layer) {
|
|
28
|
+
constructor(options = {}) {
|
|
29
|
+
super({
|
|
30
|
+
...options,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
/** @ignore */
|
|
34
|
+
this.onLoad = this.onLoad.bind(this);
|
|
35
|
+
|
|
36
|
+
/** @ignore */
|
|
37
|
+
this.onMove = this.onMove.bind(this);
|
|
38
|
+
|
|
39
|
+
/** @ignore */
|
|
40
|
+
this.onMoveEnd = this.onMoveEnd.bind(this);
|
|
41
|
+
|
|
42
|
+
/** @ignore */
|
|
43
|
+
this.onZoomEnd = this.onZoomEnd.bind(this);
|
|
44
|
+
|
|
45
|
+
/** @ignore */
|
|
46
|
+
this.onVisibilityChange = this.onVisibilityChange.bind(this);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Initialize the layer.
|
|
51
|
+
*
|
|
52
|
+
* @param {mapboxgl.Map} map A [mapbox Map](https://docs.mapbox.com/mapbox-gl-js/api/map/).
|
|
53
|
+
* @param {string} beforeId Layer's id before which we want to add the new layer.
|
|
54
|
+
* @override
|
|
55
|
+
*/
|
|
56
|
+
init(map, beforeId) {
|
|
57
|
+
if (!map) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const canvas = map.getCanvas();
|
|
62
|
+
|
|
63
|
+
super.init(map, {
|
|
64
|
+
width: canvas.width / this.pixelRatio,
|
|
65
|
+
height: canvas.height / this.pixelRatio,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
this.source = {
|
|
69
|
+
type: 'canvas',
|
|
70
|
+
canvas: this.tracker.canvas,
|
|
71
|
+
coordinates: getSourceCoordinates(map, this.pixelRatio),
|
|
72
|
+
// Set to true if the canvas source is animated. If the canvas is static, animate should be set to false to improve performance.
|
|
73
|
+
animate: true,
|
|
74
|
+
attribution: this.copyrights && this.copyrights.join(', '),
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
this.beforeId = beforeId;
|
|
78
|
+
this.layer = {
|
|
79
|
+
id: this.key,
|
|
80
|
+
type: 'raster',
|
|
81
|
+
source: this.key,
|
|
82
|
+
layout: {
|
|
83
|
+
visibility: this.visible ? 'visible' : 'none',
|
|
84
|
+
},
|
|
85
|
+
paint: {
|
|
86
|
+
'raster-opacity': 1,
|
|
87
|
+
'raster-fade-duration': 0,
|
|
88
|
+
'raster-resampling': 'nearest', // important otherwise it looks blurry
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
if (map.isStyleLoaded()) {
|
|
93
|
+
this.onLoad();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
this.map.on('load', this.onLoad);
|
|
97
|
+
|
|
98
|
+
this.listeners = [this.on('change:visible', this.onVisibilityChange)];
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Remove listeners from the Mapbox Map.
|
|
103
|
+
*/
|
|
104
|
+
terminate() {
|
|
105
|
+
if (this.map) {
|
|
106
|
+
this.map.off('load', this.onLoad);
|
|
107
|
+
|
|
108
|
+
this.listeners.forEach((listener) => {
|
|
109
|
+
unByKey(listener);
|
|
110
|
+
});
|
|
111
|
+
if (this.map.getLayer(this.key)) {
|
|
112
|
+
this.map.removeLayer(this.key);
|
|
113
|
+
}
|
|
114
|
+
if (this.map.getSource(this.key)) {
|
|
115
|
+
this.map.removeSource(this.key);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
super.terminate();
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Start updating vehicles position.
|
|
123
|
+
*
|
|
124
|
+
* @listens {mapboxgl.map.event:zoomend} Listen to zoom end event.
|
|
125
|
+
* @listens {mapboxgl.map.event:mousemove} Listen to mousemove end.
|
|
126
|
+
* @override
|
|
127
|
+
*/
|
|
128
|
+
start() {
|
|
129
|
+
super.start();
|
|
130
|
+
|
|
131
|
+
this.map.on('move', this.onMove);
|
|
132
|
+
this.map.on('moveend', this.onMoveEnd);
|
|
133
|
+
this.map.on('zoomend', this.onZoomEnd);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Stop updating vehicles position, and unlisten events.
|
|
138
|
+
*
|
|
139
|
+
* @override
|
|
140
|
+
*/
|
|
141
|
+
stop() {
|
|
142
|
+
super.stop();
|
|
143
|
+
if (this.map) {
|
|
144
|
+
this.map.off('move', this.onMove);
|
|
145
|
+
this.map.off('moveend', this.onMoveEnd);
|
|
146
|
+
this.map.off('zoomend', this.onZoomEnd);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
onLoad() {
|
|
151
|
+
if (!this.map.getSource(this.key)) {
|
|
152
|
+
this.map.addSource(this.key, this.source);
|
|
153
|
+
}
|
|
154
|
+
if (!this.map.getLayer(this.key)) {
|
|
155
|
+
this.map.addLayer(this.layer, this.beforeId);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Function triggered when the user click the map.
|
|
161
|
+
* @override
|
|
162
|
+
*/
|
|
163
|
+
onUserClickCallback(evt) {
|
|
164
|
+
super.onUserClickCallback({
|
|
165
|
+
coordinate: fromLonLat(evt.lngLat.toArray()),
|
|
166
|
+
...evt,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Function triggered when the user moves the cursor over the map.
|
|
172
|
+
* @override
|
|
173
|
+
*/
|
|
174
|
+
onUserMoveCallback(evt) {
|
|
175
|
+
super.onUserMoveCallback({
|
|
176
|
+
coordinate: fromLonLat(evt.lngLat.toArray()),
|
|
177
|
+
...evt,
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Render the trajectories using current map's size, resolution and rotation.
|
|
183
|
+
* @param {boolean} noInterpolate if true, renders the vehicles without interpolating theirs positions.
|
|
184
|
+
* @overrides
|
|
185
|
+
*/
|
|
186
|
+
renderTrajectories(noInterpolate) {
|
|
187
|
+
const { width, height } = this.map.getCanvas();
|
|
188
|
+
const center = this.map.getCenter();
|
|
189
|
+
|
|
190
|
+
// We use turf here to have good transform.
|
|
191
|
+
const leftBottom = this.map.unproject({
|
|
192
|
+
x: 0,
|
|
193
|
+
y: height / this.pixelRatio,
|
|
194
|
+
}); // southWest
|
|
195
|
+
const rightTop = this.map.unproject({ x: width / this.pixelRatio, y: 0 }); // north east
|
|
196
|
+
|
|
197
|
+
const coord0 = transformRotate(
|
|
198
|
+
point([leftBottom.lng, leftBottom.lat]),
|
|
199
|
+
-this.map.getBearing(),
|
|
200
|
+
{
|
|
201
|
+
pivot: [center.lng, center.lat],
|
|
202
|
+
},
|
|
203
|
+
).geometry.coordinates;
|
|
204
|
+
const coord1 = transformRotate(
|
|
205
|
+
point([rightTop.lng, rightTop.lat]),
|
|
206
|
+
-this.map.getBearing(),
|
|
207
|
+
{
|
|
208
|
+
pivot: [center.lng, center.lat],
|
|
209
|
+
},
|
|
210
|
+
).geometry.coordinates;
|
|
211
|
+
|
|
212
|
+
const bounds = [...fromLonLat(coord0), ...fromLonLat(coord1)];
|
|
213
|
+
const xResolution = getWidth(bounds) / (width / this.pixelRatio);
|
|
214
|
+
const yResolution = getHeight(bounds) / (height / this.pixelRatio);
|
|
215
|
+
const res = Math.max(xResolution, yResolution);
|
|
216
|
+
|
|
217
|
+
// Coordinate of trajectories are in mercator so we have to pass the proper resolution and center in mercator.
|
|
218
|
+
const viewState = {
|
|
219
|
+
size: [width / this.pixelRatio, height / this.pixelRatio],
|
|
220
|
+
center: fromLonLat([center.lng, center.lat]),
|
|
221
|
+
extent: bounds,
|
|
222
|
+
resolution: res,
|
|
223
|
+
zoom: this.map.getZoom(),
|
|
224
|
+
rotation: -(this.map.getBearing() * Math.PI) / 180,
|
|
225
|
+
pixelRatio: this.pixelRatio,
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
super.renderTrajectories(viewState, noInterpolate);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Return the delay in ms before the next rendering.
|
|
233
|
+
*/
|
|
234
|
+
getRefreshTimeInMs() {
|
|
235
|
+
return super.getRefreshTimeInMs(this.map.getZoom());
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
getFeatureInfoAtCoordinate(coordinate, options = {}) {
|
|
239
|
+
const resolution = getMercatorResolution(this.map);
|
|
240
|
+
return super.getFeatureInfoAtCoordinate(coordinate, {
|
|
241
|
+
resolution,
|
|
242
|
+
...options,
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
onVisibilityChange() {
|
|
247
|
+
if (this.visible && !this.map.getLayer(this.key)) {
|
|
248
|
+
this.map.addLayer(this.layer, this.beforeId);
|
|
249
|
+
} else if (this.map.getLayer(this.key)) {
|
|
250
|
+
this.map.removeLayer(this.key);
|
|
251
|
+
}
|
|
252
|
+
// We can't use setLayoutProperty it triggers an error probably a bug in mapbox
|
|
253
|
+
// this.map.setLayoutProperty(
|
|
254
|
+
// this.key,
|
|
255
|
+
// 'visibilty',
|
|
256
|
+
// this.visible ? 'visible' : 'none',
|
|
257
|
+
// );
|
|
258
|
+
}
|
|
259
|
+
|
|
22
260
|
/**
|
|
23
261
|
* Remove the trajectory form the list if necessary.
|
|
24
262
|
*
|
|
@@ -45,6 +283,20 @@ class TralisLayer extends mixin(TrackerLayer) {
|
|
|
45
283
|
super.setBbox(newExtent, newZoom);
|
|
46
284
|
}
|
|
47
285
|
|
|
286
|
+
/**
|
|
287
|
+
* Callback on 'move' event.
|
|
288
|
+
*
|
|
289
|
+
* @private
|
|
290
|
+
*/
|
|
291
|
+
onMove() {
|
|
292
|
+
const extent = getSourceCoordinates(this.map, this.pixelRatio);
|
|
293
|
+
const source = this.map.getSource(this.key);
|
|
294
|
+
if (source) {
|
|
295
|
+
source.setCoordinates(extent);
|
|
296
|
+
}
|
|
297
|
+
this.renderTrajectories();
|
|
298
|
+
}
|
|
299
|
+
|
|
48
300
|
/**
|
|
49
301
|
* Send the new BBOX to the websocket.
|
|
50
302
|
*
|
|
@@ -52,13 +304,26 @@ class TralisLayer extends mixin(TrackerLayer) {
|
|
|
52
304
|
* @private
|
|
53
305
|
* @override
|
|
54
306
|
*/
|
|
55
|
-
onMoveEnd(
|
|
56
|
-
|
|
307
|
+
onMoveEnd() {
|
|
308
|
+
this.renderTrajectories();
|
|
57
309
|
|
|
58
310
|
if (this.visible && this.isUpdateBboxOnMoveEnd) {
|
|
59
311
|
this.setBbox();
|
|
60
312
|
}
|
|
61
313
|
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Update the cursor style when hovering a vehicle.
|
|
317
|
+
*
|
|
318
|
+
* @private
|
|
319
|
+
* @override
|
|
320
|
+
*/
|
|
321
|
+
onFeatureHover(features, layer, coordinate) {
|
|
322
|
+
super.onFeatureHover(features, layer, coordinate);
|
|
323
|
+
this.map.getCanvasContainer().style.cursor = features.length
|
|
324
|
+
? 'pointer'
|
|
325
|
+
: 'auto';
|
|
326
|
+
}
|
|
62
327
|
}
|
|
63
328
|
|
|
64
329
|
export default TralisLayer;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import TralisLayer from './TralisLayer';
|
|
2
|
+
|
|
3
|
+
let layer;
|
|
4
|
+
let onClick;
|
|
5
|
+
|
|
6
|
+
describe('TralisLayer', () => {
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
onClick = jest.fn();
|
|
9
|
+
layer = new TralisLayer({
|
|
10
|
+
onClick,
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
test('should be instanced.', () => {
|
|
15
|
+
expect(layer).toBeInstanceOf(TralisLayer);
|
|
16
|
+
expect(layer.clickCallbacks[0]).toBe(onClick);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test('#onClick', () => {
|
|
20
|
+
const f = () => {};
|
|
21
|
+
layer.onClick(f);
|
|
22
|
+
expect(layer.clickCallbacks[1]).toBe(f);
|
|
23
|
+
expect(layer.clickCallbacks.length).toBe(2);
|
|
24
|
+
layer.onClick(f);
|
|
25
|
+
expect(layer.clickCallbacks.length).toBe(2);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('#unClick', () => {
|
|
29
|
+
const foo = () => {};
|
|
30
|
+
const bar = () => {};
|
|
31
|
+
layer.onClick(foo);
|
|
32
|
+
layer.onClick(bar);
|
|
33
|
+
expect(layer.clickCallbacks[1]).toBe(foo);
|
|
34
|
+
expect(layer.clickCallbacks[2]).toBe(bar);
|
|
35
|
+
expect(layer.clickCallbacks.length).toBe(3);
|
|
36
|
+
layer.unClick(foo);
|
|
37
|
+
expect(layer.clickCallbacks[1]).toBe(bar);
|
|
38
|
+
expect(layer.clickCallbacks.length).toBe(2);
|
|
39
|
+
});
|
|
40
|
+
});
|
package/module.js
CHANGED
|
@@ -1,28 +1,20 @@
|
|
|
1
|
-
import Map from './ol/Map';
|
|
2
1
|
import {
|
|
3
2
|
Layer as olLayer,
|
|
4
3
|
WMSLayer as olWMSLayer,
|
|
5
4
|
MapboxLayer as olMapboxLayer,
|
|
6
|
-
TrajservLayer as olTrajservLayer,
|
|
7
5
|
TralisLayer as olTralisLayer,
|
|
8
6
|
VectorLayer as olVectorLayer,
|
|
9
7
|
} from './ol';
|
|
10
|
-
import {
|
|
11
|
-
TrajservLayer as mbTrajservLayer,
|
|
12
|
-
TralisLayer as mbTralisLayer,
|
|
13
|
-
} from './mapbox';
|
|
8
|
+
import { TralisLayer as mbTralisLayer } from './mapbox';
|
|
14
9
|
|
|
15
10
|
const exports = {
|
|
16
11
|
mapbox: {
|
|
17
|
-
TrajservLayer: mbTrajservLayer,
|
|
18
12
|
TralisLayer: mbTralisLayer,
|
|
19
13
|
},
|
|
20
14
|
ol: {
|
|
21
|
-
Map,
|
|
22
15
|
Layer: olLayer,
|
|
23
16
|
WMSLayer: olWMSLayer,
|
|
24
17
|
MapboxLayer: olMapboxLayer,
|
|
25
|
-
TrajservLayer: olTrajservLayer,
|
|
26
18
|
TralisLayer: olTralisLayer,
|
|
27
19
|
VectorLayer: olVectorLayer,
|
|
28
20
|
},
|
|
@@ -7,14 +7,14 @@ import removeDuplicate from '../../common/utils/removeDuplicate';
|
|
|
7
7
|
* Display layer's copyrights.
|
|
8
8
|
*
|
|
9
9
|
* @example
|
|
10
|
-
* import { Map
|
|
10
|
+
* import { Map } from 'ol';
|
|
11
|
+
* import { CopyrightControl } from 'mobility-toolbox-js/ol';
|
|
11
12
|
*
|
|
12
13
|
* const map = new Map({
|
|
13
14
|
* target: 'map',
|
|
14
|
-
* controls: [
|
|
15
|
-
* new CopyrightControl()
|
|
16
|
-
* ]
|
|
17
15
|
* });
|
|
16
|
+
* const control = new CopyrightControl();
|
|
17
|
+
* control.map = map
|
|
18
18
|
*
|
|
19
19
|
*
|
|
20
20
|
* @see <a href="/example/ol-copyright">Openlayers copyright example</a>
|
|
@@ -3,7 +3,7 @@ import Tile from 'ol/Tile';
|
|
|
3
3
|
import TileLayer from 'ol/layer/Tile';
|
|
4
4
|
import TileSource from 'ol/source/Tile';
|
|
5
5
|
import { createXYZ } from 'ol/tilegrid';
|
|
6
|
-
import Map from '
|
|
6
|
+
import { Map } from 'ol';
|
|
7
7
|
import Layer from '../layers/Layer';
|
|
8
8
|
import CopyrightControl from './CopyrightControl';
|
|
9
9
|
|
|
@@ -48,8 +48,8 @@ describe('CopyrightControl', () => {
|
|
|
48
48
|
center: [0, 0],
|
|
49
49
|
zoom: 0,
|
|
50
50
|
}),
|
|
51
|
-
layers: [getLayer(true, 'bar')],
|
|
52
51
|
});
|
|
52
|
+
getLayer(true, 'bar').init(map);
|
|
53
53
|
map.setSize([200, 200]);
|
|
54
54
|
map.renderSync();
|
|
55
55
|
});
|
|
@@ -70,7 +70,7 @@ describe('CopyrightControl', () => {
|
|
|
70
70
|
const control = new CopyrightControl();
|
|
71
71
|
control.map = map;
|
|
72
72
|
expect(control.element.innerHTML).toBe('');
|
|
73
|
-
|
|
73
|
+
getLayer('copyright').init(map);
|
|
74
74
|
map.renderSync();
|
|
75
75
|
expect(control.element.innerHTML).toBe('copyright');
|
|
76
76
|
});
|
|
@@ -79,7 +79,7 @@ describe('CopyrightControl', () => {
|
|
|
79
79
|
const control = new CopyrightControl();
|
|
80
80
|
control.map = map;
|
|
81
81
|
expect(control.element.innerHTML).toBe('');
|
|
82
|
-
|
|
82
|
+
getLayer(['copyright 1', 'copyright 2']).init(map);
|
|
83
83
|
map.renderSync();
|
|
84
84
|
expect(control.element.innerHTML).toBe('copyright 1 | copyright 2');
|
|
85
85
|
});
|
|
@@ -88,9 +88,9 @@ describe('CopyrightControl', () => {
|
|
|
88
88
|
const control = new CopyrightControl();
|
|
89
89
|
control.map = map;
|
|
90
90
|
expect(control.element.innerHTML).toBe('');
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
91
|
+
getLayer(['copyright 1', 'copyright 2']).init(map);
|
|
92
|
+
getLayer('copyright 1').init(map);
|
|
93
|
+
getLayer(['copyright 2']).init(map);
|
|
94
94
|
map.renderSync();
|
|
95
95
|
expect(control.element.innerHTML).toBe('copyright 1 | copyright 2');
|
|
96
96
|
});
|
|
@@ -100,9 +100,9 @@ describe('CopyrightControl', () => {
|
|
|
100
100
|
control.map = map;
|
|
101
101
|
expect(control.element.innerHTML).toBe('');
|
|
102
102
|
const layer1 = getLayer('copyright hidden', false);
|
|
103
|
+
layer1.init(map);
|
|
103
104
|
const layer2 = getLayer('copyright', true);
|
|
104
|
-
|
|
105
|
-
map.addLayer(layer2);
|
|
105
|
+
layer2.init(map);
|
|
106
106
|
map.renderSync();
|
|
107
107
|
expect(control.element.innerHTML).toBe('copyright');
|
|
108
108
|
|
|
@@ -115,7 +115,7 @@ describe('CopyrightControl', () => {
|
|
|
115
115
|
});
|
|
116
116
|
|
|
117
117
|
test('should activate the control on construction then deactivate it', () => {
|
|
118
|
-
|
|
118
|
+
getLayer('copyright 1').init(map);
|
|
119
119
|
const control = new CopyrightControl({ active: true });
|
|
120
120
|
control.map = map;
|
|
121
121
|
map.renderSync();
|
|
@@ -133,12 +133,12 @@ describe('CopyrightControl', () => {
|
|
|
133
133
|
});
|
|
134
134
|
|
|
135
135
|
test('should deactivate the control on constrcution then activate it', () => {
|
|
136
|
-
|
|
136
|
+
getLayer('copyright 1').init(map);
|
|
137
137
|
const control = new CopyrightControl({ active: false });
|
|
138
138
|
control.map = map;
|
|
139
139
|
map.renderSync();
|
|
140
140
|
|
|
141
|
-
expect(control.element.parentNode).toBe(map.
|
|
141
|
+
expect(control.element.parentNode).toBe(map.getTargetElement());
|
|
142
142
|
|
|
143
143
|
// Should be activated by default.
|
|
144
144
|
expect(control.active).toBe(false);
|
|
@@ -152,14 +152,14 @@ describe('CopyrightControl', () => {
|
|
|
152
152
|
});
|
|
153
153
|
|
|
154
154
|
test('should add copyrights in the map container element then remove it.', () => {
|
|
155
|
-
|
|
155
|
+
getLayer('copyright value').init(map);
|
|
156
156
|
map.renderSync();
|
|
157
157
|
|
|
158
158
|
const control = new CopyrightControl();
|
|
159
159
|
|
|
160
160
|
// Add control
|
|
161
161
|
control.map = map;
|
|
162
|
-
expect(control.element.parentNode).toBe(map.
|
|
162
|
+
expect(control.element.parentNode).toBe(map.getTargetElement());
|
|
163
163
|
|
|
164
164
|
// Remove control
|
|
165
165
|
control.map = null;
|
|
@@ -167,7 +167,7 @@ describe('CopyrightControl', () => {
|
|
|
167
167
|
});
|
|
168
168
|
|
|
169
169
|
test('should add copyrights in the target element then remove it.', () => {
|
|
170
|
-
|
|
170
|
+
getLayer(['copyright value']).init(map);
|
|
171
171
|
map.renderSync();
|
|
172
172
|
|
|
173
173
|
const target = document.createElement('div');
|
|
@@ -200,7 +200,7 @@ describe('CopyrightControl', () => {
|
|
|
200
200
|
},
|
|
201
201
|
});
|
|
202
202
|
control.map = map;
|
|
203
|
-
|
|
203
|
+
getLayer(['copyright 1', 'copyright 2', 'copyright 3']).init(map);
|
|
204
204
|
map.renderSync();
|
|
205
205
|
|
|
206
206
|
// Add control
|
|
@@ -45,15 +45,17 @@ const getFlatCoordinatesFromSegments = (segmentArray) => {
|
|
|
45
45
|
* Display a route of a specified mean of transport.
|
|
46
46
|
*
|
|
47
47
|
* @example
|
|
48
|
-
* import { Map
|
|
48
|
+
* import { Map } from 'ol';
|
|
49
|
+
* import { RoutingControl } from 'mobility-toolbox-js/ol';
|
|
49
50
|
*
|
|
50
51
|
* const map = new Map({
|
|
51
|
-
* target: 'map'
|
|
52
|
-
* controls: [
|
|
53
|
-
* new RoutingControl()
|
|
54
|
-
* ]
|
|
52
|
+
* target: 'map'
|
|
55
53
|
* });
|
|
56
54
|
*
|
|
55
|
+
* const control = new RoutingControl();
|
|
56
|
+
*
|
|
57
|
+
* control.map = map
|
|
58
|
+
*
|
|
57
59
|
* @classproperty {string} apiKey - Key used for RoutingApi requests.
|
|
58
60
|
* @classproperty {string} stopsApiKey - Key used for Stop lookup requests (defaults to apiKey).
|
|
59
61
|
* @classproperty {string} stopsApiUrl - Url used for Stop lookup requests (defaults to https://api.geops.io/stops/v1/lookup/).
|
|
@@ -724,7 +726,7 @@ class RoutingControl extends Control {
|
|
|
724
726
|
this.map.removeInteraction(this.modifyInteraction);
|
|
725
727
|
|
|
726
728
|
// Add modify interaction, RoutingLayer and listeners
|
|
727
|
-
this.
|
|
729
|
+
this.routingLayer.init(this.map);
|
|
728
730
|
this.map.addInteraction(this.modifyInteraction);
|
|
729
731
|
this.modifyInteraction.setActive(this.modify);
|
|
730
732
|
this.addListeners();
|
|
@@ -738,7 +740,7 @@ class RoutingControl extends Control {
|
|
|
738
740
|
deactivate() {
|
|
739
741
|
if (this.map) {
|
|
740
742
|
// Remove modify interaction, RoutingLayer, listeners and viaPoints
|
|
741
|
-
this.
|
|
743
|
+
this.routingLayer.terminate(this.map);
|
|
742
744
|
this.map.removeInteraction(this.modifyInteraction);
|
|
743
745
|
this.removeListeners();
|
|
744
746
|
this.reset();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fetch from 'jest-fetch-mock';
|
|
2
2
|
import View from 'ol/View';
|
|
3
3
|
import qs from 'query-string';
|
|
4
|
-
import Map from '
|
|
4
|
+
import Map from 'ol/Map';
|
|
5
5
|
import RoutingControl from './RoutingControl';
|
|
6
6
|
|
|
7
7
|
import RoutingControlStation1 from './snapshots/RoutingControlStation1.json';
|
|
@@ -6,17 +6,19 @@ import mixin from '../../common/mixins/SearchMixin';
|
|
|
6
6
|
* Search stations.
|
|
7
7
|
*
|
|
8
8
|
* @example
|
|
9
|
-
* import { Map
|
|
9
|
+
* import { Map } from 'ol';
|
|
10
|
+
* import { StopFinderControl } from 'mobility-toolbox-js/ol';
|
|
10
11
|
*
|
|
11
12
|
* const map = new Map({
|
|
12
13
|
* target: 'map',
|
|
13
|
-
* controls: [
|
|
14
|
-
* new StopFinderControl({
|
|
15
|
-
* apiKey: [yourApiKey]
|
|
16
|
-
* })
|
|
17
|
-
* ]
|
|
18
14
|
* });
|
|
19
15
|
*
|
|
16
|
+
* const control = new StopFinderControl({
|
|
17
|
+
* apiKey: [yourApiKey]
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* control.map = map;
|
|
21
|
+
*
|
|
20
22
|
*
|
|
21
23
|
* @see <a href="/example/ol-search">Openlayers search example</a>
|
|
22
24
|
*
|
package/ol/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
export { default as Map } from './Map';
|
|
2
1
|
export { default as Layer } from './layers/Layer';
|
|
3
2
|
export { default as MapboxLayer } from './layers/MapboxLayer';
|
|
3
|
+
export { default as MaplibreLayer } from './layers/MaplibreLayer';
|
|
4
4
|
export { default as MapboxStyleLayer } from './layers/MapboxStyleLayer';
|
|
5
5
|
export { default as RoutingLayer } from './layers/RoutingLayer';
|
|
6
|
-
export { default as TrackerLayer } from './layers/TrackerLayer';
|
|
7
|
-
export { default as TrajservLayer } from './layers/TrajservLayer';
|
|
8
6
|
export { default as TralisLayer } from './layers/TralisLayer';
|
|
9
7
|
export { default as VectorLayer } from './layers/VectorLayer';
|
|
10
8
|
export { default as WMSLayer } from './layers/WMSLayer';
|
|
11
9
|
export { default as CopyrightControl } from './controls/CopyrightControl';
|
|
12
10
|
export { default as RoutingControl } from './controls/RoutingControl';
|
|
13
11
|
export { default as StopFinderControl } from './controls/StopFinderControl';
|
|
12
|
+
export * from '../common/styles';
|
|
13
|
+
export * from './styles';
|
package/ol/layers/Layer.js
CHANGED
|
@@ -67,6 +67,10 @@ class Layer extends LayerCommon {
|
|
|
67
67
|
return;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
+
if (this.map && this.olLayer) {
|
|
71
|
+
this.map.addLayer(this.olLayer);
|
|
72
|
+
}
|
|
73
|
+
|
|
70
74
|
this.olListenersKeys.push(
|
|
71
75
|
this.map.getLayers().on('remove', (evt) => {
|
|
72
76
|
if (evt.element === this.olLayer) {
|
|
@@ -103,6 +107,11 @@ class Layer extends LayerCommon {
|
|
|
103
107
|
*/
|
|
104
108
|
terminate() {
|
|
105
109
|
unByKey(this.olListenersKeys);
|
|
110
|
+
|
|
111
|
+
if (this.map && this.olLayer) {
|
|
112
|
+
this.map.removeLayer(this.olLayer);
|
|
113
|
+
}
|
|
114
|
+
|
|
106
115
|
super.terminate();
|
|
107
116
|
}
|
|
108
117
|
|