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
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import Control from './Control';
|
|
2
|
+
describe('Control', () => {
|
|
3
|
+
test('should be activated by default', () => {
|
|
4
|
+
const control = new Control();
|
|
5
|
+
expect(control.active).toBe(true);
|
|
6
|
+
});
|
|
7
|
+
test('should not be activated if set to false in the options', () => {
|
|
8
|
+
const control = new Control({ active: false });
|
|
9
|
+
expect(control.active).toBe(false);
|
|
10
|
+
});
|
|
11
|
+
test('should call activate/deactivate when active is set to true/false', () => {
|
|
12
|
+
const control = new Control();
|
|
13
|
+
const spy1 = jest.spyOn(control, 'activate');
|
|
14
|
+
const spy2 = jest.spyOn(control, 'deactivate');
|
|
15
|
+
const spy3 = jest.spyOn(control, 'render');
|
|
16
|
+
control.active = false;
|
|
17
|
+
expect(spy1).toBeCalledTimes(0);
|
|
18
|
+
expect(spy2).toBeCalledTimes(1);
|
|
19
|
+
expect(spy3).toBeCalledTimes(1);
|
|
20
|
+
control.active = true;
|
|
21
|
+
expect(spy1).toBeCalledTimes(1);
|
|
22
|
+
expect(spy2).toBeCalledTimes(2);
|
|
23
|
+
expect(spy3).toBeCalledTimes(2);
|
|
24
|
+
});
|
|
25
|
+
test('should append/remove the element to the map container when map is set', () => {
|
|
26
|
+
const element = document.createElement('div');
|
|
27
|
+
const target = document.createElement('div');
|
|
28
|
+
const control = new Control({
|
|
29
|
+
element,
|
|
30
|
+
});
|
|
31
|
+
const spy1 = jest.spyOn(control, 'activate');
|
|
32
|
+
const spy2 = jest.spyOn(control, 'deactivate');
|
|
33
|
+
const spy3 = jest.spyOn(control, 'render');
|
|
34
|
+
control.map = {
|
|
35
|
+
getContainer() {
|
|
36
|
+
return target;
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
expect(target.childNodes[0]).toBe(element);
|
|
40
|
+
expect(spy1).toBeCalledTimes(1);
|
|
41
|
+
expect(spy2).toBeCalledTimes(2);
|
|
42
|
+
expect(spy3).toBeCalledTimes(1);
|
|
43
|
+
control.detachFromMap();
|
|
44
|
+
expect(target.childNodes[0]).toBe();
|
|
45
|
+
expect(spy1).toBeCalledTimes(1);
|
|
46
|
+
expect(spy2).toBeCalledTimes(3);
|
|
47
|
+
expect(spy3).toBeCalledTimes(2);
|
|
48
|
+
});
|
|
49
|
+
test('should append/remove the element to the target property when map is set', () => {
|
|
50
|
+
const element = document.createElement('div');
|
|
51
|
+
const target = document.createElement('div');
|
|
52
|
+
const control = new Control({
|
|
53
|
+
target,
|
|
54
|
+
element,
|
|
55
|
+
});
|
|
56
|
+
const spy1 = jest.spyOn(control, 'activate');
|
|
57
|
+
const spy2 = jest.spyOn(control, 'deactivate');
|
|
58
|
+
const spy3 = jest.spyOn(control, 'render');
|
|
59
|
+
control.map = {};
|
|
60
|
+
expect(target.childNodes[0]).toBe(element);
|
|
61
|
+
expect(spy1).toBeCalledTimes(1);
|
|
62
|
+
expect(spy2).toBeCalledTimes(2);
|
|
63
|
+
expect(spy3).toBeCalledTimes(1);
|
|
64
|
+
control.detachFromMap();
|
|
65
|
+
expect(target.childNodes[0]).toBe();
|
|
66
|
+
expect(spy1).toBeCalledTimes(1);
|
|
67
|
+
expect(spy2).toBeCalledTimes(3);
|
|
68
|
+
expect(spy3).toBeCalledTimes(2);
|
|
69
|
+
});
|
|
70
|
+
test('set a custom render method', () => {
|
|
71
|
+
const spy = jest.fn();
|
|
72
|
+
// eslint-disable-next-line no-unused-vars
|
|
73
|
+
const control = new Control({
|
|
74
|
+
render: spy,
|
|
75
|
+
});
|
|
76
|
+
expect(spy).toBeCalledTimes(1);
|
|
77
|
+
});
|
|
78
|
+
test('pass function params to custom render method', () => {
|
|
79
|
+
const spy = jest.fn();
|
|
80
|
+
// eslint-disable-next-line no-unused-vars
|
|
81
|
+
const control = new Control({
|
|
82
|
+
render: spy,
|
|
83
|
+
});
|
|
84
|
+
control.render('foo', 'bar');
|
|
85
|
+
expect(spy).toBeCalledTimes(2);
|
|
86
|
+
expect(spy.mock.calls[1][0]).toBe('foo');
|
|
87
|
+
expect(spy.mock.calls[1][1]).toBe('bar');
|
|
88
|
+
});
|
|
89
|
+
});
|
package/common/index.js
CHANGED
|
@@ -1,18 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
__exportStar(require("./utils"), exports);
|
|
18
|
-
__exportStar(require("./styles"), exports);
|
|
1
|
+
export * from './utils';
|
|
2
|
+
export * from './styles';
|
package/common/layers/Layer.d.ts
CHANGED
|
@@ -31,19 +31,19 @@ export default class Layer extends BaseObject {
|
|
|
31
31
|
* @param {Object} [options.properties={}] Application-specific layer properties.
|
|
32
32
|
*/
|
|
33
33
|
constructor(options?: {
|
|
34
|
-
key?: string;
|
|
35
|
-
name?: string;
|
|
36
|
-
copyrights?: string[];
|
|
37
|
-
children?:
|
|
38
|
-
visible?: boolean;
|
|
39
|
-
disabled?: boolean;
|
|
40
|
-
hitTolerance?: number;
|
|
41
|
-
properties?:
|
|
34
|
+
key?: string | undefined;
|
|
35
|
+
name?: string | undefined;
|
|
36
|
+
copyrights?: string[] | undefined;
|
|
37
|
+
children?: Layer[] | undefined;
|
|
38
|
+
visible?: boolean | undefined;
|
|
39
|
+
disabled?: boolean | undefined;
|
|
40
|
+
hitTolerance?: number | undefined;
|
|
41
|
+
properties?: Object | undefined;
|
|
42
42
|
});
|
|
43
43
|
visible: boolean;
|
|
44
44
|
group: any;
|
|
45
|
-
copyrights: string[];
|
|
46
|
-
children: Layer[];
|
|
45
|
+
copyrights: string[] | undefined;
|
|
46
|
+
children: Layer[] | undefined;
|
|
47
47
|
/**
|
|
48
48
|
* Define layer's properties that needs custom get and set.
|
|
49
49
|
*
|
|
@@ -70,7 +70,7 @@ export default class Layer extends BaseObject {
|
|
|
70
70
|
* @param {Object} options Some options. See child classes to see which are supported.
|
|
71
71
|
* @return {Promise<FeatureInfo>} An empty response.
|
|
72
72
|
*/
|
|
73
|
-
getFeatureInfoAtCoordinate(coordinate: any, options:
|
|
73
|
+
getFeatureInfoAtCoordinate(coordinate: any, options: Object): Promise<FeatureInfo>;
|
|
74
74
|
/**
|
|
75
75
|
* Return the an array containing all the descendants of the layer in a flat array. Including the current layer.
|
|
76
76
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Layer.d.ts","sourceRoot":"","sources":["../../../src/common/layers/Layer.js"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;GAiBG;AACH;IACE;;;;;;;;;;;;OAYG;IACH;QAT4B,GAAG
|
|
1
|
+
{"version":3,"file":"Layer.d.ts","sourceRoot":"","sources":["../../../src/common/layers/Layer.js"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;GAiBG;AACH;IACE;;;;;;;;;;;;OAYG;IACH;QAT4B,GAAG;QACH,IAAI;QACF,UAAU;QACN,QAAQ;QACb,OAAO;QACP,QAAQ;QACT,YAAY;QACZ,UAAU;OA+BrC;IAvBC,iBAAuE;IAEvE,WAA0B;IAE1B,iCAAoC;IAEpC,8BAAgC;IAmBlC;;;;OAIG;IACH,qCA0HC;IAED;;;;OAIG;IACH,4BAUC;IARC,cAAc;IACd,SAAc;IAShB;;OAEG;IAEH,sBAGC;IAED;;;;;;;OAOG;IAEH,qDAJW,MAAM,GACL,QAAQ,WAAW,CAAC,CAiB/B;IAED;;OAEG;IACH,cAEC;CACF"}
|
package/common/layers/Layer.js
CHANGED
|
@@ -1,34 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
var Object_1 = require("ol/Object");
|
|
30
|
-
var uuid_1 = require("uuid");
|
|
31
|
-
var getLayersAsFlatArray_1 = require("../utils/getLayersAsFlatArray");
|
|
1
|
+
import BaseObject from 'ol/Object';
|
|
2
|
+
import { v4 as uuid } from 'uuid';
|
|
3
|
+
import getLayersAsFlatArray from '../utils/getLayersAsFlatArray';
|
|
32
4
|
/**
|
|
33
5
|
* A class representing a layer to display on map.
|
|
34
6
|
*
|
|
@@ -47,8 +19,7 @@ var getLayersAsFlatArray_1 = require("../utils/getLayersAsFlatArray");
|
|
|
47
19
|
* @classproperty {Object} properties - Custom properties.
|
|
48
20
|
* @classproperty {ol/Map~Map|mapboxgl.Map} map - The map where the layer is displayed.
|
|
49
21
|
*/
|
|
50
|
-
|
|
51
|
-
__extends(Layer, _super);
|
|
22
|
+
export default class Layer extends BaseObject {
|
|
52
23
|
/**
|
|
53
24
|
* Constructor
|
|
54
25
|
*
|
|
@@ -62,40 +33,37 @@ var Layer = /** @class */ (function (_super) {
|
|
|
62
33
|
* @param {number} [options.hitTolerance=5] Hit-detection tolerance in css pixels. Pixels inside the radius around the given position will be checked for features.
|
|
63
34
|
* @param {Object} [options.properties={}] Application-specific layer properties.
|
|
64
35
|
*/
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
_this.children = options.children;
|
|
36
|
+
constructor(options = {}) {
|
|
37
|
+
super();
|
|
38
|
+
this.defineProperties(options);
|
|
39
|
+
this.setProperties(options.properties);
|
|
40
|
+
this.visible = options.visible === undefined ? true : !!options.visible;
|
|
41
|
+
this.group = options.group;
|
|
42
|
+
this.copyrights = options.copyrights;
|
|
43
|
+
this.children = options.children;
|
|
74
44
|
// Listen for group visiblity change
|
|
75
45
|
// if a layer from a group is newly visible we hide the others.
|
|
76
|
-
|
|
46
|
+
this.on(`change:visible:group`, (evt) => {
|
|
77
47
|
// We hide layer of the same group
|
|
78
|
-
if (
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
48
|
+
if (this.group === evt.target.group &&
|
|
49
|
+
this !== evt.target &&
|
|
50
|
+
this.visible) {
|
|
51
|
+
this.visible = false;
|
|
82
52
|
// Propagate event to parent
|
|
83
53
|
}
|
|
84
|
-
else if (
|
|
85
|
-
|
|
54
|
+
else if (this.children) {
|
|
55
|
+
this.children.forEach((child) => child.dispatchEvent(evt));
|
|
86
56
|
}
|
|
87
57
|
});
|
|
88
|
-
return _this;
|
|
89
58
|
}
|
|
90
59
|
/**
|
|
91
60
|
* Define layer's properties that needs custom get and set.
|
|
92
61
|
*
|
|
93
62
|
* @ignore
|
|
94
63
|
*/
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
var uid = (0, uuid_1.v4)();
|
|
64
|
+
defineProperties(options) {
|
|
65
|
+
const { name, key, properties, hitTolerance } = Object.assign({}, options);
|
|
66
|
+
const uid = uuid();
|
|
99
67
|
Object.defineProperties(this, {
|
|
100
68
|
/* Layer's information properties */
|
|
101
69
|
name: {
|
|
@@ -105,18 +73,18 @@ var Layer = /** @class */ (function (_super) {
|
|
|
105
73
|
value: key || uid,
|
|
106
74
|
},
|
|
107
75
|
group: {
|
|
108
|
-
get:
|
|
109
|
-
set:
|
|
110
|
-
|
|
76
|
+
get: () => this.get('group'),
|
|
77
|
+
set: (newGroup) => {
|
|
78
|
+
this.set('group', newGroup);
|
|
111
79
|
},
|
|
112
80
|
},
|
|
113
81
|
copyrights: {
|
|
114
|
-
get:
|
|
115
|
-
set:
|
|
116
|
-
|
|
82
|
+
get: () => this.get('copyrights'),
|
|
83
|
+
set: (newCopyrights) => {
|
|
84
|
+
const arrValue = newCopyrights && !Array.isArray(newCopyrights)
|
|
117
85
|
? [newCopyrights]
|
|
118
86
|
: newCopyrights;
|
|
119
|
-
|
|
87
|
+
this.set('copyrights', arrValue || []);
|
|
120
88
|
},
|
|
121
89
|
},
|
|
122
90
|
// options is used for clone function.
|
|
@@ -128,47 +96,47 @@ var Layer = /** @class */ (function (_super) {
|
|
|
128
96
|
},
|
|
129
97
|
/* Layer's state properties */
|
|
130
98
|
visible: {
|
|
131
|
-
get:
|
|
132
|
-
set:
|
|
133
|
-
if (newVisible ===
|
|
99
|
+
get: () => this.get('visible'),
|
|
100
|
+
set: (newVisible) => {
|
|
101
|
+
if (newVisible === this.visible) {
|
|
134
102
|
return;
|
|
135
103
|
}
|
|
136
|
-
|
|
137
|
-
if (
|
|
138
|
-
if (
|
|
139
|
-
|
|
104
|
+
this.set('visible', newVisible);
|
|
105
|
+
if (this.visible) {
|
|
106
|
+
if (this.parent && !this.parent.visible) {
|
|
107
|
+
this.parent.visible = true;
|
|
140
108
|
}
|
|
141
|
-
if (
|
|
142
|
-
|
|
109
|
+
if (this.children && this.children.find((child) => child.group)) {
|
|
110
|
+
const child = this.children.find((childd) => !!childd.group);
|
|
143
111
|
// Make visible only radioGroup layers
|
|
144
112
|
child.visible = true;
|
|
145
113
|
}
|
|
146
114
|
// Warn the same group that a new layer is visible
|
|
147
|
-
if (
|
|
115
|
+
if (this.parent && this.group) {
|
|
148
116
|
// We search for the higher parent then it will dispatch to all the tree.
|
|
149
|
-
|
|
117
|
+
let higherParent = this.parent;
|
|
150
118
|
while (higherParent.parent) {
|
|
151
119
|
higherParent = higherParent.parent;
|
|
152
120
|
}
|
|
153
121
|
higherParent.dispatchEvent({
|
|
154
|
-
type:
|
|
155
|
-
target:
|
|
122
|
+
type: `change:visible:group`,
|
|
123
|
+
target: this,
|
|
156
124
|
});
|
|
157
125
|
}
|
|
158
126
|
}
|
|
159
|
-
else if (!
|
|
160
|
-
if (
|
|
161
|
-
|
|
162
|
-
!
|
|
163
|
-
|
|
127
|
+
else if (!this.visible) {
|
|
128
|
+
if (this.parent &&
|
|
129
|
+
this.parent.visible &&
|
|
130
|
+
!this.parent.children.find((child) => child.visible)) {
|
|
131
|
+
this.parent.visible = false;
|
|
164
132
|
}
|
|
165
133
|
}
|
|
166
134
|
},
|
|
167
135
|
},
|
|
168
136
|
disabled: {
|
|
169
|
-
get:
|
|
170
|
-
set:
|
|
171
|
-
|
|
137
|
+
get: () => this.get('disabled'),
|
|
138
|
+
set: (newValue) => {
|
|
139
|
+
this.set('disabled', newValue);
|
|
172
140
|
},
|
|
173
141
|
},
|
|
174
142
|
/* Layer's hierarchy properties */
|
|
@@ -177,19 +145,19 @@ var Layer = /** @class */ (function (_super) {
|
|
|
177
145
|
writable: true,
|
|
178
146
|
},
|
|
179
147
|
children: {
|
|
180
|
-
get:
|
|
181
|
-
set:
|
|
182
|
-
(
|
|
148
|
+
get: () => this.get('children') || [],
|
|
149
|
+
set: (newValue) => {
|
|
150
|
+
(this.children || []).forEach((child) => {
|
|
183
151
|
// eslint-disable-next-line no-param-reassign
|
|
184
152
|
child.parent = null;
|
|
185
153
|
});
|
|
186
154
|
if (Array.isArray(newValue)) {
|
|
187
|
-
newValue.forEach(
|
|
155
|
+
newValue.forEach((child) => {
|
|
188
156
|
// eslint-disable-next-line no-param-reassign
|
|
189
|
-
child.parent =
|
|
157
|
+
child.parent = this;
|
|
190
158
|
});
|
|
191
159
|
}
|
|
192
|
-
|
|
160
|
+
this.set('children', newValue || []);
|
|
193
161
|
},
|
|
194
162
|
},
|
|
195
163
|
/* Layer's query properties */
|
|
@@ -199,33 +167,33 @@ var Layer = /** @class */ (function (_super) {
|
|
|
199
167
|
},
|
|
200
168
|
/* Custom app specific properties */
|
|
201
169
|
properties: {
|
|
202
|
-
value:
|
|
170
|
+
value: Object.assign({}, (properties || {})),
|
|
203
171
|
},
|
|
204
172
|
});
|
|
205
|
-
}
|
|
173
|
+
}
|
|
206
174
|
/**
|
|
207
175
|
* Initialize the layer with the map passed in parameters.
|
|
208
176
|
*
|
|
209
177
|
* @param {ol/Map~Map|mapboxgl.Map} map A map.
|
|
210
178
|
*/
|
|
211
|
-
|
|
179
|
+
attachToMap(map) {
|
|
212
180
|
this.detachFromMap();
|
|
213
181
|
/** @ignore */
|
|
214
182
|
this.map = map;
|
|
215
183
|
if (this.children) {
|
|
216
|
-
this.children.forEach(
|
|
184
|
+
this.children.forEach((child) => {
|
|
217
185
|
child.attachToMap(map);
|
|
218
186
|
});
|
|
219
187
|
}
|
|
220
|
-
}
|
|
188
|
+
}
|
|
221
189
|
/**
|
|
222
190
|
* Terminate what was initialized in init function. Remove layer, events...
|
|
223
191
|
*/
|
|
224
192
|
// eslint-disable-next-line class-methods-use-this
|
|
225
|
-
|
|
193
|
+
detachFromMap() {
|
|
226
194
|
/** @ignore */
|
|
227
195
|
this.map = null;
|
|
228
|
-
}
|
|
196
|
+
}
|
|
229
197
|
/**
|
|
230
198
|
* Request feature information for a given coordinate.
|
|
231
199
|
* This function must be implemented by inheriting layers.
|
|
@@ -235,7 +203,7 @@ var Layer = /** @class */ (function (_super) {
|
|
|
235
203
|
* @return {Promise<FeatureInfo>} An empty response.
|
|
236
204
|
*/
|
|
237
205
|
// eslint-disable-next-line no-unused-vars,@typescript-eslint/no-unused-vars
|
|
238
|
-
|
|
206
|
+
getFeatureInfoAtCoordinate(coordinate, options) {
|
|
239
207
|
// eslint-disable-next-line no-console
|
|
240
208
|
console.error('getFeatureInfoAtCoordinate must be implemented by inheriting layers', this.key);
|
|
241
209
|
// This layer returns no feature info.
|
|
@@ -243,15 +211,13 @@ var Layer = /** @class */ (function (_super) {
|
|
|
243
211
|
return Promise.resolve({
|
|
244
212
|
layer: this,
|
|
245
213
|
features: [],
|
|
246
|
-
coordinate
|
|
214
|
+
coordinate,
|
|
247
215
|
});
|
|
248
|
-
}
|
|
216
|
+
}
|
|
249
217
|
/**
|
|
250
218
|
* Return the an array containing all the descendants of the layer in a flat array. Including the current layer.
|
|
251
219
|
*/
|
|
252
|
-
|
|
253
|
-
return (
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
}(Object_1.default));
|
|
257
|
-
exports.default = Layer;
|
|
220
|
+
flat() {
|
|
221
|
+
return getLayersAsFlatArray(this);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Layer.test.d.ts","sourceRoot":"","sources":["../../../src/common/layers/Layer.test.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import VectorLayer from 'ol/layer/Vector';
|
|
2
|
+
import VectorSource from 'ol/source/Vector';
|
|
3
|
+
import Layer from './Layer';
|
|
4
|
+
const olLayer = new VectorLayer({ source: new VectorSource() });
|
|
5
|
+
describe('Layer', () => {
|
|
6
|
+
test('should initialize.', () => {
|
|
7
|
+
const layer = new Layer({ name: 'Layer', olLayer });
|
|
8
|
+
expect(layer).toBeInstanceOf(Layer);
|
|
9
|
+
});
|
|
10
|
+
test('should define default properties.', () => {
|
|
11
|
+
const options = {
|
|
12
|
+
name: 'Layer',
|
|
13
|
+
key: 'Layerkey',
|
|
14
|
+
olLayer,
|
|
15
|
+
};
|
|
16
|
+
const layer = new Layer(options);
|
|
17
|
+
expect(layer).toBeInstanceOf(Layer);
|
|
18
|
+
expect(layer.options).toEqual(options);
|
|
19
|
+
expect(layer.name).toEqual(options.name);
|
|
20
|
+
expect(layer.key).toEqual('Layerkey');
|
|
21
|
+
expect(layer.hitTolerance).toBe(5);
|
|
22
|
+
expect(layer.copyrights).toEqual([]);
|
|
23
|
+
expect(layer.visible).toBe(true);
|
|
24
|
+
expect(layer.properties).toEqual({});
|
|
25
|
+
expect(layer.map).toBe(undefined);
|
|
26
|
+
expect(layer.group).toBe(undefined);
|
|
27
|
+
});
|
|
28
|
+
test('should be visible by default.', () => {
|
|
29
|
+
const layer = new Layer();
|
|
30
|
+
expect(layer.visible).toBe(true);
|
|
31
|
+
});
|
|
32
|
+
test('should be hidden using constructor.', () => {
|
|
33
|
+
const layer = new Layer({ visible: false });
|
|
34
|
+
expect(layer.visible).toBe(false);
|
|
35
|
+
});
|
|
36
|
+
test('should be hidden using setter.', () => {
|
|
37
|
+
const layer = new Layer();
|
|
38
|
+
layer.visible = false;
|
|
39
|
+
expect(layer.visible).toBe(false);
|
|
40
|
+
});
|
|
41
|
+
test('should visibility stay unchanged', () => {
|
|
42
|
+
const layer = new Layer();
|
|
43
|
+
layer.visible = false;
|
|
44
|
+
expect(layer.visible).toBe(false);
|
|
45
|
+
});
|
|
46
|
+
test('should return its name.', () => {
|
|
47
|
+
const layer = new Layer({ name: 'Layer' });
|
|
48
|
+
expect(layer.name).toEqual('Layer');
|
|
49
|
+
});
|
|
50
|
+
test('should called detachFromMap on initialization.', () => {
|
|
51
|
+
const layer = new Layer();
|
|
52
|
+
const spy = jest.spyOn(layer, 'detachFromMap');
|
|
53
|
+
layer.attachToMap();
|
|
54
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
55
|
+
});
|
|
56
|
+
test('should properties correctly set and get.', () => {
|
|
57
|
+
const layer = new Layer({
|
|
58
|
+
name: 'Layer',
|
|
59
|
+
olLayer,
|
|
60
|
+
properties: {
|
|
61
|
+
abc: 'foo',
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
expect(layer).toBeInstanceOf(Layer);
|
|
65
|
+
expect(layer.get('abc')).toEqual('foo');
|
|
66
|
+
layer.set('abc', 'bar');
|
|
67
|
+
expect(layer.get('abc')).toEqual('bar');
|
|
68
|
+
});
|
|
69
|
+
test('should set children', () => {
|
|
70
|
+
const layer = new Layer({
|
|
71
|
+
children: [new Layer(), new Layer()],
|
|
72
|
+
});
|
|
73
|
+
expect(layer.children.length).toBe(2);
|
|
74
|
+
expect(layer.children[0].parent).toBe(layer);
|
|
75
|
+
expect(layer.children[1].parent).toBe(layer);
|
|
76
|
+
});
|
|
77
|
+
test('should initialize copyrights property.', () => {
|
|
78
|
+
const layer = new Layer({
|
|
79
|
+
name: 'Layer',
|
|
80
|
+
olLayer,
|
|
81
|
+
copyrights: ['©: copyright', 'another copyright'],
|
|
82
|
+
});
|
|
83
|
+
expect(layer.copyrights[0]).toEqual('©: copyright');
|
|
84
|
+
});
|
|
85
|
+
test('should set and get copyright property.', () => {
|
|
86
|
+
const layer = new Layer({
|
|
87
|
+
name: 'Layer',
|
|
88
|
+
olLayer,
|
|
89
|
+
});
|
|
90
|
+
expect(layer).toBeInstanceOf(Layer);
|
|
91
|
+
expect(layer.copyright).toEqual(undefined);
|
|
92
|
+
layer.copyright = '© OSM Contributors';
|
|
93
|
+
expect(layer.copyright).toEqual('© OSM Contributors');
|
|
94
|
+
});
|
|
95
|
+
describe('#attachToMap()', () => {
|
|
96
|
+
test('should set map.', () => {
|
|
97
|
+
const layer = new Layer({
|
|
98
|
+
name: 'Layer',
|
|
99
|
+
olLayer,
|
|
100
|
+
});
|
|
101
|
+
expect(layer.map).toBe(undefined);
|
|
102
|
+
const obj = {};
|
|
103
|
+
layer.attachToMap(obj);
|
|
104
|
+
expect(layer.map).toBe(obj);
|
|
105
|
+
});
|
|
106
|
+
test('should call terminate.', () => {
|
|
107
|
+
const layer = new Layer({
|
|
108
|
+
name: 'Layer',
|
|
109
|
+
olLayer,
|
|
110
|
+
});
|
|
111
|
+
const spy = jest.spyOn(layer, 'detachFromMap');
|
|
112
|
+
layer.attachToMap();
|
|
113
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
describe('#getFeatureInfoAtCoordinate()', () => {
|
|
117
|
+
test('return an empty fetaureInfo object and display an error message', (done) => {
|
|
118
|
+
// eslint-disable-next-line no-console
|
|
119
|
+
console.error = jest.fn();
|
|
120
|
+
const layer = new Layer({
|
|
121
|
+
name: 'Layer',
|
|
122
|
+
olLayer,
|
|
123
|
+
});
|
|
124
|
+
const coord = [0, 0];
|
|
125
|
+
layer.getFeatureInfoAtCoordinate(coord).then((featureInfo) => {
|
|
126
|
+
expect(featureInfo.features).toEqual([]);
|
|
127
|
+
expect(featureInfo.layer).toEqual(layer);
|
|
128
|
+
expect(featureInfo.coordinate).toEqual(coord);
|
|
129
|
+
// eslint-disable-next-line no-console
|
|
130
|
+
expect(console.error).toHaveBeenCalledTimes(1);
|
|
131
|
+
done();
|
|
132
|
+
// eslint-disable-next-line no-console
|
|
133
|
+
console.error.mockRestore();
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
});
|