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,39 +1,17 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/* eslint-disable class-methods-use-this */
|
|
3
2
|
/* eslint-disable max-classes-per-file */
|
|
4
|
-
var __extends = (this && this.__extends) || (function () {
|
|
5
|
-
var extendStatics = function (d, b) {
|
|
6
|
-
extendStatics = Object.setPrototypeOf ||
|
|
7
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
8
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
9
|
-
return extendStatics(d, b);
|
|
10
|
-
};
|
|
11
|
-
return function (d, b) {
|
|
12
|
-
if (typeof b !== "function" && b !== null)
|
|
13
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
14
|
-
extendStatics(d, b);
|
|
15
|
-
function __() { this.constructor = d; }
|
|
16
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
17
|
-
};
|
|
18
|
-
})();
|
|
19
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.CopyrightInterface = void 0;
|
|
21
3
|
/**
|
|
22
4
|
* Copyright control interface.
|
|
23
5
|
*
|
|
24
6
|
*/
|
|
25
|
-
|
|
26
|
-
function CopyrightInterface() {
|
|
27
|
-
}
|
|
7
|
+
export class CopyrightInterface {
|
|
28
8
|
/**
|
|
29
9
|
* Return an array of layer's copyright.
|
|
30
10
|
*
|
|
31
11
|
* @return {String[]} A list of copyrights to render.
|
|
32
12
|
*/
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}());
|
|
36
|
-
exports.CopyrightInterface = CopyrightInterface;
|
|
13
|
+
getCopyrights() { }
|
|
14
|
+
}
|
|
37
15
|
/**
|
|
38
16
|
* Mixin for CopyrightInterface.
|
|
39
17
|
*
|
|
@@ -41,32 +19,25 @@ exports.CopyrightInterface = CopyrightInterface;
|
|
|
41
19
|
* @return {Class} A class that implements <CopyrightInterface> class and extends Base;
|
|
42
20
|
* @private
|
|
43
21
|
*/
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
22
|
+
const CopyrightMixin = (Base) => class extends Base {
|
|
23
|
+
render() {
|
|
24
|
+
if (!this.element) {
|
|
25
|
+
return;
|
|
49
26
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
fontSize: '.8rem',
|
|
66
|
-
padding: '0 10px',
|
|
67
|
-
});
|
|
68
|
-
};
|
|
69
|
-
return class_1;
|
|
70
|
-
}(Base));
|
|
27
|
+
this.element.innerHTML = this.active
|
|
28
|
+
? this.getCopyrights().join(' | ')
|
|
29
|
+
: '';
|
|
30
|
+
}
|
|
31
|
+
createDefaultElement() {
|
|
32
|
+
this.element = document.createElement('div');
|
|
33
|
+
this.element.id = 'mbt-copyright';
|
|
34
|
+
Object.assign(this.element.style, {
|
|
35
|
+
position: 'absolute',
|
|
36
|
+
bottom: 0,
|
|
37
|
+
right: 0,
|
|
38
|
+
fontSize: '.8rem',
|
|
39
|
+
padding: '0 10px',
|
|
40
|
+
});
|
|
41
|
+
}
|
|
71
42
|
};
|
|
72
|
-
|
|
43
|
+
export default CopyrightMixin;
|
|
@@ -1,60 +1,27 @@
|
|
|
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.MapboxLayerInterface = void 0;
|
|
30
1
|
/* eslint-disable max-classes-per-file */
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
2
|
+
import { toLonLat } from 'ol/proj';
|
|
3
|
+
import OLLayer from 'ol/layer/Layer';
|
|
4
|
+
import Source from 'ol/source/Source';
|
|
5
|
+
import GeoJSON from 'ol/format/GeoJSON';
|
|
6
|
+
import { getUrlWithParams, getMapboxMapCopyrights } from '../utils';
|
|
36
7
|
/**
|
|
37
8
|
* MapboxLayerInterface
|
|
38
9
|
*/
|
|
39
|
-
|
|
40
|
-
function MapboxLayerInterface() {
|
|
41
|
-
}
|
|
10
|
+
export class MapboxLayerInterface {
|
|
42
11
|
/**
|
|
43
12
|
* Return the render function function for the ol layer.
|
|
44
13
|
*
|
|
45
14
|
*/
|
|
46
15
|
// eslint-disable-next-line class-methods-use-this
|
|
47
|
-
|
|
16
|
+
getOlLayerRender() { }
|
|
48
17
|
/**
|
|
49
18
|
* Return the Class to instanciate for the mapbox map.
|
|
50
19
|
*
|
|
51
20
|
* @return {mapboxgl.Map|maplibregl.Map} map
|
|
52
21
|
*/
|
|
53
22
|
// eslint-disable-next-line class-methods-use-this
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}());
|
|
57
|
-
exports.MapboxLayerInterface = MapboxLayerInterface;
|
|
23
|
+
getMapboxMapClass() { }
|
|
24
|
+
}
|
|
58
25
|
/**
|
|
59
26
|
* Mixin for MapboxLayerLayerInterface.
|
|
60
27
|
* It's used to share code between Mapbox and Maplibre layers without importing both libs
|
|
@@ -63,178 +30,169 @@ exports.MapboxLayerInterface = MapboxLayerInterface;
|
|
|
63
30
|
* @return {Class} A class that implements {MapboxLayerLayerInterface} class and extends Base;
|
|
64
31
|
* @private
|
|
65
32
|
*/
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
source: new Source_1.default({}),
|
|
74
|
-
render: _this.getOlLayerRender(_this),
|
|
75
|
-
});
|
|
76
|
-
/**
|
|
77
|
-
* Url of the mapbox style.
|
|
78
|
-
* @type {string}
|
|
79
|
-
* @private
|
|
80
|
-
*/
|
|
81
|
-
_this.styleUrl = options.url;
|
|
82
|
-
/**
|
|
83
|
-
* Api key for the url of the mapbox style.
|
|
84
|
-
* If set to false, the apiKey is not required.
|
|
85
|
-
* @type {string}
|
|
86
|
-
* @private
|
|
87
|
-
*/
|
|
88
|
-
_this.apiKey = options.apiKey;
|
|
89
|
-
/**
|
|
90
|
-
* Name of the apiKey to set in the url request.
|
|
91
|
-
* Default is 'key'.
|
|
92
|
-
* @type {string}
|
|
93
|
-
* @private
|
|
94
|
-
*/
|
|
95
|
-
_this.apiKeyName = options.apiKeyName || 'key';
|
|
96
|
-
/** @ignore */
|
|
97
|
-
_this.updateAttribution = _this.updateAttribution.bind(_this);
|
|
98
|
-
return _this;
|
|
99
|
-
}
|
|
33
|
+
const MapboxLayerMixin = (Base) => class extends Base {
|
|
34
|
+
constructor(options = {}) {
|
|
35
|
+
super(options);
|
|
36
|
+
this.olLayer = new OLLayer({
|
|
37
|
+
source: new Source({}),
|
|
38
|
+
render: this.getOlLayerRender(this),
|
|
39
|
+
});
|
|
100
40
|
/**
|
|
101
|
-
*
|
|
102
|
-
* @
|
|
41
|
+
* Url of the mapbox style.
|
|
42
|
+
* @type {string}
|
|
43
|
+
* @private
|
|
103
44
|
*/
|
|
104
|
-
|
|
105
|
-
_super.prototype.attachToMap.call(this, map);
|
|
106
|
-
if (!this.map) {
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* The feature format.
|
|
111
|
-
* @type {ol/format/GeoJSON}
|
|
112
|
-
*/
|
|
113
|
-
this.format = new GeoJSON_1.default({
|
|
114
|
-
featureProjection: this.map.getView().getProjection(),
|
|
115
|
-
});
|
|
116
|
-
this.loadMbMap();
|
|
117
|
-
};
|
|
45
|
+
this.styleUrl = options.url;
|
|
118
46
|
/**
|
|
119
|
-
*
|
|
47
|
+
* Api key for the url of the mapbox style.
|
|
48
|
+
* If set to false, the apiKey is not required.
|
|
49
|
+
* @type {string}
|
|
50
|
+
* @private
|
|
120
51
|
*/
|
|
121
|
-
|
|
122
|
-
if (this.mbMap) {
|
|
123
|
-
this.mbMap.off('idle', this.updateAttribution);
|
|
124
|
-
// Some asynchrone repaints are triggered even if the mbMap has been removed,
|
|
125
|
-
// to avoid display of errors we set an empty function.
|
|
126
|
-
this.mbMap.triggerRepaint = function () { };
|
|
127
|
-
this.mbMap.remove();
|
|
128
|
-
this.mbMap = null;
|
|
129
|
-
}
|
|
130
|
-
this.loaded = false;
|
|
131
|
-
_super.prototype.detachFromMap.call(this);
|
|
132
|
-
};
|
|
52
|
+
this.apiKey = options.apiKey;
|
|
133
53
|
/**
|
|
134
|
-
*
|
|
54
|
+
* Name of the apiKey to set in the url request.
|
|
55
|
+
* Default is 'key'.
|
|
56
|
+
* @type {string}
|
|
135
57
|
* @private
|
|
136
58
|
*/
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}));
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
var container = document.createElement('div');
|
|
154
|
-
container.style.position = 'absolute';
|
|
155
|
-
container.style.width = '100%';
|
|
156
|
-
container.style.height = '100%';
|
|
157
|
-
if (!this.apiKey && !this.styleUrl.includes(this.apiKeyName)) {
|
|
158
|
-
// eslint-disable-next-line no-console
|
|
159
|
-
console.error("No apiKey defined for mapbox layer with style url to ".concat(this.styleUrl));
|
|
160
|
-
}
|
|
161
|
-
var Map = this.getMapboxMapClass();
|
|
162
|
-
/**
|
|
163
|
-
* A mapbox map
|
|
164
|
-
* @type {mapboxgl.Map}
|
|
165
|
-
*/
|
|
166
|
-
this.mbMap = new Map(__assign({ style: (0, utils_1.getUrlWithParams)(this.styleUrl, (_a = {},
|
|
167
|
-
_a[this.apiKeyName] = this.apiKey,
|
|
168
|
-
_a)).toString(), container: container, interactive: false, trackResize: false, attributionControl: false }, (this.options.mapOptions || {})));
|
|
169
|
-
this.mbMap.once('load', function () {
|
|
170
|
-
/**
|
|
171
|
-
* Is the map loaded.
|
|
172
|
-
* @type {boolean}
|
|
173
|
-
*/
|
|
174
|
-
_this.loaded = true;
|
|
175
|
-
_this.dispatchEvent({
|
|
176
|
-
type: 'load',
|
|
177
|
-
target: _this,
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
this.mbMap.on('idle', this.updateAttribution);
|
|
181
|
-
};
|
|
59
|
+
this.apiKeyName = options.apiKeyName || 'key';
|
|
60
|
+
/** @ignore */
|
|
61
|
+
this.updateAttribution = this.updateAttribution.bind(this);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Initialize the layer and listen to feature clicks.
|
|
65
|
+
* @param {ol/Map~Map} map
|
|
66
|
+
*/
|
|
67
|
+
attachToMap(map) {
|
|
68
|
+
super.attachToMap(map);
|
|
69
|
+
if (!this.map) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
182
72
|
/**
|
|
183
|
-
*
|
|
184
|
-
* @
|
|
73
|
+
* The feature format.
|
|
74
|
+
* @type {ol/format/GeoJSON}
|
|
185
75
|
*/
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
76
|
+
this.format = new GeoJSON({
|
|
77
|
+
featureProjection: this.map.getView().getProjection(),
|
|
78
|
+
});
|
|
79
|
+
this.loadMbMap();
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Terminate what was initialized in init function. Remove layer, events...
|
|
83
|
+
*/
|
|
84
|
+
detachFromMap() {
|
|
85
|
+
if (this.mbMap) {
|
|
86
|
+
this.mbMap.off('idle', this.updateAttribution);
|
|
87
|
+
// Some asynchrone repaints are triggered even if the mbMap has been removed,
|
|
88
|
+
// to avoid display of errors we set an empty function.
|
|
89
|
+
this.mbMap.triggerRepaint = () => { };
|
|
90
|
+
this.mbMap.remove();
|
|
91
|
+
this.mbMap = null;
|
|
92
|
+
}
|
|
93
|
+
this.loaded = false;
|
|
94
|
+
super.detachFromMap();
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Create the mapbox map.
|
|
98
|
+
* @private
|
|
99
|
+
*/
|
|
100
|
+
loadMbMap() {
|
|
101
|
+
this.olListenersKeys.push(this.map.on('change:target', () => {
|
|
102
|
+
this.loadMbMap();
|
|
103
|
+
}));
|
|
104
|
+
if (!this.map.getTargetElement()) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (!this.visible) {
|
|
108
|
+
// On next change of visibility we load the map
|
|
109
|
+
this.olListenersKeys.push(this.once('change:visible', () => {
|
|
110
|
+
this.loadMbMap();
|
|
111
|
+
}));
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
const container = document.createElement('div');
|
|
115
|
+
container.style.position = 'absolute';
|
|
116
|
+
container.style.width = '100%';
|
|
117
|
+
container.style.height = '100%';
|
|
118
|
+
if (!this.apiKey && !this.styleUrl.includes(this.apiKeyName)) {
|
|
119
|
+
// eslint-disable-next-line no-console
|
|
120
|
+
console.error(`No apiKey defined for mapbox layer with style url to ${this.styleUrl}`);
|
|
121
|
+
}
|
|
122
|
+
const Map = this.getMapboxMapClass();
|
|
194
123
|
/**
|
|
195
|
-
*
|
|
196
|
-
* @
|
|
197
|
-
* @param {Object} options A [mapboxgl.Map#queryrenderedfeatures](https://docs.mapbox.com/mapbox-gl-js/api/map/#map#queryrenderedfeatures) options parameter.
|
|
198
|
-
* @return {Promise<FeatureInfo>} Promise with features, layer and coordinate. The original Mapbox feature is available as a property named 'mapboxFeature'.
|
|
124
|
+
* A mapbox map
|
|
125
|
+
* @type {mapboxgl.Map}
|
|
199
126
|
*/
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
pixel = [
|
|
213
|
-
{ x: x - this.hitTolerance, y: y - this.hitTolerance },
|
|
214
|
-
{ x: x + this.hitTolerance, y: y + this.hitTolerance },
|
|
215
|
-
];
|
|
216
|
-
}
|
|
217
|
-
// At this point we get GeoJSON Mapbox feature, we transform it to an OpenLayers
|
|
218
|
-
// feature to be consistent with other layers.
|
|
219
|
-
var features = this.mbMap
|
|
220
|
-
.queryRenderedFeatures(pixel, options)
|
|
221
|
-
.map(function (feature) {
|
|
222
|
-
var olFeature = _this.format.readFeature(feature);
|
|
223
|
-
if (olFeature) {
|
|
224
|
-
// We save the original mapbox feature to avoid losing informations
|
|
225
|
-
// potentially needed for other functionnality like highlighting
|
|
226
|
-
// (id, layer id, source, sourceLayer ...)
|
|
227
|
-
olFeature.set('mapboxFeature', feature);
|
|
228
|
-
}
|
|
229
|
-
return olFeature;
|
|
230
|
-
});
|
|
231
|
-
return Promise.resolve({
|
|
232
|
-
layer: this,
|
|
233
|
-
features: features,
|
|
234
|
-
coordinate: coordinate,
|
|
127
|
+
this.mbMap = new Map(Object.assign({ style: getUrlWithParams(this.styleUrl, {
|
|
128
|
+
[this.apiKeyName]: this.apiKey,
|
|
129
|
+
}).toString(), container, interactive: false, trackResize: false, attributionControl: false }, (this.options.mapOptions || {})));
|
|
130
|
+
this.mbMap.once('load', () => {
|
|
131
|
+
/**
|
|
132
|
+
* Is the map loaded.
|
|
133
|
+
* @type {boolean}
|
|
134
|
+
*/
|
|
135
|
+
this.loaded = true;
|
|
136
|
+
this.dispatchEvent({
|
|
137
|
+
type: 'load',
|
|
138
|
+
target: this,
|
|
235
139
|
});
|
|
236
|
-
};
|
|
237
|
-
|
|
238
|
-
}
|
|
140
|
+
});
|
|
141
|
+
this.mbMap.on('idle', this.updateAttribution);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Update attributions of the source.
|
|
145
|
+
* @private
|
|
146
|
+
*/
|
|
147
|
+
updateAttribution(evt) {
|
|
148
|
+
var _a, _b;
|
|
149
|
+
const newAttributions = getMapboxMapCopyrights(evt.target) || [];
|
|
150
|
+
if (((_a = this.copyrights) === null || _a === void 0 ? void 0 : _a.toString()) !== newAttributions.toString()) {
|
|
151
|
+
this.copyrights = newAttributions;
|
|
152
|
+
(_b = this.olLayer.getSource()) === null || _b === void 0 ? void 0 : _b.setAttributions(newAttributions);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Request feature information for a given coordinate.
|
|
157
|
+
* @param {ol/coordinate~Coordinate} coordinate Coordinate to request the information at.
|
|
158
|
+
* @param {Object} options A [mapboxgl.Map#queryrenderedfeatures](https://docs.mapbox.com/mapbox-gl-js/api/map/#map#queryrenderedfeatures) options parameter.
|
|
159
|
+
* @return {Promise<FeatureInfo>} Promise with features, layer and coordinate. The original Mapbox feature is available as a property named 'mapboxFeature'.
|
|
160
|
+
*/
|
|
161
|
+
getFeatureInfoAtCoordinate(coordinate, options) {
|
|
162
|
+
// Ignore the getFeatureInfo until the mapbox map is loaded
|
|
163
|
+
if (!options ||
|
|
164
|
+
!this.format ||
|
|
165
|
+
!this.mbMap ||
|
|
166
|
+
!this.mbMap.isStyleLoaded()) {
|
|
167
|
+
return Promise.resolve({ coordinate, features: [], layer: this });
|
|
168
|
+
}
|
|
169
|
+
let pixel = coordinate && this.mbMap.project(toLonLat(coordinate));
|
|
170
|
+
if (this.hitTolerance) {
|
|
171
|
+
const { x, y } = pixel;
|
|
172
|
+
pixel = [
|
|
173
|
+
{ x: x - this.hitTolerance, y: y - this.hitTolerance },
|
|
174
|
+
{ x: x + this.hitTolerance, y: y + this.hitTolerance },
|
|
175
|
+
];
|
|
176
|
+
}
|
|
177
|
+
// At this point we get GeoJSON Mapbox feature, we transform it to an OpenLayers
|
|
178
|
+
// feature to be consistent with other layers.
|
|
179
|
+
const features = this.mbMap
|
|
180
|
+
.queryRenderedFeatures(pixel, options)
|
|
181
|
+
.map((feature) => {
|
|
182
|
+
const olFeature = this.format.readFeature(feature);
|
|
183
|
+
if (olFeature) {
|
|
184
|
+
// We save the original mapbox feature to avoid losing informations
|
|
185
|
+
// potentially needed for other functionnality like highlighting
|
|
186
|
+
// (id, layer id, source, sourceLayer ...)
|
|
187
|
+
olFeature.set('mapboxFeature', feature);
|
|
188
|
+
}
|
|
189
|
+
return olFeature;
|
|
190
|
+
});
|
|
191
|
+
return Promise.resolve({
|
|
192
|
+
layer: this,
|
|
193
|
+
features,
|
|
194
|
+
coordinate,
|
|
195
|
+
});
|
|
196
|
+
}
|
|
239
197
|
};
|
|
240
|
-
|
|
198
|
+
export default MapboxLayerMixin;
|