mobility-toolbox-js 2.0.0 → 2.0.1-beta.13
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/RoutingAPI.js +15 -0
- package/api/RoutingAPI.test.js +25 -0
- package/api/StopsAPI.js +12 -0
- package/api/StopsAPI.test.js +22 -0
- package/api/TralisAPI.js +359 -0
- package/api/TralisAPI.test.js +67 -0
- package/api/{tralis/TralisAPIUtils.js → TralisAPIUtils.js} +2 -32
- package/api/index.js +3 -3
- package/{ol/README.md → api/typedefs.js} +0 -0
- package/common/Tracker.js +14 -118
- package/common/api/HttpAPI.js +30 -0
- package/common/api/HttpAPI.test.js +50 -0
- package/common/api/WebSocketAPI.js +175 -0
- package/{api/tralis/WebSocketConnector.test.js → common/api/WebSocketAPI.test.js} +100 -145
- package/common/controls/Control.js +26 -91
- package/common/controls/Control.test.js +32 -43
- package/common/index.js +4 -0
- package/common/layers/Layer.js +53 -244
- package/common/layers/Layer.test.js +185 -244
- package/common/mixins/CopyrightMixin.js +20 -44
- package/common/mixins/SearchMixin.js +100 -166
- package/common/mixins/TralisLayerMixin.js +443 -894
- package/common/styles/index.js +4 -4
- package/common/styles/trackerDefaultStyle.js +39 -175
- package/common/styles/trackerDelayStyle.js +2 -11
- package/common/styles/trackerSimpleStyle.js +4 -8
- package/common/trackerConfig.js +61 -99
- package/common/trackerConfig.test.js +15 -17
- package/common/typedefs.js +0 -23
- package/common/utils/createTrackerFilters.js +10 -41
- package/common/utils/createTrackerFilters.test.js +40 -56
- package/common/utils/getMapboxMapCopyrights.js +3 -16
- package/common/utils/getMapboxMapCopyrights.test.js +32 -39
- package/common/utils/getMapboxStyleUrl.js +3 -13
- package/common/utils/getVehiclePosition.js +3 -33
- package/common/utils/index.js +5 -6
- package/common/utils/removeDuplicate.js +3 -17
- package/common/utils/removeDuplicate.test.js +17 -20
- package/common/utils/sortByDelay.js +2 -7
- package/common/utils/timeUtils.js +8 -32
- package/common/utils/timeUtils.test.js +7 -13
- package/index.js +8 -2
- package/mapbox/controls/CopyrightControl.js +9 -38
- package/mapbox/controls/index.js +1 -0
- package/mapbox/index.js +4 -3
- package/mapbox/layers/Layer.js +15 -76
- package/mapbox/layers/Layer.test.js +81 -101
- package/mapbox/layers/TralisLayer.js +46 -193
- package/mapbox/layers/TralisLayer.test.js +12 -14
- package/mapbox/layers/index.js +2 -0
- package/mapbox/utils.js +7 -21
- package/mbt.js +50444 -0
- package/mbt.js.map +7 -0
- package/mbt.min.js +1005 -0
- package/mbt.min.js.map +7 -0
- package/ol/controls/CopyrightControl.js +8 -46
- package/ol/controls/CopyrightControl.test.js +75 -121
- package/ol/controls/RoutingControl.js +167 -532
- package/ol/controls/RoutingControl.test.js +99 -164
- package/ol/controls/StopFinderControl.js +3 -31
- package/ol/controls/StopFinderControl.test.js +18 -29
- package/ol/controls/index.js +3 -0
- package/ol/index.js +5 -13
- package/ol/layers/Layer.js +23 -128
- package/ol/layers/Layer.test.js +79 -102
- package/ol/layers/MapboxLayer.js +62 -237
- package/ol/layers/MapboxLayer.test.js +58 -84
- package/ol/layers/MapboxStyleLayer.js +38 -268
- package/ol/layers/MapboxStyleLayer.test.js +97 -128
- package/ol/layers/MaplibreLayer.js +46 -187
- package/ol/layers/RoutingLayer.js +21 -51
- package/ol/layers/RoutingLayer.test.js +15 -24
- package/ol/layers/TralisLayer.js +102 -276
- package/ol/layers/TralisLayer.test.js +32 -50
- package/ol/layers/VectorLayer.js +3 -24
- package/ol/layers/VectorLayer.test.js +34 -45
- package/ol/layers/WMSLayer.js +15 -57
- package/ol/layers/WMSLayer.test.js +35 -43
- package/ol/layers/index.js +8 -0
- package/ol/styles/fullTrajectoryDelayStyle.js +11 -15
- package/ol/styles/fullTrajectoryStyle.js +17 -25
- package/ol/styles/index.js +2 -2
- package/package.json +35 -62
- package/api/routing/RoutingAPI.js +0 -44
- package/api/routing/RoutingAPI.test.js +0 -41
- package/api/stops/StopsAPI.js +0 -41
- package/api/stops/StopsAPI.test.js +0 -34
- package/api/tralis/TralisAPI.js +0 -731
- package/api/tralis/TralisAPI.test.js +0 -75
- package/api/tralis/WebSocketConnector.js +0 -338
- package/api/tralis/typedefs.js +0 -81
- package/common/api/api.js +0 -64
- package/common/api/api.test.js +0 -68
- package/index.js.map +0 -1
- package/module.js +0 -23
- package/ol/controls/snapshots/RoutingControlRouteGen10.json +0 -58
- package/ol/controls/snapshots/RoutingControlRouteGen100.json +0 -292
- package/ol/controls/snapshots/RoutingControlRouteGen30.json +0 -69
- package/ol/controls/snapshots/RoutingControlRouteGen5.json +0 -58
- package/ol/controls/snapshots/RoutingControlRouteOSM.json +0 -759
- package/ol/controls/snapshots/RoutingControlStation1.json +0 -60
- package/ol/controls/snapshots/RoutingControlStation2.json +0 -49
package/ol/layers/Layer.js
CHANGED
|
@@ -1,156 +1,67 @@
|
|
|
1
|
-
import { unByKey } from
|
|
2
|
-
import Group from
|
|
3
|
-
import LayerCommon from
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* A class representing a layer to display on an OpenLayers map.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* import { Layer } from 'mobility-toolbox-js/ol';
|
|
10
|
-
*
|
|
11
|
-
* const layer = new Layer({
|
|
12
|
-
* olLayer: ...,
|
|
13
|
-
* });
|
|
14
|
-
*
|
|
15
|
-
* @see <a href="/example/ol-map">Map example</a>
|
|
16
|
-
*
|
|
17
|
-
* @classproperty {ol/Map~Map} map - The map where the layer is displayed.
|
|
18
|
-
* @extends {Layer}
|
|
19
|
-
*/
|
|
1
|
+
import { unByKey } from "ol/Observable";
|
|
2
|
+
import Group from "ol/layer/Group";
|
|
3
|
+
import LayerCommon from "../../common/layers/Layer";
|
|
20
4
|
class Layer extends LayerCommon {
|
|
21
|
-
/**
|
|
22
|
-
* Constructor.
|
|
23
|
-
*
|
|
24
|
-
* @param {Object} options
|
|
25
|
-
* @param {ol/layer/Layer~Layer} options.olLayer The layer (required).
|
|
26
|
-
* @param {string} [options.name=uuid()] Layer name. Default use a generated uuid.
|
|
27
|
-
* @param {string} [options.key=uuid().toLowerCase()] Layer key, will use options.name.toLowerCase() if not specified.
|
|
28
|
-
* @param {string} [options.copyright=undefined] Copyright-Statement.
|
|
29
|
-
* @param {Array<Layer>} [options.children=[]] Sublayers.
|
|
30
|
-
* @param {Object} [options.properties={}] Application-specific layer properties.
|
|
31
|
-
* @param {boolean} [options.visible=true] If true this layer is the currently visible layer on the map.
|
|
32
|
-
* @param {boolean} [options.isBaseLayer=false] If true this layer is a baseLayer.
|
|
33
|
-
* @param {boolean} [options.isQueryable=true] If true feature information can be queried by the react-spatial LayerService. Default is true.
|
|
34
|
-
* @param {boolean} [options.isClickActive=true] If true feature information will be queried on 'singleclick' event. All results will be passed to function registered using `onClick` function. Default is true.
|
|
35
|
-
*/
|
|
36
5
|
constructor(options) {
|
|
37
6
|
super(options);
|
|
38
|
-
|
|
39
7
|
if (this.olLayer) {
|
|
40
8
|
this.olLayer.setVisible(this.visible);
|
|
41
9
|
}
|
|
42
10
|
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Define layer's properties.
|
|
46
|
-
*
|
|
47
|
-
* @ignore
|
|
48
|
-
*/
|
|
49
11
|
defineProperties(options) {
|
|
50
12
|
super.defineProperties(options);
|
|
51
13
|
Object.defineProperties(this, {
|
|
52
14
|
olLayer: { value: options.olLayer, writable: true },
|
|
53
15
|
olListenersKeys: {
|
|
54
|
-
value: []
|
|
55
|
-
}
|
|
16
|
+
value: []
|
|
17
|
+
}
|
|
56
18
|
});
|
|
57
19
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
* Initialize the layer and listen to feature clicks.
|
|
61
|
-
* @param {ol/Map~Map} map
|
|
62
|
-
*/
|
|
63
|
-
init(map) {
|
|
64
|
-
super.init(map);
|
|
65
|
-
|
|
20
|
+
attachToMap(map) {
|
|
21
|
+
super.attachToMap(map);
|
|
66
22
|
if (!this.map) {
|
|
67
23
|
return;
|
|
68
24
|
}
|
|
69
|
-
|
|
70
25
|
if (this.map && this.olLayer) {
|
|
71
26
|
this.map.addLayer(this.olLayer);
|
|
72
27
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
}),
|
|
80
|
-
);
|
|
81
|
-
|
|
28
|
+
this.olListenersKeys.push(this.map.getLayers().on("remove", (evt) => {
|
|
29
|
+
if (evt.element === this.olLayer) {
|
|
30
|
+
this.detachFromMap();
|
|
31
|
+
}
|
|
32
|
+
}));
|
|
82
33
|
if (this.isClickActive || this.isHoverActive) {
|
|
83
34
|
this.toggleVisibleListeners();
|
|
84
|
-
this.olListenersKeys.push(
|
|
85
|
-
this.on('change:visible', this.toggleVisibleListeners),
|
|
86
|
-
);
|
|
35
|
+
this.olListenersKeys.push(this.on("change:visible", this.toggleVisibleListeners));
|
|
87
36
|
}
|
|
88
|
-
|
|
89
|
-
// We set the copyright to the source used by the layer.
|
|
90
37
|
if (this.copyrights && this.olLayer) {
|
|
91
38
|
const attributions = this.copyrights || [];
|
|
92
39
|
if (this.olLayer instanceof Group) {
|
|
93
|
-
this.olLayer
|
|
94
|
-
.
|
|
95
|
-
|
|
96
|
-
.forEach((layer) => {
|
|
97
|
-
layer.getSource().setAttributions(attributions);
|
|
98
|
-
});
|
|
40
|
+
this.olLayer.getLayers().getArray().forEach((layer) => {
|
|
41
|
+
layer.getSource().setAttributions(attributions);
|
|
42
|
+
});
|
|
99
43
|
} else if (this.olLayer.getSource) {
|
|
100
44
|
this.olLayer.getSource().setAttributions(attributions);
|
|
101
45
|
}
|
|
102
46
|
}
|
|
103
47
|
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Terminate what was initialized in init function. Remove layer, events...
|
|
107
|
-
*/
|
|
108
|
-
terminate() {
|
|
48
|
+
detachFromMap() {
|
|
109
49
|
unByKey(this.olListenersKeys);
|
|
110
|
-
|
|
111
50
|
if (this.map && this.olLayer) {
|
|
112
51
|
this.map.removeLayer(this.olLayer);
|
|
113
52
|
}
|
|
114
|
-
|
|
115
|
-
super.terminate();
|
|
53
|
+
super.detachFromMap();
|
|
116
54
|
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Change the visibility of the layer
|
|
120
|
-
*
|
|
121
|
-
* @param {boolean} visible Defines the visibility of the layer
|
|
122
|
-
* @param {boolean} [stopPropagationDown]
|
|
123
|
-
* @param {boolean} [stopPropagationUp]
|
|
124
|
-
* @param {boolean} [stopPropagationSiblings]
|
|
125
|
-
*/
|
|
126
|
-
setVisible(
|
|
127
|
-
visible,
|
|
128
|
-
stopPropagationDown = false,
|
|
129
|
-
stopPropagationUp = false,
|
|
130
|
-
stopPropagationSiblings = false,
|
|
131
|
-
) {
|
|
55
|
+
setVisible(visible, stopPropagationDown = false, stopPropagationUp = false, stopPropagationSiblings = false) {
|
|
132
56
|
if (visible === this.visible) {
|
|
133
57
|
return;
|
|
134
58
|
}
|
|
135
|
-
|
|
136
|
-
super.setVisible(
|
|
137
|
-
visible,
|
|
138
|
-
stopPropagationDown,
|
|
139
|
-
stopPropagationUp,
|
|
140
|
-
stopPropagationSiblings,
|
|
141
|
-
);
|
|
142
|
-
|
|
59
|
+
super.setVisible(visible, stopPropagationDown, stopPropagationUp, stopPropagationSiblings);
|
|
143
60
|
if (this.olLayer) {
|
|
144
61
|
this.olLayer.setVisible(this.visible);
|
|
145
62
|
}
|
|
146
63
|
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Toggle listeners needed when a layer is avisible or not.
|
|
150
|
-
* @private
|
|
151
|
-
*/
|
|
152
64
|
toggleVisibleListeners() {
|
|
153
|
-
// Remove previous event
|
|
154
65
|
if (this.isClickListenerKey && this.isHoverListenerKey) {
|
|
155
66
|
[this.isClickListenerKey, this.isHoverListenerKey].forEach((key) => {
|
|
156
67
|
const index = this.olListenersKeys.indexOf(key);
|
|
@@ -160,32 +71,16 @@ class Layer extends LayerCommon {
|
|
|
160
71
|
unByKey([this.isHoverListenerKey, this.isClickListenerKey]);
|
|
161
72
|
});
|
|
162
73
|
}
|
|
163
|
-
|
|
164
74
|
if (this.visible) {
|
|
165
75
|
if (this.isClickActive) {
|
|
166
|
-
this.isClickListenerKey = this.map.on(
|
|
167
|
-
'singleclick',
|
|
168
|
-
this.onUserClickCallback,
|
|
169
|
-
);
|
|
76
|
+
this.isClickListenerKey = this.map.on("singleclick", this.onUserClickCallback);
|
|
170
77
|
}
|
|
171
78
|
if (this.isHoverActive) {
|
|
172
|
-
this.isHoverListenerKey = this.map.on(
|
|
173
|
-
'pointermove',
|
|
174
|
-
this.onUserMoveCallback,
|
|
175
|
-
);
|
|
79
|
+
this.isHoverListenerKey = this.map.on("pointermove", this.onUserMoveCallback);
|
|
176
80
|
}
|
|
177
|
-
this.olListenersKeys.push(
|
|
178
|
-
this.isClickListenerKey,
|
|
179
|
-
this.isHoverListenerKey,
|
|
180
|
-
);
|
|
81
|
+
this.olListenersKeys.push(this.isClickListenerKey, this.isHoverListenerKey);
|
|
181
82
|
}
|
|
182
83
|
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Create a copy of the Layer.
|
|
186
|
-
* @param {Object} newOptions Options to override
|
|
187
|
-
* @return {Layer} A Layer
|
|
188
|
-
*/
|
|
189
84
|
clone(newOptions) {
|
|
190
85
|
return new Layer({ ...this.options, ...newOptions });
|
|
191
86
|
}
|
package/ol/layers/Layer.test.js
CHANGED
|
@@ -1,197 +1,174 @@
|
|
|
1
|
-
import VectorLayer from
|
|
2
|
-
import VectorSource from
|
|
3
|
-
import Map from
|
|
4
|
-
import Group from
|
|
5
|
-
import Layer from
|
|
6
|
-
|
|
1
|
+
import VectorLayer from "ol/layer/Vector";
|
|
2
|
+
import VectorSource from "ol/source/Vector";
|
|
3
|
+
import Map from "ol/Map";
|
|
4
|
+
import Group from "ol/layer/Group";
|
|
5
|
+
import Layer from "./Layer";
|
|
7
6
|
let olLayer;
|
|
8
7
|
let map;
|
|
9
|
-
|
|
10
|
-
describe('Layer', () => {
|
|
8
|
+
describe("Layer", () => {
|
|
11
9
|
beforeEach(() => {
|
|
12
10
|
map = new Map({});
|
|
13
11
|
olLayer = new VectorLayer({ source: new VectorSource() });
|
|
14
12
|
});
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const layer = new Layer({ name: 'Layer', olLayer });
|
|
13
|
+
test("should initialize.", () => {
|
|
14
|
+
const layer = new Layer({ name: "Layer", olLayer });
|
|
18
15
|
expect(layer).toBeInstanceOf(Layer);
|
|
19
16
|
});
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const layer = new Layer({ name: 'Layer', olLayer });
|
|
17
|
+
test("should be visible by default.", () => {
|
|
18
|
+
const layer = new Layer({ name: "Layer", olLayer });
|
|
23
19
|
expect(layer.visible).toBe(true);
|
|
24
20
|
});
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const layer = new Layer({ name: 'Layer', visible: false, olLayer });
|
|
21
|
+
test("should be invisible if defined.", () => {
|
|
22
|
+
const layer = new Layer({ name: "Layer", visible: false, olLayer });
|
|
28
23
|
expect(layer.visible).toBe(false);
|
|
29
24
|
});
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const layer = new Layer({ name: 'Layer', olLayer });
|
|
25
|
+
test("should be invisible if set.", () => {
|
|
26
|
+
const layer = new Layer({ name: "Layer", olLayer });
|
|
33
27
|
layer.setVisible(false);
|
|
34
28
|
expect(layer.visible).toBe(false);
|
|
35
29
|
});
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const layer = new Layer({ name: 'Layer', visible: false, olLayer });
|
|
30
|
+
test("should visibility stay unchanged", () => {
|
|
31
|
+
const layer = new Layer({ name: "Layer", visible: false, olLayer });
|
|
39
32
|
layer.setVisible(false);
|
|
40
33
|
expect(layer.visible).toBe(false);
|
|
41
34
|
});
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
expect(layer.name).toEqual('Layer');
|
|
35
|
+
test("should return its name.", () => {
|
|
36
|
+
const layer = new Layer({ name: "Layer", visible: false, olLayer });
|
|
37
|
+
expect(layer.name).toEqual("Layer");
|
|
46
38
|
});
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
layer.init();
|
|
39
|
+
test("should call terminate on initialization.", () => {
|
|
40
|
+
const layer = new Layer({ name: "Layer", olLayer });
|
|
41
|
+
const spy = jest.spyOn(layer, "detachFromMap");
|
|
42
|
+
layer.attachToMap();
|
|
52
43
|
expect(spy).toHaveBeenCalledTimes(1);
|
|
53
44
|
});
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
layer.init(map);
|
|
45
|
+
test("should remove the layer when we call terminate.", () => {
|
|
46
|
+
const layer = new Layer({ name: "Layer", olLayer });
|
|
47
|
+
const spy = jest.spyOn(layer, "detachFromMap");
|
|
48
|
+
layer.attachToMap(map);
|
|
59
49
|
expect(spy).toHaveBeenCalledTimes(1);
|
|
60
|
-
layer.
|
|
50
|
+
layer.detachFromMap(map);
|
|
61
51
|
expect(spy).toHaveBeenCalledTimes(2);
|
|
62
52
|
});
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
test('should set attributions for Group.', () => {
|
|
79
|
-
const spy = jest.spyOn(VectorSource.prototype, 'setAttributions');
|
|
53
|
+
test("should manage copyrights as string.", () => {
|
|
54
|
+
const spy = jest.spyOn(VectorSource.prototype, "setAttributions");
|
|
55
|
+
const layer = new Layer({ name: "Layer", copyrights: "foo", olLayer });
|
|
56
|
+
layer.attachToMap(map);
|
|
57
|
+
expect(spy).toHaveBeenCalledWith(["foo"]);
|
|
58
|
+
});
|
|
59
|
+
test("should manage copyrights as array.", () => {
|
|
60
|
+
const spy = jest.spyOn(VectorSource.prototype, "setAttributions");
|
|
61
|
+
const layer = new Layer({ name: "Layer", copyrights: ["bar"], olLayer });
|
|
62
|
+
layer.attachToMap(map);
|
|
63
|
+
expect(spy).toHaveBeenCalledWith(["bar"]);
|
|
64
|
+
});
|
|
65
|
+
test("should set attributions for Group.", () => {
|
|
66
|
+
const spy = jest.spyOn(VectorSource.prototype, "setAttributions");
|
|
80
67
|
const layer = new Layer({
|
|
81
|
-
name:
|
|
82
|
-
copyrights: [
|
|
83
|
-
olLayer: new Group({ layers: [olLayer] })
|
|
68
|
+
name: "Layer",
|
|
69
|
+
copyrights: ["bar"],
|
|
70
|
+
olLayer: new Group({ layers: [olLayer] })
|
|
84
71
|
});
|
|
85
|
-
layer.
|
|
86
|
-
expect(spy).toHaveBeenCalledWith([
|
|
72
|
+
layer.attachToMap(map);
|
|
73
|
+
expect(spy).toHaveBeenCalledWith(["bar"]);
|
|
87
74
|
});
|
|
88
|
-
|
|
89
|
-
test('should listen for click/hover events when layer is visible by default then should not when hidden.', async () => {
|
|
75
|
+
test("should listen for click/hover events when layer is visible by default then should not when hidden.", async () => {
|
|
90
76
|
global.console.error = jest.fn();
|
|
91
|
-
const layer = new Layer({ name:
|
|
77
|
+
const layer = new Layer({ name: "Layer", olLayer });
|
|
92
78
|
expect(layer.visible).toBe(true);
|
|
93
79
|
const spy = jest.fn();
|
|
94
80
|
const spy2 = jest.fn();
|
|
95
|
-
layer.
|
|
81
|
+
layer.attachToMap(map);
|
|
96
82
|
layer.onHover(spy);
|
|
97
83
|
layer.onClick(spy2);
|
|
98
84
|
expect(spy).toHaveBeenCalledTimes(0);
|
|
99
85
|
expect(spy2).toHaveBeenCalledTimes(0);
|
|
100
|
-
|
|
101
|
-
await map.dispatchEvent({ type:
|
|
102
|
-
await map.dispatchEvent({ type: 'singleclick', map, coordinate: [0, 0] });
|
|
86
|
+
await map.dispatchEvent({ type: "pointermove", map, coordinate: [0, 0] });
|
|
87
|
+
await map.dispatchEvent({ type: "singleclick", map, coordinate: [0, 0] });
|
|
103
88
|
expect(spy).toHaveBeenCalledTimes(1);
|
|
104
89
|
expect(spy2).toHaveBeenCalledTimes(1);
|
|
105
90
|
spy.mockReset();
|
|
106
91
|
spy2.mockReset();
|
|
107
|
-
|
|
108
92
|
layer.setVisible(false);
|
|
109
|
-
await map.dispatchEvent({ type:
|
|
110
|
-
await map.dispatchEvent({ type:
|
|
93
|
+
await map.dispatchEvent({ type: "pointermove", map, coordinate: [0, 0] });
|
|
94
|
+
await map.dispatchEvent({ type: "singleclick", map, coordinate: [0, 0] });
|
|
111
95
|
expect(spy).toHaveBeenCalledTimes(0);
|
|
112
96
|
expect(spy2).toHaveBeenCalledTimes(0);
|
|
113
97
|
global.console.error.mockRestore();
|
|
114
98
|
});
|
|
115
|
-
|
|
116
|
-
test('should not listen for click/hover events when layer is not visible by default then should not when visible.', async () => {
|
|
99
|
+
test("should not listen for click/hover events when layer is not visible by default then should not when visible.", async () => {
|
|
117
100
|
global.console.error = jest.fn();
|
|
118
|
-
const layer = new Layer({ name:
|
|
101
|
+
const layer = new Layer({ name: "Layer", olLayer, visible: false });
|
|
119
102
|
expect(layer.visible).toBe(false);
|
|
120
103
|
const spy = jest.fn();
|
|
121
104
|
const spy2 = jest.fn();
|
|
122
|
-
layer.
|
|
105
|
+
layer.attachToMap(map);
|
|
123
106
|
layer.onHover(spy);
|
|
124
107
|
layer.onClick(spy2);
|
|
125
108
|
expect(spy).toHaveBeenCalledTimes(0);
|
|
126
109
|
expect(spy2).toHaveBeenCalledTimes(0);
|
|
127
|
-
|
|
128
|
-
await map.dispatchEvent({ type:
|
|
129
|
-
await map.dispatchEvent({ type: 'singleclick', map, coordinate: [0, 0] });
|
|
110
|
+
await map.dispatchEvent({ type: "pointermove", map, coordinate: [0, 0] });
|
|
111
|
+
await map.dispatchEvent({ type: "singleclick", map, coordinate: [0, 0] });
|
|
130
112
|
expect(spy).toHaveBeenCalledTimes(0);
|
|
131
113
|
expect(spy2).toHaveBeenCalledTimes(0);
|
|
132
114
|
spy.mockReset();
|
|
133
115
|
spy2.mockReset();
|
|
134
|
-
|
|
135
116
|
layer.setVisible(true);
|
|
136
|
-
await map.dispatchEvent({ type:
|
|
137
|
-
await map.dispatchEvent({ type:
|
|
117
|
+
await map.dispatchEvent({ type: "pointermove", map, coordinate: [0, 0] });
|
|
118
|
+
await map.dispatchEvent({ type: "singleclick", map, coordinate: [0, 0] });
|
|
138
119
|
expect(spy).toHaveBeenCalledTimes(1);
|
|
139
120
|
expect(spy2).toHaveBeenCalledTimes(1);
|
|
140
121
|
global.console.error.mockRestore();
|
|
141
122
|
});
|
|
142
|
-
|
|
143
|
-
test('should not listen for click/hover events after layer.terminate()', async () => {
|
|
123
|
+
test("should not listen for click/hover events after layer.detachFromMap()", async () => {
|
|
144
124
|
global.console.error = jest.fn();
|
|
145
|
-
const layer = new Layer({ name:
|
|
125
|
+
const layer = new Layer({ name: "Layer", olLayer, visible: true });
|
|
146
126
|
expect(layer.visible).toBe(true);
|
|
147
127
|
const spy = jest.fn();
|
|
148
128
|
const spy2 = jest.fn();
|
|
149
|
-
layer.
|
|
129
|
+
layer.attachToMap(map);
|
|
150
130
|
layer.onHover(spy);
|
|
151
131
|
layer.onClick(spy2);
|
|
152
132
|
expect(spy).toHaveBeenCalledTimes(0);
|
|
153
133
|
expect(spy2).toHaveBeenCalledTimes(0);
|
|
154
|
-
|
|
155
134
|
await map.dispatchEvent({
|
|
156
|
-
type:
|
|
135
|
+
type: "pointermove",
|
|
157
136
|
map,
|
|
158
|
-
coordinate: [0, 0]
|
|
137
|
+
coordinate: [0, 0]
|
|
159
138
|
});
|
|
160
139
|
await map.dispatchEvent({
|
|
161
|
-
type:
|
|
140
|
+
type: "singleclick",
|
|
162
141
|
map,
|
|
163
|
-
coordinate: [0, 0]
|
|
142
|
+
coordinate: [0, 0]
|
|
164
143
|
});
|
|
165
144
|
expect(spy).toHaveBeenCalledTimes(1);
|
|
166
145
|
expect(spy2).toHaveBeenCalledTimes(1);
|
|
167
146
|
spy.mockReset();
|
|
168
147
|
spy2.mockReset();
|
|
169
|
-
|
|
170
|
-
layer.terminate(map);
|
|
148
|
+
layer.detachFromMap(map);
|
|
171
149
|
await map.dispatchEvent({
|
|
172
|
-
type:
|
|
150
|
+
type: "pointermove",
|
|
173
151
|
map,
|
|
174
|
-
coordinate: [0, 0]
|
|
152
|
+
coordinate: [0, 0]
|
|
175
153
|
});
|
|
176
154
|
await map.dispatchEvent({
|
|
177
|
-
type:
|
|
155
|
+
type: "singleclick",
|
|
178
156
|
map,
|
|
179
|
-
coordinate: [0, 0]
|
|
157
|
+
coordinate: [0, 0]
|
|
180
158
|
});
|
|
181
159
|
expect(spy).toHaveBeenCalledTimes(0);
|
|
182
160
|
expect(spy2).toHaveBeenCalledTimes(0);
|
|
183
161
|
global.console.error.mockRestore();
|
|
184
162
|
});
|
|
185
|
-
|
|
186
|
-
test('should clone', () => {
|
|
163
|
+
test("should clone", () => {
|
|
187
164
|
const layer = new Layer({
|
|
188
|
-
name:
|
|
189
|
-
copyrights: [
|
|
190
|
-
olLayer: new Group({ layers: [olLayer] })
|
|
165
|
+
name: "Layer",
|
|
166
|
+
copyrights: ["bar"],
|
|
167
|
+
olLayer: new Group({ layers: [olLayer] })
|
|
191
168
|
});
|
|
192
|
-
const clone = layer.clone({ name:
|
|
169
|
+
const clone = layer.clone({ name: "clone" });
|
|
193
170
|
expect(clone).not.toBe(layer);
|
|
194
|
-
expect(clone.name).toBe(
|
|
171
|
+
expect(clone.name).toBe("clone");
|
|
195
172
|
expect(clone).toBeInstanceOf(Layer);
|
|
196
173
|
});
|
|
197
174
|
});
|