gisviewer-vue3-arcgis 1.0.178 → 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.
@@ -1,11 +1,11 @@
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";
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
4
  import * as b from "@arcgis/core/views/3d/externalRenderers";
5
5
  import * as a from "three";
6
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";
7
+ import { MTLLoader as C } from "three/examples/jsm/loaders/MTLLoader";
8
+ import { OBJLoader as w } from "three/examples/jsm/loaders/OBJLoader";
9
9
  import { toRaw as G } from "vue";
10
10
  import { EVehiclePlateState as m } from "../../../types/index.mjs";
11
11
  import S from "../../stores/index.mjs";
@@ -47,17 +47,17 @@ class N {
47
47
  "status"
48
48
  ]
49
49
  ], this.view = e;
50
- const i = G(this.appDataStore.mapConfig);
51
- this.assetsRoot = i.assetsRoot, document.addEventListener(
50
+ const s = G(this.appDataStore.mapConfig);
51
+ this.assetsRoot = s.assetsRoot, document.addEventListener(
52
52
  "visibilitychange",
53
53
  () => {
54
54
  this.clearVehicles(), this.tabVisible = !document.hidden;
55
55
  },
56
56
  !1
57
- ), T.watch(
57
+ ), y.watch(
58
58
  () => this.view.camera.position.z,
59
- (t, s) => {
60
- (s <= this.cameraHeightThreshold && t > this.cameraHeightThreshold || s > this.cameraHeightThreshold && t <= this.cameraHeightThreshold) && (this.updateModel = !0);
59
+ (t, i) => {
60
+ (i <= this.cameraHeightThreshold && t > this.cameraHeightThreshold || i > this.cameraHeightThreshold && t <= this.cameraHeightThreshold) && (this.updateModel = !0);
61
61
  }
62
62
  );
63
63
  }
@@ -74,40 +74,40 @@ class N {
74
74
  return this.logTable;
75
75
  }
76
76
  async init() {
77
- await y.eachAlways([
77
+ await v.eachAlways([
78
78
  new Promise((e) => {
79
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();
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();
82
82
  });
83
83
  }),
84
84
  new Promise((e) => {
85
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();
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();
88
88
  });
89
89
  }),
90
90
  new Promise((e) => {
91
91
  new f().load(`${this.assetsRoot}/3DModels/truck.glb`, (t) => {
92
- const s = t.scene;
93
- s.scale.set(1.2, 1, 1.5);
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();
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();
96
96
  });
97
97
  }),
98
98
  new Promise((e) => {
99
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();
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();
102
102
  });
103
103
  }),
104
104
  new Promise((e) => {
105
- new w().load(
105
+ new C().load(
106
106
  `${this.assetsRoot}/3DModels/bicycle.mtl`,
107
107
  (t) => {
108
108
  t.preload();
109
- const s = new M();
110
- s.setMaterials(t), s.load(
109
+ const i = new w();
110
+ i.setMaterials(t), i.load(
111
111
  `${this.assetsRoot}/3DModels/bicycle.obj`,
112
112
  (o) => {
113
113
  this.bicycleModel = o, this.bicycleModel.rotation.x = a.MathUtils.degToRad(90), e();
@@ -117,16 +117,9 @@ class N {
117
117
  );
118
118
  }),
119
119
  new Promise((e) => {
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
- );
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();
122
+ });
130
123
  }),
131
124
  new Promise((e) => {
132
125
  this.bluePlateBG = new Image(), this.bluePlateBG.src = `${this.assetsRoot}/Images/PlateBG/blue.png`, this.bluePlateBG.onload = () => {
@@ -176,11 +169,11 @@ class N {
176
169
  antialias: !0,
177
170
  powerPreference: "high-performance"
178
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;
179
- const i = this.renderer.setRenderTarget.bind(
172
+ const s = this.renderer.setRenderTarget.bind(
180
173
  this.renderer
181
174
  );
182
- this.renderer.setRenderTarget = (s) => {
183
- i(s), s == null && e.bindRenderTarget();
175
+ this.renderer.setRenderTarget = (i) => {
176
+ s(i), i == null && e.bindRenderTarget();
184
177
  }, this.scene = new a.Scene();
185
178
  const { camera: t } = e;
186
179
  this.camera = new a.PerspectiveCamera(
@@ -191,13 +184,13 @@ class N {
191
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();
192
185
  }
193
186
  async render(e) {
194
- var s;
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)
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)
199
192
  for (const o of this.vehicleObjectMap.keys()) {
200
- const l = (s = this.vehicleObjectMap.get(o)) == null ? void 0 : s.model;
193
+ const l = (i = this.vehicleObjectMap.get(o)) == null ? void 0 : i.model;
201
194
  if (!l)
202
195
  continue;
203
196
  const r = this.computeVehiclePosition(o);
@@ -223,7 +216,7 @@ class N {
223
216
  async addVehicles(e) {
224
217
  if (this.isPaused || !this.isInitialized || !this.tabVisible)
225
218
  return;
226
- const i = Date.now();
219
+ const s = Date.now();
227
220
  for (const t of e) {
228
221
  this.appDataStore.saveTrackLog && this.logTable.push([
229
222
  t.ptcId,
@@ -241,23 +234,23 @@ class N {
241
234
  t.fixAngle,
242
235
  t.roadLayer,
243
236
  t.step,
244
- i,
237
+ s,
245
238
  0,
246
239
  0
247
240
  ]);
248
- const { vehicleId: s, localTimestamp: o } = t, l = Number(t.x), r = Number(t.y), d = Number(t.heading);
249
- this.historyPositionMap.set(s, [
241
+ const { vehicleId: i, localTimestamp: o } = t, l = Number(t.x), r = Number(t.y), d = Number(t.heading);
242
+ this.historyPositionMap.set(i, [
250
243
  { pos: [l, r, 0], heading: d, time: o }
251
244
  ]);
252
245
  const h = this.getVehicleModel(t);
253
- h.name = s, h.visible = !1;
246
+ h.name = i, h.visible = !1;
254
247
  try {
255
248
  const n = await this.createPlateSprite(t);
256
249
  n && (h.add(n), n.position.set(0, 5, -4));
257
250
  } catch (n) {
258
251
  console.log("createPlateSprite error:", n);
259
252
  }
260
- this.scene.add(h), this.vehicleObjectMap.set(s, {
253
+ this.scene.add(h), this.vehicleObjectMap.set(i, {
261
254
  model: h,
262
255
  data: t,
263
256
  waitForDelete: !1,
@@ -271,47 +264,47 @@ class N {
271
264
  async updateVehicles(e) {
272
265
  if (this.isPaused || !this.isInitialized || !this.tabVisible)
273
266
  return;
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);
277
- let h = Number(s.heading);
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);
278
271
  const n = this.vehicleObjectMap.get(o), p = this.historyPositionMap.get(
279
272
  o
280
273
  );
281
274
  if (!n || !p)
282
- i.push(s);
275
+ s.push(i);
283
276
  else {
284
277
  if (this.appDataStore.saveTrackLog && this.logTable.push([
285
- s.ptcId,
286
- s.plateNo,
287
- s.timestamp,
288
- s.localTimestamp,
289
- s.speed,
290
- s.x,
291
- s.y,
292
- s.ptcType,
293
- s.vehicleType,
294
- s.vehicleColor,
295
- s.plateColor,
296
- s.heading,
297
- s.fixAngle,
298
- s.roadLayer,
299
- s.step,
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,
300
293
  t,
301
294
  p.length,
302
295
  1
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;
305
- const c = await this.createPlateSprite(s);
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);
306
299
  c && (n.model.add(c), c.position.set(0, 5, -4)), this.scene.add(n.model);
307
300
  }
308
- if (n.data.showName !== s.showName || n.data.plateColor !== s.plateColor) {
301
+ if (n.data.showName !== i.showName || n.data.plateColor !== i.plateColor) {
309
302
  const c = n.model.getObjectByName("VehiclePlate");
310
303
  c && (n.model.remove(c), this.disposeModel(c));
311
- const g = await this.createPlateSprite(s);
304
+ const g = await this.createPlateSprite(i);
312
305
  g && (n.model.add(g), g.position.set(0, 5, -4));
313
306
  }
314
- if (n.data = s, this.tabVisible) {
307
+ if (n.data = i, this.tabVisible) {
315
308
  const c = p[p.length - 1];
316
309
  Math.abs(h - c.heading) >= 180 && (h > c.heading ? c.heading += 360 : h += 360), p.push({
317
310
  pos: [r, d, 0],
@@ -327,20 +320,20 @@ class N {
327
320
  }
328
321
  }
329
322
  }
330
- await this.addVehicles(i), this.updateModel = !1;
323
+ await this.addVehicles(s), this.updateModel = !1;
331
324
  }
332
325
  toRenderCoordinates(e) {
333
- const i = [0, 0, 0];
326
+ const s = [0, 0, 0];
334
327
  return b.toRenderCoordinates(
335
328
  // @ts-ignore
336
329
  this.view,
337
330
  e,
338
331
  0,
339
- C.WGS84,
340
- i,
332
+ T.WGS84,
333
+ s,
341
334
  0,
342
335
  1
343
- ), i;
336
+ ), s;
344
337
  }
345
338
  /**
346
339
  * 删除车辆
@@ -348,7 +341,7 @@ class N {
348
341
  deleteVehicles(e) {
349
342
  if (this.isPaused)
350
343
  return;
351
- const i = Date.now();
344
+ const s = Date.now();
352
345
  e.forEach((t) => {
353
346
  if (this.appDataStore.saveTrackLog) {
354
347
  const o = this.historyPositionMap.get(t);
@@ -368,19 +361,19 @@ class N {
368
361
  "",
369
362
  "",
370
363
  "",
371
- i,
364
+ s,
372
365
  o ? o.length : 0,
373
366
  2
374
367
  ]);
375
368
  }
376
- const s = this.vehicleObjectMap.get(t);
377
- s && (this.tabVisible ? s.isMoving ? s.waitForDelete = !0 : this.deleteVehicle(s) : this.deleteVehicle(s));
369
+ const i = this.vehicleObjectMap.get(t);
370
+ i && (this.tabVisible ? i.isMoving ? i.waitForDelete = !0 : this.deleteVehicle(i) : this.deleteVehicle(i));
378
371
  });
379
372
  }
380
373
  deleteVehicle(e) {
381
374
  this.disposeModel(e.model), this.scene.remove(e.model);
382
- const i = e.data.vehicleId;
383
- this.vehicleObjectMap.delete(i), this.historyPositionMap.delete(i);
375
+ const s = e.data.vehicleId;
376
+ this.vehicleObjectMap.delete(s), this.historyPositionMap.delete(s);
384
377
  }
385
378
  async toggleTrafficInfo(e) {
386
379
  e.name === "vehiclePlate" && (e.visible === !0 && this.currentSpriteContent === m.None ? await this.updatePanelContent(m.PlateNumber) : await this.updatePanelContent(
@@ -405,11 +398,11 @@ class N {
405
398
  */
406
399
  async updatePanelContent(e) {
407
400
  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));
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));
413
406
  }
414
407
  }
415
408
  }
@@ -423,11 +416,11 @@ class N {
423
416
  * 释放模型资源
424
417
  * */
425
418
  disposeModel(e) {
426
- e.traverse((i) => {
427
- if (i instanceof a.Mesh) {
428
- i.geometry.dispose();
419
+ e.traverse((s) => {
420
+ if (s instanceof a.Mesh) {
421
+ s.geometry.dispose();
429
422
  try {
430
- i.material.dispose();
423
+ s.material.dispose();
431
424
  } catch {
432
425
  }
433
426
  }
@@ -437,26 +430,26 @@ class N {
437
430
  * 计算车辆位置
438
431
  * */
439
432
  computeVehiclePosition(e) {
440
- const i = this.historyPositionMap.get(e), t = this.vehicleObjectMap.get(e);
441
- if (!t || !i || !t.isMoving && i.length <= 2)
433
+ const s = this.historyPositionMap.get(e), t = this.vehicleObjectMap.get(e);
434
+ if (!t || !s || !t.isMoving && s.length <= 2)
442
435
  return;
443
- const s = Date.now();
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(
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(
446
439
  o / t.segmentTotalTime,
447
440
  1
448
441
  );
449
442
  if (l === 1)
450
- if (i.shift(), i.length === 1) {
443
+ if (s.shift(), s.length === 1) {
451
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));
452
445
  return;
453
446
  } else {
454
447
  t.segmentStartTime = Date.now();
455
448
  const r = o - 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);
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);
457
450
  }
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;
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;
460
453
  return [r, d, 0, h];
461
454
  } else
462
455
  return;
@@ -466,70 +459,70 @@ class N {
466
459
  * */
467
460
  getVehicleModel(e) {
468
461
  if (this.view.camera.position.z >= this.cameraHeightThreshold) {
469
- const i = new a.SphereGeometry(5, 32, 32), t = new a.MeshPhysicalMaterial({
462
+ const s = new a.SphereGeometry(5, 32, 32), t = new a.MeshPhysicalMaterial({
470
463
  color: 325253,
471
464
  emissive: 0,
472
465
  roughness: this.roughness,
473
466
  metalness: this.metalness
474
467
  });
475
- return new a.Mesh(i, t);
468
+ return new a.Mesh(s, t);
476
469
  } else {
477
- let i;
470
+ let s;
478
471
  if (e.ptcType === 2)
479
- i = this.bicycleModel.clone();
472
+ s = this.bicycleModel.clone();
480
473
  else if (e.ptcType === 3)
481
- i = this.passengerModel.clone();
474
+ s = this.passengerModel.clone();
482
475
  else {
483
476
  switch (e.vehicleType) {
484
477
  case 10:
485
- i = this.carModel.clone();
478
+ s = this.carModel.clone();
486
479
  break;
487
480
  case 20:
488
- i = this.vanModel.clone();
481
+ s = this.vanModel.clone();
489
482
  break;
490
483
  case 25:
491
- i = this.truckModel.clone();
484
+ s = this.truckModel.clone();
492
485
  break;
493
486
  case 50:
494
- i = this.busModel.clone();
487
+ s = this.busModel.clone();
495
488
  break;
496
489
  default:
497
- i = this.carModel.clone();
490
+ s = this.carModel.clone();
498
491
  break;
499
492
  }
500
493
  const t = this.materialMap.get(e.vehicleColor) || this.defaultMaterial;
501
- let s = !1;
502
- i.traverse((o) => {
503
- !s && o instanceof a.Mesh && (o.material = t, s = !0);
494
+ let i = !1;
495
+ s.traverse((o) => {
496
+ !i && o instanceof a.Mesh && (o.material = t, i = !0);
504
497
  });
505
498
  }
506
- return i;
499
+ return s;
507
500
  }
508
501
  }
509
502
  /**
510
503
  * 创建号牌canvas
511
504
  * */
512
- createCanvas(e, i, t) {
513
- const s = document.createElement("canvas"), o = e.width, l = e.height;
514
- s.width = o, s.height = l;
515
- const r = s.getContext("2d");
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");
516
509
  if (!r) {
517
510
  console.log("canvas创建失败");
518
511
  return;
519
512
  }
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;
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;
521
514
  }
522
515
  createPlateSprite(e) {
523
- return new Promise((i, t) => {
516
+ return new Promise((s, t) => {
524
517
  var h, n;
525
- const s = !e.plateNo || e.plateNo === "0" || e.plateNo === "000000";
526
- if (this.currentSpriteContent === m.None || this.currentSpriteContent === m.PlateNumber && s) {
527
- i(void 0);
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);
528
521
  return;
529
522
  }
530
523
  let o = new Image(), l = "", r = "";
531
524
  if (this.currentSpriteContent === m.PlateNumber || this.currentSpriteContent === m.Mix)
532
- if (s)
525
+ if (i)
533
526
  o = this.greyPlateBG, l = e.ptcId, r = "#ffffff";
534
527
  else
535
528
  switch (l = ((h = e.showName) == null ? void 0 : h.substring(0, 2)) + "•" + ((n = e.showName) == null ? void 0 : n.substring(2)), e.plateColor) {
@@ -562,8 +555,8 @@ class N {
562
555
  const p = new a.CanvasTexture(d), c = new a.SpriteMaterial({
563
556
  map: p,
564
557
  transparent: !1
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);
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);
567
560
  } else {
568
561
  t("canvas创建失败");
569
562
  return;
@@ -1 +1 @@
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;
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gisviewer-vue3-arcgis",
3
- "version": "1.0.178",
3
+ "version": "1.0.179",
4
4
  "main": "lib/index.js",
5
5
  "module": "es/index.mjs",
6
6
  "files": [