mobility-toolbox-js 2.0.0-beta.32 → 2.0.0-beta.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api/RealtimeAPI.d.ts +268 -0
- package/api/RealtimeAPI.d.ts.map +1 -0
- package/api/RoutingAPI.d.ts +33 -0
- package/api/RoutingAPI.d.ts.map +1 -0
- package/api/StopsAPI.d.ts +36 -0
- package/api/StopsAPI.d.ts.map +1 -0
- package/api/index.d.ts +5 -0
- package/api/index.d.ts.map +1 -0
- package/api/typedefs.d.ts +105 -0
- package/api/typedefs.d.ts.map +1 -0
- package/common/api/HttpAPI.d.ts +31 -0
- package/common/api/HttpAPI.d.ts.map +1 -0
- package/common/api/WebSocketAPI.d.ts +95 -0
- package/common/api/WebSocketAPI.d.ts.map +1 -0
- package/common/controls/Control.d.ts +74 -0
- package/common/controls/Control.d.ts.map +1 -0
- package/common/{index.js → index.d.ts} +1 -0
- package/common/index.d.ts.map +1 -0
- package/common/layers/Layer.d.ts +80 -0
- package/common/layers/Layer.d.ts.map +1 -0
- package/common/mixins/CopyrightMixin.d.ts +22 -0
- package/common/mixins/CopyrightMixin.d.ts.map +1 -0
- package/common/mixins/MapboxLayerMixin.d.ts +27 -0
- package/common/mixins/MapboxLayerMixin.d.ts.map +1 -0
- package/common/mixins/RealtimeLayerMixin.d.ts +58 -0
- package/common/mixins/RealtimeLayerMixin.d.ts.map +1 -0
- package/common/mixins/StopFinderMixin.d.ts +40 -0
- package/common/mixins/StopFinderMixin.d.ts.map +1 -0
- package/common/mixins/UserInteractionsLayerMixin.d.ts +42 -0
- package/common/mixins/UserInteractionsLayerMixin.d.ts.map +1 -0
- package/common/styles/{index.js → index.d.ts} +1 -0
- package/common/styles/index.d.ts.map +1 -0
- package/common/styles/realtimeDefaultStyle.d.ts +15 -0
- package/common/styles/realtimeDefaultStyle.d.ts.map +1 -0
- package/common/styles/realtimeDelayStyle.d.ts +11 -0
- package/common/styles/realtimeDelayStyle.d.ts.map +1 -0
- package/common/styles/realtimeSimpleStyle.d.ts +3 -0
- package/common/styles/realtimeSimpleStyle.d.ts.map +1 -0
- package/common/typedefs.d.ts +50 -0
- package/common/typedefs.d.ts.map +1 -0
- package/common/utils/cleanStopTime.d.ts +7 -0
- package/common/utils/cleanStopTime.d.ts.map +1 -0
- package/common/utils/compareDepartures.d.ts +9 -0
- package/common/utils/compareDepartures.d.ts.map +1 -0
- package/common/utils/createCanvas.d.ts +9 -0
- package/common/utils/createCanvas.d.ts.map +1 -0
- package/common/utils/createTrackerFilters.d.ts +12 -0
- package/common/utils/createTrackerFilters.d.ts.map +1 -0
- package/common/utils/getLayersAsFlatArray.d.ts +3 -0
- package/common/utils/getLayersAsFlatArray.d.ts.map +1 -0
- package/common/utils/getMapboxMapCopyrights.d.ts +8 -0
- package/common/utils/getMapboxMapCopyrights.d.ts.map +1 -0
- package/common/utils/getMapboxRender.d.ts +5 -0
- package/common/utils/getMapboxRender.d.ts.map +1 -0
- package/common/utils/getMaplibreRender.d.ts +5 -0
- package/common/utils/getMaplibreRender.d.ts.map +1 -0
- package/common/utils/getRealtimeModeSuffix.d.ts +8 -0
- package/common/utils/getRealtimeModeSuffix.d.ts.map +1 -0
- package/common/utils/getUrlWithParams.d.ts +9 -0
- package/common/utils/getUrlWithParams.d.ts.map +1 -0
- package/common/utils/getVehiclePosition.d.ts +14 -0
- package/common/utils/getVehiclePosition.d.ts.map +1 -0
- package/common/utils/{index.js → index.d.ts} +3 -0
- package/common/utils/index.d.ts.map +1 -0
- package/common/utils/removeDuplicate.d.ts +10 -0
- package/common/utils/removeDuplicate.d.ts.map +1 -0
- package/common/utils/renderTrajectories.d.ts +20 -0
- package/common/utils/renderTrajectories.d.ts.map +1 -0
- package/common/utils/sortByDelay.d.ts +3 -0
- package/common/utils/sortByDelay.d.ts.map +1 -0
- package/common/utils/timeUtils.d.ts +5 -0
- package/common/utils/timeUtils.d.ts.map +1 -0
- package/common/utils/trackerConfig.d.ts +24 -0
- package/common/utils/trackerConfig.d.ts.map +1 -0
- package/iife.d.ts +3 -0
- package/iife.d.ts.map +1 -0
- package/index.d.ts +6 -0
- package/index.d.ts.map +1 -0
- package/mapbox/controls/CopyrightControl.d.ts +32 -0
- package/mapbox/controls/CopyrightControl.d.ts.map +1 -0
- package/mapbox/controls/{index.js → index.d.ts} +1 -0
- package/mapbox/controls/index.d.ts.map +1 -0
- package/mapbox/{index.js → index.d.ts} +1 -0
- package/mapbox/index.d.ts.map +1 -0
- package/mapbox/layers/Layer.d.ts +47 -0
- package/mapbox/layers/Layer.d.ts.map +1 -0
- package/mapbox/layers/RealtimeLayer.d.ts +118 -0
- package/mapbox/layers/RealtimeLayer.d.ts.map +1 -0
- package/mapbox/layers/{index.js → index.d.ts} +1 -0
- package/mapbox/layers/index.d.ts.map +1 -0
- package/mapbox/utils.d.ts +8 -0
- package/mapbox/utils.d.ts.map +1 -0
- package/mbt.js +2049 -2106
- package/mbt.js.map +3 -3
- package/mbt.min.js +18 -18
- package/mbt.min.js.map +3 -3
- package/ol/controls/CopyrightControl.d.ts +31 -0
- package/ol/controls/CopyrightControl.d.ts.map +1 -0
- package/ol/controls/RoutingControl.d.ts +180 -0
- package/ol/controls/RoutingControl.d.ts.map +1 -0
- package/ol/controls/StopFinderControl.d.ts +32 -0
- package/ol/controls/StopFinderControl.d.ts.map +1 -0
- package/ol/controls/{index.js → index.d.ts} +1 -0
- package/ol/controls/index.d.ts.map +1 -0
- package/ol/{index.js → index.d.ts} +1 -0
- package/ol/index.d.ts.map +1 -0
- package/ol/layers/Layer.d.ts +49 -0
- package/ol/layers/Layer.d.ts.map +1 -0
- package/ol/layers/MapboxLayer.d.ts +42 -0
- package/ol/layers/MapboxLayer.d.ts.map +1 -0
- package/ol/layers/MapboxStyleLayer.d.ts +146 -0
- package/ol/layers/MapboxStyleLayer.d.ts.map +1 -0
- package/ol/layers/MaplibreLayer.d.ts +27 -0
- package/ol/layers/MaplibreLayer.d.ts.map +1 -0
- package/ol/layers/RealtimeLayer.d.ts +119 -0
- package/ol/layers/RealtimeLayer.d.ts.map +1 -0
- package/ol/layers/RoutingLayer.d.ts +24 -0
- package/ol/layers/RoutingLayer.d.ts.map +1 -0
- package/ol/layers/VectorLayer.d.ts +23 -0
- package/ol/layers/VectorLayer.d.ts.map +1 -0
- package/ol/layers/WMSLayer.d.ts +38 -0
- package/ol/layers/WMSLayer.d.ts.map +1 -0
- package/ol/layers/{index.js → index.d.ts} +1 -0
- package/ol/layers/index.d.ts.map +1 -0
- package/ol/styles/fullTrajectoryDelayStyle.d.ts +4 -0
- package/ol/styles/fullTrajectoryDelayStyle.d.ts.map +1 -0
- package/ol/styles/fullTrajectoryStyle.d.ts +4 -0
- package/ol/styles/fullTrajectoryStyle.d.ts.map +1 -0
- package/ol/styles/{index.js → index.d.ts} +1 -0
- package/ol/styles/index.d.ts.map +1 -0
- package/package.json +14 -36
- package/setupTests.d.ts +2 -0
- package/setupTests.d.ts.map +1 -0
- package/types/index.d.ts +7 -6
- package/types/routing.d.ts +25 -25
- package/types/stops.d.ts +19 -19
- package/api/RealtimeAPI.js +0 -357
- package/api/RealtimeAPI.test.js +0 -67
- package/api/RoutingAPI.js +0 -15
- package/api/RoutingAPI.test.js +0 -25
- package/api/StopsAPI.js +0 -12
- package/api/StopsAPI.test.js +0 -22
- package/api/index.js +0 -3
- package/api/typedefs.js +0 -0
- package/common/api/HttpAPI.js +0 -32
- package/common/api/HttpAPI.test.js +0 -50
- package/common/api/WebSocketAPI.js +0 -175
- package/common/api/WebSocketAPI.test.js +0 -311
- package/common/controls/Control.js +0 -81
- package/common/controls/Control.test.js +0 -87
- package/common/layers/Layer.js +0 -140
- package/common/layers/Layer.test.js +0 -134
- package/common/mixins/CopyrightMixin.js +0 -24
- package/common/mixins/RealtimeLayerMixin.js +0 -436
- package/common/mixins/StopFinderMixin.js +0 -110
- package/common/mixins/UserInteractionsLayerMixin.js +0 -124
- package/common/mixins/UserInteractionsLayerMixin.test.js +0 -199
- package/common/styles/realtimeDefaultStyle.js +0 -202
- package/common/styles/realtimeDelayStyle.js +0 -8
- package/common/styles/realtimeSimpleStyle.js +0 -18
- package/common/typedefs.js +0 -0
- package/common/utils/cleanStopTime.js +0 -19
- package/common/utils/compareDepartures.js +0 -25
- package/common/utils/createCanvas.js +0 -17
- package/common/utils/createTrackerFilters.js +0 -56
- package/common/utils/createTrackerFilters.test.js +0 -79
- package/common/utils/getLayersAsFlatArray.js +0 -14
- package/common/utils/getMapboxMapCopyrights.js +0 -19
- package/common/utils/getMapboxMapCopyrights.test.js +0 -40
- package/common/utils/getRealtimeModeSuffix.js +0 -2
- package/common/utils/getUrlWithParams.js +0 -11
- package/common/utils/getVehiclePosition.js +0 -42
- package/common/utils/removeDuplicate.js +0 -8
- package/common/utils/removeDuplicate.test.js +0 -19
- package/common/utils/renderTrajectories.js +0 -86
- package/common/utils/sortByDelay.js +0 -18
- package/common/utils/timeUtils.js +0 -20
- package/common/utils/timeUtils.test.js +0 -10
- package/common/utils/trackerConfig.js +0 -129
- package/common/utils/trackerConfig.test.js +0 -23
- package/index.js +0 -8
- package/mapbox/controls/CopyrightControl.js +0 -29
- package/mapbox/layers/Layer.js +0 -56
- package/mapbox/layers/Layer.test.js +0 -182
- package/mapbox/layers/RealtimeLayer.js +0 -185
- package/mapbox/layers/RealtimeLayer.test.js +0 -10
- package/mapbox/utils.js +0 -32
- package/ol/controls/CopyrightControl.js +0 -42
- package/ol/controls/CopyrightControl.test.js +0 -165
- package/ol/controls/RoutingControl.js +0 -388
- package/ol/controls/RoutingControl.test.js +0 -146
- package/ol/controls/StopFinderControl.js +0 -10
- package/ol/controls/StopFinderControl.test.js +0 -48
- package/ol/layers/Layer.js +0 -83
- package/ol/layers/Layer.test.js +0 -175
- package/ol/layers/MapboxLayer.js +0 -204
- package/ol/layers/MapboxLayer.test.js +0 -160
- package/ol/layers/MapboxStyleLayer.js +0 -187
- package/ol/layers/MapboxStyleLayer.test.js +0 -226
- package/ol/layers/MaplibreLayer.js +0 -140
- package/ol/layers/RealtimeLayer.js +0 -187
- package/ol/layers/RealtimeLayer.test.js +0 -67
- package/ol/layers/RoutingLayer.js +0 -61
- package/ol/layers/RoutingLayer.test.js +0 -39
- package/ol/layers/VectorLayer.js +0 -22
- package/ol/layers/VectorLayer.test.js +0 -76
- package/ol/layers/WMSLayer.js +0 -38
- package/ol/layers/WMSLayer.test.js +0 -57
- package/ol/styles/fullTrajectoryDelayStyle.js +0 -31
- package/ol/styles/fullTrajectoryStyle.js +0 -42
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
import { Map } from "maplibre-gl";
|
|
2
|
-
import { toLonLat } from "ol/proj";
|
|
3
|
-
import Layer from "./Layer";
|
|
4
|
-
let map;
|
|
5
|
-
let mapElement;
|
|
6
|
-
describe("Layer", () => {
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
mapElement = document.createElement("div");
|
|
9
|
-
const { style } = mapElement;
|
|
10
|
-
style.position = "absolute";
|
|
11
|
-
style.left = "0px";
|
|
12
|
-
style.top = "0px";
|
|
13
|
-
style.width = "400px";
|
|
14
|
-
style.height = "400px";
|
|
15
|
-
mapElement.setAttribute("id", "map");
|
|
16
|
-
document.body.appendChild(mapElement);
|
|
17
|
-
map = new Map({
|
|
18
|
-
container: document.getElementById("map"),
|
|
19
|
-
style: `path/to/style`,
|
|
20
|
-
center: toLonLat([831634, 5933959]),
|
|
21
|
-
zoom: 9
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
afterEach(() => {
|
|
25
|
-
document.body.removeChild(mapElement);
|
|
26
|
-
});
|
|
27
|
-
test("should initialize.", () => {
|
|
28
|
-
const layer = new Layer({ name: "Layer" });
|
|
29
|
-
expect(layer).toBeInstanceOf(Layer);
|
|
30
|
-
});
|
|
31
|
-
test("should be visible by default.", () => {
|
|
32
|
-
const layer = new Layer({ name: "Layer" });
|
|
33
|
-
expect(layer.visible).toBe(true);
|
|
34
|
-
});
|
|
35
|
-
test("should be invisible if defined.", () => {
|
|
36
|
-
const layer = new Layer({ name: "Layer", visible: false });
|
|
37
|
-
expect(layer.visible).toBe(false);
|
|
38
|
-
});
|
|
39
|
-
test("should be invisible if set.", () => {
|
|
40
|
-
const layer = new Layer({ name: "Layer" });
|
|
41
|
-
layer.visible = false;
|
|
42
|
-
expect(layer.visible).toBe(false);
|
|
43
|
-
});
|
|
44
|
-
test("should visibility stay unchanged", () => {
|
|
45
|
-
const layer = new Layer({ name: "Layer", visible: false });
|
|
46
|
-
layer.visible = false;
|
|
47
|
-
expect(layer.visible).toBe(false);
|
|
48
|
-
});
|
|
49
|
-
test("should return its name.", () => {
|
|
50
|
-
const layer = new Layer({ name: "Layer", visible: false });
|
|
51
|
-
expect(layer.name).toEqual("Layer");
|
|
52
|
-
});
|
|
53
|
-
test("should call terminate on initialization.", () => {
|
|
54
|
-
const layer = new Layer({ name: "Layer" });
|
|
55
|
-
const spy = jest.spyOn(layer, "detachFromMap");
|
|
56
|
-
layer.attachToMap(map);
|
|
57
|
-
expect(spy).toHaveBeenCalledTimes(1);
|
|
58
|
-
});
|
|
59
|
-
test("should listen for click/hover events when layer is visible by default then should not when hidden.", async () => {
|
|
60
|
-
global.console.error = jest.fn();
|
|
61
|
-
const layer = new Layer({ name: "Layer" });
|
|
62
|
-
expect(layer.visible).toBe(true);
|
|
63
|
-
const spy = jest.fn();
|
|
64
|
-
const spy2 = jest.fn();
|
|
65
|
-
layer.onHover(spy);
|
|
66
|
-
layer.onClick(spy2);
|
|
67
|
-
layer.attachToMap(map);
|
|
68
|
-
expect(spy).toHaveBeenCalledTimes(0);
|
|
69
|
-
expect(spy2).toHaveBeenCalledTimes(0);
|
|
70
|
-
await map.fire("mousemove", {
|
|
71
|
-
type: "mousemove",
|
|
72
|
-
lngLat: { toArray: () => [0, 0] },
|
|
73
|
-
coordinate: [0, 0]
|
|
74
|
-
});
|
|
75
|
-
await map.fire("click", {
|
|
76
|
-
type: "click",
|
|
77
|
-
lngLat: { toArray: () => [0, 0] }
|
|
78
|
-
});
|
|
79
|
-
expect(spy).toHaveBeenCalledTimes(1);
|
|
80
|
-
expect(spy2).toHaveBeenCalledTimes(1);
|
|
81
|
-
spy.mockReset();
|
|
82
|
-
spy2.mockReset();
|
|
83
|
-
layer.visible = false;
|
|
84
|
-
await map.fire("mousemove", {
|
|
85
|
-
type: "mousemove",
|
|
86
|
-
lngLat: { toArray: () => [0, 0] }
|
|
87
|
-
});
|
|
88
|
-
await map.fire("click", {
|
|
89
|
-
type: "click",
|
|
90
|
-
lngLat: { toArray: () => [0, 0] }
|
|
91
|
-
});
|
|
92
|
-
expect(spy).toHaveBeenCalledTimes(0);
|
|
93
|
-
expect(spy2).toHaveBeenCalledTimes(0);
|
|
94
|
-
global.console.error.mockRestore();
|
|
95
|
-
});
|
|
96
|
-
test("should not listen for click/hover events when layer is not visible by default then should not when visible.", async () => {
|
|
97
|
-
global.console.error = jest.fn();
|
|
98
|
-
const layer = new Layer({ name: "Layer", visible: false });
|
|
99
|
-
expect(layer.visible).toBe(false);
|
|
100
|
-
const spy = jest.fn();
|
|
101
|
-
const spy2 = jest.fn();
|
|
102
|
-
layer.onHover(spy);
|
|
103
|
-
layer.onClick(spy2);
|
|
104
|
-
layer.attachToMap(map);
|
|
105
|
-
expect(spy).toHaveBeenCalledTimes(0);
|
|
106
|
-
expect(spy2).toHaveBeenCalledTimes(0);
|
|
107
|
-
await map.fire("mousemove", {
|
|
108
|
-
type: "mousemove",
|
|
109
|
-
lngLat: { toArray: () => [0, 0] },
|
|
110
|
-
coordinate: [0, 0]
|
|
111
|
-
});
|
|
112
|
-
await map.fire("click", {
|
|
113
|
-
type: "click",
|
|
114
|
-
lngLat: { toArray: () => [0, 0] }
|
|
115
|
-
});
|
|
116
|
-
expect(spy).toHaveBeenCalledTimes(0);
|
|
117
|
-
expect(spy2).toHaveBeenCalledTimes(0);
|
|
118
|
-
spy.mockReset();
|
|
119
|
-
spy2.mockReset();
|
|
120
|
-
layer.visible = true;
|
|
121
|
-
await map.fire("mousemove", {
|
|
122
|
-
type: "mousemove",
|
|
123
|
-
lngLat: { toArray: () => [0, 0] },
|
|
124
|
-
coordinate: [0, 0]
|
|
125
|
-
});
|
|
126
|
-
await map.fire("click", {
|
|
127
|
-
type: "click",
|
|
128
|
-
lngLat: { toArray: () => [0, 0] }
|
|
129
|
-
});
|
|
130
|
-
expect(spy).toHaveBeenCalledTimes(1);
|
|
131
|
-
expect(spy2).toHaveBeenCalledTimes(1);
|
|
132
|
-
global.console.error.mockRestore();
|
|
133
|
-
});
|
|
134
|
-
test("should not listen for click/hover events after layer.detachFromMap()", async () => {
|
|
135
|
-
global.console.error = jest.fn();
|
|
136
|
-
const layer = new Layer({ name: "Layer", visible: true });
|
|
137
|
-
expect(layer.visible).toBe(true);
|
|
138
|
-
const spy = jest.fn();
|
|
139
|
-
const spy2 = jest.fn();
|
|
140
|
-
layer.onHover(spy);
|
|
141
|
-
layer.onClick(spy2);
|
|
142
|
-
layer.attachToMap(map);
|
|
143
|
-
expect(spy).toHaveBeenCalledTimes(0);
|
|
144
|
-
expect(spy2).toHaveBeenCalledTimes(0);
|
|
145
|
-
await map.fire("mousemove", {
|
|
146
|
-
type: "mousemove",
|
|
147
|
-
lngLat: { toArray: () => [0, 0] },
|
|
148
|
-
coordinate: [0, 0]
|
|
149
|
-
});
|
|
150
|
-
await map.fire("click", {
|
|
151
|
-
type: "click",
|
|
152
|
-
lngLat: { toArray: () => [0, 0] }
|
|
153
|
-
});
|
|
154
|
-
expect(spy).toHaveBeenCalledTimes(1);
|
|
155
|
-
expect(spy2).toHaveBeenCalledTimes(1);
|
|
156
|
-
spy.mockReset();
|
|
157
|
-
spy2.mockReset();
|
|
158
|
-
layer.detachFromMap();
|
|
159
|
-
await map.fire("mousemove", {
|
|
160
|
-
type: "mousemove",
|
|
161
|
-
lngLat: { toArray: () => [0, 0] },
|
|
162
|
-
coordinate: [0, 0]
|
|
163
|
-
});
|
|
164
|
-
await map.fire("click", {
|
|
165
|
-
type: "click",
|
|
166
|
-
lngLat: { toArray: () => [0, 0] }
|
|
167
|
-
});
|
|
168
|
-
expect(spy).toHaveBeenCalledTimes(0);
|
|
169
|
-
expect(spy2).toHaveBeenCalledTimes(0);
|
|
170
|
-
global.console.error.mockRestore();
|
|
171
|
-
});
|
|
172
|
-
test("should clone", () => {
|
|
173
|
-
const layer = new Layer({
|
|
174
|
-
name: "Layer",
|
|
175
|
-
copyrights: ["bar"]
|
|
176
|
-
});
|
|
177
|
-
const clone = layer.clone({ name: "clone" });
|
|
178
|
-
expect(clone).not.toBe(layer);
|
|
179
|
-
expect(clone.name).toBe("clone");
|
|
180
|
-
expect(clone).toBeInstanceOf(Layer);
|
|
181
|
-
});
|
|
182
|
-
});
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import { fromLonLat } from "ol/proj";
|
|
2
|
-
import { unByKey } from "ol/Observable";
|
|
3
|
-
import { getWidth, getHeight } from "ol/extent";
|
|
4
|
-
import transformRotate from "@turf/transform-rotate";
|
|
5
|
-
import { point } from "@turf/helpers";
|
|
6
|
-
import mixin from "../../common/mixins/RealtimeLayerMixin";
|
|
7
|
-
import Layer from "./Layer";
|
|
8
|
-
import { getSourceCoordinates, getMercatorResolution } from "../utils";
|
|
9
|
-
class RealtimeLayer extends mixin(Layer) {
|
|
10
|
-
constructor(options = {}) {
|
|
11
|
-
super({
|
|
12
|
-
...options
|
|
13
|
-
});
|
|
14
|
-
this.onLoad = this.onLoad.bind(this);
|
|
15
|
-
this.onMove = this.onMove.bind(this);
|
|
16
|
-
this.onMoveEnd = this.onMoveEnd.bind(this);
|
|
17
|
-
this.onZoomEnd = this.onZoomEnd.bind(this);
|
|
18
|
-
this.onVisibilityChange = this.onVisibilityChange.bind(this);
|
|
19
|
-
}
|
|
20
|
-
attachToMap(map, beforeId) {
|
|
21
|
-
if (!map) {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
const canvas = map.getCanvas();
|
|
25
|
-
super.attachToMap(map, {
|
|
26
|
-
width: canvas.width / this.pixelRatio,
|
|
27
|
-
height: canvas.height / this.pixelRatio
|
|
28
|
-
});
|
|
29
|
-
this.source = {
|
|
30
|
-
type: "canvas",
|
|
31
|
-
canvas: this.canvas,
|
|
32
|
-
coordinates: getSourceCoordinates(map, this.pixelRatio),
|
|
33
|
-
animate: true,
|
|
34
|
-
attribution: this.copyrights && this.copyrights.join(", ")
|
|
35
|
-
};
|
|
36
|
-
this.beforeId = beforeId;
|
|
37
|
-
this.layer = {
|
|
38
|
-
id: this.key,
|
|
39
|
-
type: "raster",
|
|
40
|
-
source: this.key,
|
|
41
|
-
layout: {
|
|
42
|
-
visibility: this.visible ? "visible" : "none"
|
|
43
|
-
},
|
|
44
|
-
paint: {
|
|
45
|
-
"raster-opacity": 1,
|
|
46
|
-
"raster-fade-duration": 0,
|
|
47
|
-
"raster-resampling": "nearest"
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
if (map.isStyleLoaded()) {
|
|
51
|
-
this.onLoad();
|
|
52
|
-
}
|
|
53
|
-
this.map.on("load", this.onLoad);
|
|
54
|
-
this.listeners = [this.on("change:visible", this.onVisibilityChange)];
|
|
55
|
-
}
|
|
56
|
-
detachFromMap() {
|
|
57
|
-
if (this.map) {
|
|
58
|
-
this.map.off("load", this.onLoad);
|
|
59
|
-
this.listeners.forEach((listener) => {
|
|
60
|
-
unByKey(listener);
|
|
61
|
-
});
|
|
62
|
-
if (this.map.getLayer(this.key)) {
|
|
63
|
-
this.map.removeLayer(this.key);
|
|
64
|
-
}
|
|
65
|
-
if (this.map.getSource(this.key)) {
|
|
66
|
-
this.map.removeSource(this.key);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
super.detachFromMap();
|
|
70
|
-
}
|
|
71
|
-
start() {
|
|
72
|
-
super.start();
|
|
73
|
-
this.map.on("move", this.onMove);
|
|
74
|
-
this.map.on("moveend", this.onMoveEnd);
|
|
75
|
-
this.map.on("zoomend", this.onZoomEnd);
|
|
76
|
-
}
|
|
77
|
-
stop() {
|
|
78
|
-
super.stop();
|
|
79
|
-
if (this.map) {
|
|
80
|
-
this.map.off("move", this.onMove);
|
|
81
|
-
this.map.off("moveend", this.onMoveEnd);
|
|
82
|
-
this.map.off("zoomend", this.onZoomEnd);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
onLoad() {
|
|
86
|
-
if (!this.map.getSource(this.key)) {
|
|
87
|
-
this.map.addSource(this.key, this.source);
|
|
88
|
-
}
|
|
89
|
-
if (!this.map.getLayer(this.key)) {
|
|
90
|
-
this.map.addLayer(this.layer, this.beforeId);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
onUserMoveCallback(evt) {
|
|
94
|
-
super.onUserMoveCallback({
|
|
95
|
-
coordinate: fromLonLat(evt.lngLat.toArray()),
|
|
96
|
-
...evt
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
renderTrajectories(noInterpolate) {
|
|
100
|
-
if (!this.map) {
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
const { width, height } = this.map.getCanvas();
|
|
104
|
-
const center = this.map.getCenter();
|
|
105
|
-
const leftBottom = this.map.unproject({
|
|
106
|
-
x: 0,
|
|
107
|
-
y: height / this.pixelRatio
|
|
108
|
-
});
|
|
109
|
-
const rightTop = this.map.unproject({ x: width / this.pixelRatio, y: 0 });
|
|
110
|
-
const coord0 = transformRotate(point([leftBottom.lng, leftBottom.lat]), -this.map.getBearing(), {
|
|
111
|
-
pivot: [center.lng, center.lat]
|
|
112
|
-
}).geometry.coordinates;
|
|
113
|
-
const coord1 = transformRotate(point([rightTop.lng, rightTop.lat]), -this.map.getBearing(), {
|
|
114
|
-
pivot: [center.lng, center.lat]
|
|
115
|
-
}).geometry.coordinates;
|
|
116
|
-
const bounds = [...fromLonLat(coord0), ...fromLonLat(coord1)];
|
|
117
|
-
const xResolution = getWidth(bounds) / (width / this.pixelRatio);
|
|
118
|
-
const yResolution = getHeight(bounds) / (height / this.pixelRatio);
|
|
119
|
-
const res = Math.max(xResolution, yResolution);
|
|
120
|
-
const viewState = {
|
|
121
|
-
size: [width / this.pixelRatio, height / this.pixelRatio],
|
|
122
|
-
center: fromLonLat([center.lng, center.lat]),
|
|
123
|
-
extent: bounds,
|
|
124
|
-
resolution: res,
|
|
125
|
-
zoom: this.map.getZoom(),
|
|
126
|
-
rotation: -(this.map.getBearing() * Math.PI) / 180,
|
|
127
|
-
pixelRatio: this.pixelRatio
|
|
128
|
-
};
|
|
129
|
-
super.renderTrajectories(viewState, noInterpolate);
|
|
130
|
-
}
|
|
131
|
-
getRefreshTimeInMs() {
|
|
132
|
-
return super.getRefreshTimeInMs(this.map.getZoom());
|
|
133
|
-
}
|
|
134
|
-
getFeatureInfoAtCoordinate(coordinate, options = {}) {
|
|
135
|
-
const resolution = getMercatorResolution(this.map);
|
|
136
|
-
return super.getFeatureInfoAtCoordinate(coordinate, {
|
|
137
|
-
resolution,
|
|
138
|
-
...options
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
onVisibilityChange() {
|
|
142
|
-
if (this.visible && !this.map.getLayer(this.key)) {
|
|
143
|
-
this.map.addLayer(this.layer, this.beforeId);
|
|
144
|
-
} else if (this.map.getLayer(this.key)) {
|
|
145
|
-
this.map.removeLayer(this.key);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
purgeTrajectory(trajectory, extent, zoom) {
|
|
149
|
-
return super.purgeTrajectory(trajectory, extent || this.getMercatorExtent(), zoom || Math.floor(this.map.getZoom() + 1));
|
|
150
|
-
}
|
|
151
|
-
setBbox(extent, zoom) {
|
|
152
|
-
let newExtent = extent;
|
|
153
|
-
let newZoom = zoom;
|
|
154
|
-
if (!newExtent && this.isUpdateBboxOnMoveEnd) {
|
|
155
|
-
newExtent = extent || this.getMercatorExtent();
|
|
156
|
-
newZoom = Math.floor(this.getOlZoom());
|
|
157
|
-
}
|
|
158
|
-
super.setBbox(newExtent, newZoom);
|
|
159
|
-
}
|
|
160
|
-
onMove() {
|
|
161
|
-
this.renderTrajectories();
|
|
162
|
-
}
|
|
163
|
-
renderTrajectoriesInternal(viewState, noInterpolate) {
|
|
164
|
-
const render = super.renderTrajectoriesInternal(viewState, noInterpolate);
|
|
165
|
-
if (render && this.map.style) {
|
|
166
|
-
const extent = getSourceCoordinates(this.map, this.pixelRatio);
|
|
167
|
-
const source = this.map.getSource(this.key);
|
|
168
|
-
if (source) {
|
|
169
|
-
source.setCoordinates(extent);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
return render;
|
|
173
|
-
}
|
|
174
|
-
onMoveEnd() {
|
|
175
|
-
this.renderTrajectories();
|
|
176
|
-
if (this.visible && this.isUpdateBboxOnMoveEnd) {
|
|
177
|
-
this.setBbox();
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
onFeatureHover(features, layer, coordinate) {
|
|
181
|
-
super.onFeatureHover(features, layer, coordinate);
|
|
182
|
-
this.map.getCanvasContainer().style.cursor = features.length ? "pointer" : "auto";
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
export default RealtimeLayer;
|
package/mapbox/utils.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { getWidth, getHeight } from "ol/extent";
|
|
2
|
-
import { fromLonLat } from "ol/proj";
|
|
3
|
-
export const getMercatorResolution = (map) => {
|
|
4
|
-
const bounds = map.getBounds().toArray();
|
|
5
|
-
const a = fromLonLat(bounds[0]);
|
|
6
|
-
const b = fromLonLat(bounds[1]);
|
|
7
|
-
const extent = [...a, ...b];
|
|
8
|
-
const { width, height } = map.getCanvas();
|
|
9
|
-
const xResolution = getWidth(extent) / width;
|
|
10
|
-
const yResolution = getHeight(extent) / height;
|
|
11
|
-
return Math.max(xResolution, yResolution);
|
|
12
|
-
};
|
|
13
|
-
export const getSourceCoordinates = (map, pixelRatio) => {
|
|
14
|
-
const { width, height } = map.getCanvas();
|
|
15
|
-
const leftTop = map.unproject({ x: 0, y: 0 });
|
|
16
|
-
const leftBottom = map.unproject({ x: 0, y: height / pixelRatio });
|
|
17
|
-
const rightBottom = map.unproject({
|
|
18
|
-
x: width / pixelRatio,
|
|
19
|
-
y: height / pixelRatio
|
|
20
|
-
});
|
|
21
|
-
const rightTop = map.unproject({ x: width / pixelRatio, y: 0 });
|
|
22
|
-
return [
|
|
23
|
-
[leftTop.lng, leftTop.lat],
|
|
24
|
-
[rightTop.lng, rightTop.lat],
|
|
25
|
-
[rightBottom.lng, rightBottom.lat],
|
|
26
|
-
[leftBottom.lng, leftBottom.lat]
|
|
27
|
-
];
|
|
28
|
-
};
|
|
29
|
-
export default {
|
|
30
|
-
getMercatorResolution,
|
|
31
|
-
getSourceCoordinates
|
|
32
|
-
};
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { inView } from "ol/layer/Layer";
|
|
2
|
-
import Control from "../../common/controls/Control";
|
|
3
|
-
import mixin from "../../common/mixins/CopyrightMixin";
|
|
4
|
-
import removeDuplicate from "../../common/utils/removeDuplicate";
|
|
5
|
-
class CopyrightControl extends mixin(Control) {
|
|
6
|
-
constructor(options) {
|
|
7
|
-
super(options);
|
|
8
|
-
this.onPostRender = this.onPostRender.bind(this);
|
|
9
|
-
}
|
|
10
|
-
getCopyrights() {
|
|
11
|
-
if (!this.frameState) {
|
|
12
|
-
return [];
|
|
13
|
-
}
|
|
14
|
-
let copyrights = [];
|
|
15
|
-
this.frameState.layerStatesArray.forEach((layerState) => {
|
|
16
|
-
const { layer } = layerState;
|
|
17
|
-
if (inView(layerState, this.frameState.viewState) && layer && layer.getSource && layer.getSource() && layer.getSource().getAttributions()) {
|
|
18
|
-
copyrights = copyrights.concat(layer.getSource().getAttributions()(this.frameState));
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
return removeDuplicate(copyrights);
|
|
22
|
-
}
|
|
23
|
-
activate() {
|
|
24
|
-
super.activate();
|
|
25
|
-
if (this.map) {
|
|
26
|
-
this.map.on("postrender", this.onPostRender);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
deactivate() {
|
|
30
|
-
if (this.map) {
|
|
31
|
-
this.map.un("postrender", this.onPostRender);
|
|
32
|
-
}
|
|
33
|
-
super.deactivate();
|
|
34
|
-
}
|
|
35
|
-
onPostRender(evt) {
|
|
36
|
-
if (this.map && this.element) {
|
|
37
|
-
this.frameState = evt.frameState;
|
|
38
|
-
this.render();
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
export default CopyrightControl;
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
import View from "ol/View";
|
|
2
|
-
import Tile from "ol/Tile";
|
|
3
|
-
import TileLayer from "ol/layer/Tile";
|
|
4
|
-
import TileSource from "ol/source/Tile";
|
|
5
|
-
import { createXYZ } from "ol/tilegrid";
|
|
6
|
-
import { Map } from "ol";
|
|
7
|
-
import Layer from "../layers/Layer";
|
|
8
|
-
import CopyrightControl from "./CopyrightControl";
|
|
9
|
-
const tileLoadFunction = () => {
|
|
10
|
-
const tile = new Tile([0, 0, -1], 2);
|
|
11
|
-
tile.getImage = () => {
|
|
12
|
-
const image = new Image();
|
|
13
|
-
image.width = 256;
|
|
14
|
-
image.height = 256;
|
|
15
|
-
return image;
|
|
16
|
-
};
|
|
17
|
-
return tile;
|
|
18
|
-
};
|
|
19
|
-
const getOLTileLayer = () => {
|
|
20
|
-
const layer = new TileLayer({
|
|
21
|
-
source: new TileSource({
|
|
22
|
-
projection: "EPSG:3857",
|
|
23
|
-
tileGrid: createXYZ()
|
|
24
|
-
})
|
|
25
|
-
});
|
|
26
|
-
layer.getSource().getTile = tileLoadFunction;
|
|
27
|
-
return layer;
|
|
28
|
-
};
|
|
29
|
-
const getLayer = (copyrights, visible = true) => new Layer({
|
|
30
|
-
visible,
|
|
31
|
-
copyrights,
|
|
32
|
-
olLayer: getOLTileLayer()
|
|
33
|
-
});
|
|
34
|
-
describe("CopyrightControl", () => {
|
|
35
|
-
let map;
|
|
36
|
-
beforeEach(() => {
|
|
37
|
-
const target = document.createElement("div");
|
|
38
|
-
document.body.appendChild(target);
|
|
39
|
-
map = new Map({
|
|
40
|
-
target,
|
|
41
|
-
view: new View({
|
|
42
|
-
center: [0, 0],
|
|
43
|
-
zoom: 0
|
|
44
|
-
})
|
|
45
|
-
});
|
|
46
|
-
getLayer(true, "bar").attachToMap(map);
|
|
47
|
-
map.setSize([200, 200]);
|
|
48
|
-
map.renderSync();
|
|
49
|
-
});
|
|
50
|
-
afterEach(() => {
|
|
51
|
-
if (map) {
|
|
52
|
-
map.setTarget(null);
|
|
53
|
-
map = null;
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
test("should be activate by default", () => {
|
|
57
|
-
const control = new CopyrightControl();
|
|
58
|
-
expect(control.active).toBe(true);
|
|
59
|
-
});
|
|
60
|
-
test("renders a string copyright", () => {
|
|
61
|
-
const control = new CopyrightControl();
|
|
62
|
-
control.attachToMap(map);
|
|
63
|
-
expect(control.element.innerHTML).toBe("");
|
|
64
|
-
getLayer("copyright").attachToMap(map);
|
|
65
|
-
map.renderSync();
|
|
66
|
-
expect(control.element.innerHTML).toBe("copyright");
|
|
67
|
-
});
|
|
68
|
-
test("renders an array of copyrights", () => {
|
|
69
|
-
const control = new CopyrightControl();
|
|
70
|
-
control.attachToMap(map);
|
|
71
|
-
expect(control.element.innerHTML).toBe("");
|
|
72
|
-
getLayer(["copyright 1", "copyright 2"]).attachToMap(map);
|
|
73
|
-
map.renderSync();
|
|
74
|
-
expect(control.element.innerHTML).toBe("copyright 1 | copyright 2");
|
|
75
|
-
});
|
|
76
|
-
test("renders unique copyrights", () => {
|
|
77
|
-
const control = new CopyrightControl();
|
|
78
|
-
control.attachToMap(map);
|
|
79
|
-
expect(control.element.innerHTML).toBe("");
|
|
80
|
-
getLayer(["copyright 1", "copyright 2"]).attachToMap(map);
|
|
81
|
-
getLayer("copyright 1").attachToMap(map);
|
|
82
|
-
getLayer(["copyright 2"]).attachToMap(map);
|
|
83
|
-
map.renderSync();
|
|
84
|
-
expect(control.element.innerHTML).toBe("copyright 1 | copyright 2");
|
|
85
|
-
});
|
|
86
|
-
test("doesn't render copyright of an hidden layer", () => {
|
|
87
|
-
const control = new CopyrightControl();
|
|
88
|
-
control.attachToMap(map);
|
|
89
|
-
expect(control.element.innerHTML).toBe("");
|
|
90
|
-
const layer1 = getLayer("copyright hidden", false);
|
|
91
|
-
layer1.attachToMap(map);
|
|
92
|
-
const layer2 = getLayer("copyright", true);
|
|
93
|
-
layer2.attachToMap(map);
|
|
94
|
-
map.renderSync();
|
|
95
|
-
expect(control.element.innerHTML).toBe("copyright");
|
|
96
|
-
layer1.visible = true;
|
|
97
|
-
map.renderSync();
|
|
98
|
-
layer2.visible = false;
|
|
99
|
-
map.renderSync();
|
|
100
|
-
expect(control.element.innerHTML).toBe("copyright hidden");
|
|
101
|
-
});
|
|
102
|
-
test("should activate the control on construction then deactivate it", () => {
|
|
103
|
-
getLayer("copyright 1").attachToMap(map);
|
|
104
|
-
const control = new CopyrightControl({ active: true });
|
|
105
|
-
control.attachToMap(map);
|
|
106
|
-
map.renderSync();
|
|
107
|
-
expect(control.element.parentNode).toBe(map.getTargetElement());
|
|
108
|
-
expect(control.active).toBe(true);
|
|
109
|
-
expect(control.element.innerHTML).toBe("copyright 1");
|
|
110
|
-
control.active = false;
|
|
111
|
-
map.renderSync();
|
|
112
|
-
expect(control.element.innerHTML).toBe("");
|
|
113
|
-
});
|
|
114
|
-
test("should deactivate the control on constrcution then activate it", () => {
|
|
115
|
-
getLayer("copyright 1").attachToMap(map);
|
|
116
|
-
const control = new CopyrightControl({ active: false });
|
|
117
|
-
control.attachToMap(map);
|
|
118
|
-
map.renderSync();
|
|
119
|
-
expect(control.element.parentNode).toBe(map.getTargetElement());
|
|
120
|
-
expect(control.active).toBe(false);
|
|
121
|
-
map.renderSync();
|
|
122
|
-
expect(control.element.innerHTML).toBe("");
|
|
123
|
-
control.active = true;
|
|
124
|
-
map.renderSync();
|
|
125
|
-
expect(control.element.innerHTML).toBe("copyright 1");
|
|
126
|
-
});
|
|
127
|
-
test("should add copyrights in the map container element then remove it.", () => {
|
|
128
|
-
getLayer("copyright value").attachToMap(map);
|
|
129
|
-
map.renderSync();
|
|
130
|
-
const control = new CopyrightControl();
|
|
131
|
-
control.attachToMap(map);
|
|
132
|
-
expect(control.element.parentNode).toBe(map.getTargetElement());
|
|
133
|
-
control.detachFromMap();
|
|
134
|
-
expect(control.element.parentNode).toBe(null);
|
|
135
|
-
});
|
|
136
|
-
test("should add copyrights in the target element then remove it.", () => {
|
|
137
|
-
getLayer(["copyright value"]).attachToMap(map);
|
|
138
|
-
map.renderSync();
|
|
139
|
-
const target = document.createElement("div");
|
|
140
|
-
target.setAttribute("id", "copyright");
|
|
141
|
-
document.body.appendChild(target);
|
|
142
|
-
const control = new CopyrightControl({
|
|
143
|
-
target: document.getElementById("copyright")
|
|
144
|
-
});
|
|
145
|
-
control.attachToMap(map);
|
|
146
|
-
expect(control.element.parentNode).toBe(target);
|
|
147
|
-
control.detachFromMap();
|
|
148
|
-
expect(control.element.parentNode).toBe(null);
|
|
149
|
-
});
|
|
150
|
-
test("renders custom copyrights with the render method ", () => {
|
|
151
|
-
const control = new CopyrightControl({
|
|
152
|
-
active: true,
|
|
153
|
-
render() {
|
|
154
|
-
if (!this.element) {
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
this.element.innerHTML = this.active ? this.getCopyrights().join(", ") : "";
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
control.attachToMap(map);
|
|
161
|
-
getLayer(["copyright 1", "copyright 2", "copyright 3"]).attachToMap(map);
|
|
162
|
-
map.renderSync();
|
|
163
|
-
expect(control.element.innerHTML).toBe("copyright 1, copyright 2, copyright 3");
|
|
164
|
-
});
|
|
165
|
-
});
|