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,139 @@
|
|
|
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
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
29
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
30
|
+
if (ar || !(i in from)) {
|
|
31
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
32
|
+
ar[i] = from[i];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
var Observable_1 = require("ol/Observable");
|
|
39
|
+
var proj_1 = require("ol/proj");
|
|
40
|
+
var Layer_1 = require("../../common/layers/Layer");
|
|
41
|
+
var UserInteractionsLayerMixin_1 = require("../../common/mixins/UserInteractionsLayerMixin");
|
|
42
|
+
/**
|
|
43
|
+
* A class representing a layer to display on an OpenLayers map.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* import { Layer } from 'mobility-toolbox-js/ol';
|
|
47
|
+
*
|
|
48
|
+
* const layer = new Layer({
|
|
49
|
+
* olLayer: ...,
|
|
50
|
+
* });
|
|
51
|
+
*
|
|
52
|
+
* @see <a href="/example/ol-map">Map example</a>
|
|
53
|
+
*
|
|
54
|
+
* @classproperty {ol/Map~Map} map - The map where the layer is displayed.
|
|
55
|
+
* @extends {Layer}
|
|
56
|
+
*/
|
|
57
|
+
var Layer = /** @class */ (function (_super) {
|
|
58
|
+
__extends(Layer, _super);
|
|
59
|
+
function Layer() {
|
|
60
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Initialize the layer and listen to user events.
|
|
64
|
+
* @param {ol/Map~Map} map
|
|
65
|
+
*/
|
|
66
|
+
Layer.prototype.attachToMap = function (map) {
|
|
67
|
+
_super.prototype.attachToMap.call(this, map);
|
|
68
|
+
if (!this.map) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (this.userInteractions) {
|
|
72
|
+
this.toggleVisibleListeners();
|
|
73
|
+
this.onChangeVisibleKey = this.on('change:visible', this.toggleVisibleListeners);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
Layer.prototype.detachFromMap = function () {
|
|
77
|
+
if (this.map) {
|
|
78
|
+
this.deactivateUserInteractions();
|
|
79
|
+
(0, Observable_1.unByKey)(this.onChangeVisibleKey);
|
|
80
|
+
}
|
|
81
|
+
_super.prototype.detachFromMap.call(this);
|
|
82
|
+
};
|
|
83
|
+
Layer.prototype.activateUserInteractions = function () {
|
|
84
|
+
this.deactivateUserInteractions();
|
|
85
|
+
if (this.map &&
|
|
86
|
+
this.userInteractions &&
|
|
87
|
+
this.userClickInteractions &&
|
|
88
|
+
this.userClickCallbacks.length) {
|
|
89
|
+
this.map.on('click', this.onUserClickCallback);
|
|
90
|
+
}
|
|
91
|
+
if (this.map &&
|
|
92
|
+
this.userInteractions &&
|
|
93
|
+
this.userHoverInteractions &&
|
|
94
|
+
this.userHoverCallbacks.length) {
|
|
95
|
+
this.map.on('mousemove', this.onUserMoveCallback);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
Layer.prototype.deactivateUserInteractions = function () {
|
|
99
|
+
if (this.map) {
|
|
100
|
+
this.map.off('mousemove', this.onUserMoveCallback);
|
|
101
|
+
this.map.off('click', this.onUserClickCallback);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Toggle listeners needed when a layer is avisible or not.
|
|
106
|
+
* @private
|
|
107
|
+
*/
|
|
108
|
+
Layer.prototype.toggleVisibleListeners = function () {
|
|
109
|
+
if (this.visible) {
|
|
110
|
+
this.activateUserInteractions();
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
this.deactivateUserInteractions();
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Returns the current extent in mercator coordinates.
|
|
118
|
+
*/
|
|
119
|
+
Layer.prototype.getMercatorExtent = function () {
|
|
120
|
+
var bounds = this.map.getBounds().toArray();
|
|
121
|
+
return (0, proj_1.transformExtent)(__spreadArray(__spreadArray([], bounds[0], true), bounds[1], true), 'EPSG:4326', 'EPSG:3857');
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* Returns the equivalent zoom in Openlayers.
|
|
125
|
+
*/
|
|
126
|
+
Layer.prototype.getOlZoom = function () {
|
|
127
|
+
return this.map.getZoom() + 1;
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* Create a copy of the Layer.
|
|
131
|
+
* @param {Object} newOptions Options to override
|
|
132
|
+
* @return {Layer} A Layer
|
|
133
|
+
*/
|
|
134
|
+
Layer.prototype.clone = function (newOptions) {
|
|
135
|
+
return new Layer(__assign(__assign({}, this.options), newOptions));
|
|
136
|
+
};
|
|
137
|
+
return Layer;
|
|
138
|
+
}((0, UserInteractionsLayerMixin_1.default)(Layer_1.default)));
|
|
139
|
+
exports.default = Layer;
|
|
@@ -0,0 +1,312 @@
|
|
|
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
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
29
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
30
|
+
if (ar || !(i in from)) {
|
|
31
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
32
|
+
ar[i] = from[i];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
var proj_1 = require("ol/proj");
|
|
39
|
+
var Observable_1 = require("ol/Observable");
|
|
40
|
+
var extent_1 = require("ol/extent");
|
|
41
|
+
var transform_rotate_1 = require("@turf/transform-rotate");
|
|
42
|
+
var helpers_1 = require("@turf/helpers");
|
|
43
|
+
var RealtimeLayerMixin_1 = require("../../common/mixins/RealtimeLayerMixin");
|
|
44
|
+
var Layer_1 = require("./Layer");
|
|
45
|
+
var utils_1 = require("../utils");
|
|
46
|
+
/**
|
|
47
|
+
* Responsible for loading and display data from a Realtime service.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* import { RealtimeLayer } from 'mobility-toolbox-js/mapbox';
|
|
51
|
+
*
|
|
52
|
+
* const layer = new RealtimeLayer({
|
|
53
|
+
* url: [yourUrl],
|
|
54
|
+
* apiKey: [yourApiKey],
|
|
55
|
+
* });
|
|
56
|
+
*
|
|
57
|
+
*
|
|
58
|
+
* @see <a href="/api/class/src/api/RealtimeAPI%20js~RealtimeAPI%20html">RealtimeAPI</a>
|
|
59
|
+
*
|
|
60
|
+
* @extends {Layer}
|
|
61
|
+
* @implements {RealtimeLayerInterface}
|
|
62
|
+
*/
|
|
63
|
+
var RealtimeLayer = /** @class */ (function (_super) {
|
|
64
|
+
__extends(RealtimeLayer, _super);
|
|
65
|
+
function RealtimeLayer(options) {
|
|
66
|
+
if (options === void 0) { options = {}; }
|
|
67
|
+
var _this = _super.call(this, __assign({}, options)) || this;
|
|
68
|
+
/** @ignore */
|
|
69
|
+
_this.onLoad = _this.onLoad.bind(_this);
|
|
70
|
+
/** @ignore */
|
|
71
|
+
_this.onMove = _this.onMove.bind(_this);
|
|
72
|
+
/** @ignore */
|
|
73
|
+
_this.onMoveEnd = _this.onMoveEnd.bind(_this);
|
|
74
|
+
/** @ignore */
|
|
75
|
+
_this.onZoomEnd = _this.onZoomEnd.bind(_this);
|
|
76
|
+
/** @ignore */
|
|
77
|
+
_this.onVisibilityChange = _this.onVisibilityChange.bind(_this);
|
|
78
|
+
return _this;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Initialize the layer.
|
|
82
|
+
*
|
|
83
|
+
* @param {mapboxgl.Map} map A [mapbox Map](https://docs.mapbox.com/mapbox-gl-js/api/map/).
|
|
84
|
+
* @param {string} beforeId Layer's id before which we want to add the new layer.
|
|
85
|
+
* @override
|
|
86
|
+
*/
|
|
87
|
+
RealtimeLayer.prototype.attachToMap = function (map, beforeId) {
|
|
88
|
+
if (!map) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
var canvas = map.getCanvas();
|
|
92
|
+
_super.prototype.attachToMap.call(this, map, {
|
|
93
|
+
width: canvas.width / this.pixelRatio,
|
|
94
|
+
height: canvas.height / this.pixelRatio,
|
|
95
|
+
});
|
|
96
|
+
this.source = {
|
|
97
|
+
type: 'canvas',
|
|
98
|
+
canvas: this.canvas,
|
|
99
|
+
coordinates: (0, utils_1.getSourceCoordinates)(map, this.pixelRatio),
|
|
100
|
+
// Set to true if the canvas source is animated. If the canvas is static, animate should be set to false to improve performance.
|
|
101
|
+
animate: true,
|
|
102
|
+
attribution: this.copyrights && this.copyrights.join(', '),
|
|
103
|
+
};
|
|
104
|
+
this.beforeId = beforeId;
|
|
105
|
+
this.layer = {
|
|
106
|
+
id: this.key,
|
|
107
|
+
type: 'raster',
|
|
108
|
+
source: this.key,
|
|
109
|
+
layout: {
|
|
110
|
+
visibility: this.visible ? 'visible' : 'none',
|
|
111
|
+
},
|
|
112
|
+
paint: {
|
|
113
|
+
'raster-opacity': 1,
|
|
114
|
+
'raster-fade-duration': 0,
|
|
115
|
+
'raster-resampling': 'nearest', // important otherwise it looks blurry
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
if (map.isStyleLoaded()) {
|
|
119
|
+
this.onLoad();
|
|
120
|
+
}
|
|
121
|
+
this.map.on('load', this.onLoad);
|
|
122
|
+
this.listeners = [this.on('change:visible', this.onVisibilityChange)];
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* Remove listeners from the Mapbox Map.
|
|
126
|
+
*/
|
|
127
|
+
RealtimeLayer.prototype.detachFromMap = function () {
|
|
128
|
+
if (this.map) {
|
|
129
|
+
this.map.off('load', this.onLoad);
|
|
130
|
+
this.listeners.forEach(function (listener) {
|
|
131
|
+
(0, Observable_1.unByKey)(listener);
|
|
132
|
+
});
|
|
133
|
+
if (this.map.style && this.map.getLayer(this.key)) {
|
|
134
|
+
this.map.removeLayer(this.key);
|
|
135
|
+
}
|
|
136
|
+
if (this.map.style && this.map.getSource(this.key)) {
|
|
137
|
+
this.map.removeSource(this.key);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
_super.prototype.detachFromMap.call(this);
|
|
141
|
+
};
|
|
142
|
+
/**
|
|
143
|
+
* Start updating vehicles position.
|
|
144
|
+
*
|
|
145
|
+
* @listens {mapboxgl.map.event:zoomend} Listen to zoom end event.
|
|
146
|
+
* @listens {mapboxgl.map.event:mousemove} Listen to mousemove end.
|
|
147
|
+
* @override
|
|
148
|
+
*/
|
|
149
|
+
RealtimeLayer.prototype.start = function () {
|
|
150
|
+
_super.prototype.start.call(this);
|
|
151
|
+
this.map.on('move', this.onMove);
|
|
152
|
+
this.map.on('moveend', this.onMoveEnd);
|
|
153
|
+
this.map.on('zoomend', this.onZoomEnd);
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* Stop updating vehicles position, and unlisten events.
|
|
157
|
+
*
|
|
158
|
+
* @override
|
|
159
|
+
*/
|
|
160
|
+
RealtimeLayer.prototype.stop = function () {
|
|
161
|
+
_super.prototype.stop.call(this);
|
|
162
|
+
if (this.map) {
|
|
163
|
+
this.map.off('move', this.onMove);
|
|
164
|
+
this.map.off('moveend', this.onMoveEnd);
|
|
165
|
+
this.map.off('zoomend', this.onZoomEnd);
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
RealtimeLayer.prototype.onLoad = function () {
|
|
169
|
+
if (!this.map.getSource(this.key)) {
|
|
170
|
+
this.map.addSource(this.key, this.source);
|
|
171
|
+
}
|
|
172
|
+
if (!this.map.getLayer(this.key)) {
|
|
173
|
+
this.map.addLayer(this.layer, this.beforeId);
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
/**
|
|
177
|
+
* Function triggered when the user moves the cursor over the map.
|
|
178
|
+
* @override
|
|
179
|
+
*/
|
|
180
|
+
RealtimeLayer.prototype.onUserMoveCallback = function (evt) {
|
|
181
|
+
_super.prototype.onUserMoveCallback.call(this, __assign({ coordinate: (0, proj_1.fromLonLat)(evt.lngLat.toArray()) }, evt));
|
|
182
|
+
};
|
|
183
|
+
/**
|
|
184
|
+
* Render the trajectories using current map's size, resolution and rotation.
|
|
185
|
+
* @param {boolean} noInterpolate if true, renders the vehicles without interpolating theirs positions.
|
|
186
|
+
* @overrides
|
|
187
|
+
*/
|
|
188
|
+
RealtimeLayer.prototype.renderTrajectories = function (noInterpolate) {
|
|
189
|
+
if (!this.map) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
var _a = this.map.getCanvas(), width = _a.width, height = _a.height;
|
|
193
|
+
var center = this.map.getCenter();
|
|
194
|
+
// We use turf here to have good transform.
|
|
195
|
+
var leftBottom = this.map.unproject({
|
|
196
|
+
x: 0,
|
|
197
|
+
y: height / this.pixelRatio,
|
|
198
|
+
}); // southWest
|
|
199
|
+
var rightTop = this.map.unproject({ x: width / this.pixelRatio, y: 0 }); // north east
|
|
200
|
+
var coord0 = (0, transform_rotate_1.default)((0, helpers_1.point)([leftBottom.lng, leftBottom.lat]), -this.map.getBearing(), {
|
|
201
|
+
pivot: [center.lng, center.lat],
|
|
202
|
+
}).geometry.coordinates;
|
|
203
|
+
var coord1 = (0, transform_rotate_1.default)((0, helpers_1.point)([rightTop.lng, rightTop.lat]), -this.map.getBearing(), {
|
|
204
|
+
pivot: [center.lng, center.lat],
|
|
205
|
+
}).geometry.coordinates;
|
|
206
|
+
var bounds = __spreadArray(__spreadArray([], (0, proj_1.fromLonLat)(coord0), true), (0, proj_1.fromLonLat)(coord1), true);
|
|
207
|
+
var xResolution = (0, extent_1.getWidth)(bounds) / (width / this.pixelRatio);
|
|
208
|
+
var yResolution = (0, extent_1.getHeight)(bounds) / (height / this.pixelRatio);
|
|
209
|
+
var res = Math.max(xResolution, yResolution);
|
|
210
|
+
// Coordinate of trajectories are in mercator so we have to pass the proper resolution and center in mercator.
|
|
211
|
+
var viewState = {
|
|
212
|
+
size: [width / this.pixelRatio, height / this.pixelRatio],
|
|
213
|
+
center: (0, proj_1.fromLonLat)([center.lng, center.lat]),
|
|
214
|
+
extent: bounds,
|
|
215
|
+
resolution: res,
|
|
216
|
+
zoom: this.map.getZoom(),
|
|
217
|
+
rotation: -(this.map.getBearing() * Math.PI) / 180,
|
|
218
|
+
pixelRatio: this.pixelRatio,
|
|
219
|
+
};
|
|
220
|
+
_super.prototype.renderTrajectories.call(this, viewState, noInterpolate);
|
|
221
|
+
};
|
|
222
|
+
/**
|
|
223
|
+
* Return the delay in ms before the next rendering.
|
|
224
|
+
*/
|
|
225
|
+
RealtimeLayer.prototype.getRefreshTimeInMs = function () {
|
|
226
|
+
return _super.prototype.getRefreshTimeInMs.call(this, this.map.getZoom());
|
|
227
|
+
};
|
|
228
|
+
RealtimeLayer.prototype.getFeatureInfoAtCoordinate = function (coordinate, options) {
|
|
229
|
+
if (options === void 0) { options = {}; }
|
|
230
|
+
var resolution = (0, utils_1.getMercatorResolution)(this.map);
|
|
231
|
+
return _super.prototype.getFeatureInfoAtCoordinate.call(this, coordinate, __assign({ resolution: resolution }, options));
|
|
232
|
+
};
|
|
233
|
+
RealtimeLayer.prototype.onVisibilityChange = function () {
|
|
234
|
+
if (this.visible && !this.map.getLayer(this.key)) {
|
|
235
|
+
this.map.addLayer(this.layer, this.beforeId);
|
|
236
|
+
}
|
|
237
|
+
else if (this.map.getLayer(this.key)) {
|
|
238
|
+
this.map.removeLayer(this.key);
|
|
239
|
+
}
|
|
240
|
+
// We can't use setLayoutProperty it triggers an error probably a bug in mapbox
|
|
241
|
+
// this.map.setLayoutProperty(
|
|
242
|
+
// this.key,
|
|
243
|
+
// 'visibilty',
|
|
244
|
+
// this.visible ? 'visible' : 'none',
|
|
245
|
+
// );
|
|
246
|
+
};
|
|
247
|
+
/**
|
|
248
|
+
* Remove the trajectory form the list if necessary.
|
|
249
|
+
*
|
|
250
|
+
* @private
|
|
251
|
+
*/
|
|
252
|
+
RealtimeLayer.prototype.purgeTrajectory = function (trajectory, extent, zoom) {
|
|
253
|
+
return _super.prototype.purgeTrajectory.call(this, trajectory, extent || this.getMercatorExtent(), zoom || Math.floor(this.map.getZoom() + 1));
|
|
254
|
+
};
|
|
255
|
+
/**
|
|
256
|
+
* Send the current bbox to the websocket
|
|
257
|
+
*/
|
|
258
|
+
RealtimeLayer.prototype.setBbox = function (extent, zoom) {
|
|
259
|
+
var newExtent = extent;
|
|
260
|
+
var newZoom = zoom;
|
|
261
|
+
if (!newExtent && this.isUpdateBboxOnMoveEnd) {
|
|
262
|
+
newExtent = extent || this.getMercatorExtent();
|
|
263
|
+
newZoom = Math.floor(this.getOlZoom());
|
|
264
|
+
}
|
|
265
|
+
_super.prototype.setBbox.call(this, newExtent, newZoom);
|
|
266
|
+
};
|
|
267
|
+
/**
|
|
268
|
+
* Callback on 'move' event.
|
|
269
|
+
*
|
|
270
|
+
* @private
|
|
271
|
+
*/
|
|
272
|
+
RealtimeLayer.prototype.onMove = function () {
|
|
273
|
+
this.renderTrajectories();
|
|
274
|
+
};
|
|
275
|
+
RealtimeLayer.prototype.renderTrajectoriesInternal = function (viewState, noInterpolate) {
|
|
276
|
+
var render = _super.prototype.renderTrajectoriesInternal.call(this, viewState, noInterpolate);
|
|
277
|
+
if (render && this.map.style) {
|
|
278
|
+
var extent = (0, utils_1.getSourceCoordinates)(this.map, this.pixelRatio);
|
|
279
|
+
var source = this.map.getSource(this.key);
|
|
280
|
+
if (source) {
|
|
281
|
+
source.setCoordinates(extent);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
return render;
|
|
285
|
+
};
|
|
286
|
+
/**
|
|
287
|
+
* Send the new BBOX to the websocket.
|
|
288
|
+
*
|
|
289
|
+
* @private
|
|
290
|
+
* @override
|
|
291
|
+
*/
|
|
292
|
+
RealtimeLayer.prototype.onMoveEnd = function () {
|
|
293
|
+
this.renderTrajectories();
|
|
294
|
+
if (this.visible && this.isUpdateBboxOnMoveEnd) {
|
|
295
|
+
this.setBbox();
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
/**
|
|
299
|
+
* Update the cursor style when hovering a vehicle.
|
|
300
|
+
*
|
|
301
|
+
* @private
|
|
302
|
+
* @override
|
|
303
|
+
*/
|
|
304
|
+
RealtimeLayer.prototype.onFeatureHover = function (features, layer, coordinate) {
|
|
305
|
+
_super.prototype.onFeatureHover.call(this, features, layer, coordinate);
|
|
306
|
+
this.map.getCanvasContainer().style.cursor = features.length
|
|
307
|
+
? 'pointer'
|
|
308
|
+
: 'auto';
|
|
309
|
+
};
|
|
310
|
+
return RealtimeLayer;
|
|
311
|
+
}((0, RealtimeLayerMixin_1.default)(Layer_1.default)));
|
|
312
|
+
exports.default = RealtimeLayer;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RealtimeLayer = exports.Layer = void 0;
|
|
4
|
+
var Layer_1 = require("./Layer");
|
|
5
|
+
Object.defineProperty(exports, "Layer", { enumerable: true, get: function () { return Layer_1.default; } });
|
|
6
|
+
var RealtimeLayer_1 = require("./RealtimeLayer");
|
|
7
|
+
Object.defineProperty(exports, "RealtimeLayer", { enumerable: true, get: function () { return RealtimeLayer_1.default; } });
|
package/mapbox/utils.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
+
if (ar || !(i in from)) {
|
|
5
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
+
ar[i] = from[i];
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getSourceCoordinates = exports.getMercatorResolution = void 0;
|
|
13
|
+
var extent_1 = require("ol/extent");
|
|
14
|
+
var proj_1 = require("ol/proj");
|
|
15
|
+
/**
|
|
16
|
+
* Get the current resolution of a Mapbox map.
|
|
17
|
+
* @param {mapboxgl.Map} map A map object.
|
|
18
|
+
* @private
|
|
19
|
+
*/
|
|
20
|
+
var getMercatorResolution = function (map) {
|
|
21
|
+
var bounds = map.getBounds().toArray();
|
|
22
|
+
var a = (0, proj_1.fromLonLat)(bounds[0]);
|
|
23
|
+
var b = (0, proj_1.fromLonLat)(bounds[1]);
|
|
24
|
+
var extent = __spreadArray(__spreadArray([], a, true), b, true);
|
|
25
|
+
var _a = map.getCanvas(), width = _a.width, height = _a.height;
|
|
26
|
+
var xResolution = (0, extent_1.getWidth)(extent) / width;
|
|
27
|
+
var yResolution = (0, extent_1.getHeight)(extent) / height;
|
|
28
|
+
return Math.max(xResolution, yResolution);
|
|
29
|
+
};
|
|
30
|
+
exports.getMercatorResolution = getMercatorResolution;
|
|
31
|
+
/**
|
|
32
|
+
* Get the canvas source coordinates of the current map's extent.
|
|
33
|
+
* @param {mapboxgl.Map} map A map object.
|
|
34
|
+
* @private
|
|
35
|
+
*/
|
|
36
|
+
var getSourceCoordinates = function (map, pixelRatio) {
|
|
37
|
+
// Requesting getBounds is not enough when we rotate the map, so we request manually each corner.
|
|
38
|
+
var _a = map.getCanvas(), width = _a.width, height = _a.height;
|
|
39
|
+
var leftTop = map.unproject({ x: 0, y: 0 });
|
|
40
|
+
var leftBottom = map.unproject({ x: 0, y: height / pixelRatio }); // southWest
|
|
41
|
+
var rightBottom = map.unproject({
|
|
42
|
+
x: width / pixelRatio,
|
|
43
|
+
y: height / pixelRatio,
|
|
44
|
+
});
|
|
45
|
+
var rightTop = map.unproject({ x: width / pixelRatio, y: 0 }); // north east
|
|
46
|
+
return [
|
|
47
|
+
[leftTop.lng, leftTop.lat],
|
|
48
|
+
[rightTop.lng, rightTop.lat],
|
|
49
|
+
[rightBottom.lng, rightBottom.lat],
|
|
50
|
+
[leftBottom.lng, leftBottom.lat],
|
|
51
|
+
];
|
|
52
|
+
};
|
|
53
|
+
exports.getSourceCoordinates = getSourceCoordinates;
|
|
54
|
+
exports.default = {
|
|
55
|
+
getMercatorResolution: exports.getMercatorResolution,
|
|
56
|
+
getSourceCoordinates: exports.getSourceCoordinates,
|
|
57
|
+
};
|