mobility-toolbox-js 2.0.0 → 2.1.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/api/RealtimeAPI.d.ts +279 -0
- package/api/RealtimeAPI.d.ts.map +1 -0
- package/api/RealtimeAPI.js +466 -0
- package/api/RoutingAPI.d.ts +37 -0
- package/api/RoutingAPI.d.ts.map +1 -0
- package/api/RoutingAPI.js +35 -0
- package/api/StopsAPI.d.ts +38 -0
- package/api/StopsAPI.d.ts.map +1 -0
- package/api/StopsAPI.js +36 -0
- package/api/index.d.ts +4 -0
- package/api/index.d.ts.map +1 -0
- package/api/index.js +3 -3
- package/api/typedefs.d.ts +179 -0
- package/api/typedefs.d.ts.map +1 -0
- package/api/{tralis/typedefs.js → typedefs.js} +4 -10
- package/common/api/HttpAPI.d.ts +31 -0
- package/common/api/HttpAPI.d.ts.map +1 -0
- package/common/api/HttpAPI.js +57 -0
- package/common/api/WebSocketAPI.d.ts +153 -0
- package/common/api/WebSocketAPI.d.ts.map +1 -0
- package/common/api/WebSocketAPI.js +341 -0
- package/common/controls/ControlCommon.d.ts +76 -0
- package/common/controls/ControlCommon.d.ts.map +1 -0
- package/common/controls/ControlCommon.js +150 -0
- package/common/controls/CopyrightControlCommon.d.ts +13 -0
- package/common/controls/CopyrightControlCommon.d.ts.map +1 -0
- package/common/controls/CopyrightControlCommon.js +34 -0
- package/common/controls/StopFinderControlCommon.d.ts +55 -0
- package/common/controls/StopFinderControlCommon.d.ts.map +1 -0
- package/common/controls/StopFinderControlCommon.js +144 -0
- package/common/index.d.ts +3 -0
- package/common/index.d.ts.map +1 -0
- package/common/index.js +2 -0
- package/common/layers/LayerCommon.d.ts +94 -0
- package/common/layers/LayerCommon.d.ts.map +1 -0
- package/common/layers/LayerCommon.js +244 -0
- package/common/mixins/RealtimeLayerMixin.d.ts +286 -0
- package/common/mixins/RealtimeLayerMixin.d.ts.map +1 -0
- package/common/mixins/RealtimeLayerMixin.js +776 -0
- package/common/mixins/UserInteractionsLayerMixin.d.ts +60 -0
- package/common/mixins/UserInteractionsLayerMixin.d.ts.map +1 -0
- package/common/mixins/UserInteractionsLayerMixin.js +241 -0
- package/common/styles/index.d.ts +5 -0
- package/common/styles/index.d.ts.map +1 -0
- package/common/styles/index.js +4 -4
- package/common/styles/realtimeDefaultStyle.d.ts +36 -0
- package/common/styles/realtimeDefaultStyle.d.ts.map +1 -0
- package/common/styles/realtimeDefaultStyle.js +275 -0
- package/common/styles/{trackerDelayStyle.js → realtimeDelayStyle.d.ts} +4 -9
- package/common/styles/realtimeDelayStyle.d.ts.map +1 -0
- package/common/styles/realtimeDelayStyle.js +13 -0
- package/common/styles/realtimeHeadingStyle.d.ts +12 -0
- package/common/styles/realtimeHeadingStyle.d.ts.map +1 -0
- package/common/styles/realtimeHeadingStyle.js +85 -0
- package/common/styles/realtimeSimpleStyle.d.ts +4 -0
- package/common/styles/realtimeSimpleStyle.d.ts.map +1 -0
- package/common/styles/realtimeSimpleStyle.js +23 -0
- package/common/typedefs.d.ts +111 -0
- package/common/typedefs.d.ts.map +1 -0
- package/common/typedefs.js +35 -6
- package/common/utils/compareDepartures.d.ts +11 -0
- package/common/utils/compareDepartures.d.ts.map +1 -0
- package/common/utils/compareDepartures.js +35 -0
- package/common/utils/createCanvas.d.ts +10 -0
- package/common/utils/createCanvas.d.ts.map +1 -0
- package/common/utils/createCanvas.js +27 -0
- package/common/utils/createRealtimeFilters.d.ts +13 -0
- package/common/utils/createRealtimeFilters.d.ts.map +1 -0
- package/common/utils/createRealtimeFilters.js +74 -0
- package/common/utils/debounceDeparturesMessages.d.ts +12 -0
- package/common/utils/debounceDeparturesMessages.d.ts.map +1 -0
- package/common/utils/debounceDeparturesMessages.js +24 -0
- package/common/utils/debounceWebsocketMessages.d.ts +11 -0
- package/common/utils/debounceWebsocketMessages.d.ts.map +1 -0
- package/common/utils/debounceWebsocketMessages.js +29 -0
- package/common/utils/getLayersAsFlatArray.d.ts +3 -0
- package/common/utils/getLayersAsFlatArray.d.ts.map +1 -0
- package/common/utils/getLayersAsFlatArray.js +15 -0
- package/common/utils/getMapboxMapCopyrights.d.ts +18 -0
- package/common/utils/getMapboxMapCopyrights.d.ts.map +1 -0
- package/common/utils/getMapboxMapCopyrights.js +21 -23
- package/common/utils/getMapboxRender.d.ts +7 -0
- package/common/utils/getMapboxRender.d.ts.map +1 -0
- package/common/utils/getMapboxRender.js +87 -0
- package/common/utils/getMaplibreRender.d.ts +7 -0
- package/common/utils/getMaplibreRender.d.ts.map +1 -0
- package/common/utils/getMaplibreRender.js +38 -0
- package/common/utils/getRealtimeModeSuffix.d.ts +10 -0
- package/common/utils/getRealtimeModeSuffix.d.ts.map +1 -0
- package/common/utils/getRealtimeModeSuffix.js +7 -0
- package/common/utils/getUrlWithParams.d.ts +9 -0
- package/common/utils/getUrlWithParams.d.ts.map +1 -0
- package/common/utils/getUrlWithParams.js +18 -0
- package/common/utils/getVehiclePosition.d.ts +16 -0
- package/common/utils/getVehiclePosition.d.ts.map +1 -0
- package/common/utils/getVehiclePosition.js +60 -60
- package/common/utils/index.d.ts +17 -0
- package/common/utils/index.d.ts.map +1 -0
- package/common/utils/index.js +13 -2
- package/common/utils/realtimeConfig.d.ts +49 -0
- package/common/utils/realtimeConfig.d.ts.map +1 -0
- package/common/utils/realtimeConfig.js +173 -0
- package/common/utils/removeDuplicate.d.ts +10 -0
- package/common/utils/removeDuplicate.d.ts.map +1 -0
- package/common/utils/removeDuplicate.js +5 -12
- package/common/utils/renderTrajectories.d.ts +17 -0
- package/common/utils/renderTrajectories.d.ts.map +1 -0
- package/common/utils/renderTrajectories.js +110 -0
- package/common/utils/sortAndFilterDepartures.d.ts +16 -0
- package/common/utils/sortAndFilterDepartures.d.ts.map +1 -0
- package/common/utils/sortAndFilterDepartures.js +58 -0
- package/common/utils/sortByDelay.d.ts +3 -0
- package/common/utils/sortByDelay.d.ts.map +1 -0
- package/common/utils/sortByDelay.js +17 -20
- package/common/utils/timeUtils.d.ts +24 -0
- package/common/utils/timeUtils.d.ts.map +1 -0
- package/common/utils/timeUtils.js +13 -18
- package/iife.d.ts +3 -0
- package/iife.d.ts.map +1 -0
- package/iife.js +5 -0
- package/index.d.ts +10 -0
- package/index.d.ts.map +1 -0
- package/index.js +10 -2
- package/mapbox/controls/CopyrightControl.d.ts +29 -0
- package/mapbox/controls/CopyrightControl.d.ts.map +1 -0
- package/mapbox/controls/CopyrightControl.js +25 -35
- package/mapbox/controls/index.d.ts +2 -0
- package/mapbox/controls/index.d.ts.map +1 -0
- package/mapbox/controls/index.js +2 -0
- package/mapbox/index.d.ts +6 -0
- package/mapbox/index.d.ts.map +1 -0
- package/mapbox/index.js +5 -3
- package/mapbox/layers/Layer.d.ts +59 -0
- package/mapbox/layers/Layer.d.ts.map +1 -0
- package/mapbox/layers/Layer.js +78 -95
- package/mapbox/layers/RealtimeLayer.d.ts +181 -0
- package/mapbox/layers/RealtimeLayer.d.ts.map +1 -0
- package/mapbox/layers/RealtimeLayer.js +276 -0
- package/mapbox/layers/index.d.ts +3 -0
- package/mapbox/layers/index.d.ts.map +1 -0
- package/mapbox/layers/index.js +2 -0
- package/mapbox/utils/getMercatorResolution.d.ts +9 -0
- package/mapbox/utils/getMercatorResolution.d.ts.map +1 -0
- package/mapbox/utils/getMercatorResolution.js +18 -0
- package/mapbox/utils/getSourceCoordinates.d.ts +9 -0
- package/mapbox/utils/getSourceCoordinates.d.ts.map +1 -0
- package/mapbox/utils/getSourceCoordinates.js +27 -0
- package/mapbox/utils/index.d.ts +3 -0
- package/mapbox/utils/index.d.ts.map +1 -0
- package/mapbox/utils/index.js +2 -0
- package/mbt.js +60005 -0
- package/mbt.js.map +7 -0
- package/mbt.min.js +1084 -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/CopyrightControl.js +44 -56
- package/ol/controls/RoutingControl.d.ts +193 -0
- package/ol/controls/RoutingControl.d.ts.map +1 -0
- package/ol/controls/RoutingControl.js +546 -667
- package/ol/controls/StopFinderControl.d.ts +30 -0
- package/ol/controls/StopFinderControl.d.ts.map +1 -0
- package/ol/controls/StopFinderControl.js +10 -16
- package/ol/controls/index.d.ts +4 -0
- package/ol/controls/index.d.ts.map +1 -0
- package/ol/controls/index.js +3 -0
- package/ol/index.d.ts +6 -0
- package/ol/index.d.ts.map +1 -0
- package/ol/index.js +4 -12
- package/ol/layers/Layer.d.ts +86 -0
- package/ol/layers/Layer.d.ts.map +1 -0
- package/ol/layers/Layer.js +147 -166
- package/ol/layers/MapGlLayer.d.ts +67 -0
- package/ol/layers/MapGlLayer.d.ts.map +1 -0
- package/ol/layers/MapGlLayer.js +218 -0
- package/ol/layers/MapboxLayer.d.ts +50 -0
- package/ol/layers/MapboxLayer.d.ts.map +1 -0
- package/ol/layers/MapboxLayer.js +79 -348
- package/ol/layers/MapboxStyleLayer.d.ts +129 -0
- package/ol/layers/MapboxStyleLayer.d.ts.map +1 -0
- package/ol/layers/MapboxStyleLayer.js +329 -368
- package/ol/layers/MaplibreLayer.d.ts +28 -0
- package/ol/layers/MaplibreLayer.d.ts.map +1 -0
- package/ol/layers/MaplibreLayer.js +13 -259
- package/ol/layers/RealtimeLayer.d.ts +202 -0
- package/ol/layers/RealtimeLayer.d.ts.map +1 -0
- package/ol/layers/RealtimeLayer.js +340 -0
- package/ol/layers/RoutingLayer.d.ts +34 -0
- package/ol/layers/RoutingLayer.d.ts.map +1 -0
- package/ol/layers/RoutingLayer.js +62 -68
- package/ol/layers/VectorLayer.d.ts +25 -0
- package/ol/layers/VectorLayer.d.ts.map +1 -0
- package/ol/layers/VectorLayer.js +27 -32
- package/ol/layers/WMSLayer.d.ts +42 -0
- package/ol/layers/WMSLayer.d.ts.map +1 -0
- package/ol/layers/WMSLayer.js +74 -66
- package/ol/layers/index.d.ts +9 -0
- package/ol/layers/index.d.ts.map +1 -0
- package/ol/layers/index.js +8 -0
- package/ol/styles/fullTrajectoryDelayStyle.d.ts +4 -0
- package/ol/styles/fullTrajectoryDelayStyle.d.ts.map +1 -0
- package/ol/styles/fullTrajectoryDelayStyle.js +23 -25
- package/ol/styles/fullTrajectoryStyle.d.ts +5 -0
- package/ol/styles/fullTrajectoryStyle.d.ts.map +1 -0
- package/ol/styles/fullTrajectoryStyle.js +37 -44
- package/ol/styles/index.d.ts +3 -0
- package/ol/styles/index.d.ts.map +1 -0
- package/package.json +98 -177
- package/setupTests.d.ts +2 -0
- package/setupTests.d.ts.map +1 -0
- package/setupTests.js +26 -0
- package/types/common.d.ts +122 -0
- package/types/index.d.ts +11 -0
- package/types/realtime.d.ts +320 -0
- package/types/routing.d.ts +206 -0
- package/types/stops.d.ts +143 -0
- package/README.md +0 -23
- 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/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/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/utils/createTrackerFilters.js +0 -87
- package/common/utils/createTrackerFilters.test.js +0 -95
- package/common/utils/getMapboxMapCopyrights.test.js +0 -47
- package/common/utils/getMapboxStyleUrl.js +0 -32
- package/common/utils/removeDuplicate.test.js +0 -22
- package/common/utils/timeUtils.test.js +0 -16
- package/index.js.map +0 -1
- 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.test.js +0 -211
- package/ol/controls/RoutingControl.test.js +0 -216
- 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/layers/Layer.test.js +0 -197
- package/ol/layers/MapboxLayer.test.js +0 -186
- package/ol/layers/MapboxStyleLayer.test.js +0 -262
- 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.test.js +0 -98
- package/ol/layers/WMSLayer.test.js +0 -84
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import BaseObject from 'ol/Object';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* A class representing a control to display on map.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* const control = new Control();
|
|
8
|
-
*
|
|
9
|
-
* @classproperty {ol/Map~Map|mapboxgl.Map} map - The map which the control refers to.
|
|
10
|
-
* @classproperty {boolean} active - Active the control.
|
|
11
|
-
* @classproperty {HTMLElement} element - The HTML element used to render the control.
|
|
12
|
-
* @classproperty {HTMLElement} target - The HTML element where to render the element property. Default is the map's element. Read only.
|
|
13
|
-
*/
|
|
14
|
-
class Control extends BaseObject {
|
|
15
|
-
/**
|
|
16
|
-
* Constructor
|
|
17
|
-
*
|
|
18
|
-
* @param {Object} [options] Control options.
|
|
19
|
-
* @param {boolean} [options.active = true] Whether the control is active or not.
|
|
20
|
-
* @param {HTMLElement} [options.element] The HTML element used to render the control.
|
|
21
|
-
* @param {HTMLElement} [options.target] The HTML element where to render the element property. Default is the map's element.
|
|
22
|
-
* @param {function} [options.render] Render function called whenever the control needs to be rerendered.
|
|
23
|
-
*/
|
|
24
|
-
constructor(options = {}) {
|
|
25
|
-
super(options);
|
|
26
|
-
this.defineProperties(options);
|
|
27
|
-
|
|
28
|
-
const { active } = {
|
|
29
|
-
active: options.active !== false,
|
|
30
|
-
...options,
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* @ignore
|
|
35
|
-
*/
|
|
36
|
-
this.active = active;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Define control's properties.
|
|
41
|
-
*
|
|
42
|
-
* @private
|
|
43
|
-
*/
|
|
44
|
-
defineProperties(options) {
|
|
45
|
-
const { target, element, render } = {
|
|
46
|
-
...options,
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
Object.defineProperties(this, {
|
|
50
|
-
active: {
|
|
51
|
-
get: () => this.get('active'),
|
|
52
|
-
set: (newActive) => {
|
|
53
|
-
this.set('active', newActive);
|
|
54
|
-
if (newActive) {
|
|
55
|
-
this.activate();
|
|
56
|
-
} else {
|
|
57
|
-
this.deactivate();
|
|
58
|
-
}
|
|
59
|
-
this.render();
|
|
60
|
-
},
|
|
61
|
-
},
|
|
62
|
-
map: {
|
|
63
|
-
get: () => this.get('map'),
|
|
64
|
-
set: (map) => {
|
|
65
|
-
// Remove previous node.
|
|
66
|
-
if (this.map && this.element && this.element.parentNode) {
|
|
67
|
-
this.element.parentNode.removeChild(this.element);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// Clean listeners
|
|
71
|
-
this.deactivate();
|
|
72
|
-
|
|
73
|
-
this.set('map', map);
|
|
74
|
-
|
|
75
|
-
if (this.map) {
|
|
76
|
-
// Add new node
|
|
77
|
-
const targett =
|
|
78
|
-
this.target ||
|
|
79
|
-
(this.map.getTargetElement && this.map.getTargetElement()) ||
|
|
80
|
-
(this.map.getContainer && this.map.getContainer());
|
|
81
|
-
|
|
82
|
-
if (!this.element) {
|
|
83
|
-
this.createDefaultElement();
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (this.element) {
|
|
87
|
-
targett.appendChild(this.element);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// Add listeners
|
|
91
|
-
if (this.active) {
|
|
92
|
-
this.activate();
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
this.render();
|
|
96
|
-
},
|
|
97
|
-
},
|
|
98
|
-
target: {
|
|
99
|
-
value: target,
|
|
100
|
-
},
|
|
101
|
-
element: {
|
|
102
|
-
value: element,
|
|
103
|
-
writable: true,
|
|
104
|
-
},
|
|
105
|
-
render: {
|
|
106
|
-
/** @ignore */
|
|
107
|
-
value: render || this.render,
|
|
108
|
-
writable: true,
|
|
109
|
-
},
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Add listeners then renders the control.
|
|
115
|
-
* To be defined in inherited classes.
|
|
116
|
-
*/
|
|
117
|
-
activate() {
|
|
118
|
-
this.deactivate();
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Remove listeners added by activate() function then renders the control.
|
|
123
|
-
* To be defined in inherited classes.
|
|
124
|
-
*/
|
|
125
|
-
// eslint-disable-next-line class-methods-use-this
|
|
126
|
-
deactivate() {}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* The default render function. It renders content in the HTML element.
|
|
130
|
-
* To be defined in inherited classes.
|
|
131
|
-
*
|
|
132
|
-
* @private
|
|
133
|
-
*/
|
|
134
|
-
render() {}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* The default element to display if this.element is not defined.
|
|
138
|
-
* To be defined in inherited classes.
|
|
139
|
-
*
|
|
140
|
-
* @private
|
|
141
|
-
*/
|
|
142
|
-
// eslint-disable-next-line class-methods-use-this
|
|
143
|
-
createDefaultElement() {}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
export default Control;
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import Control from './Control';
|
|
2
|
-
|
|
3
|
-
describe('Control', () => {
|
|
4
|
-
test('should be activated by default', () => {
|
|
5
|
-
const control = new Control();
|
|
6
|
-
expect(control.active).toBe(true);
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
test('should not be activated if set to false in the options', () => {
|
|
10
|
-
const control = new Control({ active: false });
|
|
11
|
-
expect(control.active).toBe(false);
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
test('should call activate/deactivate when active is set to true/false', () => {
|
|
15
|
-
const control = new Control();
|
|
16
|
-
const spy1 = jest.spyOn(control, 'activate');
|
|
17
|
-
const spy2 = jest.spyOn(control, 'deactivate');
|
|
18
|
-
const spy3 = jest.spyOn(control, 'render');
|
|
19
|
-
control.active = false;
|
|
20
|
-
expect(spy1).toBeCalledTimes(0);
|
|
21
|
-
expect(spy2).toBeCalledTimes(1);
|
|
22
|
-
expect(spy3).toBeCalledTimes(1);
|
|
23
|
-
control.active = true;
|
|
24
|
-
expect(spy1).toBeCalledTimes(1);
|
|
25
|
-
expect(spy2).toBeCalledTimes(2);
|
|
26
|
-
expect(spy3).toBeCalledTimes(2);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
test('should append/remove the element to the map container when map is set', () => {
|
|
30
|
-
const element = document.createElement('div');
|
|
31
|
-
const target = document.createElement('div');
|
|
32
|
-
const control = new Control({
|
|
33
|
-
element,
|
|
34
|
-
});
|
|
35
|
-
const spy1 = jest.spyOn(control, 'activate');
|
|
36
|
-
const spy2 = jest.spyOn(control, 'deactivate');
|
|
37
|
-
const spy3 = jest.spyOn(control, 'render');
|
|
38
|
-
control.map = {
|
|
39
|
-
getContainer() {
|
|
40
|
-
return target;
|
|
41
|
-
},
|
|
42
|
-
};
|
|
43
|
-
expect(target.childNodes[0]).toBe(element);
|
|
44
|
-
expect(spy1).toBeCalledTimes(1);
|
|
45
|
-
expect(spy2).toBeCalledTimes(2);
|
|
46
|
-
expect(spy3).toBeCalledTimes(1);
|
|
47
|
-
|
|
48
|
-
control.map = null;
|
|
49
|
-
expect(target.childNodes[0]).toBe();
|
|
50
|
-
expect(spy1).toBeCalledTimes(1);
|
|
51
|
-
expect(spy2).toBeCalledTimes(3);
|
|
52
|
-
expect(spy3).toBeCalledTimes(2);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
test('should append/remove the element to the target property when map is set', () => {
|
|
56
|
-
const element = document.createElement('div');
|
|
57
|
-
const target = document.createElement('div');
|
|
58
|
-
const control = new Control({
|
|
59
|
-
target,
|
|
60
|
-
element,
|
|
61
|
-
});
|
|
62
|
-
const spy1 = jest.spyOn(control, 'activate');
|
|
63
|
-
const spy2 = jest.spyOn(control, 'deactivate');
|
|
64
|
-
const spy3 = jest.spyOn(control, 'render');
|
|
65
|
-
control.map = {};
|
|
66
|
-
expect(target.childNodes[0]).toBe(element);
|
|
67
|
-
expect(spy1).toBeCalledTimes(1);
|
|
68
|
-
expect(spy2).toBeCalledTimes(2);
|
|
69
|
-
expect(spy3).toBeCalledTimes(1);
|
|
70
|
-
|
|
71
|
-
control.map = null;
|
|
72
|
-
expect(target.childNodes[0]).toBe();
|
|
73
|
-
expect(spy1).toBeCalledTimes(1);
|
|
74
|
-
expect(spy2).toBeCalledTimes(3);
|
|
75
|
-
expect(spy3).toBeCalledTimes(2);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
test('set a custom render method', () => {
|
|
79
|
-
const spy = jest.fn();
|
|
80
|
-
// eslint-disable-next-line no-unused-vars
|
|
81
|
-
const control = new Control({
|
|
82
|
-
render: spy,
|
|
83
|
-
});
|
|
84
|
-
expect(spy).toBeCalledTimes(1);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
test('pass function params to custom render method', () => {
|
|
88
|
-
const spy = jest.fn();
|
|
89
|
-
// eslint-disable-next-line no-unused-vars
|
|
90
|
-
const control = new Control({
|
|
91
|
-
render: spy,
|
|
92
|
-
});
|
|
93
|
-
control.render('foo', 'bar');
|
|
94
|
-
expect(spy).toBeCalledTimes(2);
|
|
95
|
-
expect(spy.mock.calls[1][0]).toBe('foo');
|
|
96
|
-
expect(spy.mock.calls[1][1]).toBe('bar');
|
|
97
|
-
});
|
|
98
|
-
});
|
package/common/layers/Layer.js
DELETED
|
@@ -1,404 +0,0 @@
|
|
|
1
|
-
import Observable from 'ol/Observable';
|
|
2
|
-
import { v4 as uuid } from 'uuid';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* A class representing a layer to display on map.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* const layer = new Layer({
|
|
9
|
-
* name: 'myLayer',
|
|
10
|
-
* });
|
|
11
|
-
*
|
|
12
|
-
* @classproperty {string} name - Name of the layer
|
|
13
|
-
* @classproperty {string} key - Identifier of the layer. Must be unique.
|
|
14
|
-
* @classproperty {string[]} copyrights - Array of copyrights.
|
|
15
|
-
* @classproperty {boolean} isBaseLayer - Define if the layer is a base layer. Read-only.
|
|
16
|
-
* @classproperty {boolean} isQueryable - Define if the layer can be queried. If false, it will set isHoverActive and isClickActive to false. Read-only.
|
|
17
|
-
* @classproperty {boolean} isClickActive - If true feature information will be queried on user click event. See inherited layers for more informations. Read-only.
|
|
18
|
-
* @classproperty {boolean} isHoverActive - If true feature information will be queried on pointer move event. See inherited layers for more informations. Read-only.
|
|
19
|
-
* @classproperty {boolean} isMobilityLayer - Custom property for duck typing since `instanceof` is not working when the instance was created on different bundles. Read-only.
|
|
20
|
-
* @classproperty {Layer[]} children - List of children.
|
|
21
|
-
* @classproperty {boolean} visible - Define if the layer is visible or not.
|
|
22
|
-
* @classproperty {number} hitTolerance - Hit-detection tolerance in css pixels. Pixels inside the radius around the given position will be checked for features.
|
|
23
|
-
* @classproperty {Object} properties - Custom properties.
|
|
24
|
-
* @classproperty {ol/Map~Map|mapboxgl.Map} map - The map where the layer is displayed.
|
|
25
|
-
*/
|
|
26
|
-
export default class Layer extends Observable {
|
|
27
|
-
/**
|
|
28
|
-
* Constructor
|
|
29
|
-
*
|
|
30
|
-
* @param {Object} options
|
|
31
|
-
* @param {string} [options.name=uuid()] Layer name. Default use a generated uuid.
|
|
32
|
-
* @param {string} [options.key=uuid().toLowerCase()] Layer key, will use options.name.toLowerCase() if not specified.
|
|
33
|
-
* @param {string[]} [options.copyrights=undefined] Array of copyrights.
|
|
34
|
-
* @param {Array<Layer>} [options.children=[]] Sublayers.
|
|
35
|
-
* @param {Object} [options.properties={}] Application-specific layer properties.
|
|
36
|
-
* @param {boolean} [options.visible=true] If true this layer is visible on the map.
|
|
37
|
-
* @param {boolean} [options.isBaseLayer=false] If true this layer is a baseLayer.
|
|
38
|
-
* @param {boolean} [options.isQueryable=true] Define if the layer can be queried. If false, it will also set isHoverActive and isClickActive to false. Read-only.
|
|
39
|
-
* @param {boolean} [options.isClickActive=true] If true feature information will be queried on click event. See inherited layers for more informations. Read-only.
|
|
40
|
-
* @param {boolean} [options.isHoverActive=true] If true feature information will be queried on pointer move event. See inherited layers for more informations. Read-only.
|
|
41
|
-
* @param {number} [options.hitTolerance=5] Hit-detection tolerance in css pixels. Pixels inside the radius around the given position will be checked for features.
|
|
42
|
-
*/
|
|
43
|
-
constructor(options = {}) {
|
|
44
|
-
super();
|
|
45
|
-
this.defineProperties(options);
|
|
46
|
-
|
|
47
|
-
// Add mouse event callbacks
|
|
48
|
-
const { onClick, onHover } = options;
|
|
49
|
-
|
|
50
|
-
if (onHover) {
|
|
51
|
-
this.onHover(onHover);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (onClick) {
|
|
55
|
-
this.onClick(onClick);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// This if is very important if you remove it you break the copyright control.
|
|
59
|
-
if (options.copyrights) {
|
|
60
|
-
/** @ignore */
|
|
61
|
-
this.copyrights = options.copyrights;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/** @ignore */
|
|
65
|
-
this.onUserClickCallback = this.onUserClickCallback.bind(this);
|
|
66
|
-
|
|
67
|
-
/** @ignore */
|
|
68
|
-
this.onUserMoveCallback = this.onUserMoveCallback.bind(this);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Define layer's properties.
|
|
73
|
-
*
|
|
74
|
-
* @ignore
|
|
75
|
-
*/
|
|
76
|
-
defineProperties(options) {
|
|
77
|
-
const {
|
|
78
|
-
name,
|
|
79
|
-
key,
|
|
80
|
-
children,
|
|
81
|
-
visible,
|
|
82
|
-
properties,
|
|
83
|
-
isBaseLayer,
|
|
84
|
-
isQueryable,
|
|
85
|
-
isClickActive,
|
|
86
|
-
isHoverActive,
|
|
87
|
-
hitTolerance,
|
|
88
|
-
} = {
|
|
89
|
-
isQueryable: true,
|
|
90
|
-
isClickActive: true,
|
|
91
|
-
isHoverActive: true,
|
|
92
|
-
...options,
|
|
93
|
-
};
|
|
94
|
-
const uid = uuid();
|
|
95
|
-
const dfltName = name || uid;
|
|
96
|
-
Object.defineProperties(this, {
|
|
97
|
-
// options is used for clone function.
|
|
98
|
-
options: {
|
|
99
|
-
value: options,
|
|
100
|
-
},
|
|
101
|
-
name: {
|
|
102
|
-
value: dfltName,
|
|
103
|
-
},
|
|
104
|
-
key: {
|
|
105
|
-
value: key || dfltName.toLowerCase(),
|
|
106
|
-
},
|
|
107
|
-
isBaseLayer: {
|
|
108
|
-
value: !!isBaseLayer,
|
|
109
|
-
},
|
|
110
|
-
isQueryable: {
|
|
111
|
-
value: !!isQueryable,
|
|
112
|
-
writable: true,
|
|
113
|
-
},
|
|
114
|
-
isClickActive: {
|
|
115
|
-
value: !!isQueryable && !!isClickActive,
|
|
116
|
-
writable: true,
|
|
117
|
-
},
|
|
118
|
-
isHoverActive: {
|
|
119
|
-
value: !!isQueryable && !!isHoverActive,
|
|
120
|
-
writable: true,
|
|
121
|
-
},
|
|
122
|
-
hitTolerance: {
|
|
123
|
-
value: hitTolerance || 5,
|
|
124
|
-
writable: true,
|
|
125
|
-
},
|
|
126
|
-
// Custom property for duck typing since `instanceof` is not working
|
|
127
|
-
// when the instance was created on different bundles.
|
|
128
|
-
isMobilityLayer: {
|
|
129
|
-
value: true,
|
|
130
|
-
},
|
|
131
|
-
children: {
|
|
132
|
-
value: children || [],
|
|
133
|
-
writable: true,
|
|
134
|
-
},
|
|
135
|
-
copyrights: {
|
|
136
|
-
get: () => this.get('copyrights'),
|
|
137
|
-
set: (newCopyrights) => {
|
|
138
|
-
const arrValue = !Array.isArray(newCopyrights)
|
|
139
|
-
? [newCopyrights]
|
|
140
|
-
: newCopyrights;
|
|
141
|
-
this.set('copyrights', arrValue);
|
|
142
|
-
},
|
|
143
|
-
},
|
|
144
|
-
visible: {
|
|
145
|
-
value: visible === undefined ? true : visible,
|
|
146
|
-
writable: true,
|
|
147
|
-
},
|
|
148
|
-
properties: {
|
|
149
|
-
value: { ...(properties || {}) },
|
|
150
|
-
},
|
|
151
|
-
map: {
|
|
152
|
-
writable: true,
|
|
153
|
-
},
|
|
154
|
-
/**
|
|
155
|
-
* Callback function when a user click on a feature.
|
|
156
|
-
*/
|
|
157
|
-
clickCallbacks: {
|
|
158
|
-
value: [],
|
|
159
|
-
},
|
|
160
|
-
/**
|
|
161
|
-
* Callback function when a user hover on a feature.
|
|
162
|
-
*/
|
|
163
|
-
hoverCallbacks: {
|
|
164
|
-
value: [],
|
|
165
|
-
},
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Initialize the layer with the map passed in parameters.
|
|
171
|
-
*
|
|
172
|
-
* @param {ol/Map~Map|mapboxgl.Map} map A map.
|
|
173
|
-
*/
|
|
174
|
-
init(map) {
|
|
175
|
-
this.terminate();
|
|
176
|
-
/** @ignore */
|
|
177
|
-
this.map = map;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* Terminate what was initialized in init function. Remove layer, events...
|
|
182
|
-
*/
|
|
183
|
-
// eslint-disable-next-line class-methods-use-this
|
|
184
|
-
terminate() {}
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* Get a layer property.
|
|
188
|
-
*
|
|
189
|
-
* @param {string} name Property name.
|
|
190
|
-
* @return {property} Property
|
|
191
|
-
*/
|
|
192
|
-
get(name) {
|
|
193
|
-
return this.properties[name];
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Set a layer property.
|
|
198
|
-
*
|
|
199
|
-
* @param {string} name Property name.
|
|
200
|
-
* @param {string} value Value.
|
|
201
|
-
*/
|
|
202
|
-
set(name, value) {
|
|
203
|
-
if (value !== this.properties[name]) {
|
|
204
|
-
this.properties[name] = value;
|
|
205
|
-
this.dispatchEvent({
|
|
206
|
-
type: `change:${name}`,
|
|
207
|
-
target: this,
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* Change the visibility of the layer
|
|
214
|
-
*
|
|
215
|
-
* @param {boolean} visible Defines the visibility of the layer
|
|
216
|
-
* @param {boolean} [stopPropagationDown]
|
|
217
|
-
* @param {boolean} [stopPropagationUp]
|
|
218
|
-
* @param {boolean} [stopPropagationSiblings]
|
|
219
|
-
*/
|
|
220
|
-
setVisible(
|
|
221
|
-
visible,
|
|
222
|
-
stopPropagationDown = false,
|
|
223
|
-
stopPropagationUp = false,
|
|
224
|
-
stopPropagationSiblings = false,
|
|
225
|
-
) {
|
|
226
|
-
if (visible === this.visible) {
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
/** @ignore */
|
|
231
|
-
this.visible = visible;
|
|
232
|
-
|
|
233
|
-
this.dispatchEvent({
|
|
234
|
-
type: 'change:visible',
|
|
235
|
-
target: this,
|
|
236
|
-
stopPropagationDown,
|
|
237
|
-
stopPropagationUp,
|
|
238
|
-
stopPropagationSiblings,
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Returns an array with visible child layers
|
|
244
|
-
*
|
|
245
|
-
* @return {Layer[]} Visible children
|
|
246
|
-
*/
|
|
247
|
-
getVisibleChildren() {
|
|
248
|
-
return this.children.filter((child) => child.visible);
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* Checks whether the layer has child layers with visible set to True
|
|
253
|
-
*
|
|
254
|
-
* @return {boolean} True if the layer has visible child layers
|
|
255
|
-
* @deprecated
|
|
256
|
-
*/
|
|
257
|
-
hasVisibleChildren() {
|
|
258
|
-
return !!this.children.find((child) => child.visible === true);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* Request feature information for a given coordinate.
|
|
263
|
-
* This function must be implemented by inheriting layers.
|
|
264
|
-
*
|
|
265
|
-
* @param {ol/coordinate~Coordinate} coordinate Coordinate.
|
|
266
|
-
* @param {Object} options Some options. See child classes to see which are supported.
|
|
267
|
-
* @return {Promise<FeatureInfo>} An empty response.
|
|
268
|
-
*/
|
|
269
|
-
// eslint-disable-next-line no-unused-vars
|
|
270
|
-
getFeatureInfoAtCoordinate(coordinate, options) {
|
|
271
|
-
// eslint-disable-next-line no-console
|
|
272
|
-
console.error(
|
|
273
|
-
'getFeatureInfoAtCoordinate must be implemented by inheriting layers',
|
|
274
|
-
this.key,
|
|
275
|
-
);
|
|
276
|
-
|
|
277
|
-
// No response so we modify the properties accordingly, to avoid spaming the console.
|
|
278
|
-
this.isQueryable = false;
|
|
279
|
-
// this.isClickActive = false;
|
|
280
|
-
// this.isHoverActive = false;
|
|
281
|
-
|
|
282
|
-
// This layer returns no feature info.
|
|
283
|
-
// The function is implemented by inheriting layers.
|
|
284
|
-
return Promise.resolve({
|
|
285
|
-
layer: this,
|
|
286
|
-
features: [],
|
|
287
|
-
coordinate,
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
/**
|
|
292
|
-
* Listens to click events on the layer.
|
|
293
|
-
* @param {function} callback Callback function, called with the clicked
|
|
294
|
-
* features,
|
|
295
|
-
* the layer instance and the click event.
|
|
296
|
-
*/
|
|
297
|
-
onClick(callback) {
|
|
298
|
-
if (typeof callback === 'function') {
|
|
299
|
-
if (!this.clickCallbacks.includes(callback)) {
|
|
300
|
-
this.clickCallbacks.push(callback);
|
|
301
|
-
}
|
|
302
|
-
} else {
|
|
303
|
-
throw new Error('onClick callback must be of type function:', callback);
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
/**
|
|
308
|
-
* Unlistens to click events on the layer.
|
|
309
|
-
* @param {function} callback Callback function, called with the clicked
|
|
310
|
-
* features,
|
|
311
|
-
* the layer instance and the click event.
|
|
312
|
-
*/
|
|
313
|
-
unClick(callback) {
|
|
314
|
-
if (typeof callback === 'function') {
|
|
315
|
-
const idx = this.clickCallbacks.indexOf(callback);
|
|
316
|
-
if (idx > -1) {
|
|
317
|
-
this.clickCallbacks.splice(idx, 1);
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
/**
|
|
323
|
-
* Function triggered when the user click the map.
|
|
324
|
-
* @private
|
|
325
|
-
*/
|
|
326
|
-
onUserClickCallback(evt) {
|
|
327
|
-
const emptyFeatureInfo = {
|
|
328
|
-
features: [],
|
|
329
|
-
layer: this,
|
|
330
|
-
coordinate: evt.coordinate,
|
|
331
|
-
event: evt,
|
|
332
|
-
};
|
|
333
|
-
|
|
334
|
-
if (!this.isClickActive || !this.clickCallbacks.length) {
|
|
335
|
-
return Promise.resolve(emptyFeatureInfo);
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
return this.getFeatureInfoAtCoordinate(evt.coordinate)
|
|
339
|
-
.then((featureInfo) => {
|
|
340
|
-
const { features, layer, coordinate } = featureInfo;
|
|
341
|
-
this.clickCallbacks.forEach((callback) =>
|
|
342
|
-
callback(features, layer, coordinate),
|
|
343
|
-
);
|
|
344
|
-
return featureInfo;
|
|
345
|
-
})
|
|
346
|
-
.catch(() => emptyFeatureInfo);
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
/**
|
|
350
|
-
* Listens to hover events on the layer.
|
|
351
|
-
* @param {function} callback Callback function, called with the clicked
|
|
352
|
-
* features, the layer instance and the click event.
|
|
353
|
-
*/
|
|
354
|
-
onHover(callback) {
|
|
355
|
-
if (typeof callback === 'function') {
|
|
356
|
-
if (!this.hoverCallbacks.includes(callback)) {
|
|
357
|
-
this.hoverCallbacks.push(callback);
|
|
358
|
-
}
|
|
359
|
-
} else {
|
|
360
|
-
throw new Error('callback must be of type function.');
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
/**
|
|
365
|
-
* Unlistens to hover events on the layer.
|
|
366
|
-
* @param {function} callback Callback function, called with the hovered
|
|
367
|
-
* features, the layer instance and the click event.
|
|
368
|
-
*/
|
|
369
|
-
unHover(callback) {
|
|
370
|
-
if (typeof callback === 'function') {
|
|
371
|
-
const idx = this.hoverCallbacks.indexOf(callback);
|
|
372
|
-
if (idx > -1) {
|
|
373
|
-
this.hoverCallbacks.splice(idx, 1);
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
/**
|
|
379
|
-
* Function triggered when the user move the cursor.
|
|
380
|
-
* @private
|
|
381
|
-
*/
|
|
382
|
-
onUserMoveCallback(evt) {
|
|
383
|
-
const emptyFeatureInfo = {
|
|
384
|
-
features: [],
|
|
385
|
-
layer: this,
|
|
386
|
-
coordinate: evt.coordinate,
|
|
387
|
-
event: evt,
|
|
388
|
-
};
|
|
389
|
-
|
|
390
|
-
if (!this.isHoverActive || !this.hoverCallbacks.length) {
|
|
391
|
-
return Promise.resolve(emptyFeatureInfo);
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
return this.getFeatureInfoAtCoordinate(evt.coordinate)
|
|
395
|
-
.then((featureInfo) => {
|
|
396
|
-
const { features, layer, coordinate } = featureInfo;
|
|
397
|
-
this.hoverCallbacks.forEach((callback) =>
|
|
398
|
-
callback(features, layer, coordinate),
|
|
399
|
-
);
|
|
400
|
-
return featureInfo;
|
|
401
|
-
})
|
|
402
|
-
.catch(() => emptyFeatureInfo);
|
|
403
|
-
}
|
|
404
|
-
}
|