gisviewer-vue3-arcgis 1.0.114 → 1.0.115
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/es/src/gis-map/utils/holo-flow/trace-holo-flow.d.ts +0 -2
- package/es/src/gis-map/utils/holo-flow/trace-holo-flow.mjs +42 -118
- package/es/src/gis-map/utils/holo-flow/trace-renderer-external.d.ts +4 -0
- package/es/src/gis-map/utils/holo-flow/trace-renderer-external.mjs +200 -108
- package/es/src/gis-map/utils/holo-flow/trace-renderer-layer.d.ts +3 -0
- package/es/src/gis-map/utils/holo-flow/trace-renderer-layer.mjs +42 -15
- package/es/src/types/index.d.ts +2 -0
- package/lib/src/gis-map/utils/holo-flow/trace-holo-flow.d.ts +0 -2
- package/lib/src/gis-map/utils/holo-flow/trace-holo-flow.js +2 -2
- package/lib/src/gis-map/utils/holo-flow/trace-renderer-external.d.ts +4 -0
- package/lib/src/gis-map/utils/holo-flow/trace-renderer-external.js +1 -1
- package/lib/src/gis-map/utils/holo-flow/trace-renderer-layer.d.ts +3 -0
- package/lib/src/gis-map/utils/holo-flow/trace-renderer-layer.js +1 -1
- package/lib/src/types/index.d.ts +2 -0
- package/package.json +1 -1
|
@@ -1,123 +1,46 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
class R {
|
|
1
|
+
import * as m from "@arcgis/core/views/3d/externalRenderers";
|
|
2
|
+
import f from "./trace-renderer-external.mjs";
|
|
3
|
+
import R from "./trace-renderer-layer.mjs";
|
|
4
|
+
class V {
|
|
6
5
|
constructor(e) {
|
|
7
|
-
|
|
8
|
-
[
|
|
9
|
-
"uuid",
|
|
10
|
-
"ptcId",
|
|
11
|
-
"plateno",
|
|
12
|
-
"timestamp",
|
|
13
|
-
"localTimestamp",
|
|
14
|
-
"timestamp_str",
|
|
15
|
-
"speed",
|
|
16
|
-
"laneNo",
|
|
17
|
-
"objHeight",
|
|
18
|
-
"objLength",
|
|
19
|
-
"latitude",
|
|
20
|
-
"longitude",
|
|
21
|
-
"ptcType",
|
|
22
|
-
"vehicleType",
|
|
23
|
-
"vehicleColor",
|
|
24
|
-
"plateColor",
|
|
25
|
-
"sbdm",
|
|
26
|
-
"heading",
|
|
27
|
-
"fixAngle",
|
|
28
|
-
"roadLayer",
|
|
29
|
-
"status",
|
|
30
|
-
"step",
|
|
31
|
-
"receiveTimestamp"
|
|
32
|
-
]
|
|
33
|
-
], e.type === "3d" ? (this.traceRenderer = new T(e), u.add(
|
|
6
|
+
e.type === "3d" ? (this.traceRenderer = new f(e), m.add(
|
|
34
7
|
e,
|
|
35
8
|
this.traceRenderer
|
|
36
|
-
)) : this.traceRenderer = new
|
|
9
|
+
)) : this.traceRenderer = new R(e);
|
|
37
10
|
}
|
|
38
11
|
async init() {
|
|
39
12
|
await this.traceRenderer.init();
|
|
40
13
|
}
|
|
41
14
|
downloadLog() {
|
|
42
|
-
const e = this.
|
|
43
|
-
`).replace(/null/g, ""),
|
|
44
|
-
|
|
15
|
+
const e = this.traceRenderer.getLog().map((s) => s.join(",")).join(`
|
|
16
|
+
`).replace(/null/g, ""), o = new Blob([e], { type: "text/csv;charset=utf-8;" }), i = URL.createObjectURL(o), r = document.createElement("a");
|
|
17
|
+
r.setAttribute("href", i), r.setAttribute("download", "trace-log.csv"), r.style.visibility = "hidden", document.body.appendChild(r), r.click(), document.body.removeChild(r);
|
|
45
18
|
}
|
|
46
19
|
/**
|
|
47
20
|
* 处理全息流轨迹数据
|
|
48
21
|
* */
|
|
49
22
|
async handleVehicleTraceData(e) {
|
|
50
|
-
const { newVehList:
|
|
51
|
-
if (
|
|
52
|
-
for (const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
t.plateno,
|
|
57
|
-
t.timestamp,
|
|
58
|
-
t.localTimestamp,
|
|
59
|
-
t.timestamp_str,
|
|
60
|
-
t.speed,
|
|
61
|
-
t.laneNo,
|
|
62
|
-
t.objHeight,
|
|
63
|
-
t.objLength,
|
|
64
|
-
t.latitude,
|
|
65
|
-
t.longitude,
|
|
66
|
-
t.ptcType,
|
|
67
|
-
t.vehicleType,
|
|
68
|
-
t.vehicleColor,
|
|
69
|
-
t.plateColor,
|
|
70
|
-
t.sbdm,
|
|
71
|
-
t.heading,
|
|
72
|
-
t.fixAngle,
|
|
73
|
-
t.roadLayer,
|
|
74
|
-
t.status,
|
|
75
|
-
t.step,
|
|
76
|
-
h
|
|
77
|
-
]);
|
|
78
|
-
const o = this.buildVehicleTrackData(t, i);
|
|
79
|
-
o && c.push(o);
|
|
23
|
+
const { newVehList: o, updateVehList: i, deleteVehList: r, jgsj: s } = e, n = e.crossId || "", l = [], a = [];
|
|
24
|
+
if (o && o.length > 0) {
|
|
25
|
+
for (const c of o) {
|
|
26
|
+
c.localTimestamp || (c.localTimestamp = s || Date.now());
|
|
27
|
+
const t = this.buildVehicleTrackData(c, n);
|
|
28
|
+
t && l.push(t);
|
|
80
29
|
}
|
|
81
|
-
await this.traceRenderer.addVehicles(
|
|
30
|
+
await this.traceRenderer.addVehicles(l);
|
|
82
31
|
}
|
|
83
|
-
if (
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
o.uuid,
|
|
88
|
-
o.ptcId,
|
|
89
|
-
o.plateno,
|
|
90
|
-
o.timestamp,
|
|
91
|
-
o.localTimestamp,
|
|
92
|
-
o.timestamp_str,
|
|
93
|
-
o.speed,
|
|
94
|
-
o.laneNo,
|
|
95
|
-
o.objHeight,
|
|
96
|
-
o.objLength,
|
|
97
|
-
o.latitude,
|
|
98
|
-
o.longitude,
|
|
99
|
-
o.ptcType,
|
|
100
|
-
o.vehicleType,
|
|
101
|
-
o.vehicleColor,
|
|
102
|
-
o.plateColor,
|
|
103
|
-
o.sbdm,
|
|
104
|
-
o.heading,
|
|
105
|
-
o.fixAngle,
|
|
106
|
-
o.roadLayer,
|
|
107
|
-
o.status,
|
|
108
|
-
o.step,
|
|
109
|
-
t
|
|
110
|
-
]);
|
|
111
|
-
const p = this.buildVehicleTrackData(o, i);
|
|
112
|
-
p && n.push(p);
|
|
32
|
+
if (i && i.length > 0) {
|
|
33
|
+
for (const c of i) {
|
|
34
|
+
const t = this.buildVehicleTrackData(c, n);
|
|
35
|
+
t && a.push(t);
|
|
113
36
|
}
|
|
114
|
-
await this.traceRenderer.updateVehicles(
|
|
37
|
+
await this.traceRenderer.updateVehicles(a);
|
|
115
38
|
}
|
|
116
|
-
if (
|
|
117
|
-
const
|
|
118
|
-
(
|
|
39
|
+
if (r && r.length > 0) {
|
|
40
|
+
const c = r.map(
|
|
41
|
+
(t) => n + "-" + (t.ptcId || t.vehno || t.vehNo)
|
|
119
42
|
);
|
|
120
|
-
this.traceRenderer.deleteVehicles(
|
|
43
|
+
this.traceRenderer.deleteVehicles(c);
|
|
121
44
|
}
|
|
122
45
|
}
|
|
123
46
|
/**
|
|
@@ -151,28 +74,29 @@ class R {
|
|
|
151
74
|
setInterpolate(e) {
|
|
152
75
|
this.traceRenderer.setInterpolate(e);
|
|
153
76
|
}
|
|
154
|
-
buildVehicleTrackData(e,
|
|
155
|
-
const
|
|
156
|
-
if (!(
|
|
77
|
+
buildVehicleTrackData(e, o) {
|
|
78
|
+
const i = e.longitude, r = e.latitude, s = e.ptcId, n = Number(e.ptcType), l = e.heading, a = Number(e.vehicleType), c = Number(e.vehicleColor), t = e.plateNo || e.plateno, h = Number(e.plateColor), d = e.timestamp, p = e.localTimestamp, u = e.roadLayer ? String(e.roadLayer) : "1", g = e.step;
|
|
79
|
+
if (!(n < 0 || n > 8))
|
|
157
80
|
return {
|
|
158
81
|
ptcId: s,
|
|
159
|
-
crossId:
|
|
160
|
-
vehicleId:
|
|
161
|
-
x:
|
|
162
|
-
y:
|
|
163
|
-
ptcType:
|
|
164
|
-
vehicleType:
|
|
165
|
-
heading:
|
|
166
|
-
vehicleColor:
|
|
82
|
+
crossId: o,
|
|
83
|
+
vehicleId: o + "-" + s,
|
|
84
|
+
x: i,
|
|
85
|
+
y: r,
|
|
86
|
+
ptcType: n,
|
|
87
|
+
vehicleType: a,
|
|
88
|
+
heading: n === 2 ? -l : l,
|
|
89
|
+
vehicleColor: c,
|
|
167
90
|
showName: t && t !== "" && t !== "0" && t !== "000000" ? t : "",
|
|
168
91
|
plateNo: t,
|
|
169
|
-
plateColor:
|
|
170
|
-
timestamp:
|
|
171
|
-
localTimestamp:
|
|
172
|
-
roadLayer:
|
|
92
|
+
plateColor: h,
|
|
93
|
+
timestamp: d,
|
|
94
|
+
localTimestamp: p,
|
|
95
|
+
roadLayer: u,
|
|
96
|
+
step: g
|
|
173
97
|
};
|
|
174
98
|
}
|
|
175
99
|
}
|
|
176
100
|
export {
|
|
177
|
-
|
|
101
|
+
V as default
|
|
178
102
|
};
|
|
@@ -38,7 +38,11 @@ export default class TraceRendererExternal implements ITraceRendererInterface {
|
|
|
38
38
|
private vehicleObjectMap;
|
|
39
39
|
private needInterpolate;
|
|
40
40
|
private updateModel;
|
|
41
|
+
private appDataStore;
|
|
42
|
+
/** 轨迹日志 */
|
|
43
|
+
private logTable;
|
|
41
44
|
constructor(view: __esri.SceneView);
|
|
45
|
+
getLog(): (string | number | undefined)[][];
|
|
42
46
|
init(): Promise<void>;
|
|
43
47
|
setInterpolate(needInterpolate: boolean): void;
|
|
44
48
|
private context;
|
|
@@ -4,8 +4,8 @@ import v from "@arcgis/core/geometry/SpatialReference";
|
|
|
4
4
|
import * as u from "@arcgis/core/views/3d/externalRenderers";
|
|
5
5
|
import * as l from "three";
|
|
6
6
|
import { GLTFLoader as y } from "three/examples/jsm/loaders/GLTFLoader";
|
|
7
|
-
import { EVehiclePlateState as
|
|
8
|
-
import
|
|
7
|
+
import { EVehiclePlateState as m } from "../../../types/index.mjs";
|
|
8
|
+
import T from "../../stores/index.mjs";
|
|
9
9
|
class I {
|
|
10
10
|
constructor(i) {
|
|
11
11
|
this.cameraHeightThreshold = 1e3, this.roughness = 0.2, this.metalness = 0.8, this.defaultMaterial = new l.MeshPhongMaterial({
|
|
@@ -22,14 +22,33 @@ class I {
|
|
|
22
22
|
[9, this.createCarMaterial(2105376)],
|
|
23
23
|
[10, this.createCarMaterial(9662683)],
|
|
24
24
|
[99, this.createCarMaterial(6908265)]
|
|
25
|
-
]), this.isInitialized = !1, this.showGroundVehicle = !0, this.showElevatedVehicle = !0, this.isPaused = !1, this.currentSpriteContent =
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
]), this.isInitialized = !1, this.showGroundVehicle = !0, this.showElevatedVehicle = !0, this.isPaused = !1, this.currentSpriteContent = m.None, this.historyPositionMap = /* @__PURE__ */ new Map(), this.vehicleObjectMap = /* @__PURE__ */ new Map(), this.needInterpolate = !0, this.updateModel = !1, this.appDataStore = T.useAppDataStore, this.logTable = [
|
|
26
|
+
[
|
|
27
|
+
"ptcId",
|
|
28
|
+
"plateno",
|
|
29
|
+
"timestamp",
|
|
30
|
+
"localTimestamp",
|
|
31
|
+
"speed",
|
|
32
|
+
"longitude",
|
|
33
|
+
"latitude",
|
|
34
|
+
"ptcType",
|
|
35
|
+
"vehicleType",
|
|
36
|
+
"vehicleColor",
|
|
37
|
+
"plateColor",
|
|
38
|
+
"heading",
|
|
39
|
+
"fixAngle",
|
|
40
|
+
"roadLayer",
|
|
41
|
+
"step",
|
|
42
|
+
"receiveTimestamp",
|
|
43
|
+
"queueLength",
|
|
44
|
+
"status"
|
|
45
|
+
]
|
|
46
|
+
], this.assetsRoot = JSON.parse(
|
|
47
|
+
JSON.stringify(this.appDataStore.mapConfig)
|
|
29
48
|
).assetsRoot, this.view = i, b.watch(
|
|
30
49
|
() => this.view.camera.position.z,
|
|
31
|
-
(
|
|
32
|
-
(
|
|
50
|
+
(e, t) => {
|
|
51
|
+
(t <= this.cameraHeightThreshold && e > this.cameraHeightThreshold || t > this.cameraHeightThreshold && e <= this.cameraHeightThreshold) && (this.updateModel = !0);
|
|
33
52
|
}
|
|
34
53
|
);
|
|
35
54
|
}
|
|
@@ -42,6 +61,9 @@ class I {
|
|
|
42
61
|
// metalness: this.metalness
|
|
43
62
|
});
|
|
44
63
|
}
|
|
64
|
+
getLog() {
|
|
65
|
+
return this.logTable;
|
|
66
|
+
}
|
|
45
67
|
async init() {
|
|
46
68
|
const i = new y();
|
|
47
69
|
await P.eachAlways([
|
|
@@ -121,8 +143,8 @@ class I {
|
|
|
121
143
|
const e = this.renderer.setRenderTarget.bind(
|
|
122
144
|
this.renderer
|
|
123
145
|
);
|
|
124
|
-
this.renderer.setRenderTarget = (
|
|
125
|
-
e(
|
|
146
|
+
this.renderer.setRenderTarget = (s) => {
|
|
147
|
+
e(s), s == null && i.bindRenderTarget();
|
|
126
148
|
}, this.scene = new l.Scene();
|
|
127
149
|
const { camera: t } = i;
|
|
128
150
|
this.camera = new l.PerspectiveCamera(
|
|
@@ -133,19 +155,19 @@ class I {
|
|
|
133
155
|
), this.ambient = new l.AmbientLight(16777215, 2), this.scene.add(this.ambient), this.sun = new l.DirectionalLight(16777215, 2), this.scene.add(this.sun), i.resetWebGLState();
|
|
134
156
|
}
|
|
135
157
|
async render(i) {
|
|
136
|
-
var
|
|
158
|
+
var s;
|
|
137
159
|
const e = i.camera;
|
|
138
160
|
if (this.camera.position.set(e.eye[0], e.eye[1], e.eye[2]), this.camera.up.set(e.up[0], e.up[1], e.up[2]), this.camera.lookAt(
|
|
139
161
|
new l.Vector3(e.center[0], e.center[1], e.center[2])
|
|
140
162
|
), this.camera.projectionMatrix.fromArray(e.projectionMatrix), !this.isPaused && this.needInterpolate)
|
|
141
|
-
for (const
|
|
142
|
-
const n = (
|
|
163
|
+
for (const a of this.vehicleObjectMap.keys()) {
|
|
164
|
+
const n = (s = this.vehicleObjectMap.get(a)) == null ? void 0 : s.model;
|
|
143
165
|
if (!n)
|
|
144
166
|
continue;
|
|
145
|
-
const
|
|
146
|
-
if (
|
|
147
|
-
const
|
|
148
|
-
n.position.set(
|
|
167
|
+
const o = this.computeVehiclePosition(a);
|
|
168
|
+
if (o) {
|
|
169
|
+
const d = this.toRenderCoordinates(o);
|
|
170
|
+
n.position.set(d[0], d[1], d[2]), n.rotation.y = l.MathUtils.degToRad(-o[3]);
|
|
149
171
|
}
|
|
150
172
|
}
|
|
151
173
|
const t = i.sunLight;
|
|
@@ -163,27 +185,49 @@ class I {
|
|
|
163
185
|
* 新增车辆
|
|
164
186
|
* */
|
|
165
187
|
async addVehicles(i) {
|
|
166
|
-
if (
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
188
|
+
if (this.isPaused || !this.isInitialized)
|
|
189
|
+
return;
|
|
190
|
+
const e = Date.now();
|
|
191
|
+
for (const t of i) {
|
|
192
|
+
this.appDataStore.saveTrackLog && this.logTable.push([
|
|
193
|
+
t.ptcId,
|
|
194
|
+
t.plateNo,
|
|
195
|
+
t.timestamp,
|
|
196
|
+
t.localTimestamp,
|
|
197
|
+
t.speed,
|
|
198
|
+
t.x,
|
|
199
|
+
t.y,
|
|
200
|
+
t.ptcType,
|
|
201
|
+
t.vehicleType,
|
|
202
|
+
t.vehicleColor,
|
|
203
|
+
t.plateColor,
|
|
204
|
+
t.heading,
|
|
205
|
+
t.fixAngle,
|
|
206
|
+
t.roadLayer,
|
|
207
|
+
t.step,
|
|
208
|
+
e,
|
|
209
|
+
0,
|
|
210
|
+
0
|
|
211
|
+
]);
|
|
212
|
+
const { vehicleId: s, localTimestamp: a } = t, n = Number(t.x), o = Number(t.y), d = Number(t.heading);
|
|
213
|
+
this.historyPositionMap.set(s, [
|
|
214
|
+
{ pos: [n, o, 0], heading: d, time: a }
|
|
215
|
+
]);
|
|
216
|
+
const h = this.getVehicleModel(t);
|
|
217
|
+
h.name = s, h.visible = !1;
|
|
218
|
+
try {
|
|
219
|
+
const r = await this.createPlateSprite(t);
|
|
220
|
+
r && (h.add(r), r.position.set(0, 5, -4));
|
|
221
|
+
} catch (r) {
|
|
222
|
+
console.log("createPlateSprite error:", r);
|
|
186
223
|
}
|
|
224
|
+
this.scene.add(h), this.vehicleObjectMap.set(s, {
|
|
225
|
+
model: h,
|
|
226
|
+
data: t,
|
|
227
|
+
waitForDelete: !1,
|
|
228
|
+
isMoving: !1
|
|
229
|
+
});
|
|
230
|
+
}
|
|
187
231
|
}
|
|
188
232
|
/**
|
|
189
233
|
* 更新车辆
|
|
@@ -191,39 +235,58 @@ class I {
|
|
|
191
235
|
async updateVehicles(i) {
|
|
192
236
|
if (this.isPaused || !this.isInitialized)
|
|
193
237
|
return;
|
|
194
|
-
const e = [];
|
|
195
|
-
for (const
|
|
196
|
-
const { vehicleId:
|
|
197
|
-
let h = Number(
|
|
198
|
-
const r = this.vehicleObjectMap.get(
|
|
199
|
-
|
|
238
|
+
const e = [], t = Date.now();
|
|
239
|
+
for (const s of i) {
|
|
240
|
+
const { vehicleId: a, timestamp: n } = s, o = Number(s.x), d = Number(s.y);
|
|
241
|
+
let h = Number(s.heading);
|
|
242
|
+
const r = this.vehicleObjectMap.get(a), p = this.historyPositionMap.get(
|
|
243
|
+
a
|
|
200
244
|
);
|
|
201
|
-
if (!r || !
|
|
202
|
-
e.push(
|
|
245
|
+
if (!r || !p)
|
|
246
|
+
e.push(s);
|
|
203
247
|
else {
|
|
204
|
-
if (this.
|
|
205
|
-
|
|
206
|
-
|
|
248
|
+
if (this.appDataStore.saveTrackLog && this.logTable.push([
|
|
249
|
+
s.ptcId,
|
|
250
|
+
s.plateNo,
|
|
251
|
+
s.timestamp,
|
|
252
|
+
s.localTimestamp,
|
|
253
|
+
s.speed,
|
|
254
|
+
s.x,
|
|
255
|
+
s.y,
|
|
256
|
+
s.ptcType,
|
|
257
|
+
s.vehicleType,
|
|
258
|
+
s.vehicleColor,
|
|
259
|
+
s.plateColor,
|
|
260
|
+
s.heading,
|
|
261
|
+
s.fixAngle,
|
|
262
|
+
s.roadLayer,
|
|
263
|
+
s.step,
|
|
264
|
+
t,
|
|
265
|
+
p.length,
|
|
266
|
+
1
|
|
267
|
+
]), this.updateModel || r.data.vehicleColor !== s.vehicleColor || r.data.vehicleType !== s.vehicleType) {
|
|
268
|
+
this.scene.remove(r.model), this.disposeModel(r.model), r.model = this.getVehicleModel(s), r.model.visible = !0;
|
|
269
|
+
const c = await this.createPlateSprite(s);
|
|
207
270
|
c && (r.model.add(c), c.position.set(0, 5, -4)), this.scene.add(r.model);
|
|
208
271
|
}
|
|
209
|
-
if (r.data.showName !==
|
|
272
|
+
if (r.data.showName !== s.showName || r.data.plateColor !== s.plateColor) {
|
|
210
273
|
const c = r.model.getObjectByName("VehiclePlate");
|
|
211
274
|
c && (r.model.remove(c), this.disposeModel(c));
|
|
212
|
-
const
|
|
213
|
-
|
|
275
|
+
const g = await this.createPlateSprite(s);
|
|
276
|
+
g && (r.model.add(g), g.position.set(0, 5, -4));
|
|
214
277
|
}
|
|
215
|
-
if (r.data =
|
|
216
|
-
const c =
|
|
217
|
-
Math.abs(h - c.heading) >= 180 && (h > c.heading ? c.heading += 360 : h += 360),
|
|
218
|
-
pos: [
|
|
278
|
+
if (r.data = s, this.needInterpolate) {
|
|
279
|
+
const c = p[p.length - 1];
|
|
280
|
+
Math.abs(h - c.heading) >= 180 && (h > c.heading ? c.heading += 360 : h += 360), p.push({
|
|
281
|
+
pos: [o, d, 0],
|
|
219
282
|
heading: h,
|
|
220
|
-
time:
|
|
283
|
+
time: n
|
|
221
284
|
});
|
|
222
285
|
} else {
|
|
223
|
-
this.historyPositionMap.set(
|
|
224
|
-
{ pos: [
|
|
286
|
+
this.historyPositionMap.set(a, [
|
|
287
|
+
{ pos: [o, d, 0], heading: h, time: n }
|
|
225
288
|
]);
|
|
226
|
-
const c = this.toRenderCoordinates([
|
|
289
|
+
const c = this.toRenderCoordinates([o, d, 0]);
|
|
227
290
|
r.model.position.set(c[0], c[1], c[2]), r.model.rotation.y = l.MathUtils.degToRad(-h);
|
|
228
291
|
}
|
|
229
292
|
}
|
|
@@ -247,9 +310,35 @@ class I {
|
|
|
247
310
|
* 删除车辆
|
|
248
311
|
* */
|
|
249
312
|
deleteVehicles(i) {
|
|
250
|
-
this.isPaused
|
|
251
|
-
|
|
252
|
-
|
|
313
|
+
if (this.isPaused)
|
|
314
|
+
return;
|
|
315
|
+
const e = Date.now();
|
|
316
|
+
i.forEach((t) => {
|
|
317
|
+
if (this.appDataStore.saveTrackLog) {
|
|
318
|
+
const a = this.historyPositionMap.get(t);
|
|
319
|
+
this.logTable.push([
|
|
320
|
+
t,
|
|
321
|
+
"",
|
|
322
|
+
"",
|
|
323
|
+
"",
|
|
324
|
+
"",
|
|
325
|
+
"",
|
|
326
|
+
"",
|
|
327
|
+
"",
|
|
328
|
+
"",
|
|
329
|
+
"",
|
|
330
|
+
"",
|
|
331
|
+
"",
|
|
332
|
+
"",
|
|
333
|
+
"",
|
|
334
|
+
"",
|
|
335
|
+
e,
|
|
336
|
+
a ? a.length : 0,
|
|
337
|
+
2
|
|
338
|
+
]);
|
|
339
|
+
}
|
|
340
|
+
const s = this.vehicleObjectMap.get(t);
|
|
341
|
+
s && (this.needInterpolate ? s.isMoving ? s.waitForDelete = !0 : this.deleteVehicle(s) : this.deleteVehicle(s));
|
|
253
342
|
});
|
|
254
343
|
}
|
|
255
344
|
deleteVehicle(i) {
|
|
@@ -258,8 +347,8 @@ class I {
|
|
|
258
347
|
this.vehicleObjectMap.delete(e), this.historyPositionMap.delete(e);
|
|
259
348
|
}
|
|
260
349
|
async toggleTrafficInfo(i) {
|
|
261
|
-
i.name === "vehiclePlate" && (i.visible === !0 && this.currentSpriteContent ===
|
|
262
|
-
i.visible ? this.currentSpriteContent :
|
|
350
|
+
i.name === "vehiclePlate" && (i.visible === !0 && this.currentSpriteContent === m.None ? await this.updatePanelContent(m.PlateNumber) : await this.updatePanelContent(
|
|
351
|
+
i.visible ? this.currentSpriteContent : m.None
|
|
263
352
|
));
|
|
264
353
|
}
|
|
265
354
|
togglePause(i) {
|
|
@@ -286,10 +375,10 @@ class I {
|
|
|
286
375
|
for (const e of this.vehicleObjectMap.keys()) {
|
|
287
376
|
const t = this.vehicleObjectMap.get(e);
|
|
288
377
|
if (t) {
|
|
289
|
-
const
|
|
290
|
-
if (
|
|
291
|
-
const
|
|
292
|
-
|
|
378
|
+
const s = t.model.getObjectByName("VehiclePlate");
|
|
379
|
+
if (s && (t.model.remove(s), this.disposeModel(s)), i !== m.None) {
|
|
380
|
+
const a = await this.createPlateSprite(t.data);
|
|
381
|
+
a && (t.model.add(a), a.position.set(0, 5, -4));
|
|
293
382
|
}
|
|
294
383
|
}
|
|
295
384
|
}
|
|
@@ -316,21 +405,24 @@ class I {
|
|
|
316
405
|
const e = this.historyPositionMap.get(i), t = this.vehicleObjectMap.get(i);
|
|
317
406
|
if (!t || !e || !t.isMoving && e.length <= 2)
|
|
318
407
|
return;
|
|
319
|
-
const
|
|
320
|
-
t.isMoving = !0, t.data.roadLayer === "1" ? t.model.visible = this.showGroundVehicle : t.model.visible = this.showElevatedVehicle, t.segmentStartTime || (t.segmentStartTime =
|
|
321
|
-
const
|
|
322
|
-
|
|
408
|
+
const s = Date.now();
|
|
409
|
+
t.isMoving = !0, t.data.roadLayer === "1" ? t.model.visible = this.showGroundVehicle : t.model.visible = this.showElevatedVehicle, t.segmentStartTime || (t.segmentStartTime = s, t.segmentTotalTime = e[1].time - e[0].time);
|
|
410
|
+
const a = s - t.segmentStartTime, n = Math.min(
|
|
411
|
+
a / t.segmentTotalTime,
|
|
323
412
|
1
|
|
324
413
|
);
|
|
325
414
|
if (n === 1)
|
|
326
415
|
if (e.shift(), e.length === 1) {
|
|
327
416
|
t.waitForDelete === !0 ? this.deleteVehicle(t) : (t.segmentStartTime = void 0, t.segmentTotalTime = void 0, t.model.visible = !1, t.isMoving = !1, console.log("hide vehicle", i));
|
|
328
417
|
return;
|
|
329
|
-
} else
|
|
330
|
-
|
|
418
|
+
} else {
|
|
419
|
+
const o = a - t.segmentTotalTime;
|
|
420
|
+
return t.segmentStartTime = Date.now(), t.segmentTotalTime = e[1].time - e[0].time - // 补偿损耗时间
|
|
421
|
+
(o > 0 ? o : 0), (e[1].heading >= 270 && e[0].heading <= 90 || e[1].heading <= 90 && e[0].heading >= 270) && (e[1].heading > e[0].heading ? e[0].heading += 360 : e[1].heading += 360), e[0].pos.concat(e[0].heading);
|
|
422
|
+
}
|
|
331
423
|
else if (e.length >= 2) {
|
|
332
|
-
const
|
|
333
|
-
return [
|
|
424
|
+
const o = e[0].pos[0] + (e[1].pos[0] - e[0].pos[0]) * n, d = e[0].pos[1] + (e[1].pos[1] - e[0].pos[1]) * n, h = e[0].heading + (e[1].heading - e[0].heading) * n;
|
|
425
|
+
return [o, d, 0, h];
|
|
334
426
|
} else
|
|
335
427
|
return;
|
|
336
428
|
}
|
|
@@ -369,9 +461,9 @@ class I {
|
|
|
369
461
|
break;
|
|
370
462
|
}
|
|
371
463
|
const t = this.materialMap.get(i.vehicleColor) || this.defaultMaterial;
|
|
372
|
-
let
|
|
373
|
-
e.traverse((
|
|
374
|
-
!
|
|
464
|
+
let s = !1;
|
|
465
|
+
e.traverse((a) => {
|
|
466
|
+
!s && a instanceof l.Mesh && (a.material = t, s = !0);
|
|
375
467
|
});
|
|
376
468
|
}
|
|
377
469
|
return e;
|
|
@@ -381,66 +473,66 @@ class I {
|
|
|
381
473
|
* 创建号牌canvas
|
|
382
474
|
* */
|
|
383
475
|
createCanvas(i, e, t) {
|
|
384
|
-
const
|
|
385
|
-
|
|
386
|
-
const
|
|
387
|
-
if (!
|
|
476
|
+
const s = document.createElement("canvas"), a = i.width, n = i.height;
|
|
477
|
+
s.width = a, s.height = n;
|
|
478
|
+
const o = s.getContext("2d");
|
|
479
|
+
if (!o) {
|
|
388
480
|
console.log("canvas创建失败");
|
|
389
481
|
return;
|
|
390
482
|
}
|
|
391
|
-
return
|
|
483
|
+
return o.fillStyle = "rgba(0,0,0,0.0)", o.fillRect(0, 0, a, n), o.drawImage(i, 0, 0, a, n), o.beginPath(), o.translate(a / 2, n / 2), o.fillStyle = t, o.font = "bold 32px 宋体", o.textBaseline = "middle", o.textAlign = "center", o.fillText(e, 0, 0), s;
|
|
392
484
|
}
|
|
393
485
|
createPlateSprite(i) {
|
|
394
486
|
return new Promise((e, t) => {
|
|
395
|
-
var
|
|
396
|
-
const
|
|
397
|
-
if (this.currentSpriteContent ===
|
|
487
|
+
var h, r;
|
|
488
|
+
const s = !i.plateNo || i.plateNo === "0" || i.plateNo === "000000";
|
|
489
|
+
if (this.currentSpriteContent === m.None || this.currentSpriteContent === m.PlateNumber && s) {
|
|
398
490
|
e(void 0);
|
|
399
491
|
return;
|
|
400
492
|
}
|
|
401
|
-
let
|
|
402
|
-
if (this.currentSpriteContent ===
|
|
403
|
-
if (
|
|
404
|
-
|
|
493
|
+
let a = new Image(), n = "", o = "";
|
|
494
|
+
if (this.currentSpriteContent === m.PlateNumber || this.currentSpriteContent === m.Mix)
|
|
495
|
+
if (s)
|
|
496
|
+
a = this.greyPlateBG, n = i.ptcId, o = "#ffffff";
|
|
405
497
|
else
|
|
406
|
-
switch (n = ((
|
|
498
|
+
switch (n = ((h = i.showName) == null ? void 0 : h.substring(0, 2)) + "•" + ((r = i.showName) == null ? void 0 : r.substring(2)), i.plateColor) {
|
|
407
499
|
case 1:
|
|
408
|
-
|
|
500
|
+
a = this.bluePlateBG, o = "#ffffff";
|
|
409
501
|
break;
|
|
410
502
|
case 2:
|
|
411
|
-
|
|
503
|
+
a = this.yellowPlateBG, o = "#000000";
|
|
412
504
|
break;
|
|
413
505
|
case 3:
|
|
414
|
-
|
|
506
|
+
a = this.whitePlateBG, o = "#000000";
|
|
415
507
|
break;
|
|
416
508
|
case 4:
|
|
417
|
-
|
|
509
|
+
a = this.blackPlateBG, o = "#ffffff";
|
|
418
510
|
break;
|
|
419
511
|
case 5:
|
|
420
|
-
|
|
512
|
+
a = this.neoYellowPlateBG, o = "#000000";
|
|
421
513
|
break;
|
|
422
514
|
case 6:
|
|
423
|
-
|
|
515
|
+
a = this.neoGreenPlateBG, o = "#000000";
|
|
424
516
|
break;
|
|
425
517
|
default:
|
|
426
|
-
|
|
518
|
+
a = this.greyPlateBG, n = i.plateNo, o = "#ffffff";
|
|
427
519
|
break;
|
|
428
520
|
}
|
|
429
521
|
else
|
|
430
|
-
this.currentSpriteContent ===
|
|
431
|
-
const
|
|
432
|
-
if (
|
|
433
|
-
const
|
|
434
|
-
map:
|
|
522
|
+
this.currentSpriteContent === m.Id && (a = this.greyPlateBG, n = i.ptcId, o = "#ffffff");
|
|
523
|
+
const d = this.createCanvas(a, n, o);
|
|
524
|
+
if (d) {
|
|
525
|
+
const p = new l.CanvasTexture(d), c = new l.SpriteMaterial({
|
|
526
|
+
map: p,
|
|
435
527
|
transparent: !1
|
|
436
|
-
}), g = new l.Sprite(
|
|
437
|
-
g.scale.set(
|
|
528
|
+
}), g = new l.Sprite(c), f = 0.05, w = d.width * f, M = d.height * f;
|
|
529
|
+
g.scale.set(w, M, 1), g.name = "VehiclePlate", e(g);
|
|
438
530
|
} else {
|
|
439
531
|
t("canvas创建失败");
|
|
440
532
|
return;
|
|
441
533
|
}
|
|
442
|
-
|
|
443
|
-
console.log(`号牌背景加载失败: ${
|
|
534
|
+
a.onerror = (p) => {
|
|
535
|
+
console.log(`号牌背景加载失败: ${a.src}`, p), t(p);
|
|
444
536
|
};
|
|
445
537
|
});
|
|
446
538
|
}
|
|
@@ -4,7 +4,10 @@ export default class TraceRendererLayer implements ITraceRendererInterface {
|
|
|
4
4
|
private readonly vehicleLayer;
|
|
5
5
|
private mapConfig;
|
|
6
6
|
private rafSignal;
|
|
7
|
+
private appDataStore;
|
|
8
|
+
private logTable;
|
|
7
9
|
constructor(view: __esri.MapView);
|
|
10
|
+
getLog(): (string | number)[][];
|
|
8
11
|
init(): Promise<void>;
|
|
9
12
|
private needInterpolate;
|
|
10
13
|
private isPaused;
|
|
@@ -3,12 +3,39 @@ import p from "@arcgis/core/layers/GraphicsLayer";
|
|
|
3
3
|
import m from "../../stores/index.mjs";
|
|
4
4
|
class f {
|
|
5
5
|
constructor(i) {
|
|
6
|
-
this.
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
this.appDataStore = m.useAppDataStore, this.logTable = [
|
|
7
|
+
[
|
|
8
|
+
"uuid",
|
|
9
|
+
"ptcId",
|
|
10
|
+
"plateno",
|
|
11
|
+
"timestamp",
|
|
12
|
+
"localTimestamp",
|
|
13
|
+
"timestamp_str",
|
|
14
|
+
"speed",
|
|
15
|
+
"laneNo",
|
|
16
|
+
"objHeight",
|
|
17
|
+
"objLength",
|
|
18
|
+
"latitude",
|
|
19
|
+
"longitude",
|
|
20
|
+
"ptcType",
|
|
21
|
+
"vehicleType",
|
|
22
|
+
"vehicleColor",
|
|
23
|
+
"plateColor",
|
|
24
|
+
"sbdm",
|
|
25
|
+
"heading",
|
|
26
|
+
"fixAngle",
|
|
27
|
+
"roadLayer",
|
|
28
|
+
"status",
|
|
29
|
+
"step",
|
|
30
|
+
"receiveTimestamp"
|
|
31
|
+
]
|
|
32
|
+
], this.needInterpolate = !0, this.isPaused = !1, this.showVehiclePlate = !1, this.showGroundVehicle = !0, this.showElevatedVehicle = !0, this.historyPositionMap = /* @__PURE__ */ new Map(), this.vehicleObjectMap = /* @__PURE__ */ new Map(), this.view = i, this.mapConfig = JSON.parse(JSON.stringify(this.appDataStore.mapConfig)), this.vehicleLayer = new p({
|
|
9
33
|
id: "vehicleLayer"
|
|
10
34
|
}), this.view.map.add(this.vehicleLayer), this.rafSignal = requestAnimationFrame(() => this.render());
|
|
11
35
|
}
|
|
36
|
+
getLog() {
|
|
37
|
+
return this.logTable;
|
|
38
|
+
}
|
|
12
39
|
async init() {
|
|
13
40
|
console.log("init");
|
|
14
41
|
}
|
|
@@ -19,27 +46,27 @@ class f {
|
|
|
19
46
|
return;
|
|
20
47
|
}
|
|
21
48
|
const t = i.map((s) => {
|
|
22
|
-
const { vehicleId: o, heading: a, localTimestamp: h } = s, r = Number(s.x),
|
|
49
|
+
const { vehicleId: o, heading: a, localTimestamp: h } = s, r = Number(s.x), l = Number(s.y);
|
|
23
50
|
this.historyPositionMap.set(o, [
|
|
24
|
-
{ pos: [r,
|
|
51
|
+
{ pos: [r, l, 0], heading: a, time: h }
|
|
25
52
|
]);
|
|
26
|
-
const
|
|
53
|
+
const n = new c({
|
|
27
54
|
geometry: {
|
|
28
55
|
type: "point",
|
|
29
56
|
x: r,
|
|
30
|
-
y:
|
|
57
|
+
y: l
|
|
31
58
|
},
|
|
32
59
|
attributes: {
|
|
33
60
|
...s
|
|
34
61
|
},
|
|
35
62
|
symbol: this.createCIMSymbol(s)
|
|
36
63
|
});
|
|
37
|
-
return
|
|
38
|
-
graphic:
|
|
64
|
+
return n.visible = !1, this.vehicleObjectMap.set(o, {
|
|
65
|
+
graphic: n,
|
|
39
66
|
data: s,
|
|
40
67
|
waitForDelete: !1,
|
|
41
68
|
isMoving: !1
|
|
42
|
-
}),
|
|
69
|
+
}), n;
|
|
43
70
|
});
|
|
44
71
|
this.vehicleLayer.addMany(t), e();
|
|
45
72
|
});
|
|
@@ -52,11 +79,11 @@ class f {
|
|
|
52
79
|
}
|
|
53
80
|
const t = [];
|
|
54
81
|
i.forEach((s) => {
|
|
55
|
-
const { vehicleId: o, heading: a, localTimestamp: h } = s, r = Number(s.x),
|
|
56
|
-
|
|
82
|
+
const { vehicleId: o, heading: a, localTimestamp: h } = s, r = Number(s.x), l = Number(s.y), n = this.vehicleObjectMap.get(o);
|
|
83
|
+
n ? (n.data = s, this.historyPositionMap.get(
|
|
57
84
|
o
|
|
58
85
|
).push({
|
|
59
|
-
pos: [r,
|
|
86
|
+
pos: [r, l, 0],
|
|
60
87
|
heading: a,
|
|
61
88
|
time: h
|
|
62
89
|
})) : t.push(s);
|
|
@@ -123,12 +150,12 @@ class f {
|
|
|
123
150
|
y: e[0].pos[1]
|
|
124
151
|
};
|
|
125
152
|
else {
|
|
126
|
-
const h = e[0].pos[0] + (e[1].pos[0] - e[0].pos[0]) * a, r = e[0].pos[1] + (e[1].pos[1] - e[0].pos[1]) * a,
|
|
153
|
+
const h = e[0].pos[0] + (e[1].pos[0] - e[0].pos[0]) * a, r = e[0].pos[1] + (e[1].pos[1] - e[0].pos[1]) * a, l = e[0].heading + (e[1].heading - e[0].heading) * a;
|
|
127
154
|
t.graphic.geometry = {
|
|
128
155
|
type: "point",
|
|
129
156
|
x: h,
|
|
130
157
|
y: r
|
|
131
|
-
}, t.data.heading =
|
|
158
|
+
}, t.data.heading = l, t.graphic.symbol = this.createCIMSymbol(t.data);
|
|
132
159
|
}
|
|
133
160
|
}
|
|
134
161
|
/**
|
package/es/src/types/index.d.ts
CHANGED
|
@@ -37,6 +37,7 @@ export interface IVehicleTrack {
|
|
|
37
37
|
speed?: number;
|
|
38
38
|
plateNo?: string;
|
|
39
39
|
roadLayer?: string;
|
|
40
|
+
step?: number;
|
|
40
41
|
}
|
|
41
42
|
export interface IVehicleRecord {
|
|
42
43
|
model: Three.Group | Three.Mesh;
|
|
@@ -151,6 +152,7 @@ export interface IToggleTrafficInfoParams {
|
|
|
151
152
|
}
|
|
152
153
|
export interface ITraceRendererInterface {
|
|
153
154
|
init(): Promise<void>;
|
|
155
|
+
getLog(): (string | number | undefined)[][];
|
|
154
156
|
addVehicles(objects: IVehicleTrack[]): Promise<void>;
|
|
155
157
|
updateVehicles(objects: IVehicleTrack[]): Promise<void>;
|
|
156
158
|
deleteVehicles(idList: string[]): void;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const m=require("@arcgis/core/views/3d/externalRenderers"),b=require("
|
|
2
|
-
`).replace(/null/g,""),r=new Blob([e],{type:"text/csv;charset=utf-8;"}),
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const m=require("@arcgis/core/views/3d/externalRenderers"),b=require("./trace-renderer-external.js"),y=require("./trace-renderer-layer.js");function R(i){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(i){for(const r in i)if(r!=="default"){const n=Object.getOwnPropertyDescriptor(i,r);Object.defineProperty(e,r,n.get?n:{enumerable:!0,get:()=>i[r]})}}return e.default=i,Object.freeze(e)}const T=R(m);class v{constructor(e){e.type==="3d"?(this.traceRenderer=new b.default(e),T.add(e,this.traceRenderer)):this.traceRenderer=new y.default(e)}async init(){await this.traceRenderer.init()}downloadLog(){const e=this.traceRenderer.getLog().map(s=>s.join(",")).join(`
|
|
2
|
+
`).replace(/null/g,""),r=new Blob([e],{type:"text/csv;charset=utf-8;"}),n=URL.createObjectURL(r),c=document.createElement("a");c.setAttribute("href",n),c.setAttribute("download","trace-log.csv"),c.style.visibility="hidden",document.body.appendChild(c),c.click(),document.body.removeChild(c)}async handleVehicleTraceData(e){const{newVehList:r,updateVehList:n,deleteVehList:c,jgsj:s}=e,l=e.crossId||"",a=[],d=[];if(r&&r.length>0){for(const o of r){o.localTimestamp||(o.localTimestamp=s||Date.now());const t=this.buildVehicleTrackData(o,l);t&&a.push(t)}await this.traceRenderer.addVehicles(a)}if(n&&n.length>0){for(const o of n){const t=this.buildVehicleTrackData(o,l);t&&d.push(t)}await this.traceRenderer.updateVehicles(d)}if(c&&c.length>0){const o=c.map(t=>l+"-"+(t.ptcId||t.vehno||t.vehNo));this.traceRenderer.deleteVehicles(o)}}toggleTrafficInfo(e){this.traceRenderer.toggleTrafficInfo(e)}clearTrace(){this.traceRenderer.clearVehicles()}togglePause(e){this.traceRenderer.togglePause(e)}updatePanelContent(e){this.traceRenderer.updatePanelContent(e)}toggleGroundVehicle(e){this.traceRenderer.toggleGroundVehicle(e)}toggleElevatedVehicle(e){this.traceRenderer.toggleElevatedVehicle(e)}setInterpolate(e){this.traceRenderer.setInterpolate(e)}buildVehicleTrackData(e,r){const n=e.longitude,c=e.latitude,s=e.ptcId,l=Number(e.ptcType),a=e.heading,d=Number(e.vehicleType),o=Number(e.vehicleColor),t=e.plateNo||e.plateno,h=Number(e.plateColor),u=e.timestamp,p=e.localTimestamp,g=e.roadLayer?String(e.roadLayer):"1",f=e.step;if(!(l<0||l>8))return{ptcId:s,crossId:r,vehicleId:r+"-"+s,x:n,y:c,ptcType:l,vehicleType:d,heading:l===2?-a:a,vehicleColor:o,showName:t&&t!==""&&t!=="0"&&t!=="000000"?t:"",plateNo:t,plateColor:h,timestamp:u,localTimestamp:p,roadLayer:g,step:f}}}exports.default=v;
|
|
@@ -38,7 +38,11 @@ export default class TraceRendererExternal implements ITraceRendererInterface {
|
|
|
38
38
|
private vehicleObjectMap;
|
|
39
39
|
private needInterpolate;
|
|
40
40
|
private updateModel;
|
|
41
|
+
private appDataStore;
|
|
42
|
+
/** 轨迹日志 */
|
|
43
|
+
private logTable;
|
|
41
44
|
constructor(view: __esri.SceneView);
|
|
45
|
+
getLog(): (string | number | undefined)[][];
|
|
42
46
|
init(): Promise<void>;
|
|
43
47
|
setInterpolate(needInterpolate: boolean): void;
|
|
44
48
|
private context;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const v=require("@arcgis/core/core/promiseUtils.js"),y=require("@arcgis/core/core/reactiveUtils.js"),S=require("@arcgis/core/geometry/SpatialReference"),G=require("@arcgis/core/views/3d/externalRenderers"),C=require("three"),T=require("three/examples/jsm/loaders/GLTFLoader"),d=require("../../../types/index.js"),B=require("../../stores/index.js");function u(m){const i=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(m){for(const e in m)if(e!=="default"){const t=Object.getOwnPropertyDescriptor(m,e);Object.defineProperty(i,e,t.get?t:{enumerable:!0,get:()=>m[e]})}}return i.default=m,Object.freeze(i)}const R=u(v),V=u(y),M=u(G),l=u(C);class I{constructor(i){this.cameraHeightThreshold=1e3,this.roughness=.2,this.metalness=.8,this.defaultMaterial=new l.MeshPhongMaterial({color:16777215}),this.materialMap=new Map([[1,this.createCarMaterial(16777215)],[2,this.createCarMaterial(7833753)],[3,this.createCarMaterial(16766720)],[4,this.createCarMaterial(16758465)],[5,this.createCarMaterial(14423100)],[6,this.createCarMaterial(3329330)],[7,this.createCarMaterial(2003183)],[8,this.createCarMaterial(16032864)],[9,this.createCarMaterial(2105376)],[10,this.createCarMaterial(9662683)],[99,this.createCarMaterial(6908265)]]),this.isInitialized=!1,this.showGroundVehicle=!0,this.showElevatedVehicle=!0,this.isPaused=!1,this.currentSpriteContent=d.EVehiclePlateState.None,this.historyPositionMap=new Map,this.vehicleObjectMap=new Map,this.needInterpolate=!0,this.updateModel=!1;const e=B.default.useAppDataStore;this.assetsRoot=JSON.parse(JSON.stringify(e.mapConfig)).assetsRoot,this.view=i,V.watch(()=>this.view.camera.position.z,(t,o)=>{(o<=this.cameraHeightThreshold&&t>this.cameraHeightThreshold||o>this.cameraHeightThreshold&&t<=this.cameraHeightThreshold)&&(this.updateModel=!0)})}createCarMaterial(i){return new l.MeshPhongMaterial({color:i})}async init(){const i=new T.GLTFLoader;await R.eachAlways([new Promise(e=>{i.load(`${this.assetsRoot}/3DModels/car.glb`,t=>{this.carModel=t.scene,this.carModel.rotation.x=l.MathUtils.degToRad(90),e()})}),new Promise(e=>{i.load(`${this.assetsRoot}/3DModels/van.glb`,t=>{this.vanModel=t.scene,this.vanModel.rotation.x=l.MathUtils.degToRad(90),e()})}),new Promise(e=>{i.load(`${this.assetsRoot}/3DModels/truck.glb`,t=>{this.truckModel=t.scene,this.truckModel.scale.set(1.2,1,1.5),this.truckModel.rotation.x=l.MathUtils.degToRad(90),e()})}),new Promise(e=>{i.load(`${this.assetsRoot}/3DModels/bus.glb`,t=>{this.busModel=t.scene,this.busModel.rotation.x=l.MathUtils.degToRad(90),e()})}),new Promise(e=>{i.load(`${this.assetsRoot}/3DModels/bicycle.glb`,t=>{this.bicycleModel=t.scene,this.bicycleModel.rotation.x=l.MathUtils.degToRad(90),this.bicycleModel.rotation.y=l.MathUtils.degToRad(180),e()})}),new Promise(e=>{this.bluePlateBG=new Image,this.bluePlateBG.src=`${this.assetsRoot}/Images/PlateBG/blue.png`,this.bluePlateBG.onload=()=>{e()}}),new Promise(e=>{this.yellowPlateBG=new Image,this.yellowPlateBG.src=`${this.assetsRoot}/Images/PlateBG/yellow.png`,this.yellowPlateBG.onload=()=>{e()}}),new Promise(e=>{this.whitePlateBG=new Image,this.whitePlateBG.src=`${this.assetsRoot}/Images/PlateBG/white.png`,this.whitePlateBG.onload=()=>{e()}}),new Promise(e=>{this.blackPlateBG=new Image,this.blackPlateBG.src=`${this.assetsRoot}/Images/PlateBG/black.png`,this.blackPlateBG.onload=()=>{e()}}),new Promise(e=>{this.neoYellowPlateBG=new Image,this.neoYellowPlateBG.src=`${this.assetsRoot}/Images/PlateBG/neo_yellow.png`,this.neoYellowPlateBG.onload=()=>{e()}}),new Promise(e=>{this.neoGreenPlateBG=new Image,this.neoGreenPlateBG.src=`${this.assetsRoot}/Images/PlateBG/neo_green.png`,this.neoGreenPlateBG.onload=()=>{e()}}),new Promise(e=>{this.greyPlateBG=new Image,this.greyPlateBG.src=`${this.assetsRoot}/Images/PlateBG/grey.png`,this.greyPlateBG.onload=()=>{e()}})]),this.isInitialized=!0}setInterpolate(i){this.clearVehicles(),this.needInterpolate=i}async setup(i){this.context=i,this.renderer=new l.WebGLRenderer({context:i.gl,premultipliedAlpha:!0,logarithmicDepthBuffer:!0,antialias:!0,powerPreference:"high-performance"}),this.renderer.shadowMap.enabled=!0,this.renderer.setPixelRatio(window.devicePixelRatio),this.renderer.setViewport(0,0,this.view.width,this.view.height),this.renderer.autoClearDepth=!1,this.renderer.autoClearStencil=!1,this.renderer.autoClearColor=!1;const e=this.renderer.setRenderTarget.bind(this.renderer);this.renderer.setRenderTarget=o=>{e(o),o==null&&i.bindRenderTarget()},this.scene=new l.Scene;const{camera:t}=i;this.camera=new l.PerspectiveCamera(t.fovY,t.aspect,.1,1e5),this.ambient=new l.AmbientLight(16777215,2),this.scene.add(this.ambient),this.sun=new l.DirectionalLight(16777215,2),this.scene.add(this.sun),i.resetWebGLState()}async render(i){var o;const e=i.camera;if(this.camera.position.set(e.eye[0],e.eye[1],e.eye[2]),this.camera.up.set(e.up[0],e.up[1],e.up[2]),this.camera.lookAt(new l.Vector3(e.center[0],e.center[1],e.center[2])),this.camera.projectionMatrix.fromArray(e.projectionMatrix),!this.isPaused&&this.needInterpolate)for(const s of this.vehicleObjectMap.keys()){const n=(o=this.vehicleObjectMap.get(s))==null?void 0:o.model;if(!n)continue;const a=this.computeVehiclePosition(s);if(a){const h=this.toRenderCoordinates(a);n.position.set(h[0],h[1],h[2]),n.rotation.y=l.MathUtils.degToRad(-a[3])}}const t=i.sunLight;this.sun.position.set(t.direction[0],t.direction[1],t.direction[2]),this.sun.intensity=t.diffuse.intensity,this.sun.color=new l.Color(t.diffuse.color[0],t.diffuse.color[1],t.diffuse.color[2]),this.ambient.intensity=t.ambient.intensity,this.ambient.color=new l.Color(t.ambient.color[0],t.ambient.color[1],t.ambient.color[2]),this.renderer.resetState(),i.bindRenderTarget(),this.renderer.render(this.scene,this.camera),M.requestRender(this.view),i.resetWebGLState()}async addVehicles(i){if(!(this.isPaused||!this.isInitialized))for(const e of i){const{vehicleId:t,localTimestamp:o}=e,s=Number(e.x),n=Number(e.y),a=Number(e.heading);this.historyPositionMap.set(t,[{pos:[s,n,0],heading:a,time:o}]);const h=this.getVehicleModel(e);h.name=t,h.visible=!1;try{const r=await this.createPlateSprite(e);r&&(h.add(r),r.position.set(0,5,-4))}catch(r){console.log("createPlateSprite error:",r)}this.scene.add(h),this.vehicleObjectMap.set(t,{model:h,data:e,waitForDelete:!1,isMoving:!1})}}async updateVehicles(i){if(this.isPaused||!this.isInitialized)return;const e=[];for(const t of i){const{vehicleId:o,timestamp:s}=t,n=Number(t.x),a=Number(t.y);let h=Number(t.heading);const r=this.vehicleObjectMap.get(o),p=this.historyPositionMap.get(o);if(!r||!p)e.push(t);else{if(this.updateModel||r.data.vehicleColor!==t.vehicleColor||r.data.vehicleType!==t.vehicleType){this.scene.remove(r.model),this.disposeModel(r.model),r.model=this.getVehicleModel(t),r.model.visible=!0;const c=await this.createPlateSprite(t);c&&(r.model.add(c),c.position.set(0,5,-4)),this.scene.add(r.model)}if(r.data.showName!==t.showName||r.data.plateColor!==t.plateColor){const c=r.model.getObjectByName("VehiclePlate");c&&(r.model.remove(c),this.disposeModel(c));const g=await this.createPlateSprite(t);g&&(r.model.add(g),g.position.set(0,5,-4))}if(r.data=t,this.needInterpolate){const c=p[p.length-1];Math.abs(h-c.heading)>=180&&(h>c.heading?c.heading+=360:h+=360),p.push({pos:[n,a,0],heading:h,time:s})}else{this.historyPositionMap.set(o,[{pos:[n,a,0],heading:h,time:s}]);const c=this.toRenderCoordinates([n,a,0]);r.model.position.set(c[0],c[1],c[2]),r.model.rotation.y=l.MathUtils.degToRad(-h)}}}await this.addVehicles(e),this.updateModel=!1,this.needInterpolate||this.render(this.context)}toRenderCoordinates(i){const e=[0,0,0];return M.toRenderCoordinates(this.view,i,0,S.WGS84,e,0,1),e}deleteVehicles(i){this.isPaused||i.forEach(e=>{const t=this.vehicleObjectMap.get(e);t&&(this.needInterpolate?t.isMoving?t.waitForDelete=!0:this.deleteVehicle(t):this.deleteVehicle(t))})}deleteVehicle(i){this.scene.remove(i.model),this.disposeModel(i.model);const e=i.data.vehicleId;this.vehicleObjectMap.delete(e),this.historyPositionMap.delete(e)}async toggleTrafficInfo(i){i.name==="vehiclePlate"&&(i.visible===!0&&this.currentSpriteContent===d.EVehiclePlateState.None?await this.updatePanelContent(d.EVehiclePlateState.PlateNumber):await this.updatePanelContent(i.visible?this.currentSpriteContent:d.EVehiclePlateState.None))}togglePause(i){this.isPaused=i}clearVehicles(){for(const i of this.vehicleObjectMap.keys()){const e=this.vehicleObjectMap.get(i);e&&(this.scene.remove(e.model),this.disposeModel(e.model))}this.vehicleObjectMap.clear(),this.historyPositionMap.clear()}async updatePanelContent(i){if(i!==this.currentSpriteContent){this.currentSpriteContent=i;for(const e of this.vehicleObjectMap.keys()){const t=this.vehicleObjectMap.get(e);if(t){const o=t.model.getObjectByName("VehiclePlate");if(o&&(t.model.remove(o),this.disposeModel(o)),i!==d.EVehiclePlateState.None){const s=await this.createPlateSprite(t.data);s&&(t.model.add(s),s.position.set(0,5,-4))}}}}}toggleGroundVehicle(i){console.log("toggleGroundVehicle",i),this.showGroundVehicle=i}toggleElevatedVehicle(i){this.showElevatedVehicle=i}disposeModel(i){i.traverse(e=>{e instanceof l.Mesh&&(e.geometry.dispose(),e.material.dispose())})}computeVehiclePosition(i){const e=this.historyPositionMap.get(i),t=this.vehicleObjectMap.get(i);if(!t||!e||!t.isMoving&&e.length<=2)return;const o=Date.now();t.isMoving=!0,t.data.roadLayer==="1"?t.model.visible=this.showGroundVehicle:t.model.visible=this.showElevatedVehicle,t.segmentStartTime||(t.segmentStartTime=o,t.segmentTotalTime=e[1].time-e[0].time);const s=o-t.segmentStartTime,n=Math.min(s/t.segmentTotalTime,1);if(n===1)if(e.shift(),e.length===1){t.waitForDelete===!0?this.deleteVehicle(t):(t.segmentStartTime=void 0,t.segmentTotalTime=void 0,t.model.visible=!1,t.isMoving=!1,console.log("hide vehicle",i));return}else return t.segmentStartTime=Date.now(),t.segmentTotalTime=e[1].time-e[0].time,(e[1].heading>=270&&e[0].heading<=90||e[1].heading<=90&&e[0].heading>=270)&&(e[1].heading>e[0].heading?e[0].heading+=360:e[1].heading+=360),e[0].pos.concat(e[0].heading);else if(e.length>=2){const a=e[0].pos[0]+(e[1].pos[0]-e[0].pos[0])*n,h=e[0].pos[1]+(e[1].pos[1]-e[0].pos[1])*n,r=e[0].heading+(e[1].heading-e[0].heading)*n;return[a,h,0,r]}else return}getVehicleModel(i){if(this.view.camera.position.z>=this.cameraHeightThreshold){const e=new l.SphereGeometry(5,32,32),t=new l.MeshPhysicalMaterial({color:325253,emissive:0,roughness:this.roughness,metalness:this.metalness});return new l.Mesh(e,t)}else{let e;if(i.ptcType===2)e=this.bicycleModel.clone();else{switch(i.vehicleType){case 10:e=this.carModel.clone();break;case 20:e=this.vanModel.clone();break;case 25:e=this.truckModel.clone();break;case 50:e=this.busModel.clone();break;default:e=this.carModel.clone();break}const t=this.materialMap.get(i.vehicleColor)||this.defaultMaterial;let o=!1;e.traverse(s=>{!o&&s instanceof l.Mesh&&(s.material=t,o=!0)})}return e}}createCanvas(i,e,t){const o=document.createElement("canvas"),s=i.width,n=i.height;o.width=s,o.height=n;const a=o.getContext("2d");if(!a){console.log("canvas创建失败");return}return a.fillStyle="rgba(0,0,0,0.0)",a.fillRect(0,0,s,n),a.drawImage(i,0,0,s,n),a.beginPath(),a.translate(s/2,n/2),a.fillStyle=t,a.font="bold 32px 宋体",a.textBaseline="middle",a.textAlign="center",a.fillText(e,0,0),o}createPlateSprite(i){return new Promise((e,t)=>{var r,p;const o=!i.plateNo||i.plateNo==="0"||i.plateNo==="000000";if(this.currentSpriteContent===d.EVehiclePlateState.None||this.currentSpriteContent===d.EVehiclePlateState.PlateNumber&&o){e(void 0);return}let s=new Image,n="",a="";if(this.currentSpriteContent===d.EVehiclePlateState.PlateNumber||this.currentSpriteContent===d.EVehiclePlateState.Mix)if(o)s=this.greyPlateBG,n=i.ptcId,a="#ffffff";else switch(n=((r=i.showName)==null?void 0:r.substring(0,2))+"•"+((p=i.showName)==null?void 0:p.substring(2)),i.plateColor){case 1:s=this.bluePlateBG,a="#ffffff";break;case 2:s=this.yellowPlateBG,a="#000000";break;case 3:s=this.whitePlateBG,a="#000000";break;case 4:s=this.blackPlateBG,a="#ffffff";break;case 5:s=this.neoYellowPlateBG,a="#000000";break;case 6:s=this.neoGreenPlateBG,a="#000000";break;default:s=this.greyPlateBG,n=i.plateNo,a="#ffffff";break}else this.currentSpriteContent===d.EVehiclePlateState.Id&&(s=this.greyPlateBG,n=i.ptcId,a="#ffffff");const h=this.createCanvas(s,n,a);if(h){const c=new l.CanvasTexture(h),g=new l.SpriteMaterial({map:c,transparent:!1}),f=new l.Sprite(g),P=.05,w=h.width*P,b=h.height*P;f.scale.set(w,b,1),f.name="VehiclePlate",e(f)}else{t("canvas创建失败");return}s.onerror=c=>{console.log(`号牌背景加载失败: ${s.src}`,c),t(c)}})}}exports.default=I;
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const v=require("@arcgis/core/core/promiseUtils.js"),y=require("@arcgis/core/core/reactiveUtils.js"),T=require("@arcgis/core/geometry/SpatialReference"),S=require("@arcgis/core/views/3d/externalRenderers"),C=require("three"),G=require("three/examples/jsm/loaders/GLTFLoader"),m=require("../../../types/index.js"),B=require("../../stores/index.js");function f(u){const i=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(u){for(const e in u)if(e!=="default"){const t=Object.getOwnPropertyDescriptor(u,e);Object.defineProperty(i,e,t.get?t:{enumerable:!0,get:()=>u[e]})}}return i.default=u,Object.freeze(i)}const R=f(v),I=f(y),M=f(S),l=f(C);class V{constructor(i){this.cameraHeightThreshold=1e3,this.roughness=.2,this.metalness=.8,this.defaultMaterial=new l.MeshPhongMaterial({color:16777215}),this.materialMap=new Map([[1,this.createCarMaterial(16777215)],[2,this.createCarMaterial(7833753)],[3,this.createCarMaterial(16766720)],[4,this.createCarMaterial(16758465)],[5,this.createCarMaterial(14423100)],[6,this.createCarMaterial(3329330)],[7,this.createCarMaterial(2003183)],[8,this.createCarMaterial(16032864)],[9,this.createCarMaterial(2105376)],[10,this.createCarMaterial(9662683)],[99,this.createCarMaterial(6908265)]]),this.isInitialized=!1,this.showGroundVehicle=!0,this.showElevatedVehicle=!0,this.isPaused=!1,this.currentSpriteContent=m.EVehiclePlateState.None,this.historyPositionMap=new Map,this.vehicleObjectMap=new Map,this.needInterpolate=!0,this.updateModel=!1,this.appDataStore=B.default.useAppDataStore,this.logTable=[["ptcId","plateno","timestamp","localTimestamp","speed","longitude","latitude","ptcType","vehicleType","vehicleColor","plateColor","heading","fixAngle","roadLayer","step","receiveTimestamp","queueLength","status"]],this.assetsRoot=JSON.parse(JSON.stringify(this.appDataStore.mapConfig)).assetsRoot,this.view=i,I.watch(()=>this.view.camera.position.z,(e,t)=>{(t<=this.cameraHeightThreshold&&e>this.cameraHeightThreshold||t>this.cameraHeightThreshold&&e<=this.cameraHeightThreshold)&&(this.updateModel=!0)})}createCarMaterial(i){return new l.MeshPhongMaterial({color:i})}getLog(){return this.logTable}async init(){const i=new G.GLTFLoader;await R.eachAlways([new Promise(e=>{i.load(`${this.assetsRoot}/3DModels/car.glb`,t=>{this.carModel=t.scene,this.carModel.rotation.x=l.MathUtils.degToRad(90),e()})}),new Promise(e=>{i.load(`${this.assetsRoot}/3DModels/van.glb`,t=>{this.vanModel=t.scene,this.vanModel.rotation.x=l.MathUtils.degToRad(90),e()})}),new Promise(e=>{i.load(`${this.assetsRoot}/3DModels/truck.glb`,t=>{this.truckModel=t.scene,this.truckModel.scale.set(1.2,1,1.5),this.truckModel.rotation.x=l.MathUtils.degToRad(90),e()})}),new Promise(e=>{i.load(`${this.assetsRoot}/3DModels/bus.glb`,t=>{this.busModel=t.scene,this.busModel.rotation.x=l.MathUtils.degToRad(90),e()})}),new Promise(e=>{i.load(`${this.assetsRoot}/3DModels/bicycle.glb`,t=>{this.bicycleModel=t.scene,this.bicycleModel.rotation.x=l.MathUtils.degToRad(90),this.bicycleModel.rotation.y=l.MathUtils.degToRad(180),e()})}),new Promise(e=>{this.bluePlateBG=new Image,this.bluePlateBG.src=`${this.assetsRoot}/Images/PlateBG/blue.png`,this.bluePlateBG.onload=()=>{e()}}),new Promise(e=>{this.yellowPlateBG=new Image,this.yellowPlateBG.src=`${this.assetsRoot}/Images/PlateBG/yellow.png`,this.yellowPlateBG.onload=()=>{e()}}),new Promise(e=>{this.whitePlateBG=new Image,this.whitePlateBG.src=`${this.assetsRoot}/Images/PlateBG/white.png`,this.whitePlateBG.onload=()=>{e()}}),new Promise(e=>{this.blackPlateBG=new Image,this.blackPlateBG.src=`${this.assetsRoot}/Images/PlateBG/black.png`,this.blackPlateBG.onload=()=>{e()}}),new Promise(e=>{this.neoYellowPlateBG=new Image,this.neoYellowPlateBG.src=`${this.assetsRoot}/Images/PlateBG/neo_yellow.png`,this.neoYellowPlateBG.onload=()=>{e()}}),new Promise(e=>{this.neoGreenPlateBG=new Image,this.neoGreenPlateBG.src=`${this.assetsRoot}/Images/PlateBG/neo_green.png`,this.neoGreenPlateBG.onload=()=>{e()}}),new Promise(e=>{this.greyPlateBG=new Image,this.greyPlateBG.src=`${this.assetsRoot}/Images/PlateBG/grey.png`,this.greyPlateBG.onload=()=>{e()}})]),this.isInitialized=!0}setInterpolate(i){this.clearVehicles(),this.needInterpolate=i}async setup(i){this.context=i,this.renderer=new l.WebGLRenderer({context:i.gl,premultipliedAlpha:!0,logarithmicDepthBuffer:!0,antialias:!0,powerPreference:"high-performance"}),this.renderer.shadowMap.enabled=!0,this.renderer.setPixelRatio(window.devicePixelRatio),this.renderer.setViewport(0,0,this.view.width,this.view.height),this.renderer.autoClearDepth=!1,this.renderer.autoClearStencil=!1,this.renderer.autoClearColor=!1;const e=this.renderer.setRenderTarget.bind(this.renderer);this.renderer.setRenderTarget=s=>{e(s),s==null&&i.bindRenderTarget()},this.scene=new l.Scene;const{camera:t}=i;this.camera=new l.PerspectiveCamera(t.fovY,t.aspect,.1,1e5),this.ambient=new l.AmbientLight(16777215,2),this.scene.add(this.ambient),this.sun=new l.DirectionalLight(16777215,2),this.scene.add(this.sun),i.resetWebGLState()}async render(i){var s;const e=i.camera;if(this.camera.position.set(e.eye[0],e.eye[1],e.eye[2]),this.camera.up.set(e.up[0],e.up[1],e.up[2]),this.camera.lookAt(new l.Vector3(e.center[0],e.center[1],e.center[2])),this.camera.projectionMatrix.fromArray(e.projectionMatrix),!this.isPaused&&this.needInterpolate)for(const a of this.vehicleObjectMap.keys()){const n=(s=this.vehicleObjectMap.get(a))==null?void 0:s.model;if(!n)continue;const o=this.computeVehiclePosition(a);if(o){const d=this.toRenderCoordinates(o);n.position.set(d[0],d[1],d[2]),n.rotation.y=l.MathUtils.degToRad(-o[3])}}const t=i.sunLight;this.sun.position.set(t.direction[0],t.direction[1],t.direction[2]),this.sun.intensity=t.diffuse.intensity,this.sun.color=new l.Color(t.diffuse.color[0],t.diffuse.color[1],t.diffuse.color[2]),this.ambient.intensity=t.ambient.intensity,this.ambient.color=new l.Color(t.ambient.color[0],t.ambient.color[1],t.ambient.color[2]),this.renderer.resetState(),i.bindRenderTarget(),this.renderer.render(this.scene,this.camera),M.requestRender(this.view),i.resetWebGLState()}async addVehicles(i){if(this.isPaused||!this.isInitialized)return;const e=Date.now();for(const t of i){this.appDataStore.saveTrackLog&&this.logTable.push([t.ptcId,t.plateNo,t.timestamp,t.localTimestamp,t.speed,t.x,t.y,t.ptcType,t.vehicleType,t.vehicleColor,t.plateColor,t.heading,t.fixAngle,t.roadLayer,t.step,e,0,0]);const{vehicleId:s,localTimestamp:a}=t,n=Number(t.x),o=Number(t.y),d=Number(t.heading);this.historyPositionMap.set(s,[{pos:[n,o,0],heading:d,time:a}]);const h=this.getVehicleModel(t);h.name=s,h.visible=!1;try{const r=await this.createPlateSprite(t);r&&(h.add(r),r.position.set(0,5,-4))}catch(r){console.log("createPlateSprite error:",r)}this.scene.add(h),this.vehicleObjectMap.set(s,{model:h,data:t,waitForDelete:!1,isMoving:!1})}}async updateVehicles(i){if(this.isPaused||!this.isInitialized)return;const e=[],t=Date.now();for(const s of i){const{vehicleId:a,timestamp:n}=s,o=Number(s.x),d=Number(s.y);let h=Number(s.heading);const r=this.vehicleObjectMap.get(a),p=this.historyPositionMap.get(a);if(!r||!p)e.push(s);else{if(this.appDataStore.saveTrackLog&&this.logTable.push([s.ptcId,s.plateNo,s.timestamp,s.localTimestamp,s.speed,s.x,s.y,s.ptcType,s.vehicleType,s.vehicleColor,s.plateColor,s.heading,s.fixAngle,s.roadLayer,s.step,t,p.length,1]),this.updateModel||r.data.vehicleColor!==s.vehicleColor||r.data.vehicleType!==s.vehicleType){this.scene.remove(r.model),this.disposeModel(r.model),r.model=this.getVehicleModel(s),r.model.visible=!0;const c=await this.createPlateSprite(s);c&&(r.model.add(c),c.position.set(0,5,-4)),this.scene.add(r.model)}if(r.data.showName!==s.showName||r.data.plateColor!==s.plateColor){const c=r.model.getObjectByName("VehiclePlate");c&&(r.model.remove(c),this.disposeModel(c));const g=await this.createPlateSprite(s);g&&(r.model.add(g),g.position.set(0,5,-4))}if(r.data=s,this.needInterpolate){const c=p[p.length-1];Math.abs(h-c.heading)>=180&&(h>c.heading?c.heading+=360:h+=360),p.push({pos:[o,d,0],heading:h,time:n})}else{this.historyPositionMap.set(a,[{pos:[o,d,0],heading:h,time:n}]);const c=this.toRenderCoordinates([o,d,0]);r.model.position.set(c[0],c[1],c[2]),r.model.rotation.y=l.MathUtils.degToRad(-h)}}}await this.addVehicles(e),this.updateModel=!1,this.needInterpolate||this.render(this.context)}toRenderCoordinates(i){const e=[0,0,0];return M.toRenderCoordinates(this.view,i,0,T.WGS84,e,0,1),e}deleteVehicles(i){if(this.isPaused)return;const e=Date.now();i.forEach(t=>{if(this.appDataStore.saveTrackLog){const a=this.historyPositionMap.get(t);this.logTable.push([t,"","","","","","","","","","","","","","",e,a?a.length:0,2])}const s=this.vehicleObjectMap.get(t);s&&(this.needInterpolate?s.isMoving?s.waitForDelete=!0:this.deleteVehicle(s):this.deleteVehicle(s))})}deleteVehicle(i){this.scene.remove(i.model),this.disposeModel(i.model);const e=i.data.vehicleId;this.vehicleObjectMap.delete(e),this.historyPositionMap.delete(e)}async toggleTrafficInfo(i){i.name==="vehiclePlate"&&(i.visible===!0&&this.currentSpriteContent===m.EVehiclePlateState.None?await this.updatePanelContent(m.EVehiclePlateState.PlateNumber):await this.updatePanelContent(i.visible?this.currentSpriteContent:m.EVehiclePlateState.None))}togglePause(i){this.isPaused=i}clearVehicles(){for(const i of this.vehicleObjectMap.keys()){const e=this.vehicleObjectMap.get(i);e&&(this.scene.remove(e.model),this.disposeModel(e.model))}this.vehicleObjectMap.clear(),this.historyPositionMap.clear()}async updatePanelContent(i){if(i!==this.currentSpriteContent){this.currentSpriteContent=i;for(const e of this.vehicleObjectMap.keys()){const t=this.vehicleObjectMap.get(e);if(t){const s=t.model.getObjectByName("VehiclePlate");if(s&&(t.model.remove(s),this.disposeModel(s)),i!==m.EVehiclePlateState.None){const a=await this.createPlateSprite(t.data);a&&(t.model.add(a),a.position.set(0,5,-4))}}}}}toggleGroundVehicle(i){console.log("toggleGroundVehicle",i),this.showGroundVehicle=i}toggleElevatedVehicle(i){this.showElevatedVehicle=i}disposeModel(i){i.traverse(e=>{e instanceof l.Mesh&&(e.geometry.dispose(),e.material.dispose())})}computeVehiclePosition(i){const e=this.historyPositionMap.get(i),t=this.vehicleObjectMap.get(i);if(!t||!e||!t.isMoving&&e.length<=2)return;const s=Date.now();t.isMoving=!0,t.data.roadLayer==="1"?t.model.visible=this.showGroundVehicle:t.model.visible=this.showElevatedVehicle,t.segmentStartTime||(t.segmentStartTime=s,t.segmentTotalTime=e[1].time-e[0].time);const a=s-t.segmentStartTime,n=Math.min(a/t.segmentTotalTime,1);if(n===1)if(e.shift(),e.length===1){t.waitForDelete===!0?this.deleteVehicle(t):(t.segmentStartTime=void 0,t.segmentTotalTime=void 0,t.model.visible=!1,t.isMoving=!1,console.log("hide vehicle",i));return}else{const o=a-t.segmentTotalTime;return t.segmentStartTime=Date.now(),t.segmentTotalTime=e[1].time-e[0].time-(o>0?o:0),(e[1].heading>=270&&e[0].heading<=90||e[1].heading<=90&&e[0].heading>=270)&&(e[1].heading>e[0].heading?e[0].heading+=360:e[1].heading+=360),e[0].pos.concat(e[0].heading)}else if(e.length>=2){const o=e[0].pos[0]+(e[1].pos[0]-e[0].pos[0])*n,d=e[0].pos[1]+(e[1].pos[1]-e[0].pos[1])*n,h=e[0].heading+(e[1].heading-e[0].heading)*n;return[o,d,0,h]}else return}getVehicleModel(i){if(this.view.camera.position.z>=this.cameraHeightThreshold){const e=new l.SphereGeometry(5,32,32),t=new l.MeshPhysicalMaterial({color:325253,emissive:0,roughness:this.roughness,metalness:this.metalness});return new l.Mesh(e,t)}else{let e;if(i.ptcType===2)e=this.bicycleModel.clone();else{switch(i.vehicleType){case 10:e=this.carModel.clone();break;case 20:e=this.vanModel.clone();break;case 25:e=this.truckModel.clone();break;case 50:e=this.busModel.clone();break;default:e=this.carModel.clone();break}const t=this.materialMap.get(i.vehicleColor)||this.defaultMaterial;let s=!1;e.traverse(a=>{!s&&a instanceof l.Mesh&&(a.material=t,s=!0)})}return e}}createCanvas(i,e,t){const s=document.createElement("canvas"),a=i.width,n=i.height;s.width=a,s.height=n;const o=s.getContext("2d");if(!o){console.log("canvas创建失败");return}return o.fillStyle="rgba(0,0,0,0.0)",o.fillRect(0,0,a,n),o.drawImage(i,0,0,a,n),o.beginPath(),o.translate(a/2,n/2),o.fillStyle=t,o.font="bold 32px 宋体",o.textBaseline="middle",o.textAlign="center",o.fillText(e,0,0),s}createPlateSprite(i){return new Promise((e,t)=>{var h,r;const s=!i.plateNo||i.plateNo==="0"||i.plateNo==="000000";if(this.currentSpriteContent===m.EVehiclePlateState.None||this.currentSpriteContent===m.EVehiclePlateState.PlateNumber&&s){e(void 0);return}let a=new Image,n="",o="";if(this.currentSpriteContent===m.EVehiclePlateState.PlateNumber||this.currentSpriteContent===m.EVehiclePlateState.Mix)if(s)a=this.greyPlateBG,n=i.ptcId,o="#ffffff";else switch(n=((h=i.showName)==null?void 0:h.substring(0,2))+"•"+((r=i.showName)==null?void 0:r.substring(2)),i.plateColor){case 1:a=this.bluePlateBG,o="#ffffff";break;case 2:a=this.yellowPlateBG,o="#000000";break;case 3:a=this.whitePlateBG,o="#000000";break;case 4:a=this.blackPlateBG,o="#ffffff";break;case 5:a=this.neoYellowPlateBG,o="#000000";break;case 6:a=this.neoGreenPlateBG,o="#000000";break;default:a=this.greyPlateBG,n=i.plateNo,o="#ffffff";break}else this.currentSpriteContent===m.EVehiclePlateState.Id&&(a=this.greyPlateBG,n=i.ptcId,o="#ffffff");const d=this.createCanvas(a,n,o);if(d){const p=new l.CanvasTexture(d),c=new l.SpriteMaterial({map:p,transparent:!1}),g=new l.Sprite(c),P=.05,w=d.width*P,b=d.height*P;g.scale.set(w,b,1),g.name="VehiclePlate",e(g)}else{t("canvas创建失败");return}a.onerror=p=>{console.log(`号牌背景加载失败: ${a.src}`,p),t(p)}})}}exports.default=V;
|
|
@@ -4,7 +4,10 @@ export default class TraceRendererLayer implements ITraceRendererInterface {
|
|
|
4
4
|
private readonly vehicleLayer;
|
|
5
5
|
private mapConfig;
|
|
6
6
|
private rafSignal;
|
|
7
|
+
private appDataStore;
|
|
8
|
+
private logTable;
|
|
7
9
|
constructor(view: __esri.MapView);
|
|
10
|
+
getLog(): (string | number)[][];
|
|
8
11
|
init(): Promise<void>;
|
|
9
12
|
private needInterpolate;
|
|
10
13
|
private isPaused;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const c=require("@arcgis/core/Graphic"),p=require("@arcgis/core/layers/GraphicsLayer"),m=require("../../stores/index.js");class g{constructor(i){this.needInterpolate=!0,this.isPaused=!1,this.showVehiclePlate=!1,this.showGroundVehicle=!0,this.showElevatedVehicle=!0,this.historyPositionMap=new Map,this.vehicleObjectMap=new Map,this.view=i
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const c=require("@arcgis/core/Graphic"),p=require("@arcgis/core/layers/GraphicsLayer"),m=require("../../stores/index.js");class g{constructor(i){this.appDataStore=m.default.useAppDataStore,this.logTable=[["uuid","ptcId","plateno","timestamp","localTimestamp","timestamp_str","speed","laneNo","objHeight","objLength","latitude","longitude","ptcType","vehicleType","vehicleColor","plateColor","sbdm","heading","fixAngle","roadLayer","status","step","receiveTimestamp"]],this.needInterpolate=!0,this.isPaused=!1,this.showVehiclePlate=!1,this.showGroundVehicle=!0,this.showElevatedVehicle=!0,this.historyPositionMap=new Map,this.vehicleObjectMap=new Map,this.view=i,this.mapConfig=JSON.parse(JSON.stringify(this.appDataStore.mapConfig)),this.vehicleLayer=new p({id:"vehicleLayer"}),this.view.map.add(this.vehicleLayer),this.rafSignal=requestAnimationFrame(()=>this.render())}getLog(){return this.logTable}async init(){console.log("init")}addVehicles(i){return new Promise(e=>{if(this.isPaused){e();return}const t=i.map(s=>{const{vehicleId:o,heading:a,localTimestamp:h}=s,r=Number(s.x),l=Number(s.y);this.historyPositionMap.set(o,[{pos:[r,l,0],heading:a,time:h}]);const n=new c({geometry:{type:"point",x:r,y:l},attributes:{...s},symbol:this.createCIMSymbol(s)});return n.visible=!1,this.vehicleObjectMap.set(o,{graphic:n,data:s,waitForDelete:!1,isMoving:!1}),n});this.vehicleLayer.addMany(t),e()})}updateVehicles(i){return new Promise(e=>{if(this.isPaused){e();return}const t=[];i.forEach(s=>{const{vehicleId:o,heading:a,localTimestamp:h}=s,r=Number(s.x),l=Number(s.y),n=this.vehicleObjectMap.get(o);n?(n.data=s,this.historyPositionMap.get(o).push({pos:[r,l,0],heading:a,time:h})):t.push(s)}),this.addVehicles(t),e()})}deleteVehicles(i){this.isPaused||i.forEach(e=>{const t=this.vehicleObjectMap.get(e);t&&(t.waitForDelete=!0)})}clearVehicles(){this.vehicleLayer.removeAll(),this.vehicleObjectMap.clear(),this.historyPositionMap.clear()}toggleGroundVehicle(i){this.showGroundVehicle=i}toggleElevatedVehicle(i){this.showElevatedVehicle=i}toggleTrafficInfo(i){i.name==="vehiclePlate"&&(this.showVehiclePlate=i.visible)}togglePause(i){this.isPaused=i,this.isPaused?cancelAnimationFrame(this.rafSignal):this.rafSignal=requestAnimationFrame(()=>this.render())}updatePanelContent(i){console.log(i)}setInterpolate(i){this.needInterpolate=i}render(){this.isPaused||this.vehicleObjectMap.forEach((i,e)=>{this.updatePosition(e)}),this.rafSignal=requestAnimationFrame(()=>this.render())}updatePosition(i){const e=this.historyPositionMap.get(i),t=this.vehicleObjectMap.get(i);if(!e||!t||!t.isMoving&&e.length<=2)return;t.isMoving=!0,(t.graphic.getAttribute("roadLayer")||"1")==="1"?t.graphic.visible=this.showGroundVehicle:t.graphic.visible=this.showElevatedVehicle,t.segmentStartTime||(t.segmentStartTime=Date.now(),t.segmentTotalTime=e[1].time-e[0].time);const o=Date.now()-t.segmentStartTime,a=Math.min(1,o/t.segmentTotalTime);if(a===1)if(e.shift(),e.length===1){t.waitForDelete?(this.vehicleLayer.remove(t.graphic),this.vehicleObjectMap.delete(i),this.historyPositionMap.delete(i)):(t.segmentStartTime=void 0,t.segmentTotalTime=void 0,t.graphic.visible=!1,t.isMoving=!1);return}else t.segmentStartTime=Date.now(),t.segmentTotalTime=e[1].time-e[0].time,(e[1].heading>=270&&e[0].heading<=90||e[1].heading<=90&&e[0].heading>=270)&&(e[1].heading>e[0].heading?e[0].heading+=360:e[1].heading+=360),t.graphic.geometry={type:"point",x:e[0].pos[0],y:e[0].pos[1]};else{const h=e[0].pos[0]+(e[1].pos[0]-e[0].pos[0])*a,r=e[0].pos[1]+(e[1].pos[1]-e[0].pos[1])*a,l=e[0].heading+(e[1].heading-e[0].heading)*a;t.graphic.geometry={type:"point",x:h,y:r},t.data.heading=l,t.graphic.symbol=this.createCIMSymbol(t.data)}}createCIMSymbol(i){const e=this.getPlateFontColor(i.plateColor);return{type:"cim",data:{type:"CIMSymbolReference",primitiveOverrides:[{type:"CIMPrimitiveOverride",primitiveName:"textGraphic",propertyName:"TextString",valueExpressionInfo:{type:"CIMExpressionInfo",title:"Custom",expression:"$feature.showName",returnType:"Default"}}],symbol:{type:"CIMPointSymbol",symbolLayers:[{type:"CIMVectorMarker",enable:this.showVehiclePlate,size:32,colorLocked:!0,anchorPointUnits:"Relative",frame:{xmin:-8,ymin:-8,xmax:8,ymax:8},markerGraphics:[{type:"CIMMarkerGraphic",primitiveName:"textGraphic",geometry:{x:0,y:0},symbol:{type:"CIMTextSymbol",height:4,horizontalAlignment:"Center",offsetX:0,offsetY:8,haloSize:1,haloSymbol:{type:"CIMPolygonSymbol",symbolLayers:[{type:"CIMSolidFill",enable:!0,color:e.backgroundColor}]},symbol:{type:"CIMPolygonSymbol",symbolLayers:[{type:"CIMSolidFill",enable:!0,color:e.fillColor}]},verticalAlignment:"Center"},textString:""}],scaleSymbolsProportionally:!0,respectFrame:!0},{type:"CIMPictureMarker",enable:!0,anchorPoint:{x:0,y:0},anchorPointUnits:"Relative",size:30,rotation:i.heading,rotateClockwise:!0,textureFilter:"Picture",url:`${this.mapConfig.assetsRoot}Images/car/${this.getCarPic(i.vehicleColor)}`}]}}}}getCarPic(i){if(this.view.zoom<=15)return"point.png";let e="grey";switch(typeof i=="string"&&(i=i.toLowerCase()),i){case"a":case 1:e="white";break;case"b":case 2:e="grey";break;case"c":case 3:e="yellow";break;case"d":case 4:e="pink";break;case"e":case 5:e="red";break;case"f":case 10:e="purple";break;case"g":case 6:e="green";break;case"h":case 7:e="blue";break;case"i":case 8:e="brown";break;case"j":case 9:e="black";break}return e+".png"}getPlateFontColor(i){let e=[255,255,255,255],t=[169,169,169,255];switch(i){case 0:e=[0,0,0,255],t=[255,255,255,255];break;case 1:e=[0,0,0,255],t=[244,164,96,255];break;case 2:e=[255,255,255,255],t=[65,105,225,255];break;case 3:e=[255,255,255,255],t=[0,0,0,255];break;case 15:e=[244,164,96,255],t=[0,250,154,255];break;case 16:e=[0,0,0,255],t=[0,250,154,255];break}return{fillColor:e,backgroundColor:t}}}exports.default=g;
|
package/lib/src/types/index.d.ts
CHANGED
|
@@ -37,6 +37,7 @@ export interface IVehicleTrack {
|
|
|
37
37
|
speed?: number;
|
|
38
38
|
plateNo?: string;
|
|
39
39
|
roadLayer?: string;
|
|
40
|
+
step?: number;
|
|
40
41
|
}
|
|
41
42
|
export interface IVehicleRecord {
|
|
42
43
|
model: Three.Group | Three.Mesh;
|
|
@@ -151,6 +152,7 @@ export interface IToggleTrafficInfoParams {
|
|
|
151
152
|
}
|
|
152
153
|
export interface ITraceRendererInterface {
|
|
153
154
|
init(): Promise<void>;
|
|
155
|
+
getLog(): (string | number | undefined)[][];
|
|
154
156
|
addVehicles(objects: IVehicleTrack[]): Promise<void>;
|
|
155
157
|
updateVehicles(objects: IVehicleTrack[]): Promise<void>;
|
|
156
158
|
deleteVehicles(idList: string[]): void;
|