mobility-toolbox-js 2.0.1-beta.13 → 2.2.0-beta.0
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 +281 -0
- package/api/RealtimeAPI.d.ts.map +1 -0
- package/api/RealtimeAPI.js +490 -0
- package/api/RoutingAPI.d.ts +37 -0
- package/api/RoutingAPI.d.ts.map +1 -0
- package/api/RoutingAPI.js +32 -12
- package/api/StopsAPI.d.ts +38 -0
- package/api/StopsAPI.d.ts.map +1 -0
- package/api/StopsAPI.js +33 -9
- package/api/index.d.ts +4 -0
- package/api/index.d.ts.map +1 -0
- package/api/index.js +3 -3
- package/api/typedefs.d.ts +179 -0
- package/api/typedefs.d.ts.map +1 -0
- package/api/typedefs.js +75 -0
- package/common/api/HttpAPI.d.ts +31 -0
- package/common/api/HttpAPI.d.ts.map +1 -0
- package/common/api/HttpAPI.js +54 -27
- package/common/api/WebSocketAPI.d.ts +153 -0
- package/common/api/WebSocketAPI.d.ts.map +1 -0
- package/common/api/WebSocketAPI.js +330 -164
- package/common/controls/ControlCommon.d.ts +76 -0
- package/common/controls/ControlCommon.d.ts.map +1 -0
- package/common/controls/ControlCommon.js +150 -0
- package/common/controls/CopyrightControlCommon.d.ts +13 -0
- package/common/controls/CopyrightControlCommon.d.ts.map +1 -0
- package/common/controls/CopyrightControlCommon.js +34 -0
- package/common/controls/StopFinderControlCommon.d.ts +55 -0
- package/common/controls/StopFinderControlCommon.d.ts.map +1 -0
- package/common/controls/StopFinderControlCommon.js +144 -0
- package/common/index.d.ts +3 -0
- package/common/index.d.ts.map +1 -0
- package/common/index.js +2 -4
- package/common/layers/LayerCommon.d.ts +94 -0
- package/common/layers/LayerCommon.d.ts.map +1 -0
- package/common/layers/LayerCommon.js +244 -0
- package/common/mixins/RealtimeLayerMixin.d.ts +286 -0
- package/common/mixins/RealtimeLayerMixin.d.ts.map +1 -0
- package/common/mixins/RealtimeLayerMixin.js +779 -0
- package/common/mixins/UserInteractionsLayerMixin.d.ts +60 -0
- package/common/mixins/UserInteractionsLayerMixin.d.ts.map +1 -0
- package/common/mixins/UserInteractionsLayerMixin.js +241 -0
- package/common/styles/index.d.ts +5 -0
- package/common/styles/index.d.ts.map +1 -0
- package/common/styles/index.js +4 -4
- package/common/styles/realtimeDefaultStyle.d.ts +36 -0
- package/common/styles/realtimeDefaultStyle.d.ts.map +1 -0
- package/common/styles/realtimeDefaultStyle.js +275 -0
- package/common/styles/realtimeDelayStyle.d.ts +12 -0
- package/common/styles/realtimeDelayStyle.d.ts.map +1 -0
- package/common/styles/realtimeDelayStyle.js +13 -0
- package/common/styles/realtimeHeadingStyle.d.ts +12 -0
- package/common/styles/realtimeHeadingStyle.d.ts.map +1 -0
- package/common/styles/realtimeHeadingStyle.js +85 -0
- package/common/styles/realtimeSimpleStyle.d.ts +4 -0
- package/common/styles/realtimeSimpleStyle.d.ts.map +1 -0
- package/common/styles/realtimeSimpleStyle.js +23 -0
- package/common/typedefs.d.ts +111 -0
- package/common/typedefs.d.ts.map +1 -0
- package/common/typedefs.js +52 -0
- package/common/utils/compareDepartures.d.ts +11 -0
- package/common/utils/compareDepartures.d.ts.map +1 -0
- package/common/utils/compareDepartures.js +35 -0
- package/common/utils/createCanvas.d.ts +10 -0
- package/common/utils/createCanvas.d.ts.map +1 -0
- package/common/utils/createCanvas.js +27 -0
- package/common/utils/createRealtimeFilters.d.ts +13 -0
- package/common/utils/createRealtimeFilters.d.ts.map +1 -0
- package/common/utils/createRealtimeFilters.js +74 -0
- package/common/utils/debounceDeparturesMessages.d.ts +12 -0
- package/common/utils/debounceDeparturesMessages.d.ts.map +1 -0
- package/common/utils/debounceDeparturesMessages.js +24 -0
- package/common/utils/debounceWebsocketMessages.d.ts +11 -0
- package/common/utils/debounceWebsocketMessages.d.ts.map +1 -0
- package/common/utils/debounceWebsocketMessages.js +29 -0
- package/common/utils/getLayersAsFlatArray.d.ts +3 -0
- package/common/utils/getLayersAsFlatArray.d.ts.map +1 -0
- package/common/utils/getLayersAsFlatArray.js +15 -0
- package/common/utils/getMapboxMapCopyrights.d.ts +18 -0
- package/common/utils/getMapboxMapCopyrights.d.ts.map +1 -0
- package/common/utils/getMapboxMapCopyrights.js +26 -15
- package/common/utils/getMapboxRender.d.ts +7 -0
- package/common/utils/getMapboxRender.d.ts.map +1 -0
- package/common/utils/getMapboxRender.js +87 -0
- package/common/utils/getMaplibreRender.d.ts +7 -0
- package/common/utils/getMaplibreRender.d.ts.map +1 -0
- package/common/utils/getMaplibreRender.js +38 -0
- package/common/utils/getRealtimeModeSuffix.d.ts +10 -0
- package/common/utils/getRealtimeModeSuffix.d.ts.map +1 -0
- package/common/utils/getRealtimeModeSuffix.js +7 -0
- package/common/utils/getUrlWithParams.d.ts +9 -0
- package/common/utils/getUrlWithParams.d.ts.map +1 -0
- package/common/utils/getUrlWithParams.js +18 -0
- package/common/utils/getVehiclePosition.d.ts +16 -0
- package/common/utils/getVehiclePosition.d.ts.map +1 -0
- package/common/utils/getVehiclePosition.js +67 -37
- package/common/utils/index.d.ts +17 -0
- package/common/utils/index.d.ts.map +1 -0
- package/common/utils/index.js +17 -5
- package/common/utils/realtimeConfig.d.ts +49 -0
- package/common/utils/realtimeConfig.d.ts.map +1 -0
- package/common/utils/realtimeConfig.js +173 -0
- package/common/utils/removeDuplicate.d.ts +10 -0
- package/common/utils/removeDuplicate.d.ts.map +1 -0
- package/common/utils/removeDuplicate.js +12 -5
- package/common/utils/renderTrajectories.d.ts +17 -0
- package/common/utils/renderTrajectories.d.ts.map +1 -0
- package/common/utils/renderTrajectories.js +110 -0
- package/common/utils/sortAndFilterDepartures.d.ts +16 -0
- package/common/utils/sortAndFilterDepartures.d.ts.map +1 -0
- package/common/utils/sortAndFilterDepartures.js +58 -0
- package/common/utils/sortByDelay.d.ts +3 -0
- package/common/utils/sortByDelay.d.ts.map +1 -0
- package/common/utils/sortByDelay.js +17 -15
- package/common/utils/timeUtils.d.ts +24 -0
- package/common/utils/timeUtils.d.ts.map +1 -0
- package/common/utils/timeUtils.js +34 -15
- package/iife.d.ts +3 -0
- package/iife.d.ts.map +1 -0
- package/iife.js +5 -0
- package/index.d.ts +10 -0
- package/index.d.ts.map +1 -0
- package/index.js +8 -6
- package/mapbox/controls/CopyrightControl.d.ts +29 -0
- package/mapbox/controls/CopyrightControl.d.ts.map +1 -0
- package/mapbox/controls/CopyrightControl.js +44 -25
- package/mapbox/controls/index.d.ts +2 -0
- package/mapbox/controls/index.d.ts.map +1 -0
- package/mapbox/controls/index.js +2 -1
- package/mapbox/index.d.ts +6 -0
- package/mapbox/index.d.ts.map +1 -0
- package/mapbox/index.js +5 -4
- package/mapbox/layers/Layer.d.ts +59 -0
- package/mapbox/layers/Layer.d.ts.map +1 -0
- package/mapbox/layers/Layer.js +99 -55
- package/mapbox/layers/RealtimeLayer.d.ts +181 -0
- package/mapbox/layers/RealtimeLayer.d.ts.map +1 -0
- package/mapbox/layers/RealtimeLayer.js +276 -0
- package/mapbox/layers/index.d.ts +3 -0
- package/mapbox/layers/index.d.ts.map +1 -0
- package/mapbox/layers/index.js +2 -2
- package/mapbox/utils/getMercatorResolution.d.ts +9 -0
- package/mapbox/utils/getMercatorResolution.d.ts.map +1 -0
- package/mapbox/utils/getMercatorResolution.js +18 -0
- package/mapbox/utils/getSourceCoordinates.d.ts +9 -0
- package/mapbox/utils/getSourceCoordinates.d.ts.map +1 -0
- package/mapbox/utils/getSourceCoordinates.js +27 -0
- package/mapbox/utils/index.d.ts +3 -0
- package/mapbox/utils/index.d.ts.map +1 -0
- package/mapbox/utils/index.js +2 -0
- package/mbt.js +26074 -16501
- package/mbt.js.map +4 -4
- package/mbt.min.js +205 -126
- package/mbt.min.js.map +4 -4
- package/ol/controls/CopyrightControl.d.ts +31 -0
- package/ol/controls/CopyrightControl.d.ts.map +1 -0
- package/ol/controls/CopyrightControl.js +62 -36
- package/ol/controls/RoutingControl.d.ts +193 -0
- package/ol/controls/RoutingControl.d.ts.map +1 -0
- package/ol/controls/RoutingControl.js +601 -357
- package/ol/controls/StopFinderControl.d.ts +30 -0
- package/ol/controls/StopFinderControl.d.ts.map +1 -0
- package/ol/controls/StopFinderControl.js +30 -8
- package/ol/controls/index.d.ts +4 -0
- package/ol/controls/index.d.ts.map +1 -0
- package/ol/controls/index.js +3 -3
- package/ol/index.d.ts +6 -0
- package/ol/index.d.ts.map +1 -0
- package/ol/index.js +5 -5
- package/ol/layers/Layer.d.ts +86 -0
- package/ol/layers/Layer.d.ts.map +1 -0
- package/ol/layers/Layer.js +163 -77
- package/ol/layers/MapGlLayer.d.ts +67 -0
- package/ol/layers/MapGlLayer.d.ts.map +1 -0
- package/ol/layers/MapGlLayer.js +218 -0
- package/ol/layers/MapboxLayer.d.ts +50 -0
- package/ol/layers/MapboxLayer.d.ts.map +1 -0
- package/ol/layers/MapboxLayer.js +99 -193
- package/ol/layers/MapboxStyleLayer.d.ts +129 -0
- package/ol/layers/MapboxStyleLayer.d.ts.map +1 -0
- package/ol/layers/MapboxStyleLayer.js +362 -171
- package/ol/layers/MaplibreLayer.d.ts +28 -0
- package/ol/layers/MaplibreLayer.d.ts.map +1 -0
- package/ol/layers/MaplibreLayer.js +30 -135
- package/ol/layers/RealtimeLayer.d.ts +202 -0
- package/ol/layers/RealtimeLayer.d.ts.map +1 -0
- package/ol/layers/RealtimeLayer.js +340 -0
- package/ol/layers/RoutingLayer.d.ts +34 -0
- package/ol/layers/RoutingLayer.d.ts.map +1 -0
- package/ol/layers/RoutingLayer.js +72 -48
- package/ol/layers/VectorLayer.d.ts +25 -0
- package/ol/layers/VectorLayer.d.ts.map +1 -0
- package/ol/layers/VectorLayer.js +34 -18
- package/ol/layers/WMSLayer.d.ts +42 -0
- package/ol/layers/WMSLayer.d.ts.map +1 -0
- package/ol/layers/WMSLayer.js +84 -34
- package/ol/layers/index.d.ts +9 -0
- package/ol/layers/index.d.ts.map +1 -0
- package/ol/layers/index.js +8 -8
- package/ol/styles/fullTrajectoryDelayStyle.d.ts +4 -0
- package/ol/styles/fullTrajectoryDelayStyle.d.ts.map +1 -0
- package/ol/styles/fullTrajectoryDelayStyle.js +26 -24
- package/ol/styles/fullTrajectoryStyle.d.ts +5 -0
- package/ol/styles/fullTrajectoryStyle.d.ts.map +1 -0
- package/ol/styles/fullTrajectoryStyle.js +40 -39
- package/ol/styles/index.d.ts +3 -0
- package/ol/styles/index.d.ts.map +1 -0
- package/ol/styles/index.js +2 -2
- package/package.json +81 -133
- package/setupTests.d.ts +2 -0
- package/setupTests.d.ts.map +1 -0
- package/setupTests.js +26 -0
- package/types/common.d.ts +122 -0
- package/types/index.d.ts +13 -0
- package/types/realtime.d.ts +320 -0
- package/types/routing.d.ts +206 -0
- package/types/stops.d.ts +143 -0
- package/README.md +0 -23
- package/api/RoutingAPI.test.js +0 -25
- package/api/StopsAPI.test.js +0 -22
- package/api/TralisAPI.js +0 -359
- package/api/TralisAPI.test.js +0 -67
- package/api/TralisAPIUtils.js +0 -43
- package/common/Tracker.js +0 -93
- package/common/api/HttpAPI.test.js +0 -50
- 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 -213
- package/common/layers/Layer.test.js +0 -526
- package/common/mixins/CopyrightMixin.js +0 -24
- package/common/mixins/SearchMixin.js +0 -110
- package/common/mixins/TralisLayerMixin.js +0 -479
- package/common/styles/trackerDefaultStyle.js +0 -197
- package/common/styles/trackerDelayStyle.js +0 -8
- package/common/styles/trackerSimpleStyle.js +0 -18
- package/common/trackerConfig.js +0 -152
- package/common/trackerConfig.test.js +0 -23
- package/common/utils/createTrackerFilters.js +0 -56
- package/common/utils/createTrackerFilters.test.js +0 -79
- package/common/utils/getMapboxMapCopyrights.test.js +0 -40
- package/common/utils/getMapboxStyleUrl.js +0 -22
- package/common/utils/removeDuplicate.test.js +0 -19
- package/common/utils/timeUtils.test.js +0 -10
- package/mapbox/layers/Layer.test.js +0 -182
- package/mapbox/layers/TralisLayer.js +0 -182
- package/mapbox/layers/TralisLayer.test.js +0 -38
- package/mapbox/utils.js +0 -32
- package/ol/controls/CopyrightControl.test.js +0 -165
- package/ol/controls/RoutingControl.test.js +0 -151
- package/ol/controls/StopFinderControl.test.js +0 -48
- package/ol/layers/Layer.test.js +0 -174
- package/ol/layers/MapboxLayer.test.js +0 -160
- package/ol/layers/MapboxStyleLayer.test.js +0 -231
- package/ol/layers/RoutingLayer.test.js +0 -40
- package/ol/layers/TralisLayer.js +0 -185
- package/ol/layers/TralisLayer.test.js +0 -79
- package/ol/layers/VectorLayer.test.js +0 -87
- package/ol/layers/WMSLayer.test.js +0 -76
|
@@ -1,479 +0,0 @@
|
|
|
1
|
-
import qs from "query-string";
|
|
2
|
-
import { buffer, containsCoordinate, intersects } from "ol/extent";
|
|
3
|
-
import { unByKey } from "ol/Observable";
|
|
4
|
-
import GeoJSON from "ol/format/GeoJSON";
|
|
5
|
-
import Point from "ol/geom/Point";
|
|
6
|
-
import debounce from "lodash.debounce";
|
|
7
|
-
import throttle from "lodash.throttle";
|
|
8
|
-
import { fromLonLat } from "ol/proj";
|
|
9
|
-
import Tracker from "../Tracker";
|
|
10
|
-
import { timeSteps } from "../trackerConfig";
|
|
11
|
-
import createFilters from "../utils/createTrackerFilters";
|
|
12
|
-
import trackerDefaultStyle from "../styles/trackerDefaultStyle";
|
|
13
|
-
import { TralisAPI, TralisModes } from "../../api";
|
|
14
|
-
const LINE_FILTER = "publishedlinename";
|
|
15
|
-
const ROUTE_FILTER = "tripnumber";
|
|
16
|
-
const OPERATOR_FILTER = "operator";
|
|
17
|
-
export class TralisLayerInterface {
|
|
18
|
-
constructor(options = {}) {
|
|
19
|
-
}
|
|
20
|
-
attachToMap(map) {
|
|
21
|
-
}
|
|
22
|
-
detachFromMap() {
|
|
23
|
-
}
|
|
24
|
-
start() {
|
|
25
|
-
}
|
|
26
|
-
stop() {
|
|
27
|
-
}
|
|
28
|
-
setBbox(extent, zoom) {
|
|
29
|
-
}
|
|
30
|
-
setMode(mode) {
|
|
31
|
-
}
|
|
32
|
-
getTrajectoryInfos(id, mode) {
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
const TralisLayerMixin = (Base) => class extends Base {
|
|
36
|
-
constructor(options = {}) {
|
|
37
|
-
super({ hitTolerance: 10, ...options });
|
|
38
|
-
this.debug = options.debug;
|
|
39
|
-
this.mode = options.mode || TralisModes.TOPOGRAPHIC;
|
|
40
|
-
this.api = options.api || new TralisAPI(options);
|
|
41
|
-
this.tenant = options.tenant || "";
|
|
42
|
-
this.minZoomNonTrain = options.minZoomNonTrain || 9;
|
|
43
|
-
this.minZoomInterpolation = options.minZoomInterpolation || 8;
|
|
44
|
-
this.format = new GeoJSON();
|
|
45
|
-
this.generalizationLevelByZoom = options.generalizationLevelByZoom || {
|
|
46
|
-
0: 5,
|
|
47
|
-
1: 5,
|
|
48
|
-
2: 5,
|
|
49
|
-
3: 5,
|
|
50
|
-
4: 5,
|
|
51
|
-
5: 5,
|
|
52
|
-
6: 5,
|
|
53
|
-
7: 5,
|
|
54
|
-
8: 10,
|
|
55
|
-
9: 30,
|
|
56
|
-
10: 30,
|
|
57
|
-
11: 100,
|
|
58
|
-
12: 100,
|
|
59
|
-
13: 100
|
|
60
|
-
};
|
|
61
|
-
this.isUpdateBboxOnMoveEnd = options.isUpdateBboxOnMoveEnd !== false;
|
|
62
|
-
this.throttleRenderTrajectories = throttle(this.renderTrajectoriesInternal, 50, { leading: false, trailing: true });
|
|
63
|
-
this.debounceRenderTrajectories = debounce(this.renderTrajectoriesInternal, 50, { leading: true, trailing: true, maxWait: 5e3 });
|
|
64
|
-
this.onFeatureHover = this.onFeatureHover.bind(this);
|
|
65
|
-
this.onFeatureClick = this.onFeatureClick.bind(this);
|
|
66
|
-
this.renderTrajectoriesInternal = this.renderTrajectoriesInternal.bind(this);
|
|
67
|
-
this.onTrajectoryMessage = this.onTrajectoryMessage.bind(this);
|
|
68
|
-
this.onDeleteTrajectoryMessage = this.onDeleteTrajectoryMessage.bind(this);
|
|
69
|
-
this.onDocumentVisibilityChange = this.onDocumentVisibilityChange.bind(this);
|
|
70
|
-
}
|
|
71
|
-
defineProperties(options) {
|
|
72
|
-
let { regexPublishedLineName, publishedLineName, tripNumber, operator } = options;
|
|
73
|
-
const {
|
|
74
|
-
style,
|
|
75
|
-
speed,
|
|
76
|
-
pixelRatio,
|
|
77
|
-
hoverVehicleId,
|
|
78
|
-
selectedVehicleId,
|
|
79
|
-
filter,
|
|
80
|
-
sort,
|
|
81
|
-
time,
|
|
82
|
-
live
|
|
83
|
-
} = options;
|
|
84
|
-
const initTrackerOptions = {
|
|
85
|
-
style
|
|
86
|
-
};
|
|
87
|
-
Object.keys(initTrackerOptions).forEach((key) => initTrackerOptions[key] === void 0 && delete initTrackerOptions[key]);
|
|
88
|
-
let currSpeed = speed || 1;
|
|
89
|
-
let currTime = time || new Date();
|
|
90
|
-
super.defineProperties(options);
|
|
91
|
-
Object.defineProperties(this, {
|
|
92
|
-
isTrackerLayer: { value: true },
|
|
93
|
-
style: {
|
|
94
|
-
value: (trajectory, viewState) => (style || trackerDefaultStyle)(trajectory, viewState, this)
|
|
95
|
-
},
|
|
96
|
-
speed: {
|
|
97
|
-
get: () => currSpeed,
|
|
98
|
-
set: (newSpeed) => {
|
|
99
|
-
currSpeed = newSpeed;
|
|
100
|
-
this.start();
|
|
101
|
-
}
|
|
102
|
-
},
|
|
103
|
-
filter: {
|
|
104
|
-
value: filter,
|
|
105
|
-
writable: true
|
|
106
|
-
},
|
|
107
|
-
sort: {
|
|
108
|
-
value: sort,
|
|
109
|
-
writable: true
|
|
110
|
-
},
|
|
111
|
-
tracker: { value: null, writable: true },
|
|
112
|
-
styleCache: { value: {} },
|
|
113
|
-
live: {
|
|
114
|
-
value: live === false ? live : true,
|
|
115
|
-
writable: true
|
|
116
|
-
},
|
|
117
|
-
time: {
|
|
118
|
-
get: () => currTime,
|
|
119
|
-
set: (newTime) => {
|
|
120
|
-
currTime = newTime && newTime.getTime ? newTime : new Date(newTime);
|
|
121
|
-
this.renderTrajectories();
|
|
122
|
-
}
|
|
123
|
-
},
|
|
124
|
-
trajectories: {
|
|
125
|
-
value: {},
|
|
126
|
-
writable: true
|
|
127
|
-
},
|
|
128
|
-
renderedTrajectories: {
|
|
129
|
-
get: () => this.tracker && this.tracker.renderedTrajectories || []
|
|
130
|
-
},
|
|
131
|
-
hoverVehicleId: {
|
|
132
|
-
value: hoverVehicleId,
|
|
133
|
-
writable: true
|
|
134
|
-
},
|
|
135
|
-
selectedVehicleId: {
|
|
136
|
-
value: selectedVehicleId,
|
|
137
|
-
writable: true
|
|
138
|
-
},
|
|
139
|
-
pixelRatio: {
|
|
140
|
-
value: pixelRatio || (typeof window !== "undefined" ? window.devicePixelRatio : 1),
|
|
141
|
-
writable: true
|
|
142
|
-
},
|
|
143
|
-
initTrackerOptions: {
|
|
144
|
-
value: initTrackerOptions,
|
|
145
|
-
writable: false
|
|
146
|
-
},
|
|
147
|
-
useRequestAnimationFrame: {
|
|
148
|
-
value: options.useRequestAnimationFrame || false,
|
|
149
|
-
writable: true
|
|
150
|
-
},
|
|
151
|
-
useThrottle: {
|
|
152
|
-
value: options.useThrottle || true,
|
|
153
|
-
writable: true
|
|
154
|
-
},
|
|
155
|
-
useDebounce: {
|
|
156
|
-
value: options.useDebounce || false,
|
|
157
|
-
writable: true
|
|
158
|
-
},
|
|
159
|
-
publishedLineName: {
|
|
160
|
-
get: () => publishedLineName,
|
|
161
|
-
set: (newPublishedLineName) => {
|
|
162
|
-
publishedLineName = newPublishedLineName;
|
|
163
|
-
this.updateFilters();
|
|
164
|
-
}
|
|
165
|
-
},
|
|
166
|
-
tripNumber: {
|
|
167
|
-
get: () => tripNumber,
|
|
168
|
-
set: (newTripNumber) => {
|
|
169
|
-
tripNumber = newTripNumber;
|
|
170
|
-
this.updateFilters();
|
|
171
|
-
}
|
|
172
|
-
},
|
|
173
|
-
operator: {
|
|
174
|
-
get: () => operator,
|
|
175
|
-
set: (newOperator) => {
|
|
176
|
-
operator = newOperator;
|
|
177
|
-
this.updateFilters();
|
|
178
|
-
}
|
|
179
|
-
},
|
|
180
|
-
regexPublishedLineName: {
|
|
181
|
-
get: () => regexPublishedLineName,
|
|
182
|
-
set: (newRegex) => {
|
|
183
|
-
regexPublishedLineName = newRegex;
|
|
184
|
-
this.updateFilters();
|
|
185
|
-
}
|
|
186
|
-
},
|
|
187
|
-
delayDisplay: {
|
|
188
|
-
value: options.delayDisplay || 3e5,
|
|
189
|
-
writable: true
|
|
190
|
-
},
|
|
191
|
-
delayOutlineColor: {
|
|
192
|
-
value: options.delayOutlineColor || "#000000",
|
|
193
|
-
writable: true
|
|
194
|
-
}
|
|
195
|
-
});
|
|
196
|
-
this.updateFilters();
|
|
197
|
-
}
|
|
198
|
-
attachToMap(map) {
|
|
199
|
-
super.attachToMap(map);
|
|
200
|
-
this.tracker = new Tracker({
|
|
201
|
-
style: (...args) => this.style(...args),
|
|
202
|
-
...this.initTrackerOptions
|
|
203
|
-
});
|
|
204
|
-
if (this.visible) {
|
|
205
|
-
this.start();
|
|
206
|
-
}
|
|
207
|
-
this.visibilityRef = this.on("change:visible", (evt) => {
|
|
208
|
-
if (evt.target.visible) {
|
|
209
|
-
this.start();
|
|
210
|
-
} else {
|
|
211
|
-
this.stop();
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
document.addEventListener("visibilitychange", this.onDocumentVisibilityChange);
|
|
215
|
-
}
|
|
216
|
-
detachFromMap() {
|
|
217
|
-
document.removeEventListener("visibilitychange", this.onDocumentVisibilityChange);
|
|
218
|
-
this.stop();
|
|
219
|
-
unByKey(this.visibilityRef);
|
|
220
|
-
if (this.tracker) {
|
|
221
|
-
const { canvas } = this.tracker;
|
|
222
|
-
const context = canvas.getContext("2d");
|
|
223
|
-
context.clearRect(0, 0, canvas.width, canvas.height);
|
|
224
|
-
this.tracker = null;
|
|
225
|
-
}
|
|
226
|
-
super.detachFromMap();
|
|
227
|
-
}
|
|
228
|
-
start() {
|
|
229
|
-
this.stop();
|
|
230
|
-
this.renderTrajectories();
|
|
231
|
-
this.startUpdateTime();
|
|
232
|
-
if (this.isClickActive) {
|
|
233
|
-
this.onClick(this.onFeatureClick);
|
|
234
|
-
}
|
|
235
|
-
if (this.isHoverActive) {
|
|
236
|
-
this.onHover(this.onFeatureHover);
|
|
237
|
-
}
|
|
238
|
-
this.api.open();
|
|
239
|
-
this.api.subscribeTrajectory(this.mode, this.onTrajectoryMessage, this.isUpdateBboxOnMoveEnd);
|
|
240
|
-
this.api.subscribeDeletedVehicles(this.mode, this.onDeleteTrajectoryMessage, this.isUpdateBboxOnMoveEnd);
|
|
241
|
-
if (this.isUpdateBboxOnMoveEnd) {
|
|
242
|
-
this.setBbox();
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
startUpdateTime() {
|
|
246
|
-
this.stopUpdateTime();
|
|
247
|
-
this.updateTimeDelay = this.getRefreshTimeInMs();
|
|
248
|
-
this.updateTimeInterval = setInterval(() => {
|
|
249
|
-
this.time = this.live ? new Date() : this.time.getTime() + this.updateTimeDelay * this.speed;
|
|
250
|
-
}, this.updateTimeDelay);
|
|
251
|
-
}
|
|
252
|
-
stop() {
|
|
253
|
-
this.api.unsubscribeTrajectory(this.onTrajectoryMessage);
|
|
254
|
-
this.api.unsubscribeDeletedVehicles(this.onDeleteTrajectoryMessage);
|
|
255
|
-
this.api.close();
|
|
256
|
-
}
|
|
257
|
-
stopUpdateTime() {
|
|
258
|
-
if (this.updateTimeInterval) {
|
|
259
|
-
clearInterval(this.updateTimeInterval);
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
renderTrajectoriesInternal(viewState, noInterpolate) {
|
|
263
|
-
if (!this.tracker) {
|
|
264
|
-
return false;
|
|
265
|
-
}
|
|
266
|
-
const time = this.live ? Date.now() : this.time;
|
|
267
|
-
const trajectories = Object.values(this.trajectories);
|
|
268
|
-
if (this.sort) {
|
|
269
|
-
trajectories.sort(this.sort);
|
|
270
|
-
}
|
|
271
|
-
this.renderState = this.tracker.renderTrajectories(trajectories, { ...viewState, pixelRatio: this.pixelRatio, time }, {
|
|
272
|
-
noInterpolate: viewState.zoom < this.minZoomInterpolation ? true : noInterpolate,
|
|
273
|
-
hoverVehicleId: this.hoverVehicleId,
|
|
274
|
-
selectedVehicleId: this.selectedVehicleId,
|
|
275
|
-
iconScale: this.iconScale,
|
|
276
|
-
delayDisplay: this.delayDisplay,
|
|
277
|
-
delayOutlineColor: this.delayOutlineColor
|
|
278
|
-
});
|
|
279
|
-
return true;
|
|
280
|
-
}
|
|
281
|
-
renderTrajectories(viewState, noInterpolate) {
|
|
282
|
-
if (this.requestId) {
|
|
283
|
-
cancelAnimationFrame(this.requestId);
|
|
284
|
-
this.requestId = null;
|
|
285
|
-
}
|
|
286
|
-
if (!noInterpolate && this.useRequestAnimationFrame) {
|
|
287
|
-
this.requestId = requestAnimationFrame(() => {
|
|
288
|
-
this.renderTrajectoriesInternal(viewState, noInterpolate);
|
|
289
|
-
});
|
|
290
|
-
} else if (!noInterpolate && this.useDebounce) {
|
|
291
|
-
this.debounceRenderTrajectories(viewState, noInterpolate);
|
|
292
|
-
} else if (!noInterpolate && this.useThrottle) {
|
|
293
|
-
this.throttleRenderTrajectories(viewState, noInterpolate);
|
|
294
|
-
} else {
|
|
295
|
-
this.renderTrajectoriesInternal(viewState, noInterpolate);
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
setBbox(extent, zoom) {
|
|
299
|
-
const keys = Object.keys(this.trajectories);
|
|
300
|
-
for (let i = keys.length - 1; i >= 0; i -= 1) {
|
|
301
|
-
this.purgeTrajectory(this.trajectories[keys[i]], extent, zoom);
|
|
302
|
-
}
|
|
303
|
-
const bbox = [...extent];
|
|
304
|
-
if (this.isUpdateBboxOnMoveEnd) {
|
|
305
|
-
bbox.push(zoom);
|
|
306
|
-
if (this.tenant) {
|
|
307
|
-
bbox.push(`tenant=${this.tenant}`);
|
|
308
|
-
}
|
|
309
|
-
this.generalizationLevel = this.generalizationLevelByZoom[zoom];
|
|
310
|
-
if (this.generalizationLevel) {
|
|
311
|
-
bbox.push(`gen=${this.generalizationLevel}`);
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
this.api.bbox = bbox;
|
|
315
|
-
}
|
|
316
|
-
setMode(mode) {
|
|
317
|
-
if (this.mode === mode) {
|
|
318
|
-
return;
|
|
319
|
-
}
|
|
320
|
-
this.mode = mode;
|
|
321
|
-
this.api.subscribeTrajectory(this.mode, this.onTrajectoryMessage, this.isUpdateBboxOnMoveEnd);
|
|
322
|
-
this.api.subscribeDeletedVehicles(this.mode, this.onDeleteTrajectoryMessage, this.isUpdateBboxOnMoveEnd);
|
|
323
|
-
}
|
|
324
|
-
getRefreshTimeInMs(zoom) {
|
|
325
|
-
const roundedZoom = Math.round(zoom);
|
|
326
|
-
const timeStep = timeSteps[roundedZoom] || 25;
|
|
327
|
-
const nextTick = Math.max(25, timeStep / this.speed);
|
|
328
|
-
const nextThrottleTick = Math.min(nextTick, 500);
|
|
329
|
-
if (this.useThrottle) {
|
|
330
|
-
this.throttleRenderTrajectories = throttle(this.renderTrajectoriesInternal, nextThrottleTick, { leading: true, trailing: true });
|
|
331
|
-
} else if (this.useDebounce) {
|
|
332
|
-
this.debounceRenderTrajectories = debounce(this.renderTrajectoriesInternal, nextThrottleTick, { leading: true, trailing: true, maxWait: 5e3 });
|
|
333
|
-
}
|
|
334
|
-
if (this.api?.buffer) {
|
|
335
|
-
const [, size] = this.api.buffer;
|
|
336
|
-
this.api.buffer = [nextThrottleTick, size];
|
|
337
|
-
}
|
|
338
|
-
return nextTick;
|
|
339
|
-
}
|
|
340
|
-
getVehicle(filterFc) {
|
|
341
|
-
return Object.values(this.trajectories).filter(filterFc);
|
|
342
|
-
}
|
|
343
|
-
getFeatureInfoAtCoordinate(coordinate, options = {}) {
|
|
344
|
-
const { resolution, nb } = options;
|
|
345
|
-
const ext = buffer([...coordinate, ...coordinate], this.hitTolerance * resolution);
|
|
346
|
-
let trajectories = Object.values(this.trajectories);
|
|
347
|
-
if (this.sort) {
|
|
348
|
-
trajectories = trajectories.sort(this.sort);
|
|
349
|
-
}
|
|
350
|
-
const vehicles = [];
|
|
351
|
-
for (let i = 0; i < trajectories.length; i += 1) {
|
|
352
|
-
if (trajectories[i].properties.coordinate && containsCoordinate(ext, trajectories[i].properties.coordinate)) {
|
|
353
|
-
vehicles.push(trajectories[i]);
|
|
354
|
-
}
|
|
355
|
-
if (vehicles.length === nb) {
|
|
356
|
-
break;
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
return Promise.resolve({
|
|
360
|
-
layer: this,
|
|
361
|
-
features: vehicles.map((vehicle) => this.format.readFeature(vehicle)),
|
|
362
|
-
coordinate
|
|
363
|
-
});
|
|
364
|
-
}
|
|
365
|
-
getTrajectoryInfos(id) {
|
|
366
|
-
const promises = [
|
|
367
|
-
this.api.getStopSequence(id, this.mode),
|
|
368
|
-
this.api.getFullTrajectory(id, this.mode, this.generalizationLevel)
|
|
369
|
-
];
|
|
370
|
-
return Promise.all(promises).then(([stopSequence, fullTrajectory]) => {
|
|
371
|
-
const response = {
|
|
372
|
-
stopSequence,
|
|
373
|
-
fullTrajectory
|
|
374
|
-
};
|
|
375
|
-
return response;
|
|
376
|
-
});
|
|
377
|
-
}
|
|
378
|
-
purgeTrajectory(trajectory, extent, zoom) {
|
|
379
|
-
const { type, bounds, train_id: id } = trajectory.properties;
|
|
380
|
-
if (!intersects(extent, bounds) || type !== "rail" && zoom < (this.minZoomNonTrain || 9)) {
|
|
381
|
-
this.removeTrajectory(id);
|
|
382
|
-
return true;
|
|
383
|
-
}
|
|
384
|
-
return false;
|
|
385
|
-
}
|
|
386
|
-
addTrajectory(trajectory) {
|
|
387
|
-
if (this.filter && !this.filter(trajectory)) {
|
|
388
|
-
return;
|
|
389
|
-
}
|
|
390
|
-
this.trajectories[trajectory.properties.train_id] = trajectory;
|
|
391
|
-
this.renderTrajectories();
|
|
392
|
-
}
|
|
393
|
-
removeTrajectory(id) {
|
|
394
|
-
delete this.trajectories[id];
|
|
395
|
-
}
|
|
396
|
-
onZoomEnd(evt) {
|
|
397
|
-
this.startUpdateTime();
|
|
398
|
-
}
|
|
399
|
-
onDocumentVisibilityChange() {
|
|
400
|
-
if (!this.visible) {
|
|
401
|
-
return;
|
|
402
|
-
}
|
|
403
|
-
if (document.hidden) {
|
|
404
|
-
this.stop();
|
|
405
|
-
} else {
|
|
406
|
-
this.start();
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
onTrajectoryMessage(data) {
|
|
410
|
-
if (!data.content) {
|
|
411
|
-
return;
|
|
412
|
-
}
|
|
413
|
-
const trajectory = data.content;
|
|
414
|
-
const {
|
|
415
|
-
geometry,
|
|
416
|
-
properties: {
|
|
417
|
-
train_id: id,
|
|
418
|
-
time_since_update: timeSinceUpdate,
|
|
419
|
-
raw_coordinates: rawCoordinates
|
|
420
|
-
}
|
|
421
|
-
} = trajectory;
|
|
422
|
-
if (timeSinceUpdate < 0) {
|
|
423
|
-
return;
|
|
424
|
-
}
|
|
425
|
-
if (this.purgeTrajectory(trajectory)) {
|
|
426
|
-
return;
|
|
427
|
-
}
|
|
428
|
-
if (this.debug && this.mode === TralisModes.TOPOGRAPHIC && rawCoordinates) {
|
|
429
|
-
trajectory.properties.olGeometry = {
|
|
430
|
-
type: "Point",
|
|
431
|
-
coordinates: fromLonLat(rawCoordinates, this.map.getView().getProjection())
|
|
432
|
-
};
|
|
433
|
-
} else {
|
|
434
|
-
trajectory.properties.olGeometry = this.format.readGeometry(geometry);
|
|
435
|
-
}
|
|
436
|
-
trajectory.properties.timeOffset = Date.now() - data.timestamp;
|
|
437
|
-
this.addTrajectory(trajectory);
|
|
438
|
-
}
|
|
439
|
-
onDeleteTrajectoryMessage(data) {
|
|
440
|
-
if (!data.content) {
|
|
441
|
-
return;
|
|
442
|
-
}
|
|
443
|
-
this.removeTrajectory(data.content);
|
|
444
|
-
}
|
|
445
|
-
onFeatureHover(features, layer, coordinate) {
|
|
446
|
-
const [feature] = features;
|
|
447
|
-
let id = null;
|
|
448
|
-
if (feature) {
|
|
449
|
-
id = feature.get("train_id");
|
|
450
|
-
}
|
|
451
|
-
if (this.hoverVehicleId !== id) {
|
|
452
|
-
this.hoverVehicleId = id;
|
|
453
|
-
this.renderTrajectories(true);
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
onFeatureClick(features, layer, coordinate) {
|
|
457
|
-
const [feature] = features;
|
|
458
|
-
let id = null;
|
|
459
|
-
if (feature) {
|
|
460
|
-
id = feature.get("train_id");
|
|
461
|
-
}
|
|
462
|
-
if (this.selectedVehicleId !== id) {
|
|
463
|
-
this.selectedVehicleId = id;
|
|
464
|
-
this.selectedVehicle = feature;
|
|
465
|
-
this.renderTrajectories(true);
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
updateFilters() {
|
|
469
|
-
const parameters = qs.parse(window.location.search.toLowerCase());
|
|
470
|
-
const publishedName = this.publishedLineName || parameters[LINE_FILTER];
|
|
471
|
-
const tripNumber = this.tripNumber || parameters[ROUTE_FILTER];
|
|
472
|
-
const operator = this.operator || parameters[OPERATOR_FILTER];
|
|
473
|
-
const { regexPublishedLineName } = this;
|
|
474
|
-
if (publishedName || tripNumber || operator || regexPublishedLineName) {
|
|
475
|
-
this.filter = createFilters(publishedName, tripNumber, operator, regexPublishedLineName);
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
};
|
|
479
|
-
export default TralisLayerMixin;
|
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getRadius,
|
|
3
|
-
getBgColor,
|
|
4
|
-
getDelayColor,
|
|
5
|
-
getDelayText,
|
|
6
|
-
getTextColor,
|
|
7
|
-
getTextSize
|
|
8
|
-
} from "../trackerConfig";
|
|
9
|
-
const createCanvas = (width, height) => {
|
|
10
|
-
const canvas = document.createElement("canvas");
|
|
11
|
-
canvas.width = width;
|
|
12
|
-
canvas.height = height;
|
|
13
|
-
return canvas;
|
|
14
|
-
};
|
|
15
|
-
const cacheDelayBg = {};
|
|
16
|
-
export const getDelayBgCanvas = (origin, radius, color) => {
|
|
17
|
-
const key = `${origin}, ${radius}, ${color}`;
|
|
18
|
-
if (!cacheDelayBg[key]) {
|
|
19
|
-
const canvas = createCanvas(origin * 2, origin * 2);
|
|
20
|
-
const ctx = canvas.getContext("2d");
|
|
21
|
-
ctx.beginPath();
|
|
22
|
-
ctx.arc(origin, origin, radius, 0, 2 * Math.PI, false);
|
|
23
|
-
ctx.fillStyle = color;
|
|
24
|
-
ctx.filter = "blur(1px)";
|
|
25
|
-
ctx.fill();
|
|
26
|
-
cacheDelayBg[key] = canvas;
|
|
27
|
-
}
|
|
28
|
-
return cacheDelayBg[key];
|
|
29
|
-
};
|
|
30
|
-
const cacheDelayText = {};
|
|
31
|
-
export const getDelayTextCanvas = (width, text, fontSize, font, delayColor, delayOutlineColor, pixelRatio) => {
|
|
32
|
-
const key = `${width}, ${text}, ${font}, ${delayColor}, ${delayOutlineColor}, ${pixelRatio}`;
|
|
33
|
-
if (!cacheDelayText[key]) {
|
|
34
|
-
const canvas = createCanvas(width, fontSize + 8 * pixelRatio);
|
|
35
|
-
const ctx = canvas.getContext("2d");
|
|
36
|
-
ctx.textAlign = "left";
|
|
37
|
-
ctx.textBaseline = "middle";
|
|
38
|
-
ctx.font = font;
|
|
39
|
-
ctx.fillStyle = delayColor;
|
|
40
|
-
ctx.strokeStyle = delayOutlineColor;
|
|
41
|
-
ctx.lineWidth = 1.5 * pixelRatio;
|
|
42
|
-
const delayText = text;
|
|
43
|
-
ctx.strokeText(delayText, 0, fontSize);
|
|
44
|
-
ctx.fillText(delayText, 0, fontSize);
|
|
45
|
-
cacheDelayText[key] = canvas;
|
|
46
|
-
}
|
|
47
|
-
return cacheDelayText[key];
|
|
48
|
-
};
|
|
49
|
-
const cacheCircle = {};
|
|
50
|
-
export const getCircleCanvas = (origin, radius, color, hasStroke, hasDash, pixelRatio) => {
|
|
51
|
-
const key = `${origin}, ${radius}, ${color}, ${hasStroke}, ${hasDash}, ${pixelRatio}`;
|
|
52
|
-
if (!cacheCircle[key]) {
|
|
53
|
-
const canvas = createCanvas(origin * 2, origin * 2);
|
|
54
|
-
const ctx = canvas.getContext("2d");
|
|
55
|
-
ctx.fillStyle = color;
|
|
56
|
-
if (hasStroke) {
|
|
57
|
-
ctx.lineWidth = 1 * pixelRatio;
|
|
58
|
-
ctx.strokeStyle = "#000000";
|
|
59
|
-
}
|
|
60
|
-
ctx.beginPath();
|
|
61
|
-
ctx.arc(origin, origin, radius, 0, 2 * Math.PI, false);
|
|
62
|
-
ctx.fill();
|
|
63
|
-
if (hasDash) {
|
|
64
|
-
ctx.setLineDash([5, 3]);
|
|
65
|
-
}
|
|
66
|
-
if (hasStroke) {
|
|
67
|
-
ctx.stroke();
|
|
68
|
-
}
|
|
69
|
-
cacheCircle[key] = canvas;
|
|
70
|
-
}
|
|
71
|
-
return cacheCircle[key];
|
|
72
|
-
};
|
|
73
|
-
const cacheText = {};
|
|
74
|
-
export const getTextCanvas = (text, origin, textSize, fillColor, strokeColor, hasStroke, pixelRatio) => {
|
|
75
|
-
const key = `${text}, ${origin}, ${textSize}, ${fillColor},${strokeColor}, ${hasStroke}, ${pixelRatio}`;
|
|
76
|
-
if (!cacheText[key]) {
|
|
77
|
-
const canvas = createCanvas(origin * 2, origin * 2);
|
|
78
|
-
const ctx = canvas.getContext("2d");
|
|
79
|
-
if (hasStroke) {
|
|
80
|
-
ctx.save();
|
|
81
|
-
ctx.textBaseline = "middle";
|
|
82
|
-
ctx.textAlign = "center";
|
|
83
|
-
ctx.font = `bold ${textSize + 2}px Arial`;
|
|
84
|
-
ctx.strokeStyle = strokeColor;
|
|
85
|
-
ctx.strokeText(text, origin, origin);
|
|
86
|
-
ctx.restore();
|
|
87
|
-
}
|
|
88
|
-
ctx.textBaseline = "middle";
|
|
89
|
-
ctx.textAlign = "center";
|
|
90
|
-
ctx.fillStyle = fillColor;
|
|
91
|
-
ctx.font = `bold ${textSize}px Arial`;
|
|
92
|
-
ctx.strokeStyle = strokeColor;
|
|
93
|
-
ctx.strokeText(text, origin, origin);
|
|
94
|
-
ctx.fillText(text, origin, origin);
|
|
95
|
-
cacheText[key] = canvas;
|
|
96
|
-
}
|
|
97
|
-
return cacheText[key];
|
|
98
|
-
};
|
|
99
|
-
const styleCache = {};
|
|
100
|
-
const style = (trajectory, viewState, options) => {
|
|
101
|
-
const {
|
|
102
|
-
hoverVehicleId,
|
|
103
|
-
selectedVehicleId,
|
|
104
|
-
useDelayStyle,
|
|
105
|
-
delayOutlineColor,
|
|
106
|
-
delayDisplay
|
|
107
|
-
} = options;
|
|
108
|
-
const { zoom, pixelRatio } = viewState;
|
|
109
|
-
let { type, cancelled } = trajectory.properties;
|
|
110
|
-
const {
|
|
111
|
-
train_id: id,
|
|
112
|
-
line,
|
|
113
|
-
delay,
|
|
114
|
-
state,
|
|
115
|
-
operator_provides_realtime_journey: operatorProvidesRealtime
|
|
116
|
-
} = trajectory.properties;
|
|
117
|
-
let { name, text_color: textColor, color } = line || {};
|
|
118
|
-
cancelled = cancelled === true || state === "JOURNEY_CANCELLED";
|
|
119
|
-
if (!type) {
|
|
120
|
-
type = "Rail";
|
|
121
|
-
}
|
|
122
|
-
if (!name) {
|
|
123
|
-
name = "I";
|
|
124
|
-
}
|
|
125
|
-
if (!textColor) {
|
|
126
|
-
textColor = "#000000";
|
|
127
|
-
}
|
|
128
|
-
if (color && color[0] !== "#") {
|
|
129
|
-
color = `#${color}`;
|
|
130
|
-
}
|
|
131
|
-
if (textColor[0] !== "#") {
|
|
132
|
-
textColor = `#${textColor}`;
|
|
133
|
-
}
|
|
134
|
-
const z = Math.min(Math.floor(zoom || 1), 16);
|
|
135
|
-
const hover = hoverVehicleId && hoverVehicleId === id;
|
|
136
|
-
const selected = selectedVehicleId && selectedVehicleId === id;
|
|
137
|
-
let radius = getRadius(type, z) * pixelRatio;
|
|
138
|
-
const isDisplayStrokeAndDelay = radius >= 7 * pixelRatio;
|
|
139
|
-
if (hover || selected) {
|
|
140
|
-
radius = isDisplayStrokeAndDelay ? radius + 5 * pixelRatio : 14 * pixelRatio;
|
|
141
|
-
}
|
|
142
|
-
const mustDrawText = radius > 10 * pixelRatio;
|
|
143
|
-
let key = `${radius}${type}${color}${hover}${selected}${cancelled}${delay}`;
|
|
144
|
-
if (useDelayStyle) {
|
|
145
|
-
key += `${operatorProvidesRealtime}`;
|
|
146
|
-
}
|
|
147
|
-
if (mustDrawText) {
|
|
148
|
-
key += `${name}${textColor}`;
|
|
149
|
-
}
|
|
150
|
-
if (!styleCache[key]) {
|
|
151
|
-
if (radius === 0) {
|
|
152
|
-
styleCache[key] = null;
|
|
153
|
-
return null;
|
|
154
|
-
}
|
|
155
|
-
const margin = 1 * pixelRatio;
|
|
156
|
-
const radiusDelay = radius + 2;
|
|
157
|
-
const markerSize = radius * 2;
|
|
158
|
-
const size = radiusDelay * 2 + margin * 2 + 100 * pixelRatio;
|
|
159
|
-
const origin = size / 2;
|
|
160
|
-
const canvas = createCanvas(size, size);
|
|
161
|
-
const ctx = canvas.getContext("2d");
|
|
162
|
-
if (isDisplayStrokeAndDelay && delay !== null) {
|
|
163
|
-
const delayBg = getDelayBgCanvas(origin, radiusDelay, getDelayColor(delay, cancelled));
|
|
164
|
-
ctx.drawImage(delayBg, 0, 0);
|
|
165
|
-
}
|
|
166
|
-
if (isDisplayStrokeAndDelay && (hover || delay >= delayDisplay || cancelled)) {
|
|
167
|
-
const fontSize = Math.max(cancelled ? 19 : 14, Math.min(cancelled ? 19 : 17, radius * 1.2)) * pixelRatio;
|
|
168
|
-
const text = getDelayText(delay, cancelled);
|
|
169
|
-
if (text) {
|
|
170
|
-
const textWidth = text.length * fontSize;
|
|
171
|
-
const delayText = getDelayTextCanvas(textWidth, text, fontSize, `bold ${fontSize}px arial, sans-serif`, getDelayColor(delay, cancelled, true), delayOutlineColor, pixelRatio);
|
|
172
|
-
ctx.drawImage(delayText, origin + radiusDelay + margin, origin - fontSize);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
let circleFillColor;
|
|
176
|
-
if (useDelayStyle) {
|
|
177
|
-
circleFillColor = getDelayColor(delay, cancelled);
|
|
178
|
-
} else {
|
|
179
|
-
circleFillColor = color || getBgColor(type);
|
|
180
|
-
}
|
|
181
|
-
const hasStroke = isDisplayStrokeAndDelay || hover || selected;
|
|
182
|
-
const hasDash = isDisplayStrokeAndDelay && useDelayStyle && delay === null && operatorProvidesRealtime === "yes";
|
|
183
|
-
const circle = getCircleCanvas(origin, radius, circleFillColor, hasStroke, hasDash, pixelRatio);
|
|
184
|
-
ctx.drawImage(circle, 0, 0);
|
|
185
|
-
if (mustDrawText) {
|
|
186
|
-
const fontSize = Math.max(radius, 10);
|
|
187
|
-
const textSize = getTextSize(ctx, markerSize, name, fontSize);
|
|
188
|
-
const textColor2 = !useDelayStyle ? textColor || getTextColor(type) : "#000000";
|
|
189
|
-
const hasStroke2 = useDelayStyle && delay === null && operatorProvidesRealtime === "yes";
|
|
190
|
-
const text = getTextCanvas(name, origin, textSize, textColor2, circleFillColor, hasStroke2, pixelRatio);
|
|
191
|
-
ctx.drawImage(text, 0, 0);
|
|
192
|
-
}
|
|
193
|
-
styleCache[key] = canvas;
|
|
194
|
-
}
|
|
195
|
-
return styleCache[key];
|
|
196
|
-
};
|
|
197
|
-
export default style;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
let canvas;
|
|
2
|
-
const style = () => {
|
|
3
|
-
if (!canvas) {
|
|
4
|
-
document.createElement("canvas");
|
|
5
|
-
canvas.width = 15;
|
|
6
|
-
canvas.height = 15;
|
|
7
|
-
const ctx = canvas.getContext("2d");
|
|
8
|
-
ctx.arc(8, 8, 5, 0, 2 * Math.PI, false);
|
|
9
|
-
ctx.fillStyle = "#8ED6FF";
|
|
10
|
-
ctx.fill();
|
|
11
|
-
ctx.lineWidth = 3;
|
|
12
|
-
ctx.strokeStyle = "black";
|
|
13
|
-
ctx.stroke();
|
|
14
|
-
ctx.lineWidth = 3;
|
|
15
|
-
}
|
|
16
|
-
return canvas;
|
|
17
|
-
};
|
|
18
|
-
export default style;
|