gisviewer-vue3-arcgis 1.0.176 → 1.0.178
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 +1 -0
- package/es/src/gis-map/utils/holo-flow/trace-holo-flow.mjs +42 -44
- package/es/src/gis-map/utils/holo-flow/trace-renderer-external.d.ts +1 -1
- package/es/src/gis-map/utils/holo-flow/trace-renderer-external.mjs +198 -175
- package/lib/src/gis-map/utils/holo-flow/trace-holo-flow.d.ts +1 -0
- 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 +1 -1
- package/lib/src/gis-map/utils/holo-flow/trace-renderer-external.js +1 -1
- package/package.json +1 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import
|
|
1
|
+
import * as g from "@arcgis/core/views/3d/externalRenderers";
|
|
2
|
+
import f from "./trace-renderer-external.mjs";
|
|
3
3
|
import R from "./trace-renderer-layer.mjs";
|
|
4
|
-
class
|
|
4
|
+
class V {
|
|
5
5
|
constructor(e) {
|
|
6
|
-
this.nullDataCount = 0, e.type === "3d" ? (this.traceRenderer = new
|
|
6
|
+
this.nullDataCount = 0, this.clearTraceTimer = null, e.type === "3d" ? (this.traceRenderer = new f(e), g.add(
|
|
7
7
|
e,
|
|
8
8
|
this.traceRenderer
|
|
9
9
|
)) : this.traceRenderer = new R(e);
|
|
@@ -12,40 +12,38 @@ class L {
|
|
|
12
12
|
await this.traceRenderer.init();
|
|
13
13
|
}
|
|
14
14
|
downloadLog() {
|
|
15
|
-
const e = this.traceRenderer.getLog().map((
|
|
16
|
-
`).replace(/null/g, ""),
|
|
17
|
-
r.setAttribute("href",
|
|
15
|
+
const e = this.traceRenderer.getLog().map((o) => o.join(",")).join(`
|
|
16
|
+
`).replace(/null/g, ""), n = new Blob([e], { type: "text/csv;charset=utf-8;" }), i = URL.createObjectURL(n), 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);
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
20
|
* 处理全息流轨迹数据
|
|
21
21
|
* */
|
|
22
22
|
async handleVehicleTraceData(e) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const t = this.buildVehicleTrackData(n, i);
|
|
33
|
-
t && l.push(t);
|
|
23
|
+
this.clearTraceTimer || (this.clearTraceTimer = setInterval(() => {
|
|
24
|
+
this.nullDataCount++, this.nullDataCount >= 5 && (console.log("clear trace data"), this.clearTrace(), this.nullDataCount = 0);
|
|
25
|
+
}, 1e3)), this.nullDataCount = 0;
|
|
26
|
+
const { newVehList: n, updateVehList: i, deleteVehList: r, jgsj: o } = e, l = e.crossId || "", a = [], s = [];
|
|
27
|
+
if (n && n.length > 0) {
|
|
28
|
+
for (const c of n) {
|
|
29
|
+
c.localTimestamp || (c.localTimestamp = o || Date.now());
|
|
30
|
+
const t = this.buildVehicleTrackData(c, l);
|
|
31
|
+
t && a.push(t);
|
|
34
32
|
}
|
|
35
|
-
await this.traceRenderer.addVehicles(
|
|
33
|
+
await this.traceRenderer.addVehicles(a);
|
|
36
34
|
}
|
|
37
|
-
if (
|
|
38
|
-
for (const
|
|
39
|
-
const t = this.buildVehicleTrackData(
|
|
40
|
-
t &&
|
|
35
|
+
if (i && i.length > 0) {
|
|
36
|
+
for (const c of i) {
|
|
37
|
+
const t = this.buildVehicleTrackData(c, l);
|
|
38
|
+
t && s.push(t);
|
|
41
39
|
}
|
|
42
|
-
await this.traceRenderer.updateVehicles(
|
|
40
|
+
await this.traceRenderer.updateVehicles(s);
|
|
43
41
|
}
|
|
44
42
|
if (r && r.length > 0) {
|
|
45
|
-
const
|
|
46
|
-
(t) =>
|
|
43
|
+
const c = r.map(
|
|
44
|
+
(t) => l + "-" + (t.ptcId || t.vehno || t.vehNo)
|
|
47
45
|
);
|
|
48
|
-
this.traceRenderer.deleteVehicles(
|
|
46
|
+
this.traceRenderer.deleteVehicles(c);
|
|
49
47
|
}
|
|
50
48
|
}
|
|
51
49
|
/**
|
|
@@ -59,7 +57,7 @@ class L {
|
|
|
59
57
|
* 清除轨迹流
|
|
60
58
|
* */
|
|
61
59
|
clearTrace() {
|
|
62
|
-
this.traceRenderer.clearVehicles();
|
|
60
|
+
this.clearTraceTimer && (clearInterval(this.clearTraceTimer), this.clearTraceTimer = null), this.traceRenderer.clearVehicles();
|
|
63
61
|
}
|
|
64
62
|
/**
|
|
65
63
|
* 切换暂停
|
|
@@ -79,30 +77,30 @@ class L {
|
|
|
79
77
|
setInterpolate(e) {
|
|
80
78
|
this.traceRenderer.setInterpolate(e);
|
|
81
79
|
}
|
|
82
|
-
buildVehicleTrackData(e,
|
|
83
|
-
const
|
|
84
|
-
if (!(
|
|
80
|
+
buildVehicleTrackData(e, n) {
|
|
81
|
+
const i = e.longitude, r = e.latitude, o = e.ptcId, l = Number(e.ptcType), a = e.heading, s = Number(e.vehicleType), c = Number(e.vehicleColor), t = e.plateNo || e.plateno, h = Number(e.plateColor), d = e.timestamp, u = e.localTimestamp, p = e.roadLayer ? String(e.roadLayer) : "1", m = e.step, T = e.speed;
|
|
82
|
+
if (!(l < 0 || l > 8))
|
|
85
83
|
return {
|
|
86
|
-
ptcId:
|
|
87
|
-
crossId:
|
|
88
|
-
vehicleId:
|
|
89
|
-
x:
|
|
84
|
+
ptcId: o,
|
|
85
|
+
crossId: n,
|
|
86
|
+
vehicleId: n + "-" + o,
|
|
87
|
+
x: i,
|
|
90
88
|
y: r,
|
|
91
|
-
ptcType:
|
|
92
|
-
vehicleType:
|
|
93
|
-
heading:
|
|
94
|
-
vehicleColor:
|
|
89
|
+
ptcType: l,
|
|
90
|
+
vehicleType: s,
|
|
91
|
+
heading: l === 2 ? -a : a,
|
|
92
|
+
vehicleColor: c,
|
|
95
93
|
showName: t && t !== "" && t !== "0" && t !== "000000" ? t : "",
|
|
96
94
|
plateNo: t,
|
|
97
95
|
plateColor: h,
|
|
98
96
|
timestamp: d,
|
|
99
|
-
localTimestamp:
|
|
100
|
-
roadLayer:
|
|
101
|
-
step:
|
|
102
|
-
speed:
|
|
97
|
+
localTimestamp: u,
|
|
98
|
+
roadLayer: p,
|
|
99
|
+
step: m,
|
|
100
|
+
speed: T
|
|
103
101
|
};
|
|
104
102
|
}
|
|
105
103
|
}
|
|
106
104
|
export {
|
|
107
|
-
|
|
105
|
+
V as default
|
|
108
106
|
};
|
|
@@ -37,7 +37,7 @@ export default class TraceRendererExternal implements ITraceRendererInterface {
|
|
|
37
37
|
private currentSpriteContent;
|
|
38
38
|
private historyPositionMap;
|
|
39
39
|
private vehicleObjectMap;
|
|
40
|
-
private
|
|
40
|
+
private tabVisible;
|
|
41
41
|
private updateModel;
|
|
42
42
|
private appDataStore;
|
|
43
43
|
/** 轨迹日志 */
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import * as
|
|
3
|
-
import
|
|
4
|
-
import * as
|
|
1
|
+
import * as y from "@arcgis/core/core/promiseUtils.js";
|
|
2
|
+
import * as T from "@arcgis/core/core/reactiveUtils.js";
|
|
3
|
+
import C from "@arcgis/core/geometry/SpatialReference";
|
|
4
|
+
import * as b from "@arcgis/core/views/3d/externalRenderers";
|
|
5
5
|
import * as a from "three";
|
|
6
|
-
import { GLTFLoader as
|
|
7
|
-
import {
|
|
6
|
+
import { GLTFLoader as f } from "three/examples/jsm/loaders/GLTFLoader";
|
|
7
|
+
import { MTLLoader as w } from "three/examples/jsm/loaders/MTLLoader";
|
|
8
|
+
import { OBJLoader as M } from "three/examples/jsm/loaders/OBJLoader";
|
|
9
|
+
import { toRaw as G } from "vue";
|
|
8
10
|
import { EVehiclePlateState as m } from "../../../types/index.mjs";
|
|
9
|
-
import
|
|
10
|
-
class
|
|
11
|
-
constructor(
|
|
11
|
+
import S from "../../stores/index.mjs";
|
|
12
|
+
class N {
|
|
13
|
+
constructor(e) {
|
|
12
14
|
this.cameraHeightThreshold = 1e3, this.roughness = 0.2, this.metalness = 0.8, this.defaultMaterial = new a.MeshPhongMaterial({
|
|
13
15
|
color: 16777215
|
|
14
16
|
}), this.materialMap = /* @__PURE__ */ new Map([
|
|
@@ -23,7 +25,7 @@ class V {
|
|
|
23
25
|
[9, this.createCarMaterial(2105376)],
|
|
24
26
|
[10, this.createCarMaterial(9662683)],
|
|
25
27
|
[99, this.createCarMaterial(6908265)]
|
|
26
|
-
]), 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.
|
|
28
|
+
]), 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.tabVisible = !0, this.updateModel = !1, this.appDataStore = S.useAppDataStore, this.logTable = [
|
|
27
29
|
[
|
|
28
30
|
"ptcId",
|
|
29
31
|
"plateno",
|
|
@@ -44,9 +46,15 @@ class V {
|
|
|
44
46
|
"queueLength",
|
|
45
47
|
"status"
|
|
46
48
|
]
|
|
47
|
-
], this.view =
|
|
48
|
-
const
|
|
49
|
-
this.assetsRoot =
|
|
49
|
+
], this.view = e;
|
|
50
|
+
const i = G(this.appDataStore.mapConfig);
|
|
51
|
+
this.assetsRoot = i.assetsRoot, document.addEventListener(
|
|
52
|
+
"visibilitychange",
|
|
53
|
+
() => {
|
|
54
|
+
this.clearVehicles(), this.tabVisible = !document.hidden;
|
|
55
|
+
},
|
|
56
|
+
!1
|
|
57
|
+
), T.watch(
|
|
50
58
|
() => this.view.camera.position.z,
|
|
51
59
|
(t, s) => {
|
|
52
60
|
(s <= this.cameraHeightThreshold && t > this.cameraHeightThreshold || s > this.cameraHeightThreshold && t <= this.cameraHeightThreshold) && (this.updateModel = !0);
|
|
@@ -54,9 +62,9 @@ class V {
|
|
|
54
62
|
);
|
|
55
63
|
}
|
|
56
64
|
// private readonly vehiclePool = new VehiclePool();
|
|
57
|
-
createCarMaterial(
|
|
65
|
+
createCarMaterial(e) {
|
|
58
66
|
return new a.MeshPhongMaterial({
|
|
59
|
-
color:
|
|
67
|
+
color: e
|
|
60
68
|
// // emissive: 0xc3c3c3,
|
|
61
69
|
// roughness: this.roughness,
|
|
62
70
|
// metalness: this.metalness
|
|
@@ -66,43 +74,59 @@ class V {
|
|
|
66
74
|
return this.logTable;
|
|
67
75
|
}
|
|
68
76
|
async init() {
|
|
69
|
-
|
|
70
|
-
await b.eachAlways([
|
|
77
|
+
await y.eachAlways([
|
|
71
78
|
new Promise((e) => {
|
|
72
|
-
|
|
73
|
-
const s = t.scene,
|
|
74
|
-
this.carModel = new a.Object3D(), this.carModel.rotation.x = a.MathUtils.degToRad(90), this.carModel.add(s), s.position.set(0, 0,
|
|
79
|
+
new f().load(`${this.assetsRoot}/3DModels/car.glb`, (t) => {
|
|
80
|
+
const s = t.scene, l = new a.Box3().setFromObject(s).getSize(new a.Vector3());
|
|
81
|
+
this.carModel = new a.Object3D(), this.carModel.rotation.x = a.MathUtils.degToRad(90), this.carModel.add(s), s.position.set(0, 0, l.z / 2), e();
|
|
75
82
|
});
|
|
76
83
|
}),
|
|
77
84
|
new Promise((e) => {
|
|
78
|
-
|
|
79
|
-
const s = t.scene,
|
|
80
|
-
this.vanModel = new a.Object3D(), this.vanModel.rotation.x = a.MathUtils.degToRad(90), this.vanModel.add(s), s.position.set(0, 0,
|
|
85
|
+
new f().load(`${this.assetsRoot}/3DModels/van.glb`, (t) => {
|
|
86
|
+
const s = t.scene, l = new a.Box3().setFromObject(s).getSize(new a.Vector3());
|
|
87
|
+
this.vanModel = new a.Object3D(), this.vanModel.rotation.x = a.MathUtils.degToRad(90), this.vanModel.add(s), s.position.set(0, 0, l.z / 2), e();
|
|
81
88
|
});
|
|
82
89
|
}),
|
|
83
90
|
new Promise((e) => {
|
|
84
|
-
|
|
91
|
+
new f().load(`${this.assetsRoot}/3DModels/truck.glb`, (t) => {
|
|
85
92
|
const s = t.scene;
|
|
86
93
|
s.scale.set(1.2, 1, 1.5);
|
|
87
|
-
const
|
|
88
|
-
this.truckModel = new a.Object3D(), this.truckModel.rotation.x = a.MathUtils.degToRad(90), this.truckModel.add(s), s.position.set(0, 0,
|
|
94
|
+
const l = new a.Box3().setFromObject(s).getSize(new a.Vector3());
|
|
95
|
+
this.truckModel = new a.Object3D(), this.truckModel.rotation.x = a.MathUtils.degToRad(90), this.truckModel.add(s), s.position.set(0, 0, l.z / 2), e();
|
|
89
96
|
});
|
|
90
97
|
}),
|
|
91
98
|
new Promise((e) => {
|
|
92
|
-
|
|
93
|
-
const s = t.scene,
|
|
94
|
-
this.busModel = new a.Object3D(), this.busModel.rotation.x = a.MathUtils.degToRad(90), this.busModel.add(s), s.position.set(0, 0,
|
|
99
|
+
new f().load(`${this.assetsRoot}/3DModels/bus.glb`, (t) => {
|
|
100
|
+
const s = t.scene, l = new a.Box3().setFromObject(s).getSize(new a.Vector3());
|
|
101
|
+
this.busModel = new a.Object3D(), this.busModel.rotation.x = a.MathUtils.degToRad(90), this.busModel.add(s), s.position.set(0, 0, l.z / 2), e();
|
|
95
102
|
});
|
|
96
103
|
}),
|
|
97
104
|
new Promise((e) => {
|
|
98
|
-
|
|
99
|
-
this.
|
|
100
|
-
|
|
105
|
+
new w().load(
|
|
106
|
+
`${this.assetsRoot}/3DModels/bicycle.mtl`,
|
|
107
|
+
(t) => {
|
|
108
|
+
t.preload();
|
|
109
|
+
const s = new M();
|
|
110
|
+
s.setMaterials(t), s.load(
|
|
111
|
+
`${this.assetsRoot}/3DModels/bicycle.obj`,
|
|
112
|
+
(o) => {
|
|
113
|
+
this.bicycleModel = o, this.bicycleModel.rotation.x = a.MathUtils.degToRad(90), e();
|
|
114
|
+
}
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
);
|
|
101
118
|
}),
|
|
102
119
|
new Promise((e) => {
|
|
103
|
-
|
|
104
|
-
this.
|
|
105
|
-
|
|
120
|
+
new w().load(
|
|
121
|
+
`${this.assetsRoot}/3DModels/passenger.mtl`,
|
|
122
|
+
(t) => {
|
|
123
|
+
t.preload();
|
|
124
|
+
const s = new M();
|
|
125
|
+
s.setMaterials(t), s.load(`${this.assetsRoot}/3DModels/male.obj`, (o) => {
|
|
126
|
+
o.scale.set(0.01, 0.01, 0.01), this.passengerModel = o, this.passengerModel.rotation.x = a.MathUtils.degToRad(90), this.passengerModel.rotation.y = a.MathUtils.degToRad(180), e();
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
);
|
|
106
130
|
}),
|
|
107
131
|
new Promise((e) => {
|
|
108
132
|
this.bluePlateBG = new Image(), this.bluePlateBG.src = `${this.assetsRoot}/Images/PlateBG/blue.png`, this.bluePlateBG.onload = () => {
|
|
@@ -141,48 +165,48 @@ class V {
|
|
|
141
165
|
})
|
|
142
166
|
]), this.isInitialized = !0;
|
|
143
167
|
}
|
|
144
|
-
setInterpolate(
|
|
145
|
-
this.clearVehicles(), this.
|
|
168
|
+
setInterpolate(e) {
|
|
169
|
+
this.clearVehicles(), this.tabVisible = e;
|
|
146
170
|
}
|
|
147
|
-
async setup(
|
|
148
|
-
this.context =
|
|
149
|
-
context:
|
|
171
|
+
async setup(e) {
|
|
172
|
+
this.context = e, this.renderer = new a.WebGLRenderer({
|
|
173
|
+
context: e.gl,
|
|
150
174
|
premultipliedAlpha: !0,
|
|
151
175
|
logarithmicDepthBuffer: !0,
|
|
152
176
|
antialias: !0,
|
|
153
177
|
powerPreference: "high-performance"
|
|
154
178
|
}), 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;
|
|
155
|
-
const
|
|
179
|
+
const i = this.renderer.setRenderTarget.bind(
|
|
156
180
|
this.renderer
|
|
157
181
|
);
|
|
158
182
|
this.renderer.setRenderTarget = (s) => {
|
|
159
|
-
|
|
183
|
+
i(s), s == null && e.bindRenderTarget();
|
|
160
184
|
}, this.scene = new a.Scene();
|
|
161
|
-
const { camera: t } =
|
|
185
|
+
const { camera: t } = e;
|
|
162
186
|
this.camera = new a.PerspectiveCamera(
|
|
163
187
|
t.fovY,
|
|
164
188
|
t.aspect,
|
|
165
189
|
0.1,
|
|
166
190
|
1e5
|
|
167
|
-
), this.ambient = new a.AmbientLight(16777215, 2), this.scene.add(this.ambient), this.sun = new a.DirectionalLight(16777215, 2), this.scene.add(this.sun),
|
|
191
|
+
), this.ambient = new a.AmbientLight(16777215, 2), this.scene.add(this.ambient), this.sun = new a.DirectionalLight(16777215, 2), this.scene.add(this.sun), e.resetWebGLState();
|
|
168
192
|
}
|
|
169
|
-
async render(
|
|
193
|
+
async render(e) {
|
|
170
194
|
var s;
|
|
171
|
-
const
|
|
172
|
-
if (this.camera.position.set(
|
|
173
|
-
new a.Vector3(
|
|
174
|
-
), this.camera.projectionMatrix.fromArray(
|
|
195
|
+
const i = e.camera;
|
|
196
|
+
if (this.camera.position.set(i.eye[0], i.eye[1], i.eye[2]), this.camera.up.set(i.up[0], i.up[1], i.up[2]), this.camera.lookAt(
|
|
197
|
+
new a.Vector3(i.center[0], i.center[1], i.center[2])
|
|
198
|
+
), this.camera.projectionMatrix.fromArray(i.projectionMatrix), !this.isPaused && this.tabVisible)
|
|
175
199
|
for (const o of this.vehicleObjectMap.keys()) {
|
|
176
|
-
const
|
|
177
|
-
if (!
|
|
200
|
+
const l = (s = this.vehicleObjectMap.get(o)) == null ? void 0 : s.model;
|
|
201
|
+
if (!l)
|
|
178
202
|
continue;
|
|
179
203
|
const r = this.computeVehiclePosition(o);
|
|
180
204
|
if (r) {
|
|
181
205
|
const d = this.toRenderCoordinates(r);
|
|
182
|
-
|
|
206
|
+
l.position.set(d[0], d[1], d[2]), l.rotation.y = a.MathUtils.degToRad(-r[3]);
|
|
183
207
|
}
|
|
184
208
|
}
|
|
185
|
-
const t =
|
|
209
|
+
const t = e.sunLight;
|
|
186
210
|
this.sun.position.set(t.direction[0], t.direction[1], t.direction[2]), this.sun.intensity = t.diffuse.intensity, this.sun.color = new a.Color(
|
|
187
211
|
t.diffuse.color[0],
|
|
188
212
|
t.diffuse.color[1],
|
|
@@ -191,16 +215,16 @@ class V {
|
|
|
191
215
|
t.ambient.color[0],
|
|
192
216
|
t.ambient.color[1],
|
|
193
217
|
t.ambient.color[2]
|
|
194
|
-
), this.renderer.resetState(),
|
|
218
|
+
), this.renderer.resetState(), e.bindRenderTarget(), this.renderer.render(this.scene, this.camera), b.requestRender(this.view), e.resetWebGLState();
|
|
195
219
|
}
|
|
196
220
|
/**
|
|
197
221
|
* 新增车辆
|
|
198
222
|
* */
|
|
199
|
-
async addVehicles(
|
|
200
|
-
if (this.isPaused || !this.isInitialized)
|
|
223
|
+
async addVehicles(e) {
|
|
224
|
+
if (this.isPaused || !this.isInitialized || !this.tabVisible)
|
|
201
225
|
return;
|
|
202
|
-
const
|
|
203
|
-
for (const t of
|
|
226
|
+
const i = Date.now();
|
|
227
|
+
for (const t of e) {
|
|
204
228
|
this.appDataStore.saveTrackLog && this.logTable.push([
|
|
205
229
|
t.ptcId,
|
|
206
230
|
t.plateNo,
|
|
@@ -217,21 +241,21 @@ class V {
|
|
|
217
241
|
t.fixAngle,
|
|
218
242
|
t.roadLayer,
|
|
219
243
|
t.step,
|
|
220
|
-
|
|
244
|
+
i,
|
|
221
245
|
0,
|
|
222
246
|
0
|
|
223
247
|
]);
|
|
224
|
-
const { vehicleId: s, localTimestamp: o } = t,
|
|
248
|
+
const { vehicleId: s, localTimestamp: o } = t, l = Number(t.x), r = Number(t.y), d = Number(t.heading);
|
|
225
249
|
this.historyPositionMap.set(s, [
|
|
226
|
-
{ pos: [
|
|
250
|
+
{ pos: [l, r, 0], heading: d, time: o }
|
|
227
251
|
]);
|
|
228
252
|
const h = this.getVehicleModel(t);
|
|
229
253
|
h.name = s, h.visible = !1;
|
|
230
254
|
try {
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
} catch (
|
|
234
|
-
console.log("createPlateSprite error:",
|
|
255
|
+
const n = await this.createPlateSprite(t);
|
|
256
|
+
n && (h.add(n), n.position.set(0, 5, -4));
|
|
257
|
+
} catch (n) {
|
|
258
|
+
console.log("createPlateSprite error:", n);
|
|
235
259
|
}
|
|
236
260
|
this.scene.add(h), this.vehicleObjectMap.set(s, {
|
|
237
261
|
model: h,
|
|
@@ -244,18 +268,18 @@ class V {
|
|
|
244
268
|
/**
|
|
245
269
|
* 更新车辆
|
|
246
270
|
* */
|
|
247
|
-
async updateVehicles(
|
|
248
|
-
if (this.isPaused || !this.isInitialized)
|
|
271
|
+
async updateVehicles(e) {
|
|
272
|
+
if (this.isPaused || !this.isInitialized || !this.tabVisible)
|
|
249
273
|
return;
|
|
250
|
-
const
|
|
251
|
-
for (const s of
|
|
252
|
-
const { vehicleId: o, localTimestamp:
|
|
274
|
+
const i = [], t = Date.now();
|
|
275
|
+
for (const s of e) {
|
|
276
|
+
const { vehicleId: o, localTimestamp: l } = s, r = Number(s.x), d = Number(s.y);
|
|
253
277
|
let h = Number(s.heading);
|
|
254
|
-
const
|
|
278
|
+
const n = this.vehicleObjectMap.get(o), p = this.historyPositionMap.get(
|
|
255
279
|
o
|
|
256
280
|
);
|
|
257
|
-
if (!
|
|
258
|
-
|
|
281
|
+
if (!n || !p)
|
|
282
|
+
i.push(s);
|
|
259
283
|
else {
|
|
260
284
|
if (this.appDataStore.saveTrackLog && this.logTable.push([
|
|
261
285
|
s.ptcId,
|
|
@@ -276,56 +300,56 @@ class V {
|
|
|
276
300
|
t,
|
|
277
301
|
p.length,
|
|
278
302
|
1
|
|
279
|
-
]), this.updateModel ||
|
|
280
|
-
this.scene.remove(
|
|
303
|
+
]), this.updateModel || n.data.vehicleColor !== s.vehicleColor || n.data.vehicleType !== s.vehicleType) {
|
|
304
|
+
this.scene.remove(n.model), this.disposeModel(n.model), n.model = this.getVehicleModel(s), n.model.visible = !0;
|
|
281
305
|
const c = await this.createPlateSprite(s);
|
|
282
|
-
c && (
|
|
306
|
+
c && (n.model.add(c), c.position.set(0, 5, -4)), this.scene.add(n.model);
|
|
283
307
|
}
|
|
284
|
-
if (
|
|
285
|
-
const c =
|
|
286
|
-
c && (
|
|
308
|
+
if (n.data.showName !== s.showName || n.data.plateColor !== s.plateColor) {
|
|
309
|
+
const c = n.model.getObjectByName("VehiclePlate");
|
|
310
|
+
c && (n.model.remove(c), this.disposeModel(c));
|
|
287
311
|
const g = await this.createPlateSprite(s);
|
|
288
|
-
g && (
|
|
312
|
+
g && (n.model.add(g), g.position.set(0, 5, -4));
|
|
289
313
|
}
|
|
290
|
-
if (
|
|
314
|
+
if (n.data = s, this.tabVisible) {
|
|
291
315
|
const c = p[p.length - 1];
|
|
292
316
|
Math.abs(h - c.heading) >= 180 && (h > c.heading ? c.heading += 360 : h += 360), p.push({
|
|
293
317
|
pos: [r, d, 0],
|
|
294
318
|
heading: h,
|
|
295
|
-
time:
|
|
319
|
+
time: l
|
|
296
320
|
});
|
|
297
321
|
} else {
|
|
298
322
|
this.historyPositionMap.set(o, [
|
|
299
|
-
{ pos: [r, d, 0], heading: h, time:
|
|
323
|
+
{ pos: [r, d, 0], heading: h, time: l }
|
|
300
324
|
]);
|
|
301
325
|
const c = this.toRenderCoordinates([r, d, 0]);
|
|
302
|
-
|
|
326
|
+
n.model.position.set(c[0], c[1], c[2]), n.model.rotation.y = a.MathUtils.degToRad(-h);
|
|
303
327
|
}
|
|
304
328
|
}
|
|
305
329
|
}
|
|
306
|
-
await this.addVehicles(
|
|
330
|
+
await this.addVehicles(i), this.updateModel = !1;
|
|
307
331
|
}
|
|
308
|
-
toRenderCoordinates(
|
|
309
|
-
const
|
|
310
|
-
return
|
|
332
|
+
toRenderCoordinates(e) {
|
|
333
|
+
const i = [0, 0, 0];
|
|
334
|
+
return b.toRenderCoordinates(
|
|
311
335
|
// @ts-ignore
|
|
312
336
|
this.view,
|
|
313
|
-
i,
|
|
314
|
-
0,
|
|
315
|
-
v.WGS84,
|
|
316
337
|
e,
|
|
317
338
|
0,
|
|
339
|
+
C.WGS84,
|
|
340
|
+
i,
|
|
341
|
+
0,
|
|
318
342
|
1
|
|
319
|
-
),
|
|
343
|
+
), i;
|
|
320
344
|
}
|
|
321
345
|
/**
|
|
322
346
|
* 删除车辆
|
|
323
347
|
* */
|
|
324
|
-
deleteVehicles(
|
|
348
|
+
deleteVehicles(e) {
|
|
325
349
|
if (this.isPaused)
|
|
326
350
|
return;
|
|
327
|
-
const
|
|
328
|
-
|
|
351
|
+
const i = Date.now();
|
|
352
|
+
e.forEach((t) => {
|
|
329
353
|
if (this.appDataStore.saveTrackLog) {
|
|
330
354
|
const o = this.historyPositionMap.get(t);
|
|
331
355
|
this.logTable.push([
|
|
@@ -344,36 +368,34 @@ class V {
|
|
|
344
368
|
"",
|
|
345
369
|
"",
|
|
346
370
|
"",
|
|
347
|
-
|
|
371
|
+
i,
|
|
348
372
|
o ? o.length : 0,
|
|
349
373
|
2
|
|
350
374
|
]);
|
|
351
375
|
}
|
|
352
376
|
const s = this.vehicleObjectMap.get(t);
|
|
353
|
-
s && (this.
|
|
377
|
+
s && (this.tabVisible ? s.isMoving ? s.waitForDelete = !0 : this.deleteVehicle(s) : this.deleteVehicle(s));
|
|
354
378
|
});
|
|
355
379
|
}
|
|
356
|
-
deleteVehicle(
|
|
357
|
-
this.
|
|
358
|
-
const
|
|
359
|
-
this.vehicleObjectMap.delete(
|
|
380
|
+
deleteVehicle(e) {
|
|
381
|
+
this.disposeModel(e.model), this.scene.remove(e.model);
|
|
382
|
+
const i = e.data.vehicleId;
|
|
383
|
+
this.vehicleObjectMap.delete(i), this.historyPositionMap.delete(i);
|
|
360
384
|
}
|
|
361
|
-
async toggleTrafficInfo(
|
|
362
|
-
|
|
363
|
-
|
|
385
|
+
async toggleTrafficInfo(e) {
|
|
386
|
+
e.name === "vehiclePlate" && (e.visible === !0 && this.currentSpriteContent === m.None ? await this.updatePanelContent(m.PlateNumber) : await this.updatePanelContent(
|
|
387
|
+
e.visible ? this.currentSpriteContent : m.None
|
|
364
388
|
));
|
|
365
389
|
}
|
|
366
|
-
togglePause(
|
|
367
|
-
this.isPaused =
|
|
390
|
+
togglePause(e) {
|
|
391
|
+
this.isPaused = e;
|
|
368
392
|
}
|
|
369
393
|
/**
|
|
370
394
|
* 清除全部车辆
|
|
371
395
|
* */
|
|
372
396
|
clearVehicles() {
|
|
373
|
-
for (const
|
|
374
|
-
|
|
375
|
-
e && (this.scene.remove(e.model), this.disposeModel(e.model));
|
|
376
|
-
}
|
|
397
|
+
for (const e of this.vehicleObjectMap.values())
|
|
398
|
+
this.disposeModel(e.model), this.scene.remove(e.model);
|
|
377
399
|
this.vehicleObjectMap.clear(), this.historyPositionMap.clear();
|
|
378
400
|
}
|
|
379
401
|
/**
|
|
@@ -381,59 +403,60 @@ class V {
|
|
|
381
403
|
* @param contentType
|
|
382
404
|
* @returns
|
|
383
405
|
*/
|
|
384
|
-
async updatePanelContent(
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
if (s && (t.model.remove(s), this.disposeModel(s)), i !== m.None) {
|
|
392
|
-
const o = await this.createPlateSprite(t.data);
|
|
393
|
-
o && (t.model.add(o), o.position.set(0, 5, -4));
|
|
394
|
-
}
|
|
395
|
-
}
|
|
406
|
+
async updatePanelContent(e) {
|
|
407
|
+
this.currentSpriteContent = e;
|
|
408
|
+
for (const i of this.vehicleObjectMap.values()) {
|
|
409
|
+
const t = i.model.getObjectByName("VehiclePlate");
|
|
410
|
+
if (t && (i.model.remove(t), this.disposeModel(t)), e !== m.None) {
|
|
411
|
+
const s = await this.createPlateSprite(i.data);
|
|
412
|
+
s && (i.model.add(s), s.position.set(0, 5, -4));
|
|
396
413
|
}
|
|
397
414
|
}
|
|
398
415
|
}
|
|
399
|
-
toggleGroundVehicle(
|
|
400
|
-
|
|
416
|
+
toggleGroundVehicle(e) {
|
|
417
|
+
this.showGroundVehicle = e;
|
|
401
418
|
}
|
|
402
|
-
toggleElevatedVehicle(
|
|
403
|
-
this.showElevatedVehicle =
|
|
419
|
+
toggleElevatedVehicle(e) {
|
|
420
|
+
this.showElevatedVehicle = e;
|
|
404
421
|
}
|
|
405
422
|
/**
|
|
406
423
|
* 释放模型资源
|
|
407
424
|
* */
|
|
408
|
-
disposeModel(
|
|
409
|
-
|
|
410
|
-
|
|
425
|
+
disposeModel(e) {
|
|
426
|
+
e.traverse((i) => {
|
|
427
|
+
if (i instanceof a.Mesh) {
|
|
428
|
+
i.geometry.dispose();
|
|
429
|
+
try {
|
|
430
|
+
i.material.dispose();
|
|
431
|
+
} catch {
|
|
432
|
+
}
|
|
433
|
+
}
|
|
411
434
|
});
|
|
412
435
|
}
|
|
413
436
|
/**
|
|
414
437
|
* 计算车辆位置
|
|
415
438
|
* */
|
|
416
|
-
computeVehiclePosition(
|
|
417
|
-
const
|
|
418
|
-
if (!t || !
|
|
439
|
+
computeVehiclePosition(e) {
|
|
440
|
+
const i = this.historyPositionMap.get(e), t = this.vehicleObjectMap.get(e);
|
|
441
|
+
if (!t || !i || !t.isMoving && i.length <= 2)
|
|
419
442
|
return;
|
|
420
443
|
const s = Date.now();
|
|
421
|
-
t.isMoving = !0, t.data.roadLayer === "1" ? t.model.visible = this.showGroundVehicle : t.model.visible = this.showElevatedVehicle, t.segmentStartTime || (t.segmentStartTime = s, t.segmentTotalTime =
|
|
422
|
-
const o = s - t.segmentStartTime,
|
|
444
|
+
t.isMoving = !0, t.data.roadLayer === "1" ? t.model.visible = this.showGroundVehicle : t.model.visible = this.showElevatedVehicle, t.segmentStartTime || (t.segmentStartTime = s, t.segmentTotalTime = i[1].time - i[0].time);
|
|
445
|
+
const o = s - t.segmentStartTime, l = Math.min(
|
|
423
446
|
o / t.segmentTotalTime,
|
|
424
447
|
1
|
|
425
448
|
);
|
|
426
|
-
if (
|
|
427
|
-
if (
|
|
428
|
-
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",
|
|
449
|
+
if (l === 1)
|
|
450
|
+
if (i.shift(), i.length === 1) {
|
|
451
|
+
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", e));
|
|
429
452
|
return;
|
|
430
453
|
} else {
|
|
431
454
|
t.segmentStartTime = Date.now();
|
|
432
455
|
const r = o - t.segmentTotalTime;
|
|
433
|
-
return t.segmentTotalTime =
|
|
456
|
+
return t.segmentTotalTime = i[1].time - i[0].time - r, (i[1].heading >= 270 && i[0].heading <= 90 || i[1].heading <= 90 && i[0].heading >= 270) && (i[1].heading > i[0].heading ? i[0].heading += 360 : i[1].heading += 360), i[0].pos.concat(i[0].heading);
|
|
434
457
|
}
|
|
435
|
-
else if (
|
|
436
|
-
const r =
|
|
458
|
+
else if (i.length >= 2) {
|
|
459
|
+
const r = i[0].pos[0] + (i[1].pos[0] - i[0].pos[0]) * l, d = i[0].pos[1] + (i[1].pos[1] - i[0].pos[1]) * l, h = i[0].heading + (i[1].heading - i[0].heading) * l;
|
|
437
460
|
return [r, d, 0, h];
|
|
438
461
|
} else
|
|
439
462
|
return;
|
|
@@ -441,75 +464,75 @@ class V {
|
|
|
441
464
|
/**
|
|
442
465
|
* 根据车辆类型、车身颜色获取模型
|
|
443
466
|
* */
|
|
444
|
-
getVehicleModel(
|
|
467
|
+
getVehicleModel(e) {
|
|
445
468
|
if (this.view.camera.position.z >= this.cameraHeightThreshold) {
|
|
446
|
-
const
|
|
469
|
+
const i = new a.SphereGeometry(5, 32, 32), t = new a.MeshPhysicalMaterial({
|
|
447
470
|
color: 325253,
|
|
448
471
|
emissive: 0,
|
|
449
472
|
roughness: this.roughness,
|
|
450
473
|
metalness: this.metalness
|
|
451
474
|
});
|
|
452
|
-
return new a.Mesh(
|
|
475
|
+
return new a.Mesh(i, t);
|
|
453
476
|
} else {
|
|
454
|
-
let
|
|
455
|
-
if (
|
|
456
|
-
|
|
457
|
-
else if (
|
|
458
|
-
|
|
477
|
+
let i;
|
|
478
|
+
if (e.ptcType === 2)
|
|
479
|
+
i = this.bicycleModel.clone();
|
|
480
|
+
else if (e.ptcType === 3)
|
|
481
|
+
i = this.passengerModel.clone();
|
|
459
482
|
else {
|
|
460
|
-
switch (
|
|
483
|
+
switch (e.vehicleType) {
|
|
461
484
|
case 10:
|
|
462
|
-
|
|
485
|
+
i = this.carModel.clone();
|
|
463
486
|
break;
|
|
464
487
|
case 20:
|
|
465
|
-
|
|
488
|
+
i = this.vanModel.clone();
|
|
466
489
|
break;
|
|
467
490
|
case 25:
|
|
468
|
-
|
|
491
|
+
i = this.truckModel.clone();
|
|
469
492
|
break;
|
|
470
493
|
case 50:
|
|
471
|
-
|
|
494
|
+
i = this.busModel.clone();
|
|
472
495
|
break;
|
|
473
496
|
default:
|
|
474
|
-
|
|
497
|
+
i = this.carModel.clone();
|
|
475
498
|
break;
|
|
476
499
|
}
|
|
477
|
-
const t = this.materialMap.get(
|
|
500
|
+
const t = this.materialMap.get(e.vehicleColor) || this.defaultMaterial;
|
|
478
501
|
let s = !1;
|
|
479
|
-
|
|
502
|
+
i.traverse((o) => {
|
|
480
503
|
!s && o instanceof a.Mesh && (o.material = t, s = !0);
|
|
481
504
|
});
|
|
482
505
|
}
|
|
483
|
-
return
|
|
506
|
+
return i;
|
|
484
507
|
}
|
|
485
508
|
}
|
|
486
509
|
/**
|
|
487
510
|
* 创建号牌canvas
|
|
488
511
|
* */
|
|
489
|
-
createCanvas(
|
|
490
|
-
const s = document.createElement("canvas"), o =
|
|
491
|
-
s.width = o, s.height =
|
|
512
|
+
createCanvas(e, i, t) {
|
|
513
|
+
const s = document.createElement("canvas"), o = e.width, l = e.height;
|
|
514
|
+
s.width = o, s.height = l;
|
|
492
515
|
const r = s.getContext("2d");
|
|
493
516
|
if (!r) {
|
|
494
517
|
console.log("canvas创建失败");
|
|
495
518
|
return;
|
|
496
519
|
}
|
|
497
|
-
return r.fillStyle = "rgba(0,0,0,0.0)", r.fillRect(0, 0, o,
|
|
520
|
+
return r.fillStyle = "rgba(0,0,0,0.0)", r.fillRect(0, 0, o, l), r.drawImage(e, 0, 0, o, l), r.beginPath(), r.translate(o / 2, l / 2), r.fillStyle = t, r.font = "bold 32px 宋体", r.textBaseline = "middle", r.textAlign = "center", r.fillText(i, 0, 0), s;
|
|
498
521
|
}
|
|
499
|
-
createPlateSprite(
|
|
500
|
-
return new Promise((
|
|
501
|
-
var h,
|
|
502
|
-
const s = !
|
|
522
|
+
createPlateSprite(e) {
|
|
523
|
+
return new Promise((i, t) => {
|
|
524
|
+
var h, n;
|
|
525
|
+
const s = !e.plateNo || e.plateNo === "0" || e.plateNo === "000000";
|
|
503
526
|
if (this.currentSpriteContent === m.None || this.currentSpriteContent === m.PlateNumber && s) {
|
|
504
|
-
|
|
527
|
+
i(void 0);
|
|
505
528
|
return;
|
|
506
529
|
}
|
|
507
|
-
let o = new Image(),
|
|
530
|
+
let o = new Image(), l = "", r = "";
|
|
508
531
|
if (this.currentSpriteContent === m.PlateNumber || this.currentSpriteContent === m.Mix)
|
|
509
532
|
if (s)
|
|
510
|
-
o = this.greyPlateBG,
|
|
533
|
+
o = this.greyPlateBG, l = e.ptcId, r = "#ffffff";
|
|
511
534
|
else
|
|
512
|
-
switch (
|
|
535
|
+
switch (l = ((h = e.showName) == null ? void 0 : h.substring(0, 2)) + "•" + ((n = e.showName) == null ? void 0 : n.substring(2)), e.plateColor) {
|
|
513
536
|
case 1:
|
|
514
537
|
o = this.bluePlateBG, r = "#ffffff";
|
|
515
538
|
break;
|
|
@@ -529,18 +552,18 @@ class V {
|
|
|
529
552
|
o = this.neoGreenPlateBG, r = "#000000";
|
|
530
553
|
break;
|
|
531
554
|
default:
|
|
532
|
-
o = this.greyPlateBG,
|
|
555
|
+
o = this.greyPlateBG, l = e.plateNo, r = "#ffffff";
|
|
533
556
|
break;
|
|
534
557
|
}
|
|
535
558
|
else
|
|
536
|
-
this.currentSpriteContent === m.Id && (o = this.greyPlateBG,
|
|
537
|
-
const d = this.createCanvas(o,
|
|
559
|
+
this.currentSpriteContent === m.Id && (o = this.greyPlateBG, l = e.ptcId, r = "#ffffff");
|
|
560
|
+
const d = this.createCanvas(o, l, r);
|
|
538
561
|
if (d) {
|
|
539
562
|
const p = new a.CanvasTexture(d), c = new a.SpriteMaterial({
|
|
540
563
|
map: p,
|
|
541
564
|
transparent: !1
|
|
542
|
-
}), g = new a.Sprite(c),
|
|
543
|
-
g.scale.set(
|
|
565
|
+
}), g = new a.Sprite(c), u = 0.05, P = d.width * u, v = d.height * u;
|
|
566
|
+
g.scale.set(P, v, 1), g.name = "VehiclePlate", i(g);
|
|
544
567
|
} else {
|
|
545
568
|
t("canvas创建失败");
|
|
546
569
|
return;
|
|
@@ -552,5 +575,5 @@ class V {
|
|
|
552
575
|
}
|
|
553
576
|
}
|
|
554
577
|
export {
|
|
555
|
-
|
|
578
|
+
N as default
|
|
556
579
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const
|
|
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 T=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 v=R(T);class V{constructor(e){this.nullDataCount=0,this.clearTraceTimer=null,e.type==="3d"?(this.traceRenderer=new b.default(e),v.add(e,this.traceRenderer)):this.traceRenderer=new y.default(e)}async init(){await this.traceRenderer.init()}downloadLog(){const e=this.traceRenderer.getLog().map(a=>a.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){this.clearTraceTimer||(this.clearTraceTimer=setInterval(()=>{this.nullDataCount++,this.nullDataCount>=5&&(console.log("clear trace data"),this.clearTrace(),this.nullDataCount=0)},1e3)),this.nullDataCount=0;const{newVehList:r,updateVehList:n,deleteVehList:c,jgsj:a}=e,o=e.crossId||"",s=[],h=[];if(r&&r.length>0){for(const l of r){l.localTimestamp||(l.localTimestamp=a||Date.now());const t=this.buildVehicleTrackData(l,o);t&&s.push(t)}await this.traceRenderer.addVehicles(s)}if(n&&n.length>0){for(const l of n){const t=this.buildVehicleTrackData(l,o);t&&h.push(t)}await this.traceRenderer.updateVehicles(h)}if(c&&c.length>0){const l=c.map(t=>o+"-"+(t.ptcId||t.vehno||t.vehNo));this.traceRenderer.deleteVehicles(l)}}toggleTrafficInfo(e){this.traceRenderer.toggleTrafficInfo(e)}clearTrace(){this.clearTraceTimer&&(clearInterval(this.clearTraceTimer),this.clearTraceTimer=null),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,a=e.ptcId,o=Number(e.ptcType),s=e.heading,h=Number(e.vehicleType),l=Number(e.vehicleColor),t=e.plateNo||e.plateno,d=Number(e.plateColor),u=e.timestamp,p=e.localTimestamp,g=e.roadLayer?String(e.roadLayer):"1",f=e.step,m=e.speed;if(!(o<0||o>8))return{ptcId:a,crossId:r,vehicleId:r+"-"+a,x:n,y:c,ptcType:o,vehicleType:h,heading:o===2?-s:s,vehicleColor:l,showName:t&&t!==""&&t!=="0"&&t!=="000000"?t:"",plateNo:t,plateColor:d,timestamp:u,localTimestamp:p,roadLayer:g,step:f,speed:m}}}exports.default=V;
|
|
@@ -37,7 +37,7 @@ export default class TraceRendererExternal implements ITraceRendererInterface {
|
|
|
37
37
|
private currentSpriteContent;
|
|
38
38
|
private historyPositionMap;
|
|
39
39
|
private vehicleObjectMap;
|
|
40
|
-
private
|
|
40
|
+
private tabVisible;
|
|
41
41
|
private updateModel;
|
|
42
42
|
private appDataStore;
|
|
43
43
|
/** 轨迹日志 */
|
|
@@ -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"),T=require("@arcgis/core/geometry/SpatialReference"),S=require("@arcgis/core/views/3d/externalRenderers"),C=require("three"),G=require("three/examples/jsm/loaders/GLTFLoader"),x=require("vue"),g=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),V=f(y),w=f(S),o=f(C);class I{constructor(i){this.cameraHeightThreshold=1e3,this.roughness=.2,this.metalness=.8,this.defaultMaterial=new o.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=g.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.view=i;const e=x.toRaw(this.appDataStore.mapConfig);this.assetsRoot=e.assetsRoot,V.watch(()=>this.view.camera.position.z,(t,s)=>{(s<=this.cameraHeightThreshold&&t>this.cameraHeightThreshold||s>this.cameraHeightThreshold&&t<=this.cameraHeightThreshold)&&(this.updateModel=!0)})}createCarMaterial(i){return new o.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=>{const s=t.scene,n=new o.Box3().setFromObject(s).getSize(new o.Vector3);this.carModel=new o.Object3D,this.carModel.rotation.x=o.MathUtils.degToRad(90),this.carModel.add(s),s.position.set(0,0,n.z/2),e()})}),new Promise(e=>{i.load(`${this.assetsRoot}/3DModels/van.glb`,t=>{const s=t.scene,n=new o.Box3().setFromObject(s).getSize(new o.Vector3);this.vanModel=new o.Object3D,this.vanModel.rotation.x=o.MathUtils.degToRad(90),this.vanModel.add(s),s.position.set(0,0,n.z/2),e()})}),new Promise(e=>{i.load(`${this.assetsRoot}/3DModels/truck.glb`,t=>{const s=t.scene;s.scale.set(1.2,1,1.5);const n=new o.Box3().setFromObject(s).getSize(new o.Vector3);this.truckModel=new o.Object3D,this.truckModel.rotation.x=o.MathUtils.degToRad(90),this.truckModel.add(s),s.position.set(0,0,n.z/2),e()})}),new Promise(e=>{i.load(`${this.assetsRoot}/3DModels/bus.glb`,t=>{const s=t.scene,n=new o.Box3().setFromObject(s).getSize(new o.Vector3);this.busModel=new o.Object3D,this.busModel.rotation.x=o.MathUtils.degToRad(90),this.busModel.add(s),s.position.set(0,0,n.z/2),e()})}),new Promise(e=>{i.load(`${this.assetsRoot}/3DModels/bicycle.glb`,t=>{this.bicycleModel=t.scene,this.bicycleModel.rotation.x=o.MathUtils.degToRad(90),this.bicycleModel.rotation.y=o.MathUtils.degToRad(180),e()})}),new Promise(e=>{i.load(`${this.assetsRoot}/3DModels/bicycle.glb`,t=>{this.passengerModel=t.scene,this.passengerModel.rotation.x=o.MathUtils.degToRad(90),this.passengerModel.rotation.y=o.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 o.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 o.Scene;const{camera:t}=i;this.camera=new o.PerspectiveCamera(t.fovY,t.aspect,.1,1e5),this.ambient=new o.AmbientLight(16777215,2),this.scene.add(this.ambient),this.sun=new o.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 o.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 r=this.computeVehiclePosition(a);if(r){const d=this.toRenderCoordinates(r);n.position.set(d[0],d[1],d[2]),n.rotation.y=o.MathUtils.degToRad(-r[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 o.Color(t.diffuse.color[0],t.diffuse.color[1],t.diffuse.color[2]),this.ambient.intensity=t.ambient.intensity,this.ambient.color=new o.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),w.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),r=Number(t.y),d=Number(t.heading);this.historyPositionMap.set(s,[{pos:[n,r,0],heading:d,time:a}]);const h=this.getVehicleModel(t);h.name=s,h.visible=!1;try{const l=await this.createPlateSprite(t);l&&(h.add(l),l.position.set(0,5,-4))}catch(l){console.log("createPlateSprite error:",l)}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,localTimestamp:n}=s,r=Number(s.x),d=Number(s.y);let h=Number(s.heading);const l=this.vehicleObjectMap.get(a),p=this.historyPositionMap.get(a);if(!l||!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||l.data.vehicleColor!==s.vehicleColor||l.data.vehicleType!==s.vehicleType){this.scene.remove(l.model),this.disposeModel(l.model),l.model=this.getVehicleModel(s),l.model.visible=!0;const c=await this.createPlateSprite(s);c&&(l.model.add(c),c.position.set(0,5,-4)),this.scene.add(l.model)}if(l.data.showName!==s.showName||l.data.plateColor!==s.plateColor){const c=l.model.getObjectByName("VehiclePlate");c&&(l.model.remove(c),this.disposeModel(c));const m=await this.createPlateSprite(s);m&&(l.model.add(m),m.position.set(0,5,-4))}if(l.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:[r,d,0],heading:h,time:n})}else{this.historyPositionMap.set(a,[{pos:[r,d,0],heading:h,time:n}]);const c=this.toRenderCoordinates([r,d,0]);l.model.position.set(c[0],c[1],c[2]),l.model.rotation.y=o.MathUtils.degToRad(-h)}}}await this.addVehicles(e),this.updateModel=!1,this.needInterpolate||this.render(this.context)}toRenderCoordinates(i){const e=[0,0,0];return w.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===g.EVehiclePlateState.None?await this.updatePanelContent(g.EVehiclePlateState.PlateNumber):await this.updatePanelContent(i.visible?this.currentSpriteContent:g.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!==g.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 o.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{t.segmentStartTime=Date.now();const r=a-t.segmentTotalTime;return t.segmentTotalTime=e[1].time-e[0].time-r,(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 r=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[r,d,0,h]}else return}getVehicleModel(i){if(this.view.camera.position.z>=this.cameraHeightThreshold){const e=new o.SphereGeometry(5,32,32),t=new o.MeshPhysicalMaterial({color:325253,emissive:0,roughness:this.roughness,metalness:this.metalness});return new o.Mesh(e,t)}else{let e;if(i.ptcType===2)e=this.bicycleModel.clone();else if(i.ptcType===3)e=this.passengerModel.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 o.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 r=s.getContext("2d");if(!r){console.log("canvas创建失败");return}return r.fillStyle="rgba(0,0,0,0.0)",r.fillRect(0,0,a,n),r.drawImage(i,0,0,a,n),r.beginPath(),r.translate(a/2,n/2),r.fillStyle=t,r.font="bold 32px 宋体",r.textBaseline="middle",r.textAlign="center",r.fillText(e,0,0),s}createPlateSprite(i){return new Promise((e,t)=>{var h,l;const s=!i.plateNo||i.plateNo==="0"||i.plateNo==="000000";if(this.currentSpriteContent===g.EVehiclePlateState.None||this.currentSpriteContent===g.EVehiclePlateState.PlateNumber&&s){e(void 0);return}let a=new Image,n="",r="";if(this.currentSpriteContent===g.EVehiclePlateState.PlateNumber||this.currentSpriteContent===g.EVehiclePlateState.Mix)if(s)a=this.greyPlateBG,n=i.ptcId,r="#ffffff";else switch(n=((h=i.showName)==null?void 0:h.substring(0,2))+"•"+((l=i.showName)==null?void 0:l.substring(2)),i.plateColor){case 1:a=this.bluePlateBG,r="#ffffff";break;case 2:a=this.yellowPlateBG,r="#000000";break;case 3:a=this.whitePlateBG,r="#000000";break;case 4:a=this.blackPlateBG,r="#ffffff";break;case 5:a=this.neoYellowPlateBG,r="#000000";break;case 6:a=this.neoGreenPlateBG,r="#000000";break;default:a=this.greyPlateBG,n=i.plateNo,r="#ffffff";break}else this.currentSpriteContent===g.EVehiclePlateState.Id&&(a=this.greyPlateBG,n=i.ptcId,r="#ffffff");const d=this.createCanvas(a,n,r);if(d){const p=new o.CanvasTexture(d),c=new o.SpriteMaterial({map:p,transparent:!1}),m=new o.Sprite(c),b=.05,M=d.width*b,P=d.height*b;m.scale.set(M,P,1),m.name="VehiclePlate",e(m)}else{t("canvas创建失败");return}a.onerror=p=>{console.log(`号牌背景加载失败: ${a.src}`,p),t(p)}})}}exports.default=I;
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const S=require("@arcgis/core/core/promiseUtils.js"),G=require("@arcgis/core/core/reactiveUtils.js"),C=require("@arcgis/core/geometry/SpatialReference"),L=require("@arcgis/core/views/3d/externalRenderers"),V=require("three"),f=require("three/examples/jsm/loaders/GLTFLoader"),M=require("three/examples/jsm/loaders/MTLLoader"),P=require("three/examples/jsm/loaders/OBJLoader"),B=require("vue"),m=require("../../../types/index.js"),R=require("../../stores/index.js");function b(u){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(u){for(const s in u)if(s!=="default"){const t=Object.getOwnPropertyDescriptor(u,s);Object.defineProperty(e,s,t.get?t:{enumerable:!0,get:()=>u[s]})}}return e.default=u,Object.freeze(e)}const x=b(S),I=b(G),v=b(L),o=b(V);class D{constructor(e){this.cameraHeightThreshold=1e3,this.roughness=.2,this.metalness=.8,this.defaultMaterial=new o.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.tabVisible=!0,this.updateModel=!1,this.appDataStore=R.default.useAppDataStore,this.logTable=[["ptcId","plateno","timestamp","localTimestamp","speed","longitude","latitude","ptcType","vehicleType","vehicleColor","plateColor","heading","fixAngle","roadLayer","step","receiveTimestamp","queueLength","status"]],this.view=e;const s=B.toRaw(this.appDataStore.mapConfig);this.assetsRoot=s.assetsRoot,document.addEventListener("visibilitychange",()=>{this.clearVehicles(),this.tabVisible=!document.hidden},!1),I.watch(()=>this.view.camera.position.z,(t,i)=>{(i<=this.cameraHeightThreshold&&t>this.cameraHeightThreshold||i>this.cameraHeightThreshold&&t<=this.cameraHeightThreshold)&&(this.updateModel=!0)})}createCarMaterial(e){return new o.MeshPhongMaterial({color:e})}getLog(){return this.logTable}async init(){await x.eachAlways([new Promise(e=>{new f.GLTFLoader().load(`${this.assetsRoot}/3DModels/car.glb`,t=>{const i=t.scene,l=new o.Box3().setFromObject(i).getSize(new o.Vector3);this.carModel=new o.Object3D,this.carModel.rotation.x=o.MathUtils.degToRad(90),this.carModel.add(i),i.position.set(0,0,l.z/2),e()})}),new Promise(e=>{new f.GLTFLoader().load(`${this.assetsRoot}/3DModels/van.glb`,t=>{const i=t.scene,l=new o.Box3().setFromObject(i).getSize(new o.Vector3);this.vanModel=new o.Object3D,this.vanModel.rotation.x=o.MathUtils.degToRad(90),this.vanModel.add(i),i.position.set(0,0,l.z/2),e()})}),new Promise(e=>{new f.GLTFLoader().load(`${this.assetsRoot}/3DModels/truck.glb`,t=>{const i=t.scene;i.scale.set(1.2,1,1.5);const l=new o.Box3().setFromObject(i).getSize(new o.Vector3);this.truckModel=new o.Object3D,this.truckModel.rotation.x=o.MathUtils.degToRad(90),this.truckModel.add(i),i.position.set(0,0,l.z/2),e()})}),new Promise(e=>{new f.GLTFLoader().load(`${this.assetsRoot}/3DModels/bus.glb`,t=>{const i=t.scene,l=new o.Box3().setFromObject(i).getSize(new o.Vector3);this.busModel=new o.Object3D,this.busModel.rotation.x=o.MathUtils.degToRad(90),this.busModel.add(i),i.position.set(0,0,l.z/2),e()})}),new Promise(e=>{new M.MTLLoader().load(`${this.assetsRoot}/3DModels/bicycle.mtl`,t=>{t.preload();const i=new P.OBJLoader;i.setMaterials(t),i.load(`${this.assetsRoot}/3DModels/bicycle.obj`,a=>{this.bicycleModel=a,this.bicycleModel.rotation.x=o.MathUtils.degToRad(90),e()})})}),new Promise(e=>{new M.MTLLoader().load(`${this.assetsRoot}/3DModels/passenger.mtl`,t=>{t.preload();const i=new P.OBJLoader;i.setMaterials(t),i.load(`${this.assetsRoot}/3DModels/male.obj`,a=>{a.scale.set(.01,.01,.01),this.passengerModel=a,this.passengerModel.rotation.x=o.MathUtils.degToRad(90),this.passengerModel.rotation.y=o.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(e){this.clearVehicles(),this.tabVisible=e}async setup(e){this.context=e,this.renderer=new o.WebGLRenderer({context:e.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 s=this.renderer.setRenderTarget.bind(this.renderer);this.renderer.setRenderTarget=i=>{s(i),i==null&&e.bindRenderTarget()},this.scene=new o.Scene;const{camera:t}=e;this.camera=new o.PerspectiveCamera(t.fovY,t.aspect,.1,1e5),this.ambient=new o.AmbientLight(16777215,2),this.scene.add(this.ambient),this.sun=new o.DirectionalLight(16777215,2),this.scene.add(this.sun),e.resetWebGLState()}async render(e){var i;const s=e.camera;if(this.camera.position.set(s.eye[0],s.eye[1],s.eye[2]),this.camera.up.set(s.up[0],s.up[1],s.up[2]),this.camera.lookAt(new o.Vector3(s.center[0],s.center[1],s.center[2])),this.camera.projectionMatrix.fromArray(s.projectionMatrix),!this.isPaused&&this.tabVisible)for(const a of this.vehicleObjectMap.keys()){const l=(i=this.vehicleObjectMap.get(a))==null?void 0:i.model;if(!l)continue;const r=this.computeVehiclePosition(a);if(r){const d=this.toRenderCoordinates(r);l.position.set(d[0],d[1],d[2]),l.rotation.y=o.MathUtils.degToRad(-r[3])}}const t=e.sunLight;this.sun.position.set(t.direction[0],t.direction[1],t.direction[2]),this.sun.intensity=t.diffuse.intensity,this.sun.color=new o.Color(t.diffuse.color[0],t.diffuse.color[1],t.diffuse.color[2]),this.ambient.intensity=t.ambient.intensity,this.ambient.color=new o.Color(t.ambient.color[0],t.ambient.color[1],t.ambient.color[2]),this.renderer.resetState(),e.bindRenderTarget(),this.renderer.render(this.scene,this.camera),v.requestRender(this.view),e.resetWebGLState()}async addVehicles(e){if(this.isPaused||!this.isInitialized||!this.tabVisible)return;const s=Date.now();for(const t of e){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,s,0,0]);const{vehicleId:i,localTimestamp:a}=t,l=Number(t.x),r=Number(t.y),d=Number(t.heading);this.historyPositionMap.set(i,[{pos:[l,r,0],heading:d,time:a}]);const h=this.getVehicleModel(t);h.name=i,h.visible=!1;try{const n=await this.createPlateSprite(t);n&&(h.add(n),n.position.set(0,5,-4))}catch(n){console.log("createPlateSprite error:",n)}this.scene.add(h),this.vehicleObjectMap.set(i,{model:h,data:t,waitForDelete:!1,isMoving:!1})}}async updateVehicles(e){if(this.isPaused||!this.isInitialized||!this.tabVisible)return;const s=[],t=Date.now();for(const i of e){const{vehicleId:a,localTimestamp:l}=i,r=Number(i.x),d=Number(i.y);let h=Number(i.heading);const n=this.vehicleObjectMap.get(a),p=this.historyPositionMap.get(a);if(!n||!p)s.push(i);else{if(this.appDataStore.saveTrackLog&&this.logTable.push([i.ptcId,i.plateNo,i.timestamp,i.localTimestamp,i.speed,i.x,i.y,i.ptcType,i.vehicleType,i.vehicleColor,i.plateColor,i.heading,i.fixAngle,i.roadLayer,i.step,t,p.length,1]),this.updateModel||n.data.vehicleColor!==i.vehicleColor||n.data.vehicleType!==i.vehicleType){this.scene.remove(n.model),this.disposeModel(n.model),n.model=this.getVehicleModel(i),n.model.visible=!0;const c=await this.createPlateSprite(i);c&&(n.model.add(c),c.position.set(0,5,-4)),this.scene.add(n.model)}if(n.data.showName!==i.showName||n.data.plateColor!==i.plateColor){const c=n.model.getObjectByName("VehiclePlate");c&&(n.model.remove(c),this.disposeModel(c));const g=await this.createPlateSprite(i);g&&(n.model.add(g),g.position.set(0,5,-4))}if(n.data=i,this.tabVisible){const c=p[p.length-1];Math.abs(h-c.heading)>=180&&(h>c.heading?c.heading+=360:h+=360),p.push({pos:[r,d,0],heading:h,time:l})}else{this.historyPositionMap.set(a,[{pos:[r,d,0],heading:h,time:l}]);const c=this.toRenderCoordinates([r,d,0]);n.model.position.set(c[0],c[1],c[2]),n.model.rotation.y=o.MathUtils.degToRad(-h)}}}await this.addVehicles(s),this.updateModel=!1}toRenderCoordinates(e){const s=[0,0,0];return v.toRenderCoordinates(this.view,e,0,C.WGS84,s,0,1),s}deleteVehicles(e){if(this.isPaused)return;const s=Date.now();e.forEach(t=>{if(this.appDataStore.saveTrackLog){const a=this.historyPositionMap.get(t);this.logTable.push([t,"","","","","","","","","","","","","","",s,a?a.length:0,2])}const i=this.vehicleObjectMap.get(t);i&&(this.tabVisible?i.isMoving?i.waitForDelete=!0:this.deleteVehicle(i):this.deleteVehicle(i))})}deleteVehicle(e){this.disposeModel(e.model),this.scene.remove(e.model);const s=e.data.vehicleId;this.vehicleObjectMap.delete(s),this.historyPositionMap.delete(s)}async toggleTrafficInfo(e){e.name==="vehiclePlate"&&(e.visible===!0&&this.currentSpriteContent===m.EVehiclePlateState.None?await this.updatePanelContent(m.EVehiclePlateState.PlateNumber):await this.updatePanelContent(e.visible?this.currentSpriteContent:m.EVehiclePlateState.None))}togglePause(e){this.isPaused=e}clearVehicles(){for(const e of this.vehicleObjectMap.values())this.disposeModel(e.model),this.scene.remove(e.model);this.vehicleObjectMap.clear(),this.historyPositionMap.clear()}async updatePanelContent(e){this.currentSpriteContent=e;for(const s of this.vehicleObjectMap.values()){const t=s.model.getObjectByName("VehiclePlate");if(t&&(s.model.remove(t),this.disposeModel(t)),e!==m.EVehiclePlateState.None){const i=await this.createPlateSprite(s.data);i&&(s.model.add(i),i.position.set(0,5,-4))}}}toggleGroundVehicle(e){this.showGroundVehicle=e}toggleElevatedVehicle(e){this.showElevatedVehicle=e}disposeModel(e){e.traverse(s=>{if(s instanceof o.Mesh){s.geometry.dispose();try{s.material.dispose()}catch{}}})}computeVehiclePosition(e){const s=this.historyPositionMap.get(e),t=this.vehicleObjectMap.get(e);if(!t||!s||!t.isMoving&&s.length<=2)return;const i=Date.now();t.isMoving=!0,t.data.roadLayer==="1"?t.model.visible=this.showGroundVehicle:t.model.visible=this.showElevatedVehicle,t.segmentStartTime||(t.segmentStartTime=i,t.segmentTotalTime=s[1].time-s[0].time);const a=i-t.segmentStartTime,l=Math.min(a/t.segmentTotalTime,1);if(l===1)if(s.shift(),s.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",e));return}else{t.segmentStartTime=Date.now();const r=a-t.segmentTotalTime;return t.segmentTotalTime=s[1].time-s[0].time-r,(s[1].heading>=270&&s[0].heading<=90||s[1].heading<=90&&s[0].heading>=270)&&(s[1].heading>s[0].heading?s[0].heading+=360:s[1].heading+=360),s[0].pos.concat(s[0].heading)}else if(s.length>=2){const r=s[0].pos[0]+(s[1].pos[0]-s[0].pos[0])*l,d=s[0].pos[1]+(s[1].pos[1]-s[0].pos[1])*l,h=s[0].heading+(s[1].heading-s[0].heading)*l;return[r,d,0,h]}else return}getVehicleModel(e){if(this.view.camera.position.z>=this.cameraHeightThreshold){const s=new o.SphereGeometry(5,32,32),t=new o.MeshPhysicalMaterial({color:325253,emissive:0,roughness:this.roughness,metalness:this.metalness});return new o.Mesh(s,t)}else{let s;if(e.ptcType===2)s=this.bicycleModel.clone();else if(e.ptcType===3)s=this.passengerModel.clone();else{switch(e.vehicleType){case 10:s=this.carModel.clone();break;case 20:s=this.vanModel.clone();break;case 25:s=this.truckModel.clone();break;case 50:s=this.busModel.clone();break;default:s=this.carModel.clone();break}const t=this.materialMap.get(e.vehicleColor)||this.defaultMaterial;let i=!1;s.traverse(a=>{!i&&a instanceof o.Mesh&&(a.material=t,i=!0)})}return s}}createCanvas(e,s,t){const i=document.createElement("canvas"),a=e.width,l=e.height;i.width=a,i.height=l;const r=i.getContext("2d");if(!r){console.log("canvas创建失败");return}return r.fillStyle="rgba(0,0,0,0.0)",r.fillRect(0,0,a,l),r.drawImage(e,0,0,a,l),r.beginPath(),r.translate(a/2,l/2),r.fillStyle=t,r.font="bold 32px 宋体",r.textBaseline="middle",r.textAlign="center",r.fillText(s,0,0),i}createPlateSprite(e){return new Promise((s,t)=>{var h,n;const i=!e.plateNo||e.plateNo==="0"||e.plateNo==="000000";if(this.currentSpriteContent===m.EVehiclePlateState.None||this.currentSpriteContent===m.EVehiclePlateState.PlateNumber&&i){s(void 0);return}let a=new Image,l="",r="";if(this.currentSpriteContent===m.EVehiclePlateState.PlateNumber||this.currentSpriteContent===m.EVehiclePlateState.Mix)if(i)a=this.greyPlateBG,l=e.ptcId,r="#ffffff";else switch(l=((h=e.showName)==null?void 0:h.substring(0,2))+"•"+((n=e.showName)==null?void 0:n.substring(2)),e.plateColor){case 1:a=this.bluePlateBG,r="#ffffff";break;case 2:a=this.yellowPlateBG,r="#000000";break;case 3:a=this.whitePlateBG,r="#000000";break;case 4:a=this.blackPlateBG,r="#ffffff";break;case 5:a=this.neoYellowPlateBG,r="#000000";break;case 6:a=this.neoGreenPlateBG,r="#000000";break;default:a=this.greyPlateBG,l=e.plateNo,r="#ffffff";break}else this.currentSpriteContent===m.EVehiclePlateState.Id&&(a=this.greyPlateBG,l=e.ptcId,r="#ffffff");const d=this.createCanvas(a,l,r);if(d){const p=new o.CanvasTexture(d),c=new o.SpriteMaterial({map:p,transparent:!1}),g=new o.Sprite(c),w=.05,y=d.width*w,T=d.height*w;g.scale.set(y,T,1),g.name="VehiclePlate",s(g)}else{t("canvas创建失败");return}a.onerror=p=>{console.log(`号牌背景加载失败: ${a.src}`,p),t(p)}})}}exports.default=D;
|