mobility-toolbox-js 2.0.0-beta.33 → 2.0.0-beta.34
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.js +640 -0
- package/api/RoutingAPI.js +65 -0
- package/api/StopsAPI.js +70 -0
- package/api/index.js +10 -0
- package/api/typedefs.js +72 -0
- package/common/api/HttpAPI.d.ts +2 -2
- package/common/api/HttpAPI.d.ts.map +1 -1
- package/common/api/HttpAPI.js +84 -0
- package/common/api/WebSocketAPI.js +320 -0
- package/common/controls/Control.js +170 -0
- package/common/index.js +18 -0
- package/common/layers/Layer.js +257 -0
- package/common/mixins/CopyrightMixin.js +72 -0
- package/common/mixins/MapboxLayerMixin.js +240 -0
- package/common/mixins/RealtimeLayerMixin.js +705 -0
- package/common/mixins/StopFinderMixin.js +198 -0
- package/common/mixins/UserInteractionsLayerMixin.js +225 -0
- package/common/styles/index.js +24 -0
- package/common/styles/realtimeDefaultStyle.js +248 -0
- package/common/styles/realtimeDelayStyle.js +26 -0
- package/common/styles/realtimeSimpleStyle.js +24 -0
- package/common/typedefs.js +21 -0
- package/common/utils/cleanStopTime.js +30 -0
- package/common/utils/compareDepartures.js +37 -0
- package/common/utils/createCanvas.js +29 -0
- package/common/utils/createTrackerFilters.js +77 -0
- package/common/utils/getLayersAsFlatArray.js +16 -0
- package/common/utils/getMapboxMapCopyrights.js +26 -0
- package/common/utils/getMapboxRender.js +77 -0
- package/common/utils/getMaplibreRender.js +38 -0
- package/common/utils/getRealtimeModeSuffix.js +11 -0
- package/common/utils/getUrlWithParams.js +21 -0
- package/common/utils/getVehiclePosition.js +66 -0
- package/common/utils/index.js +37 -0
- package/common/utils/removeDuplicate.js +30 -0
- package/common/utils/renderTrajectories.js +119 -0
- package/common/utils/sortByDelay.js +22 -0
- package/common/utils/timeUtils.js +49 -0
- package/common/utils/trackerConfig.js +182 -0
- package/iife.js +7 -0
- package/index.js +11 -0
- package/mapbox/controls/CopyrightControl.js +73 -0
- package/mapbox/controls/index.js +6 -0
- package/mapbox/index.js +20 -0
- package/mapbox/layers/Layer.js +139 -0
- package/mapbox/layers/RealtimeLayer.js +312 -0
- package/mapbox/layers/index.js +7 -0
- package/mapbox/utils.js +57 -0
- package/mbt.js.map +2 -2
- package/mbt.min.js.map +2 -2
- package/ol/controls/CopyrightControl.js +90 -0
- package/ol/controls/RoutingControl.js +683 -0
- package/ol/controls/StopFinderControl.js +59 -0
- package/ol/controls/index.js +9 -0
- package/ol/index.js +21 -0
- package/ol/layers/Layer.js +180 -0
- package/ol/layers/MapboxLayer.js +137 -0
- package/ol/layers/MapboxStyleLayer.js +383 -0
- package/ol/layers/MaplibreLayer.js +69 -0
- package/ol/layers/RealtimeLayer.js +330 -0
- package/ol/layers/RoutingLayer.js +116 -0
- package/ol/layers/VectorLayer.js +72 -0
- package/ol/layers/WMSLayer.js +106 -0
- package/ol/layers/index.js +19 -0
- package/ol/styles/fullTrajectoryDelayStyle.js +35 -0
- package/ol/styles/fullTrajectoryStyle.js +46 -0
- package/ol/styles/index.js +7 -0
- package/package.json +1 -1
- package/setupTests.js +15 -0
|
@@ -0,0 +1,198 @@
|
|
|
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
|
+
var __assign = (this && this.__assign) || function () {
|
|
18
|
+
__assign = Object.assign || function(t) {
|
|
19
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
+
s = arguments[i];
|
|
21
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
+
t[p] = s[p];
|
|
23
|
+
}
|
|
24
|
+
return t;
|
|
25
|
+
};
|
|
26
|
+
return __assign.apply(this, arguments);
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.StopFinderInterface = void 0;
|
|
30
|
+
/* eslint-disable no-empty-function */
|
|
31
|
+
/* eslint-disable no-useless-constructor */
|
|
32
|
+
/* eslint-disable class-methods-use-this */
|
|
33
|
+
/* eslint-disable max-classes-per-file */
|
|
34
|
+
var api_1 = require("../../api");
|
|
35
|
+
/**
|
|
36
|
+
* StopFinder control interface.
|
|
37
|
+
*
|
|
38
|
+
* @classproperty {StopsSearchParams} apiParams - Default request parameters used by the search method. See [Stops service documentation](https://developer.geops.io/apis/5dcbd702a256d90001cf1361/).
|
|
39
|
+
*/
|
|
40
|
+
var StopFinderInterface = /** @class */ (function () {
|
|
41
|
+
/**
|
|
42
|
+
* Constructor.
|
|
43
|
+
*
|
|
44
|
+
* @param {Object} options Map options
|
|
45
|
+
* @param {string} options.apiKey Access key for [geOps services](https://developer.geops.io/). See StopsAPI.
|
|
46
|
+
* @param {string} [options.url='https://api.geops.io/tracker/v1'] Stops service url. See StopsAPI.
|
|
47
|
+
* @param {string} [options.placeholder='Search for a stop...'] Input field placeholder.
|
|
48
|
+
* @param {StopsSearchParams} [options.apiParams={ limit: 20 }] Request parameters. See [Stops service documentation](https://developer.geops.io/apis/5dcbd702a256d90001cf1361/).
|
|
49
|
+
*/
|
|
50
|
+
// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-useless-constructor, @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function
|
|
51
|
+
function StopFinderInterface(options) {
|
|
52
|
+
if (options === void 0) { options = {}; }
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Launch a search.
|
|
56
|
+
*
|
|
57
|
+
* @param {String} query The query to search for.
|
|
58
|
+
* @param {AbortController} abortController Abort controller used to cancel the request.
|
|
59
|
+
* @return {Promise<Array<GeoJSONFeature>>} An array of GeoJSON features with coordinates in [EPSG:4326](http://epsg.io/4326).
|
|
60
|
+
*/
|
|
61
|
+
// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
|
|
62
|
+
StopFinderInterface.prototype.search = function (query, abortController) { };
|
|
63
|
+
return StopFinderInterface;
|
|
64
|
+
}());
|
|
65
|
+
exports.StopFinderInterface = StopFinderInterface;
|
|
66
|
+
/**
|
|
67
|
+
* Mixin for StopFinderInterface.
|
|
68
|
+
*
|
|
69
|
+
* @param {Class} Base A class to extend with {StopFinderInterface} functionnalities.
|
|
70
|
+
* @return {Class} A class that implements <StopFinderInterface> class and extends Base;
|
|
71
|
+
* @private
|
|
72
|
+
*/
|
|
73
|
+
var StopFinderMixin = function (Base) {
|
|
74
|
+
return /** @class */ (function (_super) {
|
|
75
|
+
__extends(class_1, _super);
|
|
76
|
+
function class_1(options) {
|
|
77
|
+
if (options === void 0) { options = {}; }
|
|
78
|
+
var _this = _super.call(this, options) || this;
|
|
79
|
+
var apiParams = options.apiParams, apiKey = options.apiKey, url = options.url;
|
|
80
|
+
_this.apiParams = __assign({ limit: 20 }, (apiParams || {}));
|
|
81
|
+
_this.placeholder = options.placeholder || 'Search for a stop...';
|
|
82
|
+
var apiOptions = { apiKey: apiKey };
|
|
83
|
+
if (url) {
|
|
84
|
+
apiOptions.url = url;
|
|
85
|
+
}
|
|
86
|
+
_this.api = new api_1.StopsAPI(apiOptions);
|
|
87
|
+
_this.abortController = new AbortController();
|
|
88
|
+
return _this;
|
|
89
|
+
}
|
|
90
|
+
class_1.prototype.render = function (featureCollection) {
|
|
91
|
+
var _this = this;
|
|
92
|
+
var suggestions = (featureCollection === null || featureCollection === void 0 ? void 0 : featureCollection.features) || [];
|
|
93
|
+
if (!this.suggestionsElt) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
this.suggestionsElt.style.display = suggestions.length ? 'block' : 'none';
|
|
97
|
+
this.suggestionsElt.innerHTML = '';
|
|
98
|
+
suggestions.forEach(function (suggestion) {
|
|
99
|
+
var properties = suggestion.properties;
|
|
100
|
+
var suggElt = document.createElement('div');
|
|
101
|
+
suggElt.innerHTML = properties.name;
|
|
102
|
+
suggElt.onclick = function () {
|
|
103
|
+
_this.onSuggestionClick(suggestion);
|
|
104
|
+
};
|
|
105
|
+
Object.assign(suggElt.style, {
|
|
106
|
+
padding: '5px 12px',
|
|
107
|
+
});
|
|
108
|
+
_this.suggestionsElt.appendChild(suggElt);
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
class_1.prototype.createDefaultElement = function () {
|
|
112
|
+
var _this = this;
|
|
113
|
+
/**
|
|
114
|
+
* Define a default element.
|
|
115
|
+
*/
|
|
116
|
+
this.element = document.createElement('div');
|
|
117
|
+
this.element.id = 'mbt-search';
|
|
118
|
+
Object.assign(this.element.style, {
|
|
119
|
+
position: 'absolute',
|
|
120
|
+
top: 0,
|
|
121
|
+
left: '50px',
|
|
122
|
+
margin: '10px',
|
|
123
|
+
display: 'flex',
|
|
124
|
+
flexDirection: 'column',
|
|
125
|
+
width: '320px',
|
|
126
|
+
});
|
|
127
|
+
// Create input element
|
|
128
|
+
this.inputElt = document.createElement('input');
|
|
129
|
+
this.inputElt.type = 'text';
|
|
130
|
+
this.inputElt.placeholder = this.placeholder;
|
|
131
|
+
this.inputElt.autoComplete = 'off';
|
|
132
|
+
this.inputElt.onkeyup = function (evt) {
|
|
133
|
+
_this.abortController.abort();
|
|
134
|
+
_this.abortController = new AbortController();
|
|
135
|
+
_this.search(evt.target.value, _this.abortController);
|
|
136
|
+
};
|
|
137
|
+
Object.assign(this.inputElt.style, {
|
|
138
|
+
padding: '10px 30px 10px 10px',
|
|
139
|
+
});
|
|
140
|
+
this.element.appendChild(this.inputElt);
|
|
141
|
+
// Create suggestions list element
|
|
142
|
+
this.suggestionsElt = document.createElement('div');
|
|
143
|
+
Object.assign(this.suggestionsElt.style, {
|
|
144
|
+
backgroundColor: 'white',
|
|
145
|
+
overflowY: 'auto',
|
|
146
|
+
cursor: 'pointer',
|
|
147
|
+
});
|
|
148
|
+
this.element.appendChild(this.suggestionsElt);
|
|
149
|
+
this.clearElt = document.createElement('div');
|
|
150
|
+
Object.assign(this.clearElt.style, {
|
|
151
|
+
display: 'none',
|
|
152
|
+
position: 'absolute',
|
|
153
|
+
right: '0',
|
|
154
|
+
padding: '0 10px',
|
|
155
|
+
fontSize: '200%',
|
|
156
|
+
cursor: 'pointer',
|
|
157
|
+
});
|
|
158
|
+
this.clearElt.innerHTML = '×';
|
|
159
|
+
this.clearElt.onclick = function () { return _this.clear(); };
|
|
160
|
+
this.element.appendChild(this.clearElt);
|
|
161
|
+
};
|
|
162
|
+
class_1.prototype.search = function (q, abortController) {
|
|
163
|
+
var _this = this;
|
|
164
|
+
if (q !== undefined || q !== null) {
|
|
165
|
+
this.apiParams.q = q;
|
|
166
|
+
}
|
|
167
|
+
if (this.clearElt) {
|
|
168
|
+
this.clearElt.style.display = 'block';
|
|
169
|
+
}
|
|
170
|
+
return this.api
|
|
171
|
+
.search(this.apiParams, abortController)
|
|
172
|
+
.then(function (data) {
|
|
173
|
+
_this.render(data);
|
|
174
|
+
})
|
|
175
|
+
.catch(function () {
|
|
176
|
+
_this.render();
|
|
177
|
+
});
|
|
178
|
+
};
|
|
179
|
+
/**
|
|
180
|
+
* To be defined in inherited class
|
|
181
|
+
*/
|
|
182
|
+
// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
|
|
183
|
+
class_1.prototype.onSuggestionClick = function (suggestion) { };
|
|
184
|
+
/**
|
|
185
|
+
* Clear the search field and close the control.
|
|
186
|
+
*/
|
|
187
|
+
class_1.prototype.clear = function () {
|
|
188
|
+
if (!this.suggestionsElt) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
this.inputElt.value = '';
|
|
192
|
+
this.suggestionsElt.innerHTML = '';
|
|
193
|
+
this.clearElt.style.display = 'none';
|
|
194
|
+
};
|
|
195
|
+
return class_1;
|
|
196
|
+
}(Base));
|
|
197
|
+
};
|
|
198
|
+
exports.default = StopFinderMixin;
|
|
@@ -0,0 +1,225 @@
|
|
|
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
|
+
/* eslint-disable no-empty-function,@typescript-eslint/no-empty-function */
|
|
20
|
+
/* eslint-disable no-useless-constructor,@typescript-eslint/no-useless-constructor */
|
|
21
|
+
/* eslint-disable no-unused-vars,@typescript-eslint/no-unused-vars */
|
|
22
|
+
/* eslint-disable class-methods-use-this */
|
|
23
|
+
/* eslint-disable max-classes-per-file */
|
|
24
|
+
var proj_1 = require("ol/proj");
|
|
25
|
+
var Observable_1 = require("ol/Observable");
|
|
26
|
+
/**
|
|
27
|
+
* UserInteractionsLayerInterface.
|
|
28
|
+
*/
|
|
29
|
+
var UserInteractionsLayerInterface = /** @class */ (function () {
|
|
30
|
+
/*
|
|
31
|
+
* Constructor
|
|
32
|
+
|
|
33
|
+
* @param {Object} options Layer options.
|
|
34
|
+
* @param {string} options.userInteractions If true, it listens for user mouse hover and click event.
|
|
35
|
+
* @param {string} options.userClickInteractions If true, it listens for user click event.
|
|
36
|
+
* @param {string} options.userHoverInteractions If true, it listens for user mouse over event.
|
|
37
|
+
* @param {string} options.defaultUserInteractions If true, it adds default listeners for user mouse hover and click event.
|
|
38
|
+
*/
|
|
39
|
+
function UserInteractionsLayerInterface(options) {
|
|
40
|
+
if (options === void 0) { options = {}; }
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Initialize the layer adding user interactions.
|
|
44
|
+
*
|
|
45
|
+
* @param {ol/Map~Map} map
|
|
46
|
+
*/
|
|
47
|
+
UserInteractionsLayerInterface.prototype.attachToMap = function (map) { };
|
|
48
|
+
/**
|
|
49
|
+
* Terminate the layer unsubscribing user interactions.
|
|
50
|
+
*/
|
|
51
|
+
UserInteractionsLayerInterface.prototype.detachFromMap = function () { };
|
|
52
|
+
/**
|
|
53
|
+
* Activate map listeners events.
|
|
54
|
+
*/
|
|
55
|
+
UserInteractionsLayerInterface.prototype.activateUserInteractions = function () { };
|
|
56
|
+
/**
|
|
57
|
+
* Deactivaet map listeners events.
|
|
58
|
+
*/
|
|
59
|
+
UserInteractionsLayerInterface.prototype.deactivateUserInteractions = function () { };
|
|
60
|
+
/**
|
|
61
|
+
* Terminate the layer unsubscribing user interactions.
|
|
62
|
+
*/
|
|
63
|
+
UserInteractionsLayerInterface.prototype.onClick = function (callback) { };
|
|
64
|
+
/**
|
|
65
|
+
* Terminate the layer unsubscribing user interactions.
|
|
66
|
+
*/
|
|
67
|
+
UserInteractionsLayerInterface.prototype.onHover = function (callback) { };
|
|
68
|
+
return UserInteractionsLayerInterface;
|
|
69
|
+
}());
|
|
70
|
+
exports.UserInteractionsLayerInterface = UserInteractionsLayerInterface;
|
|
71
|
+
/**
|
|
72
|
+
* Mixin for UserInteractionsLayerInterface. It provide onClick and onHover functions.
|
|
73
|
+
*
|
|
74
|
+
* @param {Class} Base A class to extend with {UserInteractionsLayerInterface} functionnalities.
|
|
75
|
+
* @return {Class} A class that implements {UserInteractionsLayerInterface} class and extends Base;
|
|
76
|
+
* @private
|
|
77
|
+
*/
|
|
78
|
+
var UserInteractionsLayerMixin = function (Base) {
|
|
79
|
+
return /** @class */ (function (_super) {
|
|
80
|
+
__extends(class_1, _super);
|
|
81
|
+
function class_1(options) {
|
|
82
|
+
if (options === void 0) { options = {}; }
|
|
83
|
+
var _this = _super.call(this, options) || this;
|
|
84
|
+
var _a = options.userInteractions, userInteractions = _a === void 0 ? true : _a, _b = options.userClickInteractions, userClickInteractions = _b === void 0 ? true : _b, _c = options.userHoverInteractions, userHoverInteractions = _c === void 0 ? true : _c, _d = options.defaultUserInteractions, defaultUserInteractions = _d === void 0 ? true : _d;
|
|
85
|
+
_this.userInteractions = userInteractions;
|
|
86
|
+
_this.userClickInteractions = userClickInteractions;
|
|
87
|
+
_this.userHoverInteractions = userHoverInteractions;
|
|
88
|
+
_this.defaultUserInteractions = defaultUserInteractions;
|
|
89
|
+
_this.userClickCallbacks = [];
|
|
90
|
+
_this.userHoverCallbacks = [];
|
|
91
|
+
_this.userClickEventsKeys = [];
|
|
92
|
+
_this.userHoverEventsKeys = [];
|
|
93
|
+
_this.onUserClickCallback = _this.onUserClickCallback.bind(_this);
|
|
94
|
+
_this.onUserMoveCallback = _this.onUserMoveCallback.bind(_this);
|
|
95
|
+
// Add mouse event callbacks
|
|
96
|
+
var onClick = options.onClick, onHover = options.onHover;
|
|
97
|
+
if (_this.userInteractions && _this.userClickInteractions && onClick) {
|
|
98
|
+
_this.onClick(onClick);
|
|
99
|
+
}
|
|
100
|
+
if (_this.userInteractions && _this.userHoverInteractions && onHover) {
|
|
101
|
+
_this.onHover(onHover);
|
|
102
|
+
}
|
|
103
|
+
return _this;
|
|
104
|
+
}
|
|
105
|
+
class_1.prototype.attachToMap = function (map, options) {
|
|
106
|
+
_super.prototype.attachToMap.call(this, map, options);
|
|
107
|
+
if (this.userInteractions &&
|
|
108
|
+
this.defaultUserInteractions &&
|
|
109
|
+
this.userClickInteractions &&
|
|
110
|
+
this.onFeatureClick) {
|
|
111
|
+
this.onClick(this.onFeatureClick);
|
|
112
|
+
}
|
|
113
|
+
if (this.userInteractions &&
|
|
114
|
+
this.defaultUserInteractions &&
|
|
115
|
+
this.userHoverInteractions &&
|
|
116
|
+
this.onFeatureHover) {
|
|
117
|
+
this.onHover(this.onFeatureHover);
|
|
118
|
+
}
|
|
119
|
+
this.listenEvents();
|
|
120
|
+
};
|
|
121
|
+
class_1.prototype.detachFromMap = function () {
|
|
122
|
+
this.unlistenEvents();
|
|
123
|
+
_super.prototype.detachFromMap.call(this);
|
|
124
|
+
};
|
|
125
|
+
class_1.prototype.listenEvents = function () {
|
|
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
|
+
}));
|
|
139
|
+
});
|
|
140
|
+
};
|
|
141
|
+
class_1.prototype.unlistenEvents = function () {
|
|
142
|
+
(0, Observable_1.unByKey)(this.userClickEventsKeys);
|
|
143
|
+
(0, Observable_1.unByKey)(this.userHoverEventsKeys);
|
|
144
|
+
this.userClickEventsKeys = [];
|
|
145
|
+
this.userHoverEventsKeys = [];
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* Listens to click events on the layer.
|
|
149
|
+
* @param {function} callback Callback function, called with the clicked
|
|
150
|
+
* features,
|
|
151
|
+
* the layer instance and the click event.
|
|
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));
|
|
224
|
+
};
|
|
225
|
+
exports.default = UserInteractionsLayerMixin;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
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);
|