mobility-toolbox-js 2.0.0-beta.34 → 2.0.0-beta.37
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 +14 -8
- package/api/RealtimeAPI.d.ts +6 -6
- package/api/RealtimeAPI.d.ts.map +1 -1
- package/api/RealtimeAPI.js +170 -197
- package/api/RealtimeAPI.test.d.ts +2 -0
- package/api/RealtimeAPI.test.d.ts.map +1 -0
- package/api/RealtimeAPI.test.js +67 -0
- package/api/RoutingAPI.d.ts +6 -2
- package/api/RoutingAPI.d.ts.map +1 -1
- package/api/RoutingAPI.js +8 -38
- package/api/RoutingAPI.test.d.ts +2 -0
- package/api/RoutingAPI.test.d.ts.map +1 -0
- package/api/RoutingAPI.test.js +29 -0
- package/api/StopsAPI.d.ts +1 -1
- package/api/StopsAPI.d.ts.map +1 -1
- package/api/StopsAPI.js +8 -40
- package/api/StopsAPI.test.d.ts +2 -0
- package/api/StopsAPI.test.d.ts.map +1 -0
- package/api/StopsAPI.test.js +26 -0
- package/api/index.d.ts +3 -4
- package/api/index.d.ts.map +1 -1
- package/api/index.js +3 -10
- package/api/typedefs.js +1 -0
- package/common/api/HttpAPI.d.ts +2 -2
- package/common/api/HttpAPI.d.ts.map +1 -1
- package/common/api/HttpAPI.js +21 -48
- package/common/api/HttpAPI.test.d.ts +2 -0
- package/common/api/HttpAPI.test.d.ts.map +1 -0
- package/common/api/HttpAPI.test.js +54 -0
- package/common/api/WebSocketAPI.d.ts +8 -4
- package/common/api/WebSocketAPI.d.ts.map +1 -1
- package/common/api/WebSocketAPI.js +125 -129
- package/common/api/WebSocketAPI.test.d.ts +2 -0
- package/common/api/WebSocketAPI.test.d.ts.map +1 -0
- package/common/api/WebSocketAPI.test.js +380 -0
- package/common/controls/Control.d.ts +5 -5
- package/common/controls/Control.d.ts.map +1 -1
- package/common/controls/Control.js +44 -77
- package/common/controls/Control.test.d.ts +2 -0
- package/common/controls/Control.test.d.ts.map +1 -0
- package/common/controls/Control.test.js +89 -0
- package/common/index.js +2 -18
- package/common/layers/Layer.d.ts +11 -11
- package/common/layers/Layer.d.ts.map +1 -1
- package/common/layers/Layer.js +70 -104
- package/common/layers/Layer.test.d.ts +2 -0
- package/common/layers/Layer.test.d.ts.map +1 -0
- package/common/layers/Layer.test.js +137 -0
- package/common/mixins/CopyrightMixin.js +23 -52
- package/common/mixins/MapboxLayerMixin.js +162 -204
- package/common/mixins/RealtimeLayerMixin.js +580 -635
- package/common/mixins/StopFinderMixin.d.ts +3 -3
- package/common/mixins/StopFinderMixin.d.ts.map +1 -1
- package/common/mixins/StopFinderMixin.js +115 -157
- package/common/mixins/UserInteractionsLayerMixin.js +142 -175
- package/common/mixins/UserInteractionsLayerMixin.test.d.ts +2 -0
- package/common/mixins/UserInteractionsLayerMixin.test.d.ts.map +1 -0
- package/common/mixins/UserInteractionsLayerMixin.test.js +214 -0
- package/common/styles/index.js +4 -24
- package/common/styles/realtimeDefaultStyle.d.ts.map +1 -1
- package/common/styles/realtimeDefaultStyle.js +67 -78
- package/common/styles/realtimeDelayStyle.js +4 -17
- package/common/styles/realtimeSimpleStyle.js +5 -7
- package/common/typedefs.js +1 -0
- package/common/utils/cleanStopTime.js +3 -5
- package/common/utils/compareDepartures.d.ts +1 -1
- package/common/utils/compareDepartures.d.ts.map +1 -1
- package/common/utils/compareDepartures.js +8 -11
- package/common/utils/createCanvas.js +3 -5
- package/common/utils/createTrackerFilters.d.ts +1 -1
- package/common/utils/createTrackerFilters.d.ts.map +1 -1
- package/common/utils/createTrackerFilters.js +22 -32
- package/common/utils/createTrackerFilters.test.d.ts +2 -0
- package/common/utils/createTrackerFilters.test.d.ts.map +1 -0
- package/common/utils/createTrackerFilters.test.js +79 -0
- package/common/utils/getLayersAsFlatArray.js +6 -8
- package/common/utils/getMapboxMapCopyrights.js +9 -11
- package/common/utils/getMapboxMapCopyrights.test.d.ts +2 -0
- package/common/utils/getMapboxMapCopyrights.test.d.ts.map +1 -0
- package/common/utils/getMapboxMapCopyrights.test.js +40 -0
- package/common/utils/getMapboxRender.js +12 -15
- package/common/utils/getMaplibreRender.js +10 -13
- package/common/utils/getRealtimeModeSuffix.js +2 -6
- package/common/utils/getUrlWithParams.js +5 -8
- package/common/utils/getVehiclePosition.js +20 -23
- package/common/utils/index.js +12 -37
- package/common/utils/removeDuplicate.d.ts +1 -1
- package/common/utils/removeDuplicate.d.ts.map +1 -1
- package/common/utils/removeDuplicate.js +6 -21
- package/common/utils/removeDuplicate.test.d.ts +2 -0
- package/common/utils/removeDuplicate.test.d.ts.map +1 -0
- package/common/utils/removeDuplicate.test.js +19 -0
- package/common/utils/renderTrajectories.js +31 -43
- package/common/utils/sortByDelay.js +4 -6
- package/common/utils/timeUtils.js +14 -24
- package/common/utils/timeUtils.test.d.ts +2 -0
- package/common/utils/timeUtils.test.d.ts.map +1 -0
- package/common/utils/timeUtils.test.js +10 -0
- package/common/utils/trackerConfig.js +27 -39
- package/common/utils/trackerConfig.test.d.ts +2 -0
- package/common/utils/trackerConfig.test.d.ts.map +1 -0
- package/common/utils/trackerConfig.test.js +23 -0
- package/iife.js +3 -5
- package/index.d.ts +4 -0
- package/index.js +9 -10
- package/mapbox/controls/CopyrightControl.d.ts +0 -1
- package/mapbox/controls/CopyrightControl.d.ts.map +1 -1
- package/mapbox/controls/CopyrightControl.js +18 -38
- package/mapbox/controls/index.js +1 -5
- package/mapbox/index.js +4 -20
- package/mapbox/layers/Layer.d.ts +1 -1
- package/mapbox/layers/Layer.d.ts.map +1 -1
- package/mapbox/layers/Layer.js +29 -71
- package/mapbox/layers/Layer.test.d.ts +2 -0
- package/mapbox/layers/Layer.test.d.ts.map +1 -0
- package/mapbox/layers/Layer.test.js +204 -0
- package/mapbox/layers/RealtimeLayer.d.ts +4 -4
- package/mapbox/layers/RealtimeLayer.d.ts.map +1 -1
- package/mapbox/layers/RealtimeLayer.js +83 -125
- package/mapbox/layers/RealtimeLayer.test.d.ts +2 -0
- package/mapbox/layers/RealtimeLayer.test.d.ts.map +1 -0
- package/mapbox/layers/RealtimeLayer.test.js +10 -0
- package/mapbox/layers/index.js +2 -7
- package/mapbox/utils.js +19 -33
- package/mbt.js +59 -37
- package/mbt.js.map +2 -2
- package/mbt.min.js +10 -10
- package/mbt.min.js.map +2 -2
- package/ol/controls/CopyrightControl.js +26 -47
- package/ol/controls/CopyrightControl.test.d.ts +2 -0
- package/ol/controls/CopyrightControl.test.d.ts.map +1 -0
- package/ol/controls/CopyrightControl.test.js +177 -0
- package/ol/controls/RoutingControl.d.ts +6 -5
- package/ol/controls/RoutingControl.d.ts.map +1 -1
- package/ol/controls/RoutingControl.js +209 -270
- package/ol/controls/RoutingControl.test.d.ts +2 -0
- package/ol/controls/RoutingControl.test.d.ts.map +1 -0
- package/ol/controls/RoutingControl.test.js +150 -0
- package/ol/controls/StopFinderControl.js +9 -32
- package/ol/controls/StopFinderControl.test.d.ts +2 -0
- package/ol/controls/StopFinderControl.test.d.ts.map +1 -0
- package/ol/controls/StopFinderControl.test.js +49 -0
- package/ol/controls/index.js +3 -9
- package/ol/index.js +5 -21
- package/ol/layers/Layer.d.ts +1 -1
- package/ol/layers/Layer.d.ts.map +1 -1
- package/ol/layers/Layer.js +40 -72
- package/ol/layers/Layer.test.d.ts +2 -0
- package/ol/layers/Layer.test.d.ts.map +1 -0
- package/ol/layers/Layer.test.js +196 -0
- package/ol/layers/MapboxLayer.d.ts +7 -7
- package/ol/layers/MapboxLayer.d.ts.map +1 -1
- package/ol/layers/MapboxLayer.js +30 -66
- package/ol/layers/MapboxLayer.test.d.ts +2 -0
- package/ol/layers/MapboxLayer.test.d.ts.map +1 -0
- package/ol/layers/MapboxLayer.test.js +164 -0
- package/ol/layers/MapboxStyleLayer.d.ts +3 -3
- package/ol/layers/MapboxStyleLayer.d.ts.map +1 -1
- package/ol/layers/MapboxStyleLayer.js +92 -135
- package/ol/layers/MapboxStyleLayer.test.d.ts +2 -0
- package/ol/layers/MapboxStyleLayer.test.d.ts.map +1 -0
- package/ol/layers/MapboxStyleLayer.test.js +232 -0
- package/ol/layers/MaplibreLayer.d.ts +1 -1
- package/ol/layers/MaplibreLayer.d.ts.map +1 -1
- package/ol/layers/MaplibreLayer.js +14 -48
- package/ol/layers/RealtimeLayer.d.ts +2 -2
- package/ol/layers/RealtimeLayer.d.ts.map +1 -1
- package/ol/layers/RealtimeLayer.js +111 -147
- package/ol/layers/RealtimeLayer.test.d.ts +2 -0
- package/ol/layers/RealtimeLayer.test.d.ts.map +1 -0
- package/ol/layers/RealtimeLayer.test.js +71 -0
- package/ol/layers/RoutingLayer.d.ts +2 -2
- package/ol/layers/RoutingLayer.d.ts.map +1 -1
- package/ol/layers/RoutingLayer.js +29 -61
- package/ol/layers/RoutingLayer.test.d.ts +2 -0
- package/ol/layers/RoutingLayer.test.d.ts.map +1 -0
- package/ol/layers/RoutingLayer.test.js +39 -0
- package/ol/layers/VectorLayer.d.ts +1 -1
- package/ol/layers/VectorLayer.d.ts.map +1 -1
- package/ol/layers/VectorLayer.js +14 -48
- package/ol/layers/VectorLayer.test.d.ts +2 -0
- package/ol/layers/VectorLayer.test.d.ts.map +1 -0
- package/ol/layers/VectorLayer.test.js +87 -0
- package/ol/layers/WMSLayer.d.ts +1 -1
- package/ol/layers/WMSLayer.d.ts.map +1 -1
- package/ol/layers/WMSLayer.js +34 -68
- package/ol/layers/WMSLayer.test.d.ts +2 -0
- package/ol/layers/WMSLayer.test.d.ts.map +1 -0
- package/ol/layers/WMSLayer.test.js +66 -0
- package/ol/layers/index.js +8 -19
- package/ol/styles/fullTrajectoryDelayStyle.js +11 -13
- package/ol/styles/fullTrajectoryStyle.js +16 -18
- package/ol/styles/index.js +2 -7
- package/package.json +5 -2
- package/setupTests.js +12 -14
|
@@ -1,32 +1,14 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.UserInteractionsLayerInterface = void 0;
|
|
19
1
|
/* eslint-disable no-empty-function,@typescript-eslint/no-empty-function */
|
|
20
2
|
/* eslint-disable no-useless-constructor,@typescript-eslint/no-useless-constructor */
|
|
21
3
|
/* eslint-disable no-unused-vars,@typescript-eslint/no-unused-vars */
|
|
22
4
|
/* eslint-disable class-methods-use-this */
|
|
23
5
|
/* eslint-disable max-classes-per-file */
|
|
24
|
-
|
|
25
|
-
|
|
6
|
+
import { fromLonLat } from 'ol/proj';
|
|
7
|
+
import { unByKey } from 'ol/Observable';
|
|
26
8
|
/**
|
|
27
9
|
* UserInteractionsLayerInterface.
|
|
28
10
|
*/
|
|
29
|
-
|
|
11
|
+
export class UserInteractionsLayerInterface {
|
|
30
12
|
/*
|
|
31
13
|
* Constructor
|
|
32
14
|
|
|
@@ -36,38 +18,34 @@ var UserInteractionsLayerInterface = /** @class */ (function () {
|
|
|
36
18
|
* @param {string} options.userHoverInteractions If true, it listens for user mouse over event.
|
|
37
19
|
* @param {string} options.defaultUserInteractions If true, it adds default listeners for user mouse hover and click event.
|
|
38
20
|
*/
|
|
39
|
-
|
|
40
|
-
if (options === void 0) { options = {}; }
|
|
41
|
-
}
|
|
21
|
+
constructor(options = {}) { }
|
|
42
22
|
/**
|
|
43
23
|
* Initialize the layer adding user interactions.
|
|
44
24
|
*
|
|
45
25
|
* @param {ol/Map~Map} map
|
|
46
26
|
*/
|
|
47
|
-
|
|
27
|
+
attachToMap(map) { }
|
|
48
28
|
/**
|
|
49
29
|
* Terminate the layer unsubscribing user interactions.
|
|
50
30
|
*/
|
|
51
|
-
|
|
31
|
+
detachFromMap() { }
|
|
52
32
|
/**
|
|
53
33
|
* Activate map listeners events.
|
|
54
34
|
*/
|
|
55
|
-
|
|
35
|
+
activateUserInteractions() { }
|
|
56
36
|
/**
|
|
57
37
|
* Deactivaet map listeners events.
|
|
58
38
|
*/
|
|
59
|
-
|
|
39
|
+
deactivateUserInteractions() { }
|
|
60
40
|
/**
|
|
61
41
|
* Terminate the layer unsubscribing user interactions.
|
|
62
42
|
*/
|
|
63
|
-
|
|
43
|
+
onClick(callback) { }
|
|
64
44
|
/**
|
|
65
45
|
* Terminate the layer unsubscribing user interactions.
|
|
66
46
|
*/
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}());
|
|
70
|
-
exports.UserInteractionsLayerInterface = UserInteractionsLayerInterface;
|
|
47
|
+
onHover(callback) { }
|
|
48
|
+
}
|
|
71
49
|
/**
|
|
72
50
|
* Mixin for UserInteractionsLayerInterface. It provide onClick and onHover functions.
|
|
73
51
|
*
|
|
@@ -75,151 +53,140 @@ exports.UserInteractionsLayerInterface = UserInteractionsLayerInterface;
|
|
|
75
53
|
* @return {Class} A class that implements {UserInteractionsLayerInterface} class and extends Base;
|
|
76
54
|
* @private
|
|
77
55
|
*/
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
56
|
+
const UserInteractionsLayerMixin = (Base) => class extends Base {
|
|
57
|
+
constructor(options = {}) {
|
|
58
|
+
super(options);
|
|
59
|
+
const { userInteractions = true, userClickInteractions = true, userHoverInteractions = true, defaultUserInteractions = true, } = options;
|
|
60
|
+
this.userInteractions = userInteractions;
|
|
61
|
+
this.userClickInteractions = userClickInteractions;
|
|
62
|
+
this.userHoverInteractions = userHoverInteractions;
|
|
63
|
+
this.defaultUserInteractions = defaultUserInteractions;
|
|
64
|
+
this.userClickCallbacks = [];
|
|
65
|
+
this.userHoverCallbacks = [];
|
|
66
|
+
this.userClickEventsKeys = [];
|
|
67
|
+
this.userHoverEventsKeys = [];
|
|
68
|
+
this.onUserClickCallback = this.onUserClickCallback.bind(this);
|
|
69
|
+
this.onUserMoveCallback = this.onUserMoveCallback.bind(this);
|
|
70
|
+
// Add mouse event callbacks
|
|
71
|
+
const { onClick, onHover } = options;
|
|
72
|
+
if (this.userInteractions && this.userClickInteractions && onClick) {
|
|
73
|
+
this.onClick(onClick);
|
|
74
|
+
}
|
|
75
|
+
if (this.userInteractions && this.userHoverInteractions && onHover) {
|
|
76
|
+
this.onHover(onHover);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
attachToMap(map, options) {
|
|
80
|
+
super.attachToMap(map, options);
|
|
81
|
+
if (this.userInteractions &&
|
|
82
|
+
this.defaultUserInteractions &&
|
|
83
|
+
this.userClickInteractions &&
|
|
84
|
+
this.onFeatureClick) {
|
|
85
|
+
this.onClick(this.onFeatureClick);
|
|
104
86
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
87
|
+
if (this.userInteractions &&
|
|
88
|
+
this.defaultUserInteractions &&
|
|
89
|
+
this.userHoverInteractions &&
|
|
90
|
+
this.onFeatureHover) {
|
|
91
|
+
this.onHover(this.onFeatureHover);
|
|
92
|
+
}
|
|
93
|
+
this.listenEvents();
|
|
94
|
+
}
|
|
95
|
+
detachFromMap() {
|
|
96
|
+
this.unlistenEvents();
|
|
97
|
+
super.detachFromMap();
|
|
98
|
+
}
|
|
99
|
+
listenEvents() {
|
|
100
|
+
this.unlistenEvents();
|
|
101
|
+
this.userClickCallbacks.forEach((callback) => {
|
|
102
|
+
this.userClickEventsKeys.push(this.on('user:click', ({ target: { features, layer, coordinate } }) => {
|
|
103
|
+
callback(features, layer, coordinate);
|
|
104
|
+
}));
|
|
105
|
+
});
|
|
106
|
+
this.userHoverCallbacks.forEach((callback) => {
|
|
107
|
+
this.userHoverEventsKeys.push(this.on('user:hover', ({ target: { features, layer, coordinate, event } }) => {
|
|
108
|
+
callback(features, layer, coordinate, event);
|
|
109
|
+
}));
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
unlistenEvents() {
|
|
113
|
+
unByKey(this.userClickEventsKeys);
|
|
114
|
+
unByKey(this.userHoverEventsKeys);
|
|
115
|
+
this.userClickEventsKeys = [];
|
|
116
|
+
this.userHoverEventsKeys = [];
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Listens to click events on the layer.
|
|
120
|
+
* @param {function} callback Callback function, called with the clicked
|
|
121
|
+
* features,
|
|
122
|
+
* the layer instance and the click event.
|
|
123
|
+
*/
|
|
124
|
+
onClick(callback) {
|
|
125
|
+
this.userClickCallbacks.push(callback);
|
|
126
|
+
this.activateUserInteractions();
|
|
127
|
+
if (this.map) {
|
|
128
|
+
// If the layer is already attached to the map we reload the events
|
|
119
129
|
this.listenEvents();
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Listens to hover events on the layer.
|
|
134
|
+
* @param {function} callback Callback function, called with the clicked
|
|
135
|
+
* features, the layer instance and the click event.
|
|
136
|
+
*/
|
|
137
|
+
onHover(callback) {
|
|
138
|
+
this.userHoverCallbacks.push(callback);
|
|
139
|
+
this.activateUserInteractions();
|
|
140
|
+
if (this.map) {
|
|
141
|
+
// If the layer is already attached to the map we reload the events
|
|
142
|
+
this.listenEvents();
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Function triggered when the user click the map.
|
|
147
|
+
* @private
|
|
148
|
+
*/
|
|
149
|
+
onUserClickCallback(evt) {
|
|
150
|
+
const coordinate = evt.coordinate || fromLonLat(evt.lngLat.toArray());
|
|
151
|
+
const emptyFeatureInfo = {
|
|
152
|
+
features: [],
|
|
153
|
+
layer: this,
|
|
154
|
+
coordinate,
|
|
155
|
+
event: evt,
|
|
120
156
|
};
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
var _this = this;
|
|
127
|
-
this.unlistenEvents();
|
|
128
|
-
this.userClickCallbacks.forEach(function (callback) {
|
|
129
|
-
_this.userClickEventsKeys.push(_this.on('user:click', function (_a) {
|
|
130
|
-
var _b = _a.target, features = _b.features, layer = _b.layer, coordinate = _b.coordinate;
|
|
131
|
-
callback(features, layer, coordinate);
|
|
132
|
-
}));
|
|
133
|
-
});
|
|
134
|
-
this.userHoverCallbacks.forEach(function (callback) {
|
|
135
|
-
_this.userHoverEventsKeys.push(_this.on('user:hover', function (_a) {
|
|
136
|
-
var _b = _a.target, features = _b.features, layer = _b.layer, coordinate = _b.coordinate, event = _b.event;
|
|
137
|
-
callback(features, layer, coordinate, event);
|
|
138
|
-
}));
|
|
157
|
+
return this.getFeatureInfoAtCoordinate(coordinate)
|
|
158
|
+
.then((featureInfo) => {
|
|
159
|
+
this.dispatchEvent({
|
|
160
|
+
type: 'user:click',
|
|
161
|
+
target: featureInfo,
|
|
139
162
|
});
|
|
163
|
+
return featureInfo;
|
|
164
|
+
})
|
|
165
|
+
.catch(() => emptyFeatureInfo);
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Function triggered when the user move the cursor.
|
|
169
|
+
* @private
|
|
170
|
+
*/
|
|
171
|
+
onUserMoveCallback(evt) {
|
|
172
|
+
const coordinate = evt.coordinate || fromLonLat(evt.lngLat.toArray());
|
|
173
|
+
const emptyFeatureInfo = {
|
|
174
|
+
features: [],
|
|
175
|
+
layer: this,
|
|
176
|
+
coordinate,
|
|
177
|
+
event: evt,
|
|
140
178
|
};
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
class_1.prototype.onClick = function (callback) {
|
|
154
|
-
this.userClickCallbacks.push(callback);
|
|
155
|
-
this.activateUserInteractions();
|
|
156
|
-
if (this.map) {
|
|
157
|
-
// If the layer is already attached to the map we reload the events
|
|
158
|
-
this.listenEvents();
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
/**
|
|
162
|
-
* Listens to hover events on the layer.
|
|
163
|
-
* @param {function} callback Callback function, called with the clicked
|
|
164
|
-
* features, the layer instance and the click event.
|
|
165
|
-
*/
|
|
166
|
-
class_1.prototype.onHover = function (callback) {
|
|
167
|
-
this.userHoverCallbacks.push(callback);
|
|
168
|
-
this.activateUserInteractions();
|
|
169
|
-
if (this.map) {
|
|
170
|
-
// If the layer is already attached to the map we reload the events
|
|
171
|
-
this.listenEvents();
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
/**
|
|
175
|
-
* Function triggered when the user click the map.
|
|
176
|
-
* @private
|
|
177
|
-
*/
|
|
178
|
-
class_1.prototype.onUserClickCallback = function (evt) {
|
|
179
|
-
var _this = this;
|
|
180
|
-
var coordinate = evt.coordinate || (0, proj_1.fromLonLat)(evt.lngLat.toArray());
|
|
181
|
-
var emptyFeatureInfo = {
|
|
182
|
-
features: [],
|
|
183
|
-
layer: this,
|
|
184
|
-
coordinate: coordinate,
|
|
185
|
-
event: evt,
|
|
186
|
-
};
|
|
187
|
-
return this.getFeatureInfoAtCoordinate(coordinate)
|
|
188
|
-
.then(function (featureInfo) {
|
|
189
|
-
_this.dispatchEvent({
|
|
190
|
-
type: 'user:click',
|
|
191
|
-
target: featureInfo,
|
|
192
|
-
});
|
|
193
|
-
return featureInfo;
|
|
194
|
-
})
|
|
195
|
-
.catch(function () { return emptyFeatureInfo; });
|
|
196
|
-
};
|
|
197
|
-
/**
|
|
198
|
-
* Function triggered when the user move the cursor.
|
|
199
|
-
* @private
|
|
200
|
-
*/
|
|
201
|
-
class_1.prototype.onUserMoveCallback = function (evt) {
|
|
202
|
-
var _this = this;
|
|
203
|
-
var coordinate = evt.coordinate || (0, proj_1.fromLonLat)(evt.lngLat.toArray());
|
|
204
|
-
var emptyFeatureInfo = {
|
|
205
|
-
features: [],
|
|
206
|
-
layer: this,
|
|
207
|
-
coordinate: coordinate,
|
|
208
|
-
event: evt,
|
|
209
|
-
};
|
|
210
|
-
return this.getFeatureInfoAtCoordinate(coordinate)
|
|
211
|
-
.then(function (featureInfo) {
|
|
212
|
-
_this.dispatchEvent({
|
|
213
|
-
type: 'user:hover',
|
|
214
|
-
target: featureInfo,
|
|
215
|
-
});
|
|
216
|
-
return featureInfo;
|
|
217
|
-
})
|
|
218
|
-
.catch(function () { return emptyFeatureInfo; });
|
|
219
|
-
};
|
|
220
|
-
class_1.prototype.activateUserInteractions = function () { };
|
|
221
|
-
class_1.prototype.deactivateUserInteractions = function () { };
|
|
222
|
-
return class_1;
|
|
223
|
-
}(Base));
|
|
179
|
+
return this.getFeatureInfoAtCoordinate(coordinate)
|
|
180
|
+
.then((featureInfo) => {
|
|
181
|
+
this.dispatchEvent({
|
|
182
|
+
type: 'user:hover',
|
|
183
|
+
target: featureInfo,
|
|
184
|
+
});
|
|
185
|
+
return featureInfo;
|
|
186
|
+
})
|
|
187
|
+
.catch(() => emptyFeatureInfo);
|
|
188
|
+
}
|
|
189
|
+
activateUserInteractions() { }
|
|
190
|
+
deactivateUserInteractions() { }
|
|
224
191
|
};
|
|
225
|
-
|
|
192
|
+
export default UserInteractionsLayerMixin;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UserInteractionsLayerMixin.test.d.ts","sourceRoot":"","sources":["../../../src/common/mixins/UserInteractionsLayerMixin.test.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import VectorLayer from 'ol/layer/Vector';
|
|
11
|
+
import VectorSource from 'ol/source/Vector';
|
|
12
|
+
import BaseLayer from '../layers/Layer';
|
|
13
|
+
import mixin from './UserInteractionsLayerMixin';
|
|
14
|
+
const olLayer = new VectorLayer({ source: new VectorSource() });
|
|
15
|
+
const Layer = mixin(BaseLayer);
|
|
16
|
+
describe('Layer', () => {
|
|
17
|
+
test('should initialize.', () => {
|
|
18
|
+
const layer = new Layer();
|
|
19
|
+
expect(layer).toBeInstanceOf(Layer);
|
|
20
|
+
});
|
|
21
|
+
test('should define default properties.', () => {
|
|
22
|
+
const layer = new Layer();
|
|
23
|
+
expect(layer).toBeInstanceOf(Layer);
|
|
24
|
+
expect(layer.userInteractions).toEqual(true);
|
|
25
|
+
expect(layer.userClickInteractions).toEqual(true);
|
|
26
|
+
expect(layer.userHoverInteractions).toEqual(true);
|
|
27
|
+
expect(layer.defaultUserInteractions).toBe(true);
|
|
28
|
+
expect(layer.userClickCallbacks).toEqual([]);
|
|
29
|
+
expect(layer.userHoverCallbacks).toEqual([]);
|
|
30
|
+
expect(layer.userClickEventsKeys).toEqual([]);
|
|
31
|
+
expect(layer.userHoverEventsKeys).toEqual([]);
|
|
32
|
+
});
|
|
33
|
+
test('should set userInteractionsXXX to false.', () => {
|
|
34
|
+
const options = {
|
|
35
|
+
userInteractions: false,
|
|
36
|
+
userClickInteractions: false,
|
|
37
|
+
userHoverInteractions: false,
|
|
38
|
+
defaultUserInteractions: false,
|
|
39
|
+
};
|
|
40
|
+
const layer = new Layer(options);
|
|
41
|
+
expect(layer).toBeInstanceOf(Layer);
|
|
42
|
+
expect(layer.userInteractions).toBe(false);
|
|
43
|
+
expect(layer.userClickInteractions).toBe(false);
|
|
44
|
+
expect(layer.userHoverInteractions).toBe(false);
|
|
45
|
+
expect(layer.defaultUserInteractions).toBe(false);
|
|
46
|
+
});
|
|
47
|
+
test('should set onClick using constructor', () => {
|
|
48
|
+
const fn = () => { };
|
|
49
|
+
const layer = new Layer({
|
|
50
|
+
onClick: fn,
|
|
51
|
+
onHover: fn,
|
|
52
|
+
});
|
|
53
|
+
expect(layer.userClickCallbacks[0]).toBe(fn);
|
|
54
|
+
expect(layer.userHoverCallbacks[0]).toBe(fn);
|
|
55
|
+
expect(layer.userClickEventsKeys.length).toBe(0);
|
|
56
|
+
expect(layer.userHoverEventsKeys.length).toBe(0);
|
|
57
|
+
});
|
|
58
|
+
describe('#attachToMap()', () => {
|
|
59
|
+
test('should not add events if no callbacks', () => {
|
|
60
|
+
const layer = new Layer({
|
|
61
|
+
olLayer,
|
|
62
|
+
});
|
|
63
|
+
expect(layer.map).toBe(undefined);
|
|
64
|
+
const obj = {};
|
|
65
|
+
layer.attachToMap(obj);
|
|
66
|
+
expect(layer.userClickEventsKeys.length).toBe(0);
|
|
67
|
+
expect(layer.userHoverEventsKeys.length).toBe(0);
|
|
68
|
+
});
|
|
69
|
+
test('should add events', () => {
|
|
70
|
+
const fn = () => { };
|
|
71
|
+
const layer = new Layer({
|
|
72
|
+
olLayer,
|
|
73
|
+
onClick: fn,
|
|
74
|
+
onHover: fn,
|
|
75
|
+
});
|
|
76
|
+
expect(layer.map).toBe(undefined);
|
|
77
|
+
const obj = {};
|
|
78
|
+
layer.attachToMap(obj);
|
|
79
|
+
expect(layer.userClickEventsKeys.length).toBe(1);
|
|
80
|
+
expect(layer.userHoverEventsKeys.length).toBe(1);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
describe('#onClick()', () => {
|
|
84
|
+
test('adds function to callback array', () => {
|
|
85
|
+
const layer = new Layer();
|
|
86
|
+
const fn = jest.fn();
|
|
87
|
+
const fn2 = jest.fn();
|
|
88
|
+
layer.onClick(fn);
|
|
89
|
+
expect(layer.userClickCallbacks).toEqual([fn]);
|
|
90
|
+
layer.onClick(fn2);
|
|
91
|
+
expect(layer.userClickCallbacks).toEqual([fn, fn2]);
|
|
92
|
+
expect(layer.userClickEventsKeys.length).toBe(0);
|
|
93
|
+
layer.attachToMap({});
|
|
94
|
+
expect(layer.userClickEventsKeys.length).toBe(2);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
describe('#onHover()', () => {
|
|
98
|
+
test('adds function to callback array', () => {
|
|
99
|
+
const layer = new Layer();
|
|
100
|
+
const fn = jest.fn();
|
|
101
|
+
const fn2 = jest.fn();
|
|
102
|
+
layer.onHover(fn);
|
|
103
|
+
expect(layer.userHoverCallbacks).toEqual([fn]);
|
|
104
|
+
layer.onHover(fn2);
|
|
105
|
+
expect(layer.userHoverCallbacks).toEqual([fn, fn2]);
|
|
106
|
+
expect(layer.userHoverEventsKeys.length).toBe(0);
|
|
107
|
+
layer.attachToMap({});
|
|
108
|
+
expect(layer.userHoverEventsKeys.length).toBe(2);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
describe('#onUserClickCallback()', () => {
|
|
112
|
+
const evt = { type: 'signleclick', coordinate: [0, 0] };
|
|
113
|
+
const getFeatureInfo = (layer, features = []) => ({
|
|
114
|
+
features,
|
|
115
|
+
layer,
|
|
116
|
+
coordinate: evt.coordinate,
|
|
117
|
+
event: evt,
|
|
118
|
+
});
|
|
119
|
+
test('calls click callback functions', (done) => __awaiter(void 0, void 0, void 0, function* () {
|
|
120
|
+
const layer = new Layer();
|
|
121
|
+
const goodFeatureInfo = getFeatureInfo(layer, [{ name: 'test' }]);
|
|
122
|
+
const fn = jest.fn();
|
|
123
|
+
const fn2 = jest.fn();
|
|
124
|
+
const spy = jest
|
|
125
|
+
.spyOn(layer, 'getFeatureInfoAtCoordinate')
|
|
126
|
+
.mockResolvedValue(goodFeatureInfo);
|
|
127
|
+
layer.onClick(fn);
|
|
128
|
+
layer.onClick(fn2);
|
|
129
|
+
layer.attachToMap({});
|
|
130
|
+
layer.onUserClickCallback(evt).then((featureInfo) => {
|
|
131
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
132
|
+
expect(spy).toHaveBeenCalledWith(evt.coordinate);
|
|
133
|
+
expect(featureInfo).toBe(goodFeatureInfo);
|
|
134
|
+
expect(fn).toHaveBeenCalledTimes(1);
|
|
135
|
+
expect(fn.mock.calls[0][0]).toBe(goodFeatureInfo.features);
|
|
136
|
+
expect(fn.mock.calls[0][1]).toBe(goodFeatureInfo.layer);
|
|
137
|
+
expect(fn.mock.calls[0][2]).toBe(goodFeatureInfo.coordinate);
|
|
138
|
+
expect(fn2).toHaveBeenCalledTimes(1);
|
|
139
|
+
expect(fn2.mock.calls[0][0]).toBe(goodFeatureInfo.features);
|
|
140
|
+
expect(fn2.mock.calls[0][1]).toBe(goodFeatureInfo.layer);
|
|
141
|
+
expect(fn2.mock.calls[0][2]).toBe(goodFeatureInfo.coordinate);
|
|
142
|
+
done();
|
|
143
|
+
});
|
|
144
|
+
}));
|
|
145
|
+
describe('returns empty feature info', () => {
|
|
146
|
+
test('if an error is thrown in click callback', (done) => {
|
|
147
|
+
const layer = new Layer();
|
|
148
|
+
layer.onClick(() => {
|
|
149
|
+
throw new Error('foo');
|
|
150
|
+
});
|
|
151
|
+
const goodFeatureInfo = getFeatureInfo(layer, [{ name: 'test' }]);
|
|
152
|
+
jest
|
|
153
|
+
.spyOn(layer, 'getFeatureInfoAtCoordinate')
|
|
154
|
+
.mockResolvedValue(goodFeatureInfo);
|
|
155
|
+
layer.attachToMap({});
|
|
156
|
+
layer.onUserClickCallback(evt).then((featureInfo) => {
|
|
157
|
+
expect(featureInfo).toEqual(getFeatureInfo(layer));
|
|
158
|
+
done();
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
describe('#onUserMoveCallback()', () => {
|
|
164
|
+
const evt = { type: 'pointermove', coordinate: [0, 0] };
|
|
165
|
+
const getFeatureInfo = (layer, features = []) => ({
|
|
166
|
+
features,
|
|
167
|
+
layer,
|
|
168
|
+
coordinate: evt.coordinate,
|
|
169
|
+
event: evt,
|
|
170
|
+
});
|
|
171
|
+
test('calls hover callback functions', (done) => {
|
|
172
|
+
const layer = new Layer();
|
|
173
|
+
const goodFeatureInfo = getFeatureInfo(layer, [{ name: 'test' }]);
|
|
174
|
+
const fn = jest.fn();
|
|
175
|
+
const fn2 = jest.fn();
|
|
176
|
+
const spy = jest
|
|
177
|
+
.spyOn(layer, 'getFeatureInfoAtCoordinate')
|
|
178
|
+
.mockResolvedValue(goodFeatureInfo);
|
|
179
|
+
layer.onHover(fn);
|
|
180
|
+
layer.onHover(fn2);
|
|
181
|
+
layer.attachToMap({});
|
|
182
|
+
layer.onUserMoveCallback(evt).then((featureInfo) => {
|
|
183
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
184
|
+
expect(spy).toHaveBeenCalledWith(evt.coordinate);
|
|
185
|
+
expect(featureInfo).toBe(goodFeatureInfo);
|
|
186
|
+
expect(fn).toHaveBeenCalledTimes(1);
|
|
187
|
+
expect(fn.mock.calls[0][0]).toBe(goodFeatureInfo.features);
|
|
188
|
+
expect(fn.mock.calls[0][1]).toBe(goodFeatureInfo.layer);
|
|
189
|
+
expect(fn.mock.calls[0][2]).toBe(goodFeatureInfo.coordinate);
|
|
190
|
+
expect(fn2).toHaveBeenCalledTimes(1);
|
|
191
|
+
expect(fn2.mock.calls[0][0]).toBe(goodFeatureInfo.features);
|
|
192
|
+
expect(fn2.mock.calls[0][1]).toBe(goodFeatureInfo.layer);
|
|
193
|
+
expect(fn2.mock.calls[0][2]).toBe(goodFeatureInfo.coordinate);
|
|
194
|
+
done();
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
describe('returns empty feature info', () => {
|
|
198
|
+
test('if an error is thrown in hover callback', (done) => {
|
|
199
|
+
const layer = new Layer();
|
|
200
|
+
layer.onHover(() => {
|
|
201
|
+
throw new Error('foo');
|
|
202
|
+
});
|
|
203
|
+
jest
|
|
204
|
+
.spyOn(layer, 'getFeatureInfoAtCoordinate')
|
|
205
|
+
.mockResolvedValue(getFeatureInfo(layer, [{ name: 'test' }]));
|
|
206
|
+
layer.attachToMap({});
|
|
207
|
+
layer.onUserMoveCallback(evt).then((featureInfo) => {
|
|
208
|
+
expect(featureInfo).toEqual(getFeatureInfo(layer));
|
|
209
|
+
done();
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
});
|
package/common/styles/index.js
CHANGED
|
@@ -1,24 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.realtimeSimpleStyle = exports.realtimeDelayStyle = exports.realtimeDefaultStyle = void 0;
|
|
18
|
-
var realtimeDefaultStyle_1 = require("./realtimeDefaultStyle");
|
|
19
|
-
Object.defineProperty(exports, "realtimeDefaultStyle", { enumerable: true, get: function () { return realtimeDefaultStyle_1.default; } });
|
|
20
|
-
var realtimeDelayStyle_1 = require("./realtimeDelayStyle");
|
|
21
|
-
Object.defineProperty(exports, "realtimeDelayStyle", { enumerable: true, get: function () { return realtimeDelayStyle_1.default; } });
|
|
22
|
-
var realtimeSimpleStyle_1 = require("./realtimeSimpleStyle");
|
|
23
|
-
Object.defineProperty(exports, "realtimeSimpleStyle", { enumerable: true, get: function () { return realtimeSimpleStyle_1.default; } });
|
|
24
|
-
__exportStar(require("./realtimeDefaultStyle"), exports);
|
|
1
|
+
export { default as realtimeDefaultStyle } from './realtimeDefaultStyle';
|
|
2
|
+
export { default as realtimeDelayStyle } from './realtimeDelayStyle';
|
|
3
|
+
export { default as realtimeSimpleStyle } from './realtimeSimpleStyle';
|
|
4
|
+
export * from './realtimeDefaultStyle';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"realtimeDefaultStyle.d.ts","sourceRoot":"","sources":["../../../src/common/styles/realtimeDefaultStyle.js"],"names":[],"mappings":"AAUO,4EAeN;AAUM,2JA2BN;AAUM,0HAoCN;AAUM,6IAuCN;;AAKD;;;;;;;GAOG;AACH,
|
|
1
|
+
{"version":3,"file":"realtimeDefaultStyle.d.ts","sourceRoot":"","sources":["../../../src/common/styles/realtimeDefaultStyle.js"],"names":[],"mappings":"AAUO,4EAeN;AAUM,2JA2BN;AAUM,0HAoCN;AAUM,6IAuCN;;AAKD;;;;;;;GAOG;AACH,0FA8LC"}
|