mobility-toolbox-js 2.0.0-beta.30 → 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.d.ts +268 -0
- package/api/RealtimeAPI.d.ts.map +1 -0
- package/api/RealtimeAPI.js +626 -343
- package/api/RoutingAPI.d.ts +33 -0
- package/api/RoutingAPI.d.ts.map +1 -0
- package/api/RoutingAPI.js +65 -15
- package/api/StopsAPI.d.ts +36 -0
- package/api/StopsAPI.d.ts.map +1 -0
- package/api/StopsAPI.js +70 -12
- package/api/index.d.ts +5 -0
- package/api/index.d.ts.map +1 -0
- package/api/index.js +10 -3
- package/api/typedefs.d.ts +105 -0
- package/api/typedefs.d.ts.map +1 -0
- package/api/typedefs.js +72 -0
- package/common/api/HttpAPI.d.ts +31 -0
- package/common/api/HttpAPI.d.ts.map +1 -0
- package/common/api/HttpAPI.js +82 -30
- package/common/api/WebSocketAPI.d.ts +95 -0
- package/common/api/WebSocketAPI.d.ts.map +1 -0
- package/common/api/WebSocketAPI.js +313 -168
- package/common/controls/Control.d.ts +74 -0
- package/common/controls/Control.d.ts.map +1 -0
- package/common/controls/Control.js +167 -78
- package/common/index.d.ts +3 -0
- package/common/index.d.ts.map +1 -0
- package/common/index.js +18 -2
- package/common/layers/Layer.d.ts +80 -0
- package/common/layers/Layer.d.ts.map +1 -0
- package/common/layers/Layer.js +251 -134
- package/common/mixins/CopyrightMixin.d.ts +22 -0
- package/common/mixins/CopyrightMixin.d.ts.map +1 -0
- package/common/mixins/CopyrightMixin.js +70 -22
- package/common/mixins/MapboxLayerMixin.d.ts +27 -0
- package/common/mixins/MapboxLayerMixin.d.ts.map +1 -0
- package/common/mixins/MapboxLayerMixin.js +240 -0
- package/common/mixins/RealtimeLayerMixin.d.ts +58 -0
- package/common/mixins/RealtimeLayerMixin.d.ts.map +1 -0
- package/common/mixins/RealtimeLayerMixin.js +698 -429
- package/common/mixins/StopFinderMixin.d.ts +40 -0
- package/common/mixins/StopFinderMixin.d.ts.map +1 -0
- package/common/mixins/StopFinderMixin.js +195 -107
- package/common/mixins/UserInteractionsLayerMixin.d.ts +42 -0
- package/common/mixins/UserInteractionsLayerMixin.d.ts.map +1 -0
- package/common/mixins/UserInteractionsLayerMixin.js +222 -121
- package/common/styles/index.d.ts +5 -0
- package/common/styles/index.d.ts.map +1 -0
- package/common/styles/index.js +24 -4
- package/common/styles/realtimeDefaultStyle.d.ts +15 -0
- package/common/styles/realtimeDefaultStyle.d.ts.map +1 -0
- package/common/styles/realtimeDefaultStyle.js +236 -190
- package/common/styles/realtimeDelayStyle.d.ts +11 -0
- package/common/styles/realtimeDelayStyle.d.ts.map +1 -0
- package/common/styles/realtimeDelayStyle.js +25 -7
- package/common/styles/realtimeSimpleStyle.d.ts +3 -0
- package/common/styles/realtimeSimpleStyle.d.ts.map +1 -0
- package/common/styles/realtimeSimpleStyle.js +23 -17
- package/common/typedefs.d.ts +50 -0
- package/common/typedefs.d.ts.map +1 -0
- package/common/typedefs.js +21 -0
- package/common/utils/cleanStopTime.d.ts +7 -0
- package/common/utils/cleanStopTime.d.ts.map +1 -0
- package/common/utils/cleanStopTime.js +28 -17
- package/common/utils/compareDepartures.d.ts +9 -0
- package/common/utils/compareDepartures.d.ts.map +1 -0
- package/common/utils/compareDepartures.js +34 -22
- package/common/utils/createCanvas.d.ts +9 -0
- package/common/utils/createCanvas.d.ts.map +1 -0
- package/common/utils/createCanvas.js +28 -16
- package/common/utils/createTrackerFilters.d.ts +12 -0
- package/common/utils/createTrackerFilters.d.ts.map +1 -0
- package/common/utils/createTrackerFilters.js +75 -54
- package/common/utils/getLayersAsFlatArray.d.ts +3 -0
- package/common/utils/getLayersAsFlatArray.d.ts.map +1 -0
- package/common/utils/getLayersAsFlatArray.js +15 -13
- package/common/utils/getMapboxMapCopyrights.d.ts +8 -0
- package/common/utils/getMapboxMapCopyrights.d.ts.map +1 -0
- package/common/utils/getMapboxMapCopyrights.js +24 -17
- package/common/utils/getMapboxRender.d.ts +5 -0
- package/common/utils/getMapboxRender.d.ts.map +1 -0
- package/common/utils/getMapboxRender.js +77 -0
- package/common/utils/getMaplibreRender.d.ts +5 -0
- package/common/utils/getMaplibreRender.d.ts.map +1 -0
- package/common/utils/getMaplibreRender.js +38 -0
- package/common/utils/getRealtimeModeSuffix.d.ts +8 -0
- package/common/utils/getRealtimeModeSuffix.d.ts.map +1 -0
- package/common/utils/getRealtimeModeSuffix.js +11 -2
- package/common/utils/getUrlWithParams.d.ts +9 -0
- package/common/utils/getUrlWithParams.d.ts.map +1 -0
- package/common/utils/getUrlWithParams.js +20 -10
- package/common/utils/getVehiclePosition.d.ts +14 -0
- package/common/utils/getVehiclePosition.d.ts.map +1 -0
- package/common/utils/getVehiclePosition.js +63 -39
- package/common/utils/index.d.ts +12 -0
- package/common/utils/index.d.ts.map +1 -0
- package/common/utils/index.js +37 -9
- package/common/utils/removeDuplicate.d.ts +10 -0
- package/common/utils/removeDuplicate.d.ts.map +1 -0
- package/common/utils/removeDuplicate.js +29 -7
- package/common/utils/renderTrajectories.d.ts +20 -0
- package/common/utils/renderTrajectories.d.ts.map +1 -0
- package/common/utils/renderTrajectories.js +111 -78
- package/common/utils/sortByDelay.d.ts +3 -0
- package/common/utils/sortByDelay.d.ts.map +1 -0
- package/common/utils/sortByDelay.js +21 -17
- package/common/utils/timeUtils.d.ts +5 -0
- package/common/utils/timeUtils.d.ts.map +1 -0
- package/common/utils/timeUtils.js +47 -18
- package/common/utils/trackerConfig.d.ts +24 -0
- package/common/utils/trackerConfig.d.ts.map +1 -0
- package/common/utils/trackerConfig.js +171 -118
- package/iife.d.ts +3 -0
- package/iife.d.ts.map +1 -0
- package/iife.js +7 -0
- package/index.d.ts +6 -0
- package/index.d.ts.map +1 -0
- package/index.js +10 -7
- package/mapbox/controls/CopyrightControl.d.ts +32 -0
- package/mapbox/controls/CopyrightControl.d.ts.map +1 -0
- package/mapbox/controls/CopyrightControl.js +72 -28
- package/mapbox/controls/index.d.ts +2 -0
- package/mapbox/controls/index.d.ts.map +1 -0
- package/mapbox/controls/index.js +6 -1
- package/mapbox/index.d.ts +5 -0
- package/mapbox/index.d.ts.map +1 -0
- package/mapbox/index.js +20 -4
- package/mapbox/layers/Layer.d.ts +47 -0
- package/mapbox/layers/Layer.d.ts.map +1 -0
- package/mapbox/layers/Layer.js +137 -54
- package/mapbox/layers/RealtimeLayer.d.ts +118 -0
- package/mapbox/layers/RealtimeLayer.d.ts.map +1 -0
- package/mapbox/layers/RealtimeLayer.js +310 -183
- package/mapbox/layers/index.d.ts +3 -0
- package/mapbox/layers/index.d.ts.map +1 -0
- package/mapbox/layers/index.js +7 -2
- package/mapbox/utils.d.ts +8 -0
- package/mapbox/utils.d.ts.map +1 -0
- package/mapbox/utils.js +54 -29
- package/mbt.js +2052 -2109
- package/mbt.js.map +3 -3
- package/mbt.min.js +18 -18
- package/mbt.min.js.map +3 -3
- package/ol/controls/CopyrightControl.d.ts +31 -0
- package/ol/controls/CopyrightControl.d.ts.map +1 -0
- package/ol/controls/CopyrightControl.js +89 -41
- package/ol/controls/RoutingControl.d.ts +180 -0
- package/ol/controls/RoutingControl.d.ts.map +1 -0
- package/ol/controls/RoutingControl.js +666 -371
- package/ol/controls/StopFinderControl.d.ts +32 -0
- package/ol/controls/StopFinderControl.d.ts.map +1 -0
- package/ol/controls/StopFinderControl.js +59 -10
- package/ol/controls/index.d.ts +4 -0
- package/ol/controls/index.d.ts.map +1 -0
- package/ol/controls/index.js +9 -3
- package/ol/index.d.ts +6 -0
- package/ol/index.d.ts.map +1 -0
- package/ol/index.js +21 -5
- package/ol/layers/Layer.d.ts +49 -0
- package/ol/layers/Layer.d.ts.map +1 -0
- package/ol/layers/Layer.js +178 -81
- package/ol/layers/MapboxLayer.d.ts +42 -0
- package/ol/layers/MapboxLayer.d.ts.map +1 -0
- package/ol/layers/MapboxLayer.js +131 -198
- package/ol/layers/MapboxStyleLayer.d.ts +146 -0
- package/ol/layers/MapboxStyleLayer.d.ts.map +1 -0
- package/ol/layers/MapboxStyleLayer.js +382 -186
- package/ol/layers/MaplibreLayer.d.ts +27 -0
- package/ol/layers/MaplibreLayer.d.ts.map +1 -0
- package/ol/layers/MaplibreLayer.js +67 -138
- package/ol/layers/RealtimeLayer.d.ts +119 -0
- package/ol/layers/RealtimeLayer.d.ts.map +1 -0
- package/ol/layers/RealtimeLayer.js +327 -184
- package/ol/layers/RoutingLayer.d.ts +24 -0
- package/ol/layers/RoutingLayer.d.ts.map +1 -0
- package/ol/layers/RoutingLayer.js +111 -56
- package/ol/layers/VectorLayer.d.ts +23 -0
- package/ol/layers/VectorLayer.d.ts.map +1 -0
- package/ol/layers/VectorLayer.js +71 -21
- package/ol/layers/WMSLayer.d.ts +38 -0
- package/ol/layers/WMSLayer.d.ts.map +1 -0
- package/ol/layers/WMSLayer.js +105 -37
- package/ol/layers/index.d.ts +9 -0
- package/ol/layers/index.d.ts.map +1 -0
- package/ol/layers/index.js +19 -8
- package/ol/styles/fullTrajectoryDelayStyle.d.ts +4 -0
- package/ol/styles/fullTrajectoryDelayStyle.d.ts.map +1 -0
- package/ol/styles/fullTrajectoryDelayStyle.js +32 -28
- package/ol/styles/fullTrajectoryStyle.d.ts +4 -0
- package/ol/styles/fullTrajectoryStyle.d.ts.map +1 -0
- package/ol/styles/fullTrajectoryStyle.js +44 -40
- package/ol/styles/index.d.ts +3 -0
- package/ol/styles/index.d.ts.map +1 -0
- package/ol/styles/index.js +7 -2
- package/package.json +14 -36
- package/setupTests.d.ts +2 -0
- package/setupTests.d.ts.map +1 -0
- package/setupTests.js +15 -0
- package/types/index.d.ts +7 -6
- package/types/routing.d.ts +25 -25
- package/types/stops.d.ts +19 -19
- package/api/RealtimeAPI.test.js +0 -67
- package/api/RoutingAPI.test.js +0 -25
- package/api/StopsAPI.test.js +0 -22
- package/common/api/HttpAPI.test.js +0 -50
- package/common/api/WebSocketAPI.test.js +0 -311
- package/common/controls/Control.test.js +0 -87
- package/common/layers/Layer.test.js +0 -134
- package/common/mixins/UserInteractionsLayerMixin.test.js +0 -199
- package/common/utils/createTrackerFilters.test.js +0 -79
- package/common/utils/getMapboxMapCopyrights.test.js +0 -40
- package/common/utils/removeDuplicate.test.js +0 -19
- package/common/utils/timeUtils.test.js +0 -10
- package/common/utils/trackerConfig.test.js +0 -23
- package/mapbox/layers/Layer.test.js +0 -182
- package/mapbox/layers/RealtimeLayer.test.js +0 -10
- package/ol/controls/CopyrightControl.test.js +0 -165
- package/ol/controls/RoutingControl.test.js +0 -146
- package/ol/controls/StopFinderControl.test.js +0 -48
- package/ol/layers/Layer.test.js +0 -175
- package/ol/layers/MapboxLayer.test.js +0 -160
- package/ol/layers/MapboxStyleLayer.test.js +0 -226
- package/ol/layers/RealtimeLayer.test.js +0 -67
- package/ol/layers/RoutingLayer.test.js +0 -39
- package/ol/layers/VectorLayer.test.js +0 -76
- package/ol/layers/WMSLayer.test.js +0 -57
package/ol/layers/MapboxLayer.js
CHANGED
|
@@ -1,204 +1,137 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
canvas.style.position = "absolute";
|
|
24
|
-
}
|
|
25
|
-
const opacity = this.olLayer.getOpacity();
|
|
26
|
-
if (this.renderState.opacity !== opacity) {
|
|
27
|
-
canvas.style.opacity = opacity;
|
|
28
|
-
this.renderState.opacity = opacity;
|
|
29
|
-
}
|
|
30
|
-
const { rotation } = viewState;
|
|
31
|
-
if (this.renderState.rotation !== rotation) {
|
|
32
|
-
this.mbMap.rotateTo(-(rotation || 0) * 180 / Math.PI, {
|
|
33
|
-
animate: false
|
|
34
|
-
});
|
|
35
|
-
changed = true;
|
|
36
|
-
this.renderState.rotation = rotation;
|
|
37
|
-
}
|
|
38
|
-
if (this.renderState.zoom !== viewState.zoom || this.renderState.center[0] !== viewState.center[0] || this.renderState.center[1] !== viewState.center[1]) {
|
|
39
|
-
this.mbMap.jumpTo({
|
|
40
|
-
center: toLonLat(viewState.center),
|
|
41
|
-
zoom: viewState.zoom - 1,
|
|
42
|
-
animate: false
|
|
43
|
-
});
|
|
44
|
-
changed = true;
|
|
45
|
-
this.renderState.zoom = viewState.zoom;
|
|
46
|
-
this.renderState.center = viewState.center;
|
|
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];
|
|
47
23
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
24
|
+
return t;
|
|
25
|
+
};
|
|
26
|
+
return __assign.apply(this, arguments);
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
/* eslint-disable no-underscore-dangle */
|
|
30
|
+
var mapbox_gl_1 = require("mapbox-gl");
|
|
31
|
+
var Layer_1 = require("./Layer");
|
|
32
|
+
var MapboxLayerMixin_1 = require("../../common/mixins/MapboxLayerMixin");
|
|
33
|
+
var utils_1 = require("../../common/utils");
|
|
34
|
+
/**
|
|
35
|
+
* A class representing Mapboxlayer to display on BasicMap
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* import { MapboxLayer } from 'mobility-toolbox-js/ol';
|
|
39
|
+
*
|
|
40
|
+
* const layer = new MapboxLayer({
|
|
41
|
+
* url: 'https://maps.geops.io/styles/travic_v2/style.json',
|
|
42
|
+
* apikey: 'yourApiKey',
|
|
43
|
+
* });
|
|
44
|
+
*
|
|
45
|
+
* @classproperty {ol/Map~Map} map - The map where the layer is displayed.
|
|
46
|
+
* @extends {Layer}
|
|
47
|
+
*/
|
|
48
|
+
var MapboxLayer = /** @class */ (function (_super) {
|
|
49
|
+
__extends(MapboxLayer, _super);
|
|
50
|
+
function MapboxLayer() {
|
|
51
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Initialize the layer and listen to feature clicks.
|
|
55
|
+
* @param {ol/Map~Map} map
|
|
56
|
+
*/
|
|
57
|
+
MapboxLayer.prototype.attachToMap = function (map) {
|
|
58
|
+
var _this = this;
|
|
59
|
+
_super.prototype.attachToMap.call(this, map);
|
|
60
|
+
if (!this.map || this.mbMap) {
|
|
61
|
+
return;
|
|
52
62
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
63
|
+
this.olListenersKeys.push(this.map.on('change:size', function () {
|
|
64
|
+
try {
|
|
65
|
+
if (_this.mbMap) {
|
|
66
|
+
_this.mbMap.resize();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
// ignore render errors
|
|
71
|
+
// eslint-disable-next-line no-console
|
|
72
|
+
console.warn(err);
|
|
58
73
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
74
|
+
}));
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Create the mapbox map.
|
|
78
|
+
* @private
|
|
79
|
+
*/
|
|
80
|
+
MapboxLayer.prototype.loadMbMap = function () {
|
|
81
|
+
var _this = this;
|
|
82
|
+
// If the map hasn't been resized, the center could be [NaN,NaN].
|
|
83
|
+
// We set default good value for the mapbox map, to avoid the app crashes.
|
|
84
|
+
var _a = this.map.getView().getCenter(), x = _a[0], y = _a[1];
|
|
85
|
+
if (!x || !y) {
|
|
86
|
+
x = 0;
|
|
87
|
+
y = 0;
|
|
63
88
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
+
// Options the last render run did happen. If something changes
|
|
90
|
+
// we have to render again
|
|
91
|
+
/** @ignore */
|
|
92
|
+
this.renderState = {
|
|
93
|
+
center: [x, y],
|
|
94
|
+
zoom: null,
|
|
95
|
+
rotation: null,
|
|
96
|
+
visible: null,
|
|
97
|
+
opacity: null,
|
|
98
|
+
size: [0, 0],
|
|
99
|
+
};
|
|
100
|
+
_super.prototype.loadMbMap.call(this);
|
|
101
|
+
this.mbMap.once('load', function () {
|
|
102
|
+
var _a;
|
|
103
|
+
_this.mbMap.resize();
|
|
104
|
+
/** @ignore */
|
|
105
|
+
_this.copyrights = (0, utils_1.getMapboxMapCopyrights)(_this.mbMap) || [];
|
|
106
|
+
(_a = _this.olLayer.getSource()) === null || _a === void 0 ? void 0 : _a.setAttributions(_this.copyrights);
|
|
107
|
+
});
|
|
108
|
+
var mapboxCanvas = this.mbMap.getCanvas();
|
|
109
|
+
if (mapboxCanvas) {
|
|
110
|
+
if (this.options.tabIndex) {
|
|
111
|
+
mapboxCanvas.setAttribute('tabindex', this.options.tabIndex);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
// With a tabIndex='-1' the mouse events works but the map is not focused when we click on it
|
|
115
|
+
// so we remove completely the tabIndex attribute.
|
|
116
|
+
mapboxCanvas.removeAttribute('tabindex');
|
|
117
|
+
}
|
|
89
118
|
}
|
|
90
|
-
} catch (err) {
|
|
91
|
-
console.warn(err);
|
|
92
|
-
}
|
|
93
|
-
}));
|
|
94
|
-
}
|
|
95
|
-
detachFromMap() {
|
|
96
|
-
if (this.mbMap) {
|
|
97
|
-
this.mbMap.off("idle", this.updateAttribution);
|
|
98
|
-
this.mbMap.triggerRepaint = () => {
|
|
99
|
-
};
|
|
100
|
-
this.mbMap.remove();
|
|
101
|
-
this.mbMap = null;
|
|
102
|
-
}
|
|
103
|
-
this.loaded = false;
|
|
104
|
-
super.detachFromMap();
|
|
105
|
-
}
|
|
106
|
-
loadMbMap() {
|
|
107
|
-
this.olListenersKeys.push(this.map.on("change:target", () => {
|
|
108
|
-
this.loadMbMap();
|
|
109
|
-
}));
|
|
110
|
-
if (!this.map.getTargetElement()) {
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
if (!this.visible) {
|
|
114
|
-
this.olListenersKeys.push(this.once("change:visible", () => {
|
|
115
|
-
this.loadMbMap();
|
|
116
|
-
}));
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
let [x, y] = this.map.getView().getCenter();
|
|
120
|
-
if (!x || !y) {
|
|
121
|
-
x = 0;
|
|
122
|
-
y = 0;
|
|
123
|
-
}
|
|
124
|
-
const container = document.createElement("div");
|
|
125
|
-
container.style.position = "absolute";
|
|
126
|
-
container.style.width = "100%";
|
|
127
|
-
container.style.height = "100%";
|
|
128
|
-
if (!this.apiKey && !this.styleUrl.includes(this.apiKeyName)) {
|
|
129
|
-
console.warn(`No apiKey is defined for request to ${this.styleUrl}`);
|
|
130
|
-
}
|
|
131
|
-
this.mbMap = new Map({
|
|
132
|
-
style: getUrlWithParams(this.styleUrl, {
|
|
133
|
-
[this.apiKeyName]: this.apiKey
|
|
134
|
-
}).toString(),
|
|
135
|
-
container,
|
|
136
|
-
interactive: false,
|
|
137
|
-
trackResize: false,
|
|
138
|
-
attributionControl: false,
|
|
139
|
-
...this.options.mapOptions || {}
|
|
140
|
-
});
|
|
141
|
-
this.renderState = {
|
|
142
|
-
center: [x, y],
|
|
143
|
-
zoom: null,
|
|
144
|
-
rotation: null,
|
|
145
|
-
visible: null,
|
|
146
|
-
opacity: null,
|
|
147
|
-
size: [0, 0]
|
|
148
119
|
};
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
this.mbMap.on("idle", this.updateAttribution);
|
|
168
|
-
}
|
|
169
|
-
updateAttribution(evt) {
|
|
170
|
-
const newAttributions = getMapboxMapCopyrights(evt.target) || [];
|
|
171
|
-
if (this.copyrights.toString() !== newAttributions.toString()) {
|
|
172
|
-
this.copyrights = newAttributions;
|
|
173
|
-
this.olLayer.getSource()?.setAttributions(newAttributions);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
getFeatureInfoAtCoordinate(coordinate, options) {
|
|
177
|
-
if (!options || !this.format || !this.mbMap || !this.mbMap.isStyleLoaded()) {
|
|
178
|
-
return Promise.resolve({ coordinate, features: [], layer: this });
|
|
179
|
-
}
|
|
180
|
-
let pixel = coordinate && this.mbMap.project(toLonLat(coordinate));
|
|
181
|
-
if (this.hitTolerance) {
|
|
182
|
-
const { x, y } = pixel;
|
|
183
|
-
pixel = [
|
|
184
|
-
{ x: x - this.hitTolerance, y: y - this.hitTolerance },
|
|
185
|
-
{ x: x + this.hitTolerance, y: y + this.hitTolerance }
|
|
186
|
-
];
|
|
187
|
-
}
|
|
188
|
-
const features = this.mbMap.queryRenderedFeatures(pixel, options).map((feature) => {
|
|
189
|
-
const olFeature = this.format.readFeature(feature);
|
|
190
|
-
if (olFeature) {
|
|
191
|
-
olFeature.set("mapboxFeature", feature);
|
|
192
|
-
}
|
|
193
|
-
return olFeature;
|
|
194
|
-
});
|
|
195
|
-
return Promise.resolve({
|
|
196
|
-
layer: this,
|
|
197
|
-
features,
|
|
198
|
-
coordinate
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
clone(newOptions) {
|
|
202
|
-
return new MapboxLayer({ ...this.options, ...newOptions });
|
|
203
|
-
}
|
|
204
|
-
}
|
|
120
|
+
MapboxLayer.prototype.getOlLayerRender = function () {
|
|
121
|
+
return (0, utils_1.getMapboxRender)(this);
|
|
122
|
+
};
|
|
123
|
+
// eslint-disable-next-line class-methods-use-this
|
|
124
|
+
MapboxLayer.prototype.getMapboxMapClass = function () {
|
|
125
|
+
return mapbox_gl_1.Map;
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* Create a copy of the MapboxLayer.
|
|
129
|
+
* @param {Object} newOptions Options to override
|
|
130
|
+
* @return {MapboxLayer} A MapboxLayer
|
|
131
|
+
*/
|
|
132
|
+
MapboxLayer.prototype.clone = function (newOptions) {
|
|
133
|
+
return new MapboxLayer(__assign(__assign({}, this.options), newOptions));
|
|
134
|
+
};
|
|
135
|
+
return MapboxLayer;
|
|
136
|
+
}((0, MapboxLayerMixin_1.default)(Layer_1.default)));
|
|
137
|
+
exports.default = MapboxLayer;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
export default MapboxStyleLayer;
|
|
2
|
+
/**
|
|
3
|
+
* Layer for visualizing a specific set of layer from a MapboxLayer.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* import { MapboxLayer, MapboxStyleLayer } from 'mobility-toolbox-js/ol';
|
|
7
|
+
*
|
|
8
|
+
* const mapboxLayer = new MapboxLayer({
|
|
9
|
+
* url: 'https://maps.geops.io/styles/travic_v2/style.json?key=[yourApiKey]',
|
|
10
|
+
* });
|
|
11
|
+
*
|
|
12
|
+
* const layer = new MapboxStyleLayer({
|
|
13
|
+
* mapboxLayer: mapboxLayer,
|
|
14
|
+
* styleLayersFilter: () => {},
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* @classproperty {ol/Map~Map} map - The map where the layer is displayed.
|
|
18
|
+
* @extends {Layer}
|
|
19
|
+
*/
|
|
20
|
+
declare class MapboxStyleLayer extends Layer {
|
|
21
|
+
/**
|
|
22
|
+
* Constructor.
|
|
23
|
+
*
|
|
24
|
+
* @param {Object} options
|
|
25
|
+
* @param {MapboxLayer} [options.mapboxLayer] The MapboxLayer to use.
|
|
26
|
+
* @param {Function} [options.styleLayersFilter] Filter function to decide which style layer to display.
|
|
27
|
+
*/
|
|
28
|
+
constructor(options?: {
|
|
29
|
+
mapboxLayer?: MapboxLayer;
|
|
30
|
+
styleLayersFilter?: Function;
|
|
31
|
+
});
|
|
32
|
+
/**
|
|
33
|
+
* MapboxLayer provided for the style Layer.
|
|
34
|
+
* @type {MapboxLayer}
|
|
35
|
+
* @private
|
|
36
|
+
*/
|
|
37
|
+
private mapboxLayer;
|
|
38
|
+
/**
|
|
39
|
+
* Define if the layer has data to display in the current mapbox layer.
|
|
40
|
+
*/
|
|
41
|
+
disabled: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Function to filter features to be displayed.
|
|
44
|
+
* @type {function}
|
|
45
|
+
* @private
|
|
46
|
+
*/
|
|
47
|
+
private styleLayersFilter;
|
|
48
|
+
/**
|
|
49
|
+
* Mapbox style layer id where to add the style layers.
|
|
50
|
+
* See [mapbox.map.addLayer](https://docs.mapbox.com/mapbox-gl-js/api/map/#map#addlayer) documentation.
|
|
51
|
+
* @type {String}
|
|
52
|
+
* @private
|
|
53
|
+
*/
|
|
54
|
+
private beforeId;
|
|
55
|
+
/**
|
|
56
|
+
* Function to filter features for getFeatureInfoAtCoordinate method.
|
|
57
|
+
* @type {function}
|
|
58
|
+
* @private
|
|
59
|
+
*/
|
|
60
|
+
private featureInfoFilter;
|
|
61
|
+
/**
|
|
62
|
+
* Function to query the rendered features.
|
|
63
|
+
* @type {function}
|
|
64
|
+
* @private
|
|
65
|
+
*/
|
|
66
|
+
private queryRenderedLayersFilter;
|
|
67
|
+
/**
|
|
68
|
+
* Array of features to highlight.
|
|
69
|
+
* @type {Array<ol/Feature~Feature>}
|
|
70
|
+
* @private
|
|
71
|
+
*/
|
|
72
|
+
private highlightedFeatures;
|
|
73
|
+
/**
|
|
74
|
+
* Array of selected features.
|
|
75
|
+
* @type {Array<ol/Feature~Feature>}
|
|
76
|
+
* @private
|
|
77
|
+
*/
|
|
78
|
+
private selectedFeatures;
|
|
79
|
+
/**
|
|
80
|
+
* Array of mapbox style layers to add.
|
|
81
|
+
* @type {Array<mapboxgl.styleLayer>}
|
|
82
|
+
* @private
|
|
83
|
+
*/
|
|
84
|
+
private styleLayers;
|
|
85
|
+
/** @ignore */
|
|
86
|
+
addStyleLayers(): void;
|
|
87
|
+
/**
|
|
88
|
+
* On Mapbox map load callback function. Add style layers and dynaimc filters.
|
|
89
|
+
* @ignore
|
|
90
|
+
*/
|
|
91
|
+
onLoad(): void;
|
|
92
|
+
/** @private */
|
|
93
|
+
private addDynamicFilters;
|
|
94
|
+
/**
|
|
95
|
+
* Terminate the layer.
|
|
96
|
+
* @param {mapboxgl.Map} map the mapbox map.
|
|
97
|
+
* @override
|
|
98
|
+
*/
|
|
99
|
+
override detachFromMap(map: mapboxgl.Map): void;
|
|
100
|
+
/** @ignore */
|
|
101
|
+
removeStyleLayers(): void;
|
|
102
|
+
/**
|
|
103
|
+
* Request feature information for a given coordinate.
|
|
104
|
+
* @param {ol/coordinate~Coordinate} coordinate Coordinate to request the information at.
|
|
105
|
+
* @return {Promise<FeatureInfo>} Promise with features, layer and coordinate.
|
|
106
|
+
*/
|
|
107
|
+
getFeatureInfoAtCoordinate(coordinate: any): Promise<FeatureInfo>;
|
|
108
|
+
/**
|
|
109
|
+
* Set filter that determines which features should be rendered in a style layer.
|
|
110
|
+
* @param {mapboxgl.filter} filter Determines which features should be rendered in a style layer.
|
|
111
|
+
*/
|
|
112
|
+
setFilter(filter: mapboxgl.filter): void;
|
|
113
|
+
/**
|
|
114
|
+
* Set if features are hovered or not.
|
|
115
|
+
* @param {Array<ol/Feature~Feature>} features
|
|
116
|
+
* @param {boolean} state Is the feature hovered
|
|
117
|
+
* @private
|
|
118
|
+
*/
|
|
119
|
+
private setHoverState;
|
|
120
|
+
/**
|
|
121
|
+
* Select a list of features.
|
|
122
|
+
* @param {Array<ol/Feature~Feature>} [features=[]] Features to select.
|
|
123
|
+
* @private
|
|
124
|
+
*/
|
|
125
|
+
private select;
|
|
126
|
+
/**
|
|
127
|
+
* Highlight a list of features.
|
|
128
|
+
* @param {Array<ol/Feature~Feature>} [features=[]] Features to highlight.
|
|
129
|
+
* @private
|
|
130
|
+
*/
|
|
131
|
+
private highlight;
|
|
132
|
+
/**
|
|
133
|
+
* Apply visibility to style layers that fits the styleLayersFilter function.
|
|
134
|
+
* @param {Event} evt Layer's event that has called the function.
|
|
135
|
+
* @private
|
|
136
|
+
*/
|
|
137
|
+
private applyLayoutVisibility;
|
|
138
|
+
/**
|
|
139
|
+
* Create a copy of the MapboxStyleLayer.
|
|
140
|
+
* @param {Object} newOptions Options to override.
|
|
141
|
+
* @return {MapboxStyleLayer} A MapboxStyleLayer.
|
|
142
|
+
*/
|
|
143
|
+
clone(newOptions: any): MapboxStyleLayer;
|
|
144
|
+
}
|
|
145
|
+
import Layer from "./Layer";
|
|
146
|
+
//# sourceMappingURL=MapboxStyleLayer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MapboxStyleLayer.d.ts","sourceRoot":"","sources":["../../../src/ol/layers/MapboxStyleLayer.js"],"names":[],"mappings":";AAGA;;;;;;;;;;;;;;;;;GAiBG;AACH;IACE;;;;;;OAMG;IACH;QAHiC,WAAW;QACd,iBAAiB;OA4F9C;IAvFC;;;;OAIG;IACH,oBAAsC;IAEtC;;OAEG;IACH,kBAAqB;IAErB;;;;OAIG;IACH,0BAAkD;IAElD;;;;;OAKG;IACH,iBAAgC;IAEhC;;;;OAIG;IACH,0BAAoE;IAEpE;;;;OAIG;IACH,kCAAkE;IAElE;;;;OAIG;IACH,4BAA6B;IAE7B;;;;OAIG;IACH,yBAA0B;IAE1B;;;;OAIG;IACH,oBACyE;IAiG3E,cAAc;IACd,uBAcC;IAiBD;;;OAGG;IACH,eAaC;IAtIG,eAAe;IACf,0BAMC;IAgEL;;;;OAIG;IACH,gDAOC;IAmBD,cAAc;IACd,0BAYC;IAqBD;;;;OAIG;IACH,6CAFY,QAAQ,WAAW,CAAC,CAiC/B;IAED;;;OAGG;IACH,yCAYC;IAED;;;;;OAKG;IACH,sBA8BC;IAED;;;;OAIG;IACH,eAIC;IAED;;;;OAIG;IACH,kBAeC;IAED;;;;OAIG;IAEH,8BA8BC;IAED;;;;OAIG;IACH,wBAFY,gBAAgB,CAI3B;CACF"}
|