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