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,79 +1,51 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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 style_1 = require("ol/style");
|
|
30
|
-
var source_1 = require("ol/source");
|
|
31
|
-
var layer_1 = require("ol/layer");
|
|
32
|
-
var Layer_1 = require("./Layer");
|
|
1
|
+
import { Circle, Fill, Stroke, Style } from 'ol/style';
|
|
2
|
+
import { Vector as VectorSource } from 'ol/source';
|
|
3
|
+
import { Vector } from 'ol/layer';
|
|
4
|
+
import Layer from './Layer';
|
|
33
5
|
/** @private */
|
|
34
|
-
|
|
6
|
+
const circleStyle = new Circle({
|
|
35
7
|
radius: 6,
|
|
36
|
-
fill: new
|
|
8
|
+
fill: new Fill({
|
|
37
9
|
color: [255, 0, 0, 1],
|
|
38
10
|
}),
|
|
39
|
-
stroke: new
|
|
11
|
+
stroke: new Stroke({
|
|
40
12
|
color: [0, 0, 0, 1],
|
|
41
13
|
width: 1,
|
|
42
14
|
}),
|
|
43
15
|
});
|
|
44
16
|
/** @private */
|
|
45
|
-
|
|
46
|
-
stroke: new
|
|
17
|
+
const blackBorder = new Style({
|
|
18
|
+
stroke: new Stroke({
|
|
47
19
|
color: [0, 0, 0, 1],
|
|
48
20
|
width: 5,
|
|
49
21
|
}),
|
|
50
22
|
});
|
|
51
23
|
/** @private */
|
|
52
|
-
|
|
24
|
+
const redLine = new Style({
|
|
53
25
|
image: circleStyle,
|
|
54
|
-
stroke: new
|
|
26
|
+
stroke: new Stroke({
|
|
55
27
|
color: [255, 0, 0, 1],
|
|
56
28
|
width: 3,
|
|
57
29
|
}),
|
|
58
30
|
});
|
|
59
31
|
/** @private */
|
|
60
|
-
|
|
32
|
+
const dashedRedLine = new Style({
|
|
61
33
|
image: circleStyle,
|
|
62
|
-
stroke: new
|
|
34
|
+
stroke: new Stroke({
|
|
63
35
|
color: [255, 0, 0, 1],
|
|
64
36
|
width: 3,
|
|
65
37
|
lineDash: [1, 10],
|
|
66
38
|
}),
|
|
67
39
|
});
|
|
68
40
|
/** @private */
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
41
|
+
const defaultStyleFunction = (feature, resolution) => {
|
|
42
|
+
const minResolution = feature.get('minResolution');
|
|
43
|
+
const maxResolution = feature.get('maxResolution');
|
|
44
|
+
const inRange = resolution <= minResolution && resolution > maxResolution;
|
|
73
45
|
if (minResolution && maxResolution && !inRange) {
|
|
74
46
|
return null;
|
|
75
47
|
}
|
|
76
|
-
|
|
48
|
+
const mot = feature.get('mot');
|
|
77
49
|
if (mot !== 'foot') {
|
|
78
50
|
return [blackBorder, redLine];
|
|
79
51
|
}
|
|
@@ -85,32 +57,28 @@ var defaultStyleFunction = function (feature, resolution) {
|
|
|
85
57
|
* @classproperty {ol/Map~Map} map - The map where the layer is displayed.
|
|
86
58
|
* @extends {Layer}
|
|
87
59
|
*/
|
|
88
|
-
|
|
89
|
-
__extends(RoutingLayer, _super);
|
|
60
|
+
class RoutingLayer extends Layer {
|
|
90
61
|
/**
|
|
91
62
|
* Constructor.
|
|
92
63
|
* @param {Object} [options]
|
|
93
64
|
* @param {ol/style/Style~StyleLike} [options.style] Style to be used for routes, uses (ol/StyleLike) [https://openlayers.org/en/latest/apidoc/module-ol_style_Style.html#~StyleLike] instances
|
|
94
65
|
*/
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
_this.olLayer =
|
|
66
|
+
constructor(options = {}) {
|
|
67
|
+
super(options);
|
|
68
|
+
this.olLayer =
|
|
99
69
|
options.olLayer ||
|
|
100
|
-
new
|
|
101
|
-
source: new
|
|
70
|
+
new Vector({
|
|
71
|
+
source: new VectorSource(),
|
|
102
72
|
style: options.style || defaultStyleFunction,
|
|
103
73
|
});
|
|
104
|
-
return _this;
|
|
105
74
|
}
|
|
106
75
|
/**
|
|
107
76
|
* Create a copy of the RoutingLayer.
|
|
108
77
|
* @param {Object} newOptions Options to override
|
|
109
78
|
* @return {RoutingLayer} A RoutingLayer
|
|
110
79
|
*/
|
|
111
|
-
|
|
112
|
-
return new RoutingLayer(
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
exports.default = RoutingLayer;
|
|
80
|
+
clone(newOptions) {
|
|
81
|
+
return new RoutingLayer(Object.assign(Object.assign({}, this.options), newOptions));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
export default RoutingLayer;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RoutingLayer.test.d.ts","sourceRoot":"","sources":["../../../src/ol/layers/RoutingLayer.test.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import fetch from 'jest-fetch-mock';
|
|
2
|
+
import Map from 'ol/Map';
|
|
3
|
+
import View from 'ol/View';
|
|
4
|
+
import RoutingLayer from './RoutingLayer';
|
|
5
|
+
let layer;
|
|
6
|
+
let onClick;
|
|
7
|
+
let olMap;
|
|
8
|
+
describe('RoutingLayer', () => {
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
global.fetch = fetch;
|
|
11
|
+
fetch.resetMocks();
|
|
12
|
+
onClick = jest.fn();
|
|
13
|
+
layer = new RoutingLayer({
|
|
14
|
+
onClick,
|
|
15
|
+
apiKey: 'apiKey',
|
|
16
|
+
});
|
|
17
|
+
olMap = new Map({
|
|
18
|
+
view: new View({
|
|
19
|
+
center: [831634, 5933959],
|
|
20
|
+
zoom: 9,
|
|
21
|
+
}),
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
test('should be instanced.', () => {
|
|
25
|
+
expect(layer).toBeInstanceOf(RoutingLayer);
|
|
26
|
+
});
|
|
27
|
+
test('should called terminate on initalization.', () => {
|
|
28
|
+
const spy = jest.spyOn(layer, 'detachFromMap');
|
|
29
|
+
fetch.mockResponseOnce(JSON.stringify(global.fetchTrajectoriesResponse));
|
|
30
|
+
layer.attachToMap(olMap);
|
|
31
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
32
|
+
});
|
|
33
|
+
test('should clone', () => {
|
|
34
|
+
const clone = layer.clone({ name: 'clone' });
|
|
35
|
+
expect(clone).not.toBe(layer);
|
|
36
|
+
expect(clone.name).toBe('clone');
|
|
37
|
+
expect(clone).toBeInstanceOf(RoutingLayer);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
@@ -17,7 +17,7 @@ declare class VectorLayer extends Layer {
|
|
|
17
17
|
* @param {Object} newOptions Options to override
|
|
18
18
|
* @return {VectorLayer} A VectorLayer
|
|
19
19
|
*/
|
|
20
|
-
clone(newOptions:
|
|
20
|
+
clone(newOptions: Object): VectorLayer;
|
|
21
21
|
}
|
|
22
22
|
import Layer from "./Layer";
|
|
23
23
|
//# sourceMappingURL=VectorLayer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VectorLayer.d.ts","sourceRoot":"","sources":["../../../src/ol/layers/VectorLayer.js"],"names":[],"mappings":";AAEA;;;;;GAKG;AACH;IACE;;;;OAIG;IACH,6CAFY,QAAQ,WAAW,CAAC,CAkB/B;IAED;;;;OAIG;IACH,
|
|
1
|
+
{"version":3,"file":"VectorLayer.d.ts","sourceRoot":"","sources":["../../../src/ol/layers/VectorLayer.js"],"names":[],"mappings":";AAEA;;;;;GAKG;AACH;IACE;;;;OAIG;IACH,6CAFY,QAAQ,WAAW,CAAC,CAkB/B;IAED;;;;OAIG;IACH,kBAHW,MAAM,GACL,WAAW,CAItB;CACF"}
|
package/ol/layers/VectorLayer.js
CHANGED
|
@@ -1,72 +1,38 @@
|
|
|
1
|
-
|
|
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
|
-
var Layer_1 = require("./Layer");
|
|
1
|
+
import Layer from './Layer';
|
|
30
2
|
/**
|
|
31
3
|
* A class use to display vector data.
|
|
32
4
|
*
|
|
33
5
|
* @classproperty {ol/Map~Map} map - The map where the layer is displayed.
|
|
34
6
|
* @extends {Layer}
|
|
35
7
|
*/
|
|
36
|
-
|
|
37
|
-
__extends(VectorLayer, _super);
|
|
38
|
-
function VectorLayer() {
|
|
39
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
40
|
-
}
|
|
8
|
+
class VectorLayer extends Layer {
|
|
41
9
|
/**
|
|
42
10
|
* Request feature information for a given coordinate.
|
|
43
11
|
* @param {ol/coordinate~Coordinate} coordinate the coordinate to request the information at.
|
|
44
12
|
* @return {Promise<FeatureInfo>} Promise with features, layer and coordinate.
|
|
45
13
|
*/
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
var features = [];
|
|
14
|
+
getFeatureInfoAtCoordinate(coordinate) {
|
|
15
|
+
let features = [];
|
|
49
16
|
if (this.map) {
|
|
50
|
-
|
|
17
|
+
const pixel = this.map.getPixelFromCoordinate(coordinate);
|
|
51
18
|
features = this.map.getFeaturesAtPixel(pixel, {
|
|
52
|
-
layerFilter:
|
|
19
|
+
layerFilter: (l) => l === this.olLayer,
|
|
53
20
|
hitTolerance: this.hitTolerance,
|
|
54
21
|
});
|
|
55
22
|
}
|
|
56
23
|
return Promise.resolve({
|
|
57
|
-
features
|
|
24
|
+
features,
|
|
58
25
|
layer: this,
|
|
59
|
-
coordinate
|
|
26
|
+
coordinate,
|
|
60
27
|
});
|
|
61
|
-
}
|
|
28
|
+
}
|
|
62
29
|
/**
|
|
63
30
|
* Create a copy of the VectorLayer.
|
|
64
31
|
* @param {Object} newOptions Options to override
|
|
65
32
|
* @return {VectorLayer} A VectorLayer
|
|
66
33
|
*/
|
|
67
|
-
|
|
68
|
-
return new VectorLayer(
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
exports.default = VectorLayer;
|
|
34
|
+
clone(newOptions) {
|
|
35
|
+
return new VectorLayer(Object.assign(Object.assign({}, this.options), newOptions));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export default VectorLayer;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VectorLayer.test.d.ts","sourceRoot":"","sources":["../../../src/ol/layers/VectorLayer.test.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import OLVectorLayer from 'ol/layer/Vector';
|
|
11
|
+
import VectorSource from 'ol/source/Vector';
|
|
12
|
+
import View from 'ol/View';
|
|
13
|
+
import Feature from 'ol/Feature';
|
|
14
|
+
import Point from 'ol/geom/Point';
|
|
15
|
+
import Map from 'ol/Map';
|
|
16
|
+
import VectorLayer from './VectorLayer';
|
|
17
|
+
const feature1 = new Feature({
|
|
18
|
+
attribute: 'bar',
|
|
19
|
+
geometry: new Point([500, 500]),
|
|
20
|
+
});
|
|
21
|
+
const olLayer = new OLVectorLayer({
|
|
22
|
+
source: new VectorSource({
|
|
23
|
+
features: [
|
|
24
|
+
feature1,
|
|
25
|
+
new Feature({
|
|
26
|
+
attribute: 'foo',
|
|
27
|
+
geometry: new Point([50, 50]),
|
|
28
|
+
}),
|
|
29
|
+
],
|
|
30
|
+
}),
|
|
31
|
+
});
|
|
32
|
+
let layer;
|
|
33
|
+
let map;
|
|
34
|
+
let onClick;
|
|
35
|
+
describe('VectorLayer', () => {
|
|
36
|
+
beforeEach(() => {
|
|
37
|
+
onClick = jest.fn();
|
|
38
|
+
layer = new VectorLayer({
|
|
39
|
+
name: 'Layer',
|
|
40
|
+
olLayer,
|
|
41
|
+
onClick,
|
|
42
|
+
});
|
|
43
|
+
map = new Map({
|
|
44
|
+
view: new View({ resolution: 5 }),
|
|
45
|
+
target: document.body,
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
test('should be instanced.', () => {
|
|
49
|
+
expect(layer).toBeInstanceOf(VectorLayer);
|
|
50
|
+
expect(layer.hitTolerance).toBe(5);
|
|
51
|
+
});
|
|
52
|
+
test('should called terminate on initalization.', () => {
|
|
53
|
+
const spy = jest.spyOn(layer, 'detachFromMap');
|
|
54
|
+
layer.attachToMap();
|
|
55
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
56
|
+
});
|
|
57
|
+
test('should call getFeatureInfoAtCoordinate on click then the callback', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
58
|
+
const coordinate = [500, 500];
|
|
59
|
+
const px = [10, 10];
|
|
60
|
+
const features = [feature1];
|
|
61
|
+
const evt = { type: 'singleclick', map, coordinate };
|
|
62
|
+
const spy = jest.spyOn(layer, 'getFeatureInfoAtCoordinate');
|
|
63
|
+
const spy2 = jest.spyOn(map, 'getPixelFromCoordinate').mockReturnValue(px);
|
|
64
|
+
const spy3 = jest
|
|
65
|
+
.spyOn(map, 'getFeaturesAtPixel')
|
|
66
|
+
.mockReturnValue(features);
|
|
67
|
+
layer.attachToMap(map);
|
|
68
|
+
expect(onClick).toHaveBeenCalledTimes(0);
|
|
69
|
+
yield map.dispatchEvent(evt);
|
|
70
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
71
|
+
expect(spy).toHaveBeenCalledWith(coordinate);
|
|
72
|
+
expect(spy2).toHaveBeenCalledTimes(1);
|
|
73
|
+
expect(spy2).toHaveBeenCalledWith(coordinate);
|
|
74
|
+
expect(spy3).toHaveBeenCalledTimes(1);
|
|
75
|
+
expect(spy3.mock.calls[0][0]).toBe(px);
|
|
76
|
+
expect(spy3.mock.calls[0][1].layerFilter(layer.olLayer)).toBe(true);
|
|
77
|
+
expect(spy3.mock.calls[0][1].layerFilter({})).toBe(false);
|
|
78
|
+
expect(onClick).toHaveBeenCalledTimes(1);
|
|
79
|
+
expect(onClick).toHaveBeenCalledWith(features, layer, coordinate);
|
|
80
|
+
}));
|
|
81
|
+
test('should clone', () => {
|
|
82
|
+
const clone = layer.clone({ name: 'clone' });
|
|
83
|
+
expect(clone).not.toBe(layer);
|
|
84
|
+
expect(clone.name).toBe('clone');
|
|
85
|
+
expect(clone).toBeInstanceOf(VectorLayer);
|
|
86
|
+
});
|
|
87
|
+
});
|
package/ol/layers/WMSLayer.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ declare class WMSLayer extends Layer {
|
|
|
31
31
|
* @param {Object} newOptions Options to override
|
|
32
32
|
* @return {WMSLayer} A WMSLayer
|
|
33
33
|
*/
|
|
34
|
-
clone(newOptions:
|
|
34
|
+
clone(newOptions: Object): WMSLayer;
|
|
35
35
|
}
|
|
36
36
|
import Layer from "./Layer";
|
|
37
37
|
import GeoJSON from "ol/format/GeoJSON";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WMSLayer.d.ts","sourceRoot":"","sources":["../../../src/ol/layers/WMSLayer.js"],"names":[],"mappings":";AAGA;;;;;GAKG;AACH;IACE;;OAEG;IACH,0BAOC;IAJC,cAAc;IACd,iCAA4C;IAC5C,cAAc;IACd,gBAA2B;IAG7B;;;;OAIG;IACH,kCAaC;IAED;;;;OAIG;IACH,6CAFY,QAAQ,WAAW,CAAC,CAsB/B;IAED;;;;OAIG;IACH,
|
|
1
|
+
{"version":3,"file":"WMSLayer.d.ts","sourceRoot":"","sources":["../../../src/ol/layers/WMSLayer.js"],"names":[],"mappings":";AAGA;;;;;GAKG;AACH;IACE;;OAEG;IACH,0BAOC;IAJC,cAAc;IACd,iCAA4C;IAC5C,cAAc;IACd,gBAA2B;IAG7B;;;;OAIG;IACH,kCAaC;IAED;;;;OAIG;IACH,6CAFY,QAAQ,WAAW,CAAC,CAsB/B;IAED;;;;OAIG;IACH,kBAHW,MAAM,GACL,QAAQ,CAInB;CACF"}
|
package/ol/layers/WMSLayer.js
CHANGED
|
@@ -1,61 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
var GeoJSON_1 = require("ol/format/GeoJSON");
|
|
30
|
-
var Layer_1 = require("./Layer");
|
|
1
|
+
import GeoJSON from 'ol/format/GeoJSON';
|
|
2
|
+
import Layer from './Layer';
|
|
31
3
|
/**
|
|
32
4
|
* Class use to display a WMS layer.
|
|
33
5
|
*
|
|
34
6
|
* @classproperty {ol/Map~Map} map - The map where the layer is displayed.
|
|
35
7
|
* @extends {Layer}
|
|
36
8
|
*/
|
|
37
|
-
|
|
38
|
-
__extends(WMSLayer, _super);
|
|
9
|
+
class WMSLayer extends Layer {
|
|
39
10
|
/**
|
|
40
11
|
* @override
|
|
41
12
|
*/
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
var _this = _super.call(this, options) || this;
|
|
13
|
+
constructor(options = {}) {
|
|
14
|
+
super(options);
|
|
45
15
|
/** @ignore */
|
|
46
|
-
|
|
16
|
+
this.abortController = new AbortController();
|
|
47
17
|
/** @ignore */
|
|
48
|
-
|
|
49
|
-
return _this;
|
|
18
|
+
this.format = new GeoJSON();
|
|
50
19
|
}
|
|
51
20
|
/**
|
|
52
21
|
* Get features infos' Url.
|
|
53
22
|
* @param {ol/coordinate~Coordinate} coord
|
|
54
23
|
* @return {ol/layer/Layer~Layer}
|
|
55
24
|
*/
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
25
|
+
getFeatureInfoUrl(coord) {
|
|
26
|
+
const projection = this.map.getView().getProjection();
|
|
27
|
+
const resolution = this.map.getView().getResolution();
|
|
59
28
|
if (this.olLayer.getSource().getFeatureInfoUrl) {
|
|
60
29
|
return this.olLayer
|
|
61
30
|
.getSource()
|
|
@@ -65,42 +34,39 @@ var WMSLayer = /** @class */ (function (_super) {
|
|
|
65
34
|
});
|
|
66
35
|
}
|
|
67
36
|
return false;
|
|
68
|
-
}
|
|
37
|
+
}
|
|
69
38
|
/**
|
|
70
39
|
* Request feature information for a given coordinate.
|
|
71
40
|
* @param {ol/coordinate~Coordinate} coordinate to request the information at.
|
|
72
41
|
* @return {Promise<FeatureInfo>} Promise with features, layer and coordinate.
|
|
73
42
|
*/
|
|
74
|
-
|
|
75
|
-
var _this = this;
|
|
43
|
+
getFeatureInfoAtCoordinate(coordinate) {
|
|
76
44
|
this.abortController.abort();
|
|
77
45
|
this.abortController = new AbortController();
|
|
78
|
-
|
|
79
|
-
return fetch(this.getFeatureInfoUrl(coordinate), { signal
|
|
80
|
-
.then(
|
|
81
|
-
.then(
|
|
82
|
-
.then(
|
|
83
|
-
layer:
|
|
84
|
-
coordinate
|
|
85
|
-
features: data.map(
|
|
86
|
-
})
|
|
87
|
-
.catch(
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
};
|
|
46
|
+
const { signal } = this.abortController;
|
|
47
|
+
return fetch(this.getFeatureInfoUrl(coordinate), { signal })
|
|
48
|
+
.then((resp) => resp.json())
|
|
49
|
+
.then((r) => r.features)
|
|
50
|
+
.then((data) => ({
|
|
51
|
+
layer: this,
|
|
52
|
+
coordinate,
|
|
53
|
+
features: data.map((d) => this.format.readFeature(d)),
|
|
54
|
+
}))
|
|
55
|
+
.catch(() =>
|
|
56
|
+
// resolve an empty feature array something fails
|
|
57
|
+
Promise.resolve({
|
|
58
|
+
features: [],
|
|
59
|
+
coordinate,
|
|
60
|
+
layer: this,
|
|
61
|
+
}));
|
|
62
|
+
}
|
|
96
63
|
/**
|
|
97
64
|
* Create a copy of the WMSLayer.
|
|
98
65
|
* @param {Object} newOptions Options to override
|
|
99
66
|
* @return {WMSLayer} A WMSLayer
|
|
100
67
|
*/
|
|
101
|
-
|
|
102
|
-
return new WMSLayer(
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
exports.default = WMSLayer;
|
|
68
|
+
clone(newOptions) {
|
|
69
|
+
return new WMSLayer(Object.assign(Object.assign({}, this.options), newOptions));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
export default WMSLayer;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WMSLayer.test.d.ts","sourceRoot":"","sources":["../../../src/ol/layers/WMSLayer.test.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import OLView from 'ol/View';
|
|
11
|
+
import ImageLayer from 'ol/layer/Image';
|
|
12
|
+
import ImageWMS from 'ol/source/ImageWMS';
|
|
13
|
+
import fetch from 'jest-fetch-mock';
|
|
14
|
+
import Map from 'ol/Map';
|
|
15
|
+
import WMSLayer from './WMSLayer';
|
|
16
|
+
describe('WMSLayer', () => {
|
|
17
|
+
let map;
|
|
18
|
+
let layer;
|
|
19
|
+
beforeEach(() => {
|
|
20
|
+
map = new Map({
|
|
21
|
+
view: new OLView({ resolution: 5 }),
|
|
22
|
+
target: document.body,
|
|
23
|
+
});
|
|
24
|
+
layer = new WMSLayer({
|
|
25
|
+
olLayer: new ImageLayer({
|
|
26
|
+
source: new ImageWMS({
|
|
27
|
+
url: 'http://dummy',
|
|
28
|
+
params: { LAYERS: 'layers' },
|
|
29
|
+
}),
|
|
30
|
+
}),
|
|
31
|
+
});
|
|
32
|
+
layer.attachToMap(map);
|
|
33
|
+
fetch.mockResponseOnce(JSON.stringify({ features: [] }));
|
|
34
|
+
global.fetch = fetch;
|
|
35
|
+
});
|
|
36
|
+
afterEach(() => {
|
|
37
|
+
layer.detachFromMap();
|
|
38
|
+
});
|
|
39
|
+
test('should initialize.', () => {
|
|
40
|
+
expect(layer).toBeInstanceOf(WMSLayer);
|
|
41
|
+
});
|
|
42
|
+
test('should called terminate on initalization.', () => {
|
|
43
|
+
const spy = jest.spyOn(layer, 'detachFromMap');
|
|
44
|
+
layer.attachToMap();
|
|
45
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
46
|
+
});
|
|
47
|
+
test('should return a promise resolving features.', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
48
|
+
const data = yield layer.getFeatureInfoAtCoordinate([50, 50]);
|
|
49
|
+
const params = new URL(fetch.mock.calls[0][0]).searchParams;
|
|
50
|
+
expect(params.get('REQUEST')).toBe('GetFeatureInfo');
|
|
51
|
+
expect(params.get('I')).toBe('50');
|
|
52
|
+
expect(params.get('J')).toBe('50');
|
|
53
|
+
expect(data.features).toEqual([]);
|
|
54
|
+
}));
|
|
55
|
+
test('should return a layer instance and a coordinate.', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
56
|
+
const data = yield layer.getFeatureInfoAtCoordinate([50, 50]);
|
|
57
|
+
expect(data.coordinate).toEqual([50, 50]);
|
|
58
|
+
expect(data.layer).toBeInstanceOf(WMSLayer);
|
|
59
|
+
}));
|
|
60
|
+
test('should clone', () => {
|
|
61
|
+
const clone = layer.clone({ name: 'clone' });
|
|
62
|
+
expect(clone).not.toBe(layer);
|
|
63
|
+
expect(clone.name).toBe('clone');
|
|
64
|
+
expect(clone).toBeInstanceOf(WMSLayer);
|
|
65
|
+
});
|
|
66
|
+
});
|
package/ol/layers/index.js
CHANGED
|
@@ -1,19 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
Object.defineProperty(exports, "MaplibreLayer", { enumerable: true, get: function () { return MaplibreLayer_1.default; } });
|
|
10
|
-
var MapboxStyleLayer_1 = require("./MapboxStyleLayer");
|
|
11
|
-
Object.defineProperty(exports, "MapboxStyleLayer", { enumerable: true, get: function () { return MapboxStyleLayer_1.default; } });
|
|
12
|
-
var RoutingLayer_1 = require("./RoutingLayer");
|
|
13
|
-
Object.defineProperty(exports, "RoutingLayer", { enumerable: true, get: function () { return RoutingLayer_1.default; } });
|
|
14
|
-
var RealtimeLayer_1 = require("./RealtimeLayer");
|
|
15
|
-
Object.defineProperty(exports, "RealtimeLayer", { enumerable: true, get: function () { return RealtimeLayer_1.default; } });
|
|
16
|
-
var VectorLayer_1 = require("./VectorLayer");
|
|
17
|
-
Object.defineProperty(exports, "VectorLayer", { enumerable: true, get: function () { return VectorLayer_1.default; } });
|
|
18
|
-
var WMSLayer_1 = require("./WMSLayer");
|
|
19
|
-
Object.defineProperty(exports, "WMSLayer", { enumerable: true, get: function () { return WMSLayer_1.default; } });
|
|
1
|
+
export { default as Layer } from './Layer';
|
|
2
|
+
export { default as MapboxLayer } from './MapboxLayer';
|
|
3
|
+
export { default as MaplibreLayer } from './MaplibreLayer';
|
|
4
|
+
export { default as MapboxStyleLayer } from './MapboxStyleLayer';
|
|
5
|
+
export { default as RoutingLayer } from './RoutingLayer';
|
|
6
|
+
export { default as RealtimeLayer } from './RealtimeLayer';
|
|
7
|
+
export { default as VectorLayer } from './VectorLayer';
|
|
8
|
+
export { default as WMSLayer } from './WMSLayer';
|