gisviewer-vue3-arcgis 1.0.112 → 1.0.113

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,16 +1,17 @@
1
- import * as v from "@arcgis/core/core/promiseUtils.js";
1
+ import * as w from "@arcgis/core/core/promiseUtils.js";
2
2
  import * as b from "@arcgis/core/core/reactiveUtils.js";
3
- import M from "@arcgis/core/geometry/SpatialReference";
3
+ import v from "@arcgis/core/geometry/SpatialReference";
4
4
  import * as u from "@arcgis/core/views/3d/externalRenderers";
5
- import * as c from "three";
5
+ import * as l from "three";
6
+ import { GLTFLoader as y } from "three/examples/jsm/loaders/GLTFLoader";
6
7
  import { EVehiclePlateState as d } from "../../../types/index.mjs";
7
- import y from "../../stores/index.mjs";
8
- import G from "./vehicle-pool.mjs";
9
- class R {
10
- constructor(e) {
11
- this.cameraHeightThreshold = 1e3, this.roughness = 0.2, this.metalness = 0.8, this.defaultMaterial = new c.MeshPhongMaterial({
8
+ import G from "../../stores/index.mjs";
9
+ import C from "./vehicle-pool.mjs";
10
+ class N {
11
+ constructor(i) {
12
+ this.cameraHeightThreshold = 1e3, this.roughness = 0.2, this.metalness = 0.8, this.defaultMaterial = new l.MeshPhongMaterial({
12
13
  color: 16777215
13
- }), this.vehiclePool = new G(), this.materialMap = /* @__PURE__ */ new Map([
14
+ }), this.vehiclePool = new C(), this.materialMap = /* @__PURE__ */ new Map([
14
15
  [1, this.createCarMaterial(16777215)],
15
16
  [2, this.createCarMaterial(7833753)],
16
17
  [3, this.createCarMaterial(16766720)],
@@ -23,69 +24,52 @@ class R {
23
24
  [10, this.createCarMaterial(9662683)],
24
25
  [99, this.createCarMaterial(6908265)]
25
26
  ]), this.isInitialized = !1, this.showGroundVehicle = !0, this.showElevatedVehicle = !0, this.isPaused = !1, this.currentSpriteContent = d.None, this.historyPositionMap = /* @__PURE__ */ new Map(), this.vehicleObjectMap = /* @__PURE__ */ new Map(), this.needInterpolate = !0, this.updateModel = !1;
26
- const t = y.useAppDataStore;
27
+ const e = G.useAppDataStore;
27
28
  this.assetsRoot = JSON.parse(
28
- JSON.stringify(t.mapConfig)
29
- ).assetsRoot, this.view = e, b.watch(
29
+ JSON.stringify(e.mapConfig)
30
+ ).assetsRoot, this.view = i, b.watch(
30
31
  () => this.view.camera.position.z,
31
- (i, o) => {
32
- (o <= this.cameraHeightThreshold && i > this.cameraHeightThreshold || o > this.cameraHeightThreshold && i <= this.cameraHeightThreshold) && (this.updateModel = !0);
32
+ (t, o) => {
33
+ (o <= this.cameraHeightThreshold && t > this.cameraHeightThreshold || o > this.cameraHeightThreshold && t <= this.cameraHeightThreshold) && (this.updateModel = !0);
33
34
  }
34
35
  );
35
36
  }
36
- createCarMaterial(e) {
37
- return new c.MeshPhongMaterial({
38
- color: e
37
+ createCarMaterial(i) {
38
+ return new l.MeshPhongMaterial({
39
+ color: i
39
40
  // // emissive: 0xc3c3c3,
40
41
  // roughness: this.roughness,
41
42
  // metalness: this.metalness
42
43
  });
43
44
  }
44
45
  async init() {
45
- await this.vehiclePool.initPool(this.assetsRoot, this.view), await v.eachAlways([
46
- // new Promise<void>((resolve) => {
47
- // gltfLoader.load(`${this.assetsRoot}/3DModels/car.glb`, (gltf) => {
48
- // this.carModel = gltf.scene;
49
- // // this.carModel.scale.set(10, 10, 10);
50
- // // 调整模型初始角度
51
- // this.carModel.rotation.x = Three.MathUtils.degToRad(90);
52
- // resolve();
53
- // });
54
- // }),
55
- // new Promise<void>((resolve) => {
56
- // gltfLoader.load(`${this.assetsRoot}/3DModels/van.glb`, (gltf) => {
57
- // this.vanModel = gltf.scene;
58
- // // 调整模型初始角度
59
- // this.vanModel.rotation.x = Three.MathUtils.degToRad(90);
60
- // resolve();
61
- // });
62
- // }),
63
- // new Promise<void>((resolve) => {
64
- // gltfLoader.load(`${this.assetsRoot}/3DModels/truck.glb`, (gltf) => {
65
- // this.truckModel = gltf.scene;
66
- // this.truckModel.scale.set(1.2, 1, 1.5);
67
- // // 调整模型初始角度
68
- // this.truckModel.rotation.x = Three.MathUtils.degToRad(90);
69
- // resolve();
70
- // });
71
- // }),
72
- // new Promise<void>((resolve) => {
73
- // gltfLoader.load(`${this.assetsRoot}/3DModels/bus.glb`, (gltf) => {
74
- // this.busModel = gltf.scene;
75
- // // 调整模型初始角度
76
- // this.busModel.rotation.x = Three.MathUtils.degToRad(90);
77
- // resolve();
78
- // });
79
- // }),
80
- // new Promise<void>((resolve) => {
81
- // gltfLoader.load(`${this.assetsRoot}/3DModels/bicycle.glb`, (gltf) => {
82
- // this.bicycleModel = gltf.scene;
83
- // // 调整模型初始角度
84
- // this.bicycleModel.rotation.x = Three.MathUtils.degToRad(90);
85
- // this.bicycleModel.rotation.y = Three.MathUtils.degToRad(180);
86
- // resolve();
87
- // });
88
- // }),
46
+ const i = new y();
47
+ await w.eachAlways([
48
+ new Promise((e) => {
49
+ i.load(`${this.assetsRoot}/3DModels/car.glb`, (t) => {
50
+ this.carModel = t.scene, this.carModel.rotation.x = l.MathUtils.degToRad(90), e();
51
+ });
52
+ }),
53
+ new Promise((e) => {
54
+ i.load(`${this.assetsRoot}/3DModels/van.glb`, (t) => {
55
+ this.vanModel = t.scene, this.vanModel.rotation.x = l.MathUtils.degToRad(90), e();
56
+ });
57
+ }),
58
+ new Promise((e) => {
59
+ i.load(`${this.assetsRoot}/3DModels/truck.glb`, (t) => {
60
+ this.truckModel = t.scene, this.truckModel.scale.set(1.2, 1, 1.5), this.truckModel.rotation.x = l.MathUtils.degToRad(90), e();
61
+ });
62
+ }),
63
+ new Promise((e) => {
64
+ i.load(`${this.assetsRoot}/3DModels/bus.glb`, (t) => {
65
+ this.busModel = t.scene, this.busModel.rotation.x = l.MathUtils.degToRad(90), e();
66
+ });
67
+ }),
68
+ new Promise((e) => {
69
+ i.load(`${this.assetsRoot}/3DModels/bicycle.glb`, (t) => {
70
+ this.bicycleModel = t.scene, this.bicycleModel.rotation.x = l.MathUtils.degToRad(90), this.bicycleModel.rotation.y = l.MathUtils.degToRad(180), e();
71
+ });
72
+ }),
89
73
  new Promise((e) => {
90
74
  this.bluePlateBG = new Image(), this.bluePlateBG.src = `${this.assetsRoot}/Images/PlateBG/blue.png`, this.bluePlateBG.onload = () => {
91
75
  e();
@@ -123,79 +107,79 @@ class R {
123
107
  })
124
108
  ]), this.isInitialized = !0;
125
109
  }
126
- setInterpolate(e) {
127
- this.clearVehicles(), this.needInterpolate = e;
110
+ setInterpolate(i) {
111
+ this.clearVehicles(), this.needInterpolate = i;
128
112
  }
129
- async setup(e) {
130
- this.context = e, this.renderer = new c.WebGLRenderer({
131
- context: e.gl,
113
+ async setup(i) {
114
+ this.context = i, this.renderer = new l.WebGLRenderer({
115
+ context: i.gl,
132
116
  premultipliedAlpha: !0,
133
117
  logarithmicDepthBuffer: !0,
134
118
  antialias: !0,
135
119
  powerPreference: "high-performance"
136
120
  }), 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;
137
- const t = this.renderer.setRenderTarget.bind(
121
+ const e = this.renderer.setRenderTarget.bind(
138
122
  this.renderer
139
123
  );
140
124
  this.renderer.setRenderTarget = (o) => {
141
- t(o), o == null && e.bindRenderTarget();
142
- }, this.scene = new c.Scene();
143
- const { camera: i } = e;
144
- this.camera = new c.PerspectiveCamera(
145
- i.fovY,
146
- i.aspect,
125
+ e(o), o == null && i.bindRenderTarget();
126
+ }, this.scene = new l.Scene();
127
+ const { camera: t } = i;
128
+ this.camera = new l.PerspectiveCamera(
129
+ t.fovY,
130
+ t.aspect,
147
131
  0.1,
148
132
  1e5
149
- ), this.ambient = new c.AmbientLight(16777215, 2), this.scene.add(this.ambient), this.sun = new c.DirectionalLight(16777215, 2), this.scene.add(this.sun), e.resetWebGLState();
133
+ ), this.ambient = new l.AmbientLight(16777215, 2), this.scene.add(this.ambient), this.sun = new l.DirectionalLight(16777215, 2), this.scene.add(this.sun), i.resetWebGLState();
150
134
  }
151
- async render(e) {
135
+ async render(i) {
152
136
  var o;
153
- const t = e.camera;
154
- if (this.camera.position.set(t.eye[0], t.eye[1], t.eye[2]), this.camera.up.set(t.up[0], t.up[1], t.up[2]), this.camera.lookAt(
155
- new c.Vector3(t.center[0], t.center[1], t.center[2])
156
- ), this.camera.projectionMatrix.fromArray(t.projectionMatrix), !this.isPaused && this.needInterpolate)
157
- for (const a of this.vehicleObjectMap.keys()) {
158
- const n = (o = this.vehicleObjectMap.get(a)) == null ? void 0 : o.model;
137
+ const e = i.camera;
138
+ if (this.camera.position.set(e.eye[0], e.eye[1], e.eye[2]), this.camera.up.set(e.up[0], e.up[1], e.up[2]), this.camera.lookAt(
139
+ new l.Vector3(e.center[0], e.center[1], e.center[2])
140
+ ), this.camera.projectionMatrix.fromArray(e.projectionMatrix), !this.isPaused && this.needInterpolate)
141
+ for (const s of this.vehicleObjectMap.keys()) {
142
+ const n = (o = this.vehicleObjectMap.get(s)) == null ? void 0 : o.model;
159
143
  if (!n)
160
144
  continue;
161
- const s = this.computeVehiclePosition(a);
162
- if (s) {
163
- const l = this.toRenderCoordinates(s);
164
- n.position.set(l[0], l[1], l[2]), n.rotation.y = c.MathUtils.degToRad(-s[3]);
145
+ const a = this.computeVehiclePosition(s);
146
+ if (a) {
147
+ const h = this.toRenderCoordinates(a);
148
+ n.position.set(h[0], h[1], h[2]), n.rotation.y = l.MathUtils.degToRad(-a[3]);
165
149
  }
166
150
  }
167
- const i = e.sunLight;
168
- this.sun.position.set(i.direction[0], i.direction[1], i.direction[2]), this.sun.intensity = i.diffuse.intensity, this.sun.color = new c.Color(
169
- i.diffuse.color[0],
170
- i.diffuse.color[1],
171
- i.diffuse.color[2]
172
- ), this.ambient.intensity = i.ambient.intensity, this.ambient.color = new c.Color(
173
- i.ambient.color[0],
174
- i.ambient.color[1],
175
- i.ambient.color[2]
176
- ), this.renderer.resetState(), e.bindRenderTarget(), this.renderer.render(this.scene, this.camera), u.requestRender(this.view), e.resetWebGLState();
151
+ const t = i.sunLight;
152
+ this.sun.position.set(t.direction[0], t.direction[1], t.direction[2]), this.sun.intensity = t.diffuse.intensity, this.sun.color = new l.Color(
153
+ t.diffuse.color[0],
154
+ t.diffuse.color[1],
155
+ t.diffuse.color[2]
156
+ ), this.ambient.intensity = t.ambient.intensity, this.ambient.color = new l.Color(
157
+ t.ambient.color[0],
158
+ t.ambient.color[1],
159
+ t.ambient.color[2]
160
+ ), this.renderer.resetState(), i.bindRenderTarget(), this.renderer.render(this.scene, this.camera), u.requestRender(this.view), i.resetWebGLState();
177
161
  }
178
162
  /**
179
163
  * 新增车辆
180
164
  * */
181
- async addVehicles(e) {
165
+ async addVehicles(i) {
182
166
  if (!(this.isPaused || !this.isInitialized))
183
- for (const t of e) {
184
- const { vehicleId: i, localTimestamp: o } = t, a = Number(t.x), n = Number(t.y), s = Number(t.heading);
185
- this.historyPositionMap.set(i, [
186
- { pos: [a, n, 0], heading: s, time: o }
167
+ for (const e of i) {
168
+ const { vehicleId: t, localTimestamp: o } = e, s = Number(e.x), n = Number(e.y), a = Number(e.heading);
169
+ this.historyPositionMap.set(t, [
170
+ { pos: [s, n, 0], heading: a, time: o }
187
171
  ]);
188
- const l = this.getVehicleModel(t);
189
- l.name = i, l.visible = !1;
172
+ const h = this.getVehicleModel(e);
173
+ h.name = t, h.visible = !1;
190
174
  try {
191
- const r = await this.createPlateSprite(t);
192
- r && (l.add(r), r.position.set(0, 5, -4));
175
+ const r = await this.createPlateSprite(e);
176
+ r && (h.add(r), r.position.set(0, 5, -4));
193
177
  } catch (r) {
194
178
  console.log("createPlateSprite error:", r);
195
179
  }
196
- this.scene.add(l), this.vehicleObjectMap.set(i, {
197
- model: l,
198
- data: t,
180
+ this.scene.add(h), this.vehicleObjectMap.set(t, {
181
+ model: h,
182
+ data: e,
199
183
  waitForDelete: !1,
200
184
  isMoving: !1
201
185
  });
@@ -204,90 +188,90 @@ class R {
204
188
  /**
205
189
  * 更新车辆
206
190
  * */
207
- async updateVehicles(e) {
191
+ async updateVehicles(i) {
208
192
  if (this.isPaused || !this.isInitialized)
209
193
  return;
210
- const t = [];
211
- for (const i of e) {
212
- const { vehicleId: o, timestamp: a } = i, n = Number(i.x), s = Number(i.y);
213
- let l = Number(i.heading);
214
- const r = this.vehicleObjectMap.get(o), p = this.historyPositionMap.get(
194
+ const e = [];
195
+ for (const t of i) {
196
+ const { vehicleId: o, timestamp: s } = t, n = Number(t.x), a = Number(t.y);
197
+ let h = Number(t.heading);
198
+ const r = this.vehicleObjectMap.get(o), m = this.historyPositionMap.get(
215
199
  o
216
200
  );
217
- if (!r || !p)
218
- t.push(i);
201
+ if (!r || !m)
202
+ e.push(t);
219
203
  else {
220
- if (this.updateModel || r.data.vehicleColor !== i.vehicleColor || r.data.vehicleType !== i.vehicleType) {
221
- this.vehiclePool.recycleInstance(r.model), r.model = this.getVehicleModel(i), r.model.visible = !0;
222
- const h = await this.createPlateSprite(i);
223
- h && (r.model.add(h), h.position.set(0, 5, -4)), this.scene.add(r.model);
204
+ if (this.updateModel || r.data.vehicleColor !== t.vehicleColor || r.data.vehicleType !== t.vehicleType) {
205
+ this.vehiclePool.recycleInstance(r.model), r.model = this.getVehicleModel(t), r.model.visible = !0;
206
+ const c = await this.createPlateSprite(t);
207
+ c && (r.model.add(c), c.position.set(0, 5, -4)), this.scene.add(r.model);
224
208
  }
225
- if (r.data.showName !== i.showName || r.data.plateColor !== i.plateColor) {
226
- const h = r.model.getObjectByName("VehiclePlate");
227
- h && (r.model.remove(h), this.disposeModel(h));
228
- const m = await this.createPlateSprite(i);
229
- m && (r.model.add(m), m.position.set(0, 5, -4));
209
+ if (r.data.showName !== t.showName || r.data.plateColor !== t.plateColor) {
210
+ const c = r.model.getObjectByName("VehiclePlate");
211
+ c && (r.model.remove(c), this.disposeModel(c));
212
+ const p = await this.createPlateSprite(t);
213
+ p && (r.model.add(p), p.position.set(0, 5, -4));
230
214
  }
231
- if (r.data = i, this.needInterpolate) {
232
- const h = p[p.length - 1];
233
- Math.abs(l - h.heading) >= 180 && (l > h.heading ? h.heading += 360 : l += 360), p.push({
234
- pos: [n, s, 0],
235
- heading: l,
236
- time: a
215
+ if (r.data = t, this.needInterpolate) {
216
+ const c = m[m.length - 1];
217
+ Math.abs(h - c.heading) >= 180 && (h > c.heading ? c.heading += 360 : h += 360), m.push({
218
+ pos: [n, a, 0],
219
+ heading: h,
220
+ time: s
237
221
  });
238
222
  } else {
239
223
  this.historyPositionMap.set(o, [
240
- { pos: [n, s, 0], heading: l, time: a }
224
+ { pos: [n, a, 0], heading: h, time: s }
241
225
  ]);
242
- const h = this.toRenderCoordinates([n, s, 0]);
243
- r.model.position.set(h[0], h[1], h[2]), r.model.rotation.y = c.MathUtils.degToRad(-l);
226
+ const c = this.toRenderCoordinates([n, a, 0]);
227
+ r.model.position.set(c[0], c[1], c[2]), r.model.rotation.y = l.MathUtils.degToRad(-h);
244
228
  }
245
229
  }
246
230
  }
247
- await this.addVehicles(t), this.updateModel = !1, this.needInterpolate || this.render(this.context);
231
+ await this.addVehicles(e), this.updateModel = !1, this.needInterpolate || this.render(this.context);
248
232
  }
249
- toRenderCoordinates(e) {
250
- const t = [0, 0, 0];
233
+ toRenderCoordinates(i) {
234
+ const e = [0, 0, 0];
251
235
  return u.toRenderCoordinates(
252
236
  // @ts-ignore
253
237
  this.view,
254
- e,
238
+ i,
255
239
  0,
256
- M.WGS84,
257
- t,
240
+ v.WGS84,
241
+ e,
258
242
  0,
259
243
  1
260
- ), t;
244
+ ), e;
261
245
  }
262
246
  /**
263
247
  * 删除车辆
264
248
  * */
265
- deleteVehicles(e) {
266
- this.isPaused || e.forEach((t) => {
267
- const i = this.vehicleObjectMap.get(t);
268
- i && (this.needInterpolate ? i.isMoving ? i.waitForDelete = !0 : this.deleteVehicle(i) : this.deleteVehicle(i));
249
+ deleteVehicles(i) {
250
+ this.isPaused || i.forEach((e) => {
251
+ const t = this.vehicleObjectMap.get(e);
252
+ t && (this.needInterpolate ? t.isMoving ? t.waitForDelete = !0 : this.deleteVehicle(t) : this.deleteVehicle(t));
269
253
  });
270
254
  }
271
- deleteVehicle(e) {
272
- this.vehiclePool.recycleInstance(e.model);
273
- const t = e.data.vehicleId;
274
- this.vehicleObjectMap.delete(t), this.historyPositionMap.delete(t);
255
+ deleteVehicle(i) {
256
+ this.vehiclePool.recycleInstance(i.model);
257
+ const e = i.data.vehicleId;
258
+ this.vehicleObjectMap.delete(e), this.historyPositionMap.delete(e);
275
259
  }
276
- async toggleTrafficInfo(e) {
277
- e.name === "vehiclePlate" && (e.visible === !0 && this.currentSpriteContent === d.None ? await this.updatePanelContent(d.PlateNumber) : await this.updatePanelContent(
278
- e.visible ? this.currentSpriteContent : d.None
260
+ async toggleTrafficInfo(i) {
261
+ i.name === "vehiclePlate" && (i.visible === !0 && this.currentSpriteContent === d.None ? await this.updatePanelContent(d.PlateNumber) : await this.updatePanelContent(
262
+ i.visible ? this.currentSpriteContent : d.None
279
263
  ));
280
264
  }
281
- togglePause(e) {
282
- this.isPaused = e;
265
+ togglePause(i) {
266
+ this.isPaused = i;
283
267
  }
284
268
  /**
285
269
  * 清除全部车辆
286
270
  * */
287
271
  clearVehicles() {
288
- for (const e of this.vehicleObjectMap.keys()) {
289
- const t = this.vehicleObjectMap.get(e);
290
- t && this.vehiclePool.recycleInstance(t.model);
272
+ for (const i of this.vehicleObjectMap.keys()) {
273
+ const e = this.vehicleObjectMap.get(i);
274
+ e && this.vehiclePool.recycleInstance(e.model);
291
275
  }
292
276
  this.vehicleObjectMap.clear(), this.historyPositionMap.clear();
293
277
  }
@@ -296,134 +280,171 @@ class R {
296
280
  * @param contentType
297
281
  * @returns
298
282
  */
299
- async updatePanelContent(e) {
300
- if (e !== this.currentSpriteContent) {
301
- this.currentSpriteContent = e;
302
- for (const t of this.vehicleObjectMap.keys()) {
303
- const i = this.vehicleObjectMap.get(t);
304
- if (i) {
305
- const o = i.model.getObjectByName("VehiclePlate");
306
- if (o && (i.model.remove(o), this.disposeModel(o)), e !== d.None) {
307
- const a = await this.createPlateSprite(i.data);
308
- a && (i.model.add(a), a.position.set(0, 5, -4));
283
+ async updatePanelContent(i) {
284
+ if (i !== this.currentSpriteContent) {
285
+ this.currentSpriteContent = i;
286
+ for (const e of this.vehicleObjectMap.keys()) {
287
+ const t = this.vehicleObjectMap.get(e);
288
+ if (t) {
289
+ const o = t.model.getObjectByName("VehiclePlate");
290
+ if (o && (t.model.remove(o), this.disposeModel(o)), i !== d.None) {
291
+ const s = await this.createPlateSprite(t.data);
292
+ s && (t.model.add(s), s.position.set(0, 5, -4));
309
293
  }
310
294
  }
311
295
  }
312
296
  }
313
297
  }
314
- toggleGroundVehicle(e) {
315
- console.log("toggleGroundVehicle", e), this.showGroundVehicle = e;
298
+ toggleGroundVehicle(i) {
299
+ console.log("toggleGroundVehicle", i), this.showGroundVehicle = i;
316
300
  }
317
- toggleElevatedVehicle(e) {
318
- this.showElevatedVehicle = e;
301
+ toggleElevatedVehicle(i) {
302
+ this.showElevatedVehicle = i;
319
303
  }
320
304
  /**
321
305
  * 释放模型资源
322
306
  * */
323
- disposeModel(e) {
324
- e.traverse((t) => {
325
- t instanceof c.Mesh && (t.geometry.dispose(), t.material.dispose());
307
+ disposeModel(i) {
308
+ i.traverse((e) => {
309
+ e instanceof l.Mesh && (e.geometry.dispose(), e.material.dispose());
326
310
  });
327
311
  }
328
312
  /**
329
313
  * 计算车辆位置
330
314
  * */
331
- computeVehiclePosition(e) {
332
- const t = this.historyPositionMap.get(e), i = this.vehicleObjectMap.get(e);
333
- if (!i || !t || !i.isMoving && t.length <= 2)
315
+ computeVehiclePosition(i) {
316
+ const e = this.historyPositionMap.get(i), t = this.vehicleObjectMap.get(i);
317
+ if (!t || !e || !t.isMoving && e.length <= 2)
334
318
  return;
335
319
  const o = Date.now();
336
- i.isMoving = !0, i.data.roadLayer === "1" ? i.model.visible = this.showGroundVehicle : i.model.visible = this.showElevatedVehicle, i.segmentStartTime || (i.segmentStartTime = o, i.segmentTotalTime = t[1].time - t[0].time);
337
- const a = o - i.segmentStartTime, n = Math.min(
338
- a / i.segmentTotalTime,
320
+ t.isMoving = !0, t.data.roadLayer === "1" ? t.model.visible = this.showGroundVehicle : t.model.visible = this.showElevatedVehicle, t.segmentStartTime || (t.segmentStartTime = o, t.segmentTotalTime = e[1].time - e[0].time);
321
+ const s = o - t.segmentStartTime, n = Math.min(
322
+ s / t.segmentTotalTime,
339
323
  1
340
324
  );
341
325
  if (n === 1)
342
- if (t.shift(), t.length === 1) {
343
- i.waitForDelete === !0 ? this.deleteVehicle(i) : (i.segmentStartTime = void 0, i.segmentTotalTime = void 0, i.model.visible = !1, i.isMoving = !1, console.log("hide vehicle", e));
326
+ if (e.shift(), e.length === 1) {
327
+ 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));
344
328
  return;
345
329
  } else
346
- return i.segmentStartTime = Date.now(), i.segmentTotalTime = t[1].time - t[0].time, (t[1].heading >= 270 && t[0].heading <= 90 || t[1].heading <= 90 && t[0].heading >= 270) && (t[1].heading > t[0].heading ? t[0].heading += 360 : t[1].heading += 360), t[0].pos.concat(t[0].heading);
347
- else if (t.length >= 2) {
348
- const s = t[0].pos[0] + (t[1].pos[0] - t[0].pos[0]) * n, l = t[0].pos[1] + (t[1].pos[1] - t[0].pos[1]) * n, r = t[0].heading + (t[1].heading - t[0].heading) * n;
349
- return [s, l, 0, r];
330
+ return t.segmentStartTime = Date.now(), t.segmentTotalTime = e[1].time - e[0].time, (e[1].heading >= 270 && e[0].heading <= 90 || e[1].heading <= 90 && e[0].heading >= 270) && (e[1].heading > e[0].heading ? e[0].heading += 360 : e[1].heading += 360), e[0].pos.concat(e[0].heading);
331
+ else if (e.length >= 2) {
332
+ const a = e[0].pos[0] + (e[1].pos[0] - e[0].pos[0]) * n, h = e[0].pos[1] + (e[1].pos[1] - e[0].pos[1]) * n, r = e[0].heading + (e[1].heading - e[0].heading) * n;
333
+ return [a, h, 0, r];
350
334
  } else
351
335
  return;
352
336
  }
353
337
  /**
354
338
  * 根据车辆类型、车身颜色获取模型
355
339
  * */
356
- getVehicleModel(e) {
357
- return this.vehiclePool.getInstance(e);
340
+ getVehicleModel(i) {
341
+ if (this.view.camera.position.z >= this.cameraHeightThreshold) {
342
+ const e = new l.SphereGeometry(5, 32, 32), t = new l.MeshPhysicalMaterial({
343
+ color: 325253,
344
+ emissive: 0,
345
+ roughness: this.roughness,
346
+ metalness: this.metalness
347
+ });
348
+ return new l.Mesh(e, t);
349
+ } else {
350
+ let e;
351
+ if (i.ptcType === 2)
352
+ e = this.bicycleModel.clone();
353
+ else {
354
+ switch (i.vehicleType) {
355
+ case 10:
356
+ e = this.carModel.clone();
357
+ break;
358
+ case 20:
359
+ e = this.vanModel.clone();
360
+ break;
361
+ case 25:
362
+ e = this.truckModel.clone();
363
+ break;
364
+ case 50:
365
+ e = this.busModel.clone();
366
+ break;
367
+ default:
368
+ e = this.carModel.clone();
369
+ break;
370
+ }
371
+ const t = this.materialMap.get(i.vehicleColor) || this.defaultMaterial;
372
+ let o = !1;
373
+ e.traverse((s) => {
374
+ !o && s instanceof l.Mesh && (s.material = t, o = !0);
375
+ });
376
+ }
377
+ return e;
378
+ }
358
379
  }
359
380
  /**
360
381
  * 创建号牌canvas
361
382
  * */
362
- createCanvas(e, t, i) {
363
- const o = document.createElement("canvas"), a = e.width, n = e.height;
364
- o.width = a, o.height = n;
365
- const s = o.getContext("2d");
366
- if (!s) {
383
+ createCanvas(i, e, t) {
384
+ const o = document.createElement("canvas"), s = i.width, n = i.height;
385
+ o.width = s, o.height = n;
386
+ const a = o.getContext("2d");
387
+ if (!a) {
367
388
  console.log("canvas创建失败");
368
389
  return;
369
390
  }
370
- return s.fillStyle = "rgba(0,0,0,0.0)", s.fillRect(0, 0, a, n), s.drawImage(e, 0, 0, a, n), s.beginPath(), s.translate(a / 2, n / 2), s.fillStyle = i, s.font = "bold 32px 宋体", s.textBaseline = "middle", s.textAlign = "center", s.fillText(t, 0, 0), o;
391
+ return a.fillStyle = "rgba(0,0,0,0.0)", a.fillRect(0, 0, s, n), a.drawImage(i, 0, 0, s, n), a.beginPath(), a.translate(s / 2, n / 2), a.fillStyle = t, a.font = "bold 32px 宋体", a.textBaseline = "middle", a.textAlign = "center", a.fillText(e, 0, 0), o;
371
392
  }
372
- createPlateSprite(e) {
373
- return new Promise((t, i) => {
374
- var r, p;
375
- const o = !e.plateNo || e.plateNo === "0" || e.plateNo === "000000";
393
+ createPlateSprite(i) {
394
+ return new Promise((e, t) => {
395
+ var r, m;
396
+ const o = !i.plateNo || i.plateNo === "0" || i.plateNo === "000000";
376
397
  if (this.currentSpriteContent === d.None || this.currentSpriteContent === d.PlateNumber && o) {
377
- t(void 0);
398
+ e(void 0);
378
399
  return;
379
400
  }
380
- let a = new Image(), n = "", s = "";
401
+ let s = new Image(), n = "", a = "";
381
402
  if (this.currentSpriteContent === d.PlateNumber || this.currentSpriteContent === d.Mix)
382
403
  if (o)
383
- a = this.greyPlateBG, n = e.ptcId, s = "#ffffff";
404
+ s = this.greyPlateBG, n = i.ptcId, a = "#ffffff";
384
405
  else
385
- switch (n = ((r = e.showName) == null ? void 0 : r.substring(0, 2)) + "•" + ((p = e.showName) == null ? void 0 : p.substring(2)), e.plateColor) {
406
+ switch (n = ((r = i.showName) == null ? void 0 : r.substring(0, 2)) + "•" + ((m = i.showName) == null ? void 0 : m.substring(2)), i.plateColor) {
386
407
  case 1:
387
- a = this.bluePlateBG, s = "#ffffff";
408
+ s = this.bluePlateBG, a = "#ffffff";
388
409
  break;
389
410
  case 2:
390
- a = this.yellowPlateBG, s = "#000000";
411
+ s = this.yellowPlateBG, a = "#000000";
391
412
  break;
392
413
  case 3:
393
- a = this.whitePlateBG, s = "#000000";
414
+ s = this.whitePlateBG, a = "#000000";
394
415
  break;
395
416
  case 4:
396
- a = this.blackPlateBG, s = "#ffffff";
417
+ s = this.blackPlateBG, a = "#ffffff";
397
418
  break;
398
419
  case 5:
399
- a = this.neoYellowPlateBG, s = "#000000";
420
+ s = this.neoYellowPlateBG, a = "#000000";
400
421
  break;
401
422
  case 6:
402
- a = this.neoGreenPlateBG, s = "#000000";
423
+ s = this.neoGreenPlateBG, a = "#000000";
403
424
  break;
404
425
  default:
405
- a = this.greyPlateBG, n = e.plateNo, s = "#ffffff";
426
+ s = this.greyPlateBG, n = i.plateNo, a = "#ffffff";
406
427
  break;
407
428
  }
408
429
  else
409
- this.currentSpriteContent === d.Id && (a = this.greyPlateBG, n = e.ptcId, s = "#ffffff");
410
- const l = this.createCanvas(a, n, s);
411
- if (l) {
412
- const h = new c.CanvasTexture(l), m = new c.SpriteMaterial({
413
- map: h,
430
+ this.currentSpriteContent === d.Id && (s = this.greyPlateBG, n = i.ptcId, a = "#ffffff");
431
+ const h = this.createCanvas(s, n, a);
432
+ if (h) {
433
+ const c = new l.CanvasTexture(h), p = new l.SpriteMaterial({
434
+ map: c,
414
435
  transparent: !1
415
- }), f = new c.Sprite(m), g = 0.05, P = l.width * g, w = l.height * g;
416
- f.scale.set(P, w, 1), f.name = "VehiclePlate", t(f);
436
+ }), g = new l.Sprite(p), f = 0.05, M = h.width * f, P = h.height * f;
437
+ g.scale.set(M, P, 1), g.name = "VehiclePlate", e(g);
417
438
  } else {
418
- i("canvas创建失败");
439
+ t("canvas创建失败");
419
440
  return;
420
441
  }
421
- a.onerror = (h) => {
422
- console.log(`号牌背景加载失败: ${a.src}`, h), i(h);
442
+ s.onerror = (c) => {
443
+ console.log(`号牌背景加载失败: ${s.src}`, c), t(c);
423
444
  };
424
445
  });
425
446
  }
426
447
  }
427
448
  export {
428
- R as default
449
+ N as default
429
450
  };
@@ -17,26 +17,26 @@ class d {
17
17
  [99, this.createCarMaterial(6908265)]
18
18
  ]), this.carPool = /* @__PURE__ */ new Map(), this.vanPool = /* @__PURE__ */ new Map(), this.truckPool = /* @__PURE__ */ new Map(), this.busPool = /* @__PURE__ */ new Map(), this.bicyclePool = [], this.ballPool = [], this.poolSize = 20, this.cameraHeightThreshold = 1e3;
19
19
  }
20
- createCarMaterial(e) {
20
+ createCarMaterial(t) {
21
21
  return new i.MeshPhongMaterial({
22
- color: e
22
+ color: t
23
23
  // // emissive: 0xc3c3c3,
24
24
  // roughness: this.roughness,
25
25
  // metalness: this.metalness
26
26
  });
27
27
  }
28
- async initPool(e, a) {
28
+ async initPool(t, a) {
29
29
  this.view = a;
30
30
  const s = new u();
31
31
  await h.eachAlways([
32
32
  new Promise((o) => {
33
- s.load(`${e}/3DModels/car.glb`, (l) => {
34
- const t = l.scene;
35
- t.rotation.x = i.MathUtils.degToRad(90), t.userData = {
33
+ s.load(`${t}/3DModels/car.glb`, (l) => {
34
+ const e = l.scene;
35
+ e.rotation.x = i.MathUtils.degToRad(90), e.userData = {
36
36
  status: "unused"
37
37
  /* UNUSED */
38
38
  }, this.materialMap.forEach((n, c) => {
39
- const r = t.clone();
39
+ const r = e.clone();
40
40
  this.materialModel(r, n), this.carPool.set(
41
41
  c,
42
42
  Array.from({ length: this.poolSize }, () => r.clone())
@@ -45,13 +45,13 @@ class d {
45
45
  });
46
46
  }),
47
47
  new Promise((o) => {
48
- s.load(`${e}/3DModels/van.glb`, (l) => {
49
- const t = l.scene;
50
- t.rotation.x = i.MathUtils.degToRad(90), t.userData = {
48
+ s.load(`${t}/3DModels/van.glb`, (l) => {
49
+ const e = l.scene;
50
+ e.rotation.x = i.MathUtils.degToRad(90), e.userData = {
51
51
  status: "unused"
52
52
  /* UNUSED */
53
53
  }, this.materialMap.forEach((n, c) => {
54
- const r = t.clone();
54
+ const r = e.clone();
55
55
  this.materialModel(r, n), this.vanPool.set(
56
56
  c,
57
57
  Array.from({ length: this.poolSize }, () => r.clone())
@@ -60,13 +60,13 @@ class d {
60
60
  });
61
61
  }),
62
62
  new Promise((o) => {
63
- s.load(`${e}/3DModels/truck.glb`, (l) => {
64
- const t = l.scene;
65
- t.scale.set(1.2, 1, 1.5), t.rotation.x = i.MathUtils.degToRad(90), t.userData = {
63
+ s.load(`${t}/3DModels/truck.glb`, (l) => {
64
+ const e = l.scene;
65
+ e.scale.set(1.2, 1, 1.5), e.rotation.x = i.MathUtils.degToRad(90), e.userData = {
66
66
  status: "unused"
67
67
  /* UNUSED */
68
68
  }, this.materialMap.forEach((n, c) => {
69
- const r = t.clone();
69
+ const r = e.clone();
70
70
  this.materialModel(r, n), this.truckPool.set(
71
71
  c,
72
72
  Array.from({ length: this.poolSize }, () => r.clone())
@@ -75,13 +75,13 @@ class d {
75
75
  });
76
76
  }),
77
77
  new Promise((o) => {
78
- s.load(`${e}/3DModels/bus.glb`, (l) => {
79
- const t = l.scene;
80
- t.rotation.x = i.MathUtils.degToRad(90), t.userData = {
78
+ s.load(`${t}/3DModels/bus.glb`, (l) => {
79
+ const e = l.scene;
80
+ e.rotation.x = i.MathUtils.degToRad(90), e.userData = {
81
81
  status: "unused"
82
82
  /* UNUSED */
83
83
  }, this.materialMap.forEach((n, c) => {
84
- const r = t.clone();
84
+ const r = e.clone();
85
85
  r.userData = {
86
86
  status: "unused"
87
87
  /* UNUSED */
@@ -93,29 +93,29 @@ class d {
93
93
  });
94
94
  }),
95
95
  new Promise((o) => {
96
- s.load(`${e}/3DModels/bicycle.glb`, (l) => {
97
- const t = l.scene;
98
- t.userData = {
96
+ s.load(`${t}/3DModels/bicycle.glb`, (l) => {
97
+ const e = l.scene;
98
+ e.userData = {
99
99
  status: "unused"
100
100
  /* UNUSED */
101
- }, t.rotation.x = i.MathUtils.degToRad(90), t.rotation.y = i.MathUtils.degToRad(180), t.userData = {
101
+ }, e.rotation.x = i.MathUtils.degToRad(90), e.rotation.y = i.MathUtils.degToRad(180), e.userData = {
102
102
  status: "unused"
103
103
  /* UNUSED */
104
104
  }, this.bicyclePool = Array.from(
105
105
  { length: this.poolSize },
106
- () => t.clone()
106
+ () => e.clone()
107
107
  ), o();
108
108
  });
109
109
  }),
110
110
  new Promise((o) => {
111
- const l = new i.SphereGeometry(5, 32, 32), t = new i.MeshPhysicalMaterial({
111
+ const l = new i.SphereGeometry(5, 32, 32), e = new i.MeshPhysicalMaterial({
112
112
  color: 325253,
113
113
  emissive: 0,
114
114
  roughness: 0.2,
115
115
  metalness: 0.8
116
116
  });
117
117
  this.ballPool = Array.from({ length: 100 }, () => {
118
- const n = new i.Mesh(l, t);
118
+ const n = new i.Mesh(l, e);
119
119
  return n.userData = {
120
120
  status: "unused"
121
121
  /* UNUSED */
@@ -128,14 +128,14 @@ class d {
128
128
  * 获取实例
129
129
  * @param data
130
130
  */
131
- getInstance(e) {
132
- if (console.log(e), this.view.camera.position.z >= this.cameraHeightThreshold)
131
+ getInstance(t) {
132
+ if (this.view.camera.position.z >= this.cameraHeightThreshold)
133
133
  return this.getInstanceFromList(this.ballPool);
134
134
  {
135
- const a = e.vehicleColor;
136
- if (e.ptcType === 2)
135
+ const a = t.vehicleColor;
136
+ if (t.ptcType === 2)
137
137
  return this.getInstanceFromList(this.bicyclePool);
138
- switch (e.vehicleType) {
138
+ switch (t.vehicleType) {
139
139
  case 1:
140
140
  case 10:
141
141
  return this.getInstanceFromPool(a, this.carPool);
@@ -154,23 +154,23 @@ class d {
154
154
  * 回收实例
155
155
  * @param instance
156
156
  */
157
- recycleInstance(e) {
158
- e.visible = !1, e.userData.status = "unused";
157
+ recycleInstance(t) {
158
+ t.visible = !1, t.userData.status = "unused";
159
159
  }
160
- getInstanceFromPool(e, a) {
161
- let s = a.get(e);
160
+ getInstanceFromPool(t, a) {
161
+ let s = a.get(t);
162
162
  return s || (s = a.get(99)), this.getInstanceFromList(s);
163
163
  }
164
- getInstanceFromList(e) {
165
- let a = e.find(
164
+ getInstanceFromList(t) {
165
+ let a = t.find(
166
166
  (s) => s.userData.status === "unused"
167
167
  /* UNUSED */
168
168
  );
169
- return a || (a = e[0].clone(), e.push(a), console.log("increase pool. pool size:", e.length)), a.userData.status = "used", a;
169
+ return a || (a = t[0].clone(), t.push(a), console.log("increase pool. pool size:", t.length)), a.userData.status = "used", a;
170
170
  }
171
- materialModel(e, a) {
171
+ materialModel(t, a) {
172
172
  let s = !1;
173
- e.traverse((o) => {
173
+ t.traverse((o) => {
174
174
  !s && o instanceof i.Mesh && (o.material = a, s = !0);
175
175
  });
176
176
  }
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const M=require("@arcgis/core/core/promiseUtils.js"),y=require("@arcgis/core/core/reactiveUtils.js"),S=require("@arcgis/core/geometry/SpatialReference"),G=require("@arcgis/core/views/3d/externalRenderers"),C=require("three"),d=require("../../../types/index.js"),B=require("../../stores/index.js"),I=require("./vehicle-pool.js");function g(m){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(m){for(const t in m)if(t!=="default"){const i=Object.getOwnPropertyDescriptor(m,t);Object.defineProperty(e,t,i.get?i:{enumerable:!0,get:()=>m[t]})}}return e.default=m,Object.freeze(e)}const V=g(M),T=g(y),w=g(G),c=g(C);class R{constructor(e){this.cameraHeightThreshold=1e3,this.roughness=.2,this.metalness=.8,this.defaultMaterial=new c.MeshPhongMaterial({color:16777215}),this.vehiclePool=new I.default,this.materialMap=new Map([[1,this.createCarMaterial(16777215)],[2,this.createCarMaterial(7833753)],[3,this.createCarMaterial(16766720)],[4,this.createCarMaterial(16758465)],[5,this.createCarMaterial(14423100)],[6,this.createCarMaterial(3329330)],[7,this.createCarMaterial(2003183)],[8,this.createCarMaterial(16032864)],[9,this.createCarMaterial(2105376)],[10,this.createCarMaterial(9662683)],[99,this.createCarMaterial(6908265)]]),this.isInitialized=!1,this.showGroundVehicle=!0,this.showElevatedVehicle=!0,this.isPaused=!1,this.currentSpriteContent=d.EVehiclePlateState.None,this.historyPositionMap=new Map,this.vehicleObjectMap=new Map,this.needInterpolate=!0,this.updateModel=!1;const t=B.default.useAppDataStore;this.assetsRoot=JSON.parse(JSON.stringify(t.mapConfig)).assetsRoot,this.view=e,T.watch(()=>this.view.camera.position.z,(i,o)=>{(o<=this.cameraHeightThreshold&&i>this.cameraHeightThreshold||o>this.cameraHeightThreshold&&i<=this.cameraHeightThreshold)&&(this.updateModel=!0)})}createCarMaterial(e){return new c.MeshPhongMaterial({color:e})}async init(){await this.vehiclePool.initPool(this.assetsRoot,this.view),await V.eachAlways([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.needInterpolate=e}async setup(e){this.context=e,this.renderer=new c.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 t=this.renderer.setRenderTarget.bind(this.renderer);this.renderer.setRenderTarget=o=>{t(o),o==null&&e.bindRenderTarget()},this.scene=new c.Scene;const{camera:i}=e;this.camera=new c.PerspectiveCamera(i.fovY,i.aspect,.1,1e5),this.ambient=new c.AmbientLight(16777215,2),this.scene.add(this.ambient),this.sun=new c.DirectionalLight(16777215,2),this.scene.add(this.sun),e.resetWebGLState()}async render(e){var o;const t=e.camera;if(this.camera.position.set(t.eye[0],t.eye[1],t.eye[2]),this.camera.up.set(t.up[0],t.up[1],t.up[2]),this.camera.lookAt(new c.Vector3(t.center[0],t.center[1],t.center[2])),this.camera.projectionMatrix.fromArray(t.projectionMatrix),!this.isPaused&&this.needInterpolate)for(const a of this.vehicleObjectMap.keys()){const n=(o=this.vehicleObjectMap.get(a))==null?void 0:o.model;if(!n)continue;const s=this.computeVehiclePosition(a);if(s){const l=this.toRenderCoordinates(s);n.position.set(l[0],l[1],l[2]),n.rotation.y=c.MathUtils.degToRad(-s[3])}}const i=e.sunLight;this.sun.position.set(i.direction[0],i.direction[1],i.direction[2]),this.sun.intensity=i.diffuse.intensity,this.sun.color=new c.Color(i.diffuse.color[0],i.diffuse.color[1],i.diffuse.color[2]),this.ambient.intensity=i.ambient.intensity,this.ambient.color=new c.Color(i.ambient.color[0],i.ambient.color[1],i.ambient.color[2]),this.renderer.resetState(),e.bindRenderTarget(),this.renderer.render(this.scene,this.camera),w.requestRender(this.view),e.resetWebGLState()}async addVehicles(e){if(!(this.isPaused||!this.isInitialized))for(const t of e){const{vehicleId:i,localTimestamp:o}=t,a=Number(t.x),n=Number(t.y),s=Number(t.heading);this.historyPositionMap.set(i,[{pos:[a,n,0],heading:s,time:o}]);const l=this.getVehicleModel(t);l.name=i,l.visible=!1;try{const r=await this.createPlateSprite(t);r&&(l.add(r),r.position.set(0,5,-4))}catch(r){console.log("createPlateSprite error:",r)}this.scene.add(l),this.vehicleObjectMap.set(i,{model:l,data:t,waitForDelete:!1,isMoving:!1})}}async updateVehicles(e){if(this.isPaused||!this.isInitialized)return;const t=[];for(const i of e){const{vehicleId:o,timestamp:a}=i,n=Number(i.x),s=Number(i.y);let l=Number(i.heading);const r=this.vehicleObjectMap.get(o),p=this.historyPositionMap.get(o);if(!r||!p)t.push(i);else{if(this.updateModel||r.data.vehicleColor!==i.vehicleColor||r.data.vehicleType!==i.vehicleType){this.vehiclePool.recycleInstance(r.model),r.model=this.getVehicleModel(i),r.model.visible=!0;const h=await this.createPlateSprite(i);h&&(r.model.add(h),h.position.set(0,5,-4)),this.scene.add(r.model)}if(r.data.showName!==i.showName||r.data.plateColor!==i.plateColor){const h=r.model.getObjectByName("VehiclePlate");h&&(r.model.remove(h),this.disposeModel(h));const f=await this.createPlateSprite(i);f&&(r.model.add(f),f.position.set(0,5,-4))}if(r.data=i,this.needInterpolate){const h=p[p.length-1];Math.abs(l-h.heading)>=180&&(l>h.heading?h.heading+=360:l+=360),p.push({pos:[n,s,0],heading:l,time:a})}else{this.historyPositionMap.set(o,[{pos:[n,s,0],heading:l,time:a}]);const h=this.toRenderCoordinates([n,s,0]);r.model.position.set(h[0],h[1],h[2]),r.model.rotation.y=c.MathUtils.degToRad(-l)}}}await this.addVehicles(t),this.updateModel=!1,this.needInterpolate||this.render(this.context)}toRenderCoordinates(e){const t=[0,0,0];return w.toRenderCoordinates(this.view,e,0,S.WGS84,t,0,1),t}deleteVehicles(e){this.isPaused||e.forEach(t=>{const i=this.vehicleObjectMap.get(t);i&&(this.needInterpolate?i.isMoving?i.waitForDelete=!0:this.deleteVehicle(i):this.deleteVehicle(i))})}deleteVehicle(e){this.vehiclePool.recycleInstance(e.model);const t=e.data.vehicleId;this.vehicleObjectMap.delete(t),this.historyPositionMap.delete(t)}async toggleTrafficInfo(e){e.name==="vehiclePlate"&&(e.visible===!0&&this.currentSpriteContent===d.EVehiclePlateState.None?await this.updatePanelContent(d.EVehiclePlateState.PlateNumber):await this.updatePanelContent(e.visible?this.currentSpriteContent:d.EVehiclePlateState.None))}togglePause(e){this.isPaused=e}clearVehicles(){for(const e of this.vehicleObjectMap.keys()){const t=this.vehicleObjectMap.get(e);t&&this.vehiclePool.recycleInstance(t.model)}this.vehicleObjectMap.clear(),this.historyPositionMap.clear()}async updatePanelContent(e){if(e!==this.currentSpriteContent){this.currentSpriteContent=e;for(const t of this.vehicleObjectMap.keys()){const i=this.vehicleObjectMap.get(t);if(i){const o=i.model.getObjectByName("VehiclePlate");if(o&&(i.model.remove(o),this.disposeModel(o)),e!==d.EVehiclePlateState.None){const a=await this.createPlateSprite(i.data);a&&(i.model.add(a),a.position.set(0,5,-4))}}}}}toggleGroundVehicle(e){console.log("toggleGroundVehicle",e),this.showGroundVehicle=e}toggleElevatedVehicle(e){this.showElevatedVehicle=e}disposeModel(e){e.traverse(t=>{t instanceof c.Mesh&&(t.geometry.dispose(),t.material.dispose())})}computeVehiclePosition(e){const t=this.historyPositionMap.get(e),i=this.vehicleObjectMap.get(e);if(!i||!t||!i.isMoving&&t.length<=2)return;const o=Date.now();i.isMoving=!0,i.data.roadLayer==="1"?i.model.visible=this.showGroundVehicle:i.model.visible=this.showElevatedVehicle,i.segmentStartTime||(i.segmentStartTime=o,i.segmentTotalTime=t[1].time-t[0].time);const a=o-i.segmentStartTime,n=Math.min(a/i.segmentTotalTime,1);if(n===1)if(t.shift(),t.length===1){i.waitForDelete===!0?this.deleteVehicle(i):(i.segmentStartTime=void 0,i.segmentTotalTime=void 0,i.model.visible=!1,i.isMoving=!1,console.log("hide vehicle",e));return}else return i.segmentStartTime=Date.now(),i.segmentTotalTime=t[1].time-t[0].time,(t[1].heading>=270&&t[0].heading<=90||t[1].heading<=90&&t[0].heading>=270)&&(t[1].heading>t[0].heading?t[0].heading+=360:t[1].heading+=360),t[0].pos.concat(t[0].heading);else if(t.length>=2){const s=t[0].pos[0]+(t[1].pos[0]-t[0].pos[0])*n,l=t[0].pos[1]+(t[1].pos[1]-t[0].pos[1])*n,r=t[0].heading+(t[1].heading-t[0].heading)*n;return[s,l,0,r]}else return}getVehicleModel(e){return this.vehiclePool.getInstance(e)}createCanvas(e,t,i){const o=document.createElement("canvas"),a=e.width,n=e.height;o.width=a,o.height=n;const s=o.getContext("2d");if(!s){console.log("canvas创建失败");return}return s.fillStyle="rgba(0,0,0,0.0)",s.fillRect(0,0,a,n),s.drawImage(e,0,0,a,n),s.beginPath(),s.translate(a/2,n/2),s.fillStyle=i,s.font="bold 32px 宋体",s.textBaseline="middle",s.textAlign="center",s.fillText(t,0,0),o}createPlateSprite(e){return new Promise((t,i)=>{var r,p;const o=!e.plateNo||e.plateNo==="0"||e.plateNo==="000000";if(this.currentSpriteContent===d.EVehiclePlateState.None||this.currentSpriteContent===d.EVehiclePlateState.PlateNumber&&o){t(void 0);return}let a=new Image,n="",s="";if(this.currentSpriteContent===d.EVehiclePlateState.PlateNumber||this.currentSpriteContent===d.EVehiclePlateState.Mix)if(o)a=this.greyPlateBG,n=e.ptcId,s="#ffffff";else switch(n=((r=e.showName)==null?void 0:r.substring(0,2))+"•"+((p=e.showName)==null?void 0:p.substring(2)),e.plateColor){case 1:a=this.bluePlateBG,s="#ffffff";break;case 2:a=this.yellowPlateBG,s="#000000";break;case 3:a=this.whitePlateBG,s="#000000";break;case 4:a=this.blackPlateBG,s="#ffffff";break;case 5:a=this.neoYellowPlateBG,s="#000000";break;case 6:a=this.neoGreenPlateBG,s="#000000";break;default:a=this.greyPlateBG,n=e.plateNo,s="#ffffff";break}else this.currentSpriteContent===d.EVehiclePlateState.Id&&(a=this.greyPlateBG,n=e.ptcId,s="#ffffff");const l=this.createCanvas(a,n,s);if(l){const h=new c.CanvasTexture(l),f=new c.SpriteMaterial({map:h,transparent:!1}),u=new c.Sprite(f),P=.05,v=l.width*P,b=l.height*P;u.scale.set(v,b,1),u.name="VehiclePlate",t(u)}else{i("canvas创建失败");return}a.onerror=h=>{console.log(`号牌背景加载失败: ${a.src}`,h),i(h)}})}}exports.default=R;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const v=require("@arcgis/core/core/promiseUtils.js"),y=require("@arcgis/core/core/reactiveUtils.js"),S=require("@arcgis/core/geometry/SpatialReference"),G=require("@arcgis/core/views/3d/externalRenderers"),C=require("three"),T=require("three/examples/jsm/loaders/GLTFLoader"),d=require("../../../types/index.js"),B=require("../../stores/index.js"),R=require("./vehicle-pool.js");function u(m){const i=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(m){for(const e in m)if(e!=="default"){const t=Object.getOwnPropertyDescriptor(m,e);Object.defineProperty(i,e,t.get?t:{enumerable:!0,get:()=>m[e]})}}return i.default=m,Object.freeze(i)}const I=u(v),V=u(y),M=u(G),l=u(C);class N{constructor(i){this.cameraHeightThreshold=1e3,this.roughness=.2,this.metalness=.8,this.defaultMaterial=new l.MeshPhongMaterial({color:16777215}),this.vehiclePool=new R.default,this.materialMap=new Map([[1,this.createCarMaterial(16777215)],[2,this.createCarMaterial(7833753)],[3,this.createCarMaterial(16766720)],[4,this.createCarMaterial(16758465)],[5,this.createCarMaterial(14423100)],[6,this.createCarMaterial(3329330)],[7,this.createCarMaterial(2003183)],[8,this.createCarMaterial(16032864)],[9,this.createCarMaterial(2105376)],[10,this.createCarMaterial(9662683)],[99,this.createCarMaterial(6908265)]]),this.isInitialized=!1,this.showGroundVehicle=!0,this.showElevatedVehicle=!0,this.isPaused=!1,this.currentSpriteContent=d.EVehiclePlateState.None,this.historyPositionMap=new Map,this.vehicleObjectMap=new Map,this.needInterpolate=!0,this.updateModel=!1;const e=B.default.useAppDataStore;this.assetsRoot=JSON.parse(JSON.stringify(e.mapConfig)).assetsRoot,this.view=i,V.watch(()=>this.view.camera.position.z,(t,o)=>{(o<=this.cameraHeightThreshold&&t>this.cameraHeightThreshold||o>this.cameraHeightThreshold&&t<=this.cameraHeightThreshold)&&(this.updateModel=!0)})}createCarMaterial(i){return new l.MeshPhongMaterial({color:i})}async init(){const i=new T.GLTFLoader;await I.eachAlways([new Promise(e=>{i.load(`${this.assetsRoot}/3DModels/car.glb`,t=>{this.carModel=t.scene,this.carModel.rotation.x=l.MathUtils.degToRad(90),e()})}),new Promise(e=>{i.load(`${this.assetsRoot}/3DModels/van.glb`,t=>{this.vanModel=t.scene,this.vanModel.rotation.x=l.MathUtils.degToRad(90),e()})}),new Promise(e=>{i.load(`${this.assetsRoot}/3DModels/truck.glb`,t=>{this.truckModel=t.scene,this.truckModel.scale.set(1.2,1,1.5),this.truckModel.rotation.x=l.MathUtils.degToRad(90),e()})}),new Promise(e=>{i.load(`${this.assetsRoot}/3DModels/bus.glb`,t=>{this.busModel=t.scene,this.busModel.rotation.x=l.MathUtils.degToRad(90),e()})}),new Promise(e=>{i.load(`${this.assetsRoot}/3DModels/bicycle.glb`,t=>{this.bicycleModel=t.scene,this.bicycleModel.rotation.x=l.MathUtils.degToRad(90),this.bicycleModel.rotation.y=l.MathUtils.degToRad(180),e()})}),new Promise(e=>{this.bluePlateBG=new Image,this.bluePlateBG.src=`${this.assetsRoot}/Images/PlateBG/blue.png`,this.bluePlateBG.onload=()=>{e()}}),new Promise(e=>{this.yellowPlateBG=new Image,this.yellowPlateBG.src=`${this.assetsRoot}/Images/PlateBG/yellow.png`,this.yellowPlateBG.onload=()=>{e()}}),new Promise(e=>{this.whitePlateBG=new Image,this.whitePlateBG.src=`${this.assetsRoot}/Images/PlateBG/white.png`,this.whitePlateBG.onload=()=>{e()}}),new Promise(e=>{this.blackPlateBG=new Image,this.blackPlateBG.src=`${this.assetsRoot}/Images/PlateBG/black.png`,this.blackPlateBG.onload=()=>{e()}}),new Promise(e=>{this.neoYellowPlateBG=new Image,this.neoYellowPlateBG.src=`${this.assetsRoot}/Images/PlateBG/neo_yellow.png`,this.neoYellowPlateBG.onload=()=>{e()}}),new Promise(e=>{this.neoGreenPlateBG=new Image,this.neoGreenPlateBG.src=`${this.assetsRoot}/Images/PlateBG/neo_green.png`,this.neoGreenPlateBG.onload=()=>{e()}}),new Promise(e=>{this.greyPlateBG=new Image,this.greyPlateBG.src=`${this.assetsRoot}/Images/PlateBG/grey.png`,this.greyPlateBG.onload=()=>{e()}})]),this.isInitialized=!0}setInterpolate(i){this.clearVehicles(),this.needInterpolate=i}async setup(i){this.context=i,this.renderer=new l.WebGLRenderer({context:i.gl,premultipliedAlpha:!0,logarithmicDepthBuffer:!0,antialias:!0,powerPreference:"high-performance"}),this.renderer.shadowMap.enabled=!0,this.renderer.setPixelRatio(window.devicePixelRatio),this.renderer.setViewport(0,0,this.view.width,this.view.height),this.renderer.autoClearDepth=!1,this.renderer.autoClearStencil=!1,this.renderer.autoClearColor=!1;const e=this.renderer.setRenderTarget.bind(this.renderer);this.renderer.setRenderTarget=o=>{e(o),o==null&&i.bindRenderTarget()},this.scene=new l.Scene;const{camera:t}=i;this.camera=new l.PerspectiveCamera(t.fovY,t.aspect,.1,1e5),this.ambient=new l.AmbientLight(16777215,2),this.scene.add(this.ambient),this.sun=new l.DirectionalLight(16777215,2),this.scene.add(this.sun),i.resetWebGLState()}async render(i){var o;const e=i.camera;if(this.camera.position.set(e.eye[0],e.eye[1],e.eye[2]),this.camera.up.set(e.up[0],e.up[1],e.up[2]),this.camera.lookAt(new l.Vector3(e.center[0],e.center[1],e.center[2])),this.camera.projectionMatrix.fromArray(e.projectionMatrix),!this.isPaused&&this.needInterpolate)for(const s of this.vehicleObjectMap.keys()){const n=(o=this.vehicleObjectMap.get(s))==null?void 0:o.model;if(!n)continue;const a=this.computeVehiclePosition(s);if(a){const h=this.toRenderCoordinates(a);n.position.set(h[0],h[1],h[2]),n.rotation.y=l.MathUtils.degToRad(-a[3])}}const t=i.sunLight;this.sun.position.set(t.direction[0],t.direction[1],t.direction[2]),this.sun.intensity=t.diffuse.intensity,this.sun.color=new l.Color(t.diffuse.color[0],t.diffuse.color[1],t.diffuse.color[2]),this.ambient.intensity=t.ambient.intensity,this.ambient.color=new l.Color(t.ambient.color[0],t.ambient.color[1],t.ambient.color[2]),this.renderer.resetState(),i.bindRenderTarget(),this.renderer.render(this.scene,this.camera),M.requestRender(this.view),i.resetWebGLState()}async addVehicles(i){if(!(this.isPaused||!this.isInitialized))for(const e of i){const{vehicleId:t,localTimestamp:o}=e,s=Number(e.x),n=Number(e.y),a=Number(e.heading);this.historyPositionMap.set(t,[{pos:[s,n,0],heading:a,time:o}]);const h=this.getVehicleModel(e);h.name=t,h.visible=!1;try{const r=await this.createPlateSprite(e);r&&(h.add(r),r.position.set(0,5,-4))}catch(r){console.log("createPlateSprite error:",r)}this.scene.add(h),this.vehicleObjectMap.set(t,{model:h,data:e,waitForDelete:!1,isMoving:!1})}}async updateVehicles(i){if(this.isPaused||!this.isInitialized)return;const e=[];for(const t of i){const{vehicleId:o,timestamp:s}=t,n=Number(t.x),a=Number(t.y);let h=Number(t.heading);const r=this.vehicleObjectMap.get(o),p=this.historyPositionMap.get(o);if(!r||!p)e.push(t);else{if(this.updateModel||r.data.vehicleColor!==t.vehicleColor||r.data.vehicleType!==t.vehicleType){this.vehiclePool.recycleInstance(r.model),r.model=this.getVehicleModel(t),r.model.visible=!0;const c=await this.createPlateSprite(t);c&&(r.model.add(c),c.position.set(0,5,-4)),this.scene.add(r.model)}if(r.data.showName!==t.showName||r.data.plateColor!==t.plateColor){const c=r.model.getObjectByName("VehiclePlate");c&&(r.model.remove(c),this.disposeModel(c));const g=await this.createPlateSprite(t);g&&(r.model.add(g),g.position.set(0,5,-4))}if(r.data=t,this.needInterpolate){const c=p[p.length-1];Math.abs(h-c.heading)>=180&&(h>c.heading?c.heading+=360:h+=360),p.push({pos:[n,a,0],heading:h,time:s})}else{this.historyPositionMap.set(o,[{pos:[n,a,0],heading:h,time:s}]);const c=this.toRenderCoordinates([n,a,0]);r.model.position.set(c[0],c[1],c[2]),r.model.rotation.y=l.MathUtils.degToRad(-h)}}}await this.addVehicles(e),this.updateModel=!1,this.needInterpolate||this.render(this.context)}toRenderCoordinates(i){const e=[0,0,0];return M.toRenderCoordinates(this.view,i,0,S.WGS84,e,0,1),e}deleteVehicles(i){this.isPaused||i.forEach(e=>{const t=this.vehicleObjectMap.get(e);t&&(this.needInterpolate?t.isMoving?t.waitForDelete=!0:this.deleteVehicle(t):this.deleteVehicle(t))})}deleteVehicle(i){this.vehiclePool.recycleInstance(i.model);const e=i.data.vehicleId;this.vehicleObjectMap.delete(e),this.historyPositionMap.delete(e)}async toggleTrafficInfo(i){i.name==="vehiclePlate"&&(i.visible===!0&&this.currentSpriteContent===d.EVehiclePlateState.None?await this.updatePanelContent(d.EVehiclePlateState.PlateNumber):await this.updatePanelContent(i.visible?this.currentSpriteContent:d.EVehiclePlateState.None))}togglePause(i){this.isPaused=i}clearVehicles(){for(const i of this.vehicleObjectMap.keys()){const e=this.vehicleObjectMap.get(i);e&&this.vehiclePool.recycleInstance(e.model)}this.vehicleObjectMap.clear(),this.historyPositionMap.clear()}async updatePanelContent(i){if(i!==this.currentSpriteContent){this.currentSpriteContent=i;for(const e of this.vehicleObjectMap.keys()){const t=this.vehicleObjectMap.get(e);if(t){const o=t.model.getObjectByName("VehiclePlate");if(o&&(t.model.remove(o),this.disposeModel(o)),i!==d.EVehiclePlateState.None){const s=await this.createPlateSprite(t.data);s&&(t.model.add(s),s.position.set(0,5,-4))}}}}}toggleGroundVehicle(i){console.log("toggleGroundVehicle",i),this.showGroundVehicle=i}toggleElevatedVehicle(i){this.showElevatedVehicle=i}disposeModel(i){i.traverse(e=>{e instanceof l.Mesh&&(e.geometry.dispose(),e.material.dispose())})}computeVehiclePosition(i){const e=this.historyPositionMap.get(i),t=this.vehicleObjectMap.get(i);if(!t||!e||!t.isMoving&&e.length<=2)return;const o=Date.now();t.isMoving=!0,t.data.roadLayer==="1"?t.model.visible=this.showGroundVehicle:t.model.visible=this.showElevatedVehicle,t.segmentStartTime||(t.segmentStartTime=o,t.segmentTotalTime=e[1].time-e[0].time);const s=o-t.segmentStartTime,n=Math.min(s/t.segmentTotalTime,1);if(n===1)if(e.shift(),e.length===1){t.waitForDelete===!0?this.deleteVehicle(t):(t.segmentStartTime=void 0,t.segmentTotalTime=void 0,t.model.visible=!1,t.isMoving=!1,console.log("hide vehicle",i));return}else return t.segmentStartTime=Date.now(),t.segmentTotalTime=e[1].time-e[0].time,(e[1].heading>=270&&e[0].heading<=90||e[1].heading<=90&&e[0].heading>=270)&&(e[1].heading>e[0].heading?e[0].heading+=360:e[1].heading+=360),e[0].pos.concat(e[0].heading);else if(e.length>=2){const a=e[0].pos[0]+(e[1].pos[0]-e[0].pos[0])*n,h=e[0].pos[1]+(e[1].pos[1]-e[0].pos[1])*n,r=e[0].heading+(e[1].heading-e[0].heading)*n;return[a,h,0,r]}else return}getVehicleModel(i){if(this.view.camera.position.z>=this.cameraHeightThreshold){const e=new l.SphereGeometry(5,32,32),t=new l.MeshPhysicalMaterial({color:325253,emissive:0,roughness:this.roughness,metalness:this.metalness});return new l.Mesh(e,t)}else{let e;if(i.ptcType===2)e=this.bicycleModel.clone();else{switch(i.vehicleType){case 10:e=this.carModel.clone();break;case 20:e=this.vanModel.clone();break;case 25:e=this.truckModel.clone();break;case 50:e=this.busModel.clone();break;default:e=this.carModel.clone();break}const t=this.materialMap.get(i.vehicleColor)||this.defaultMaterial;let o=!1;e.traverse(s=>{!o&&s instanceof l.Mesh&&(s.material=t,o=!0)})}return e}}createCanvas(i,e,t){const o=document.createElement("canvas"),s=i.width,n=i.height;o.width=s,o.height=n;const a=o.getContext("2d");if(!a){console.log("canvas创建失败");return}return a.fillStyle="rgba(0,0,0,0.0)",a.fillRect(0,0,s,n),a.drawImage(i,0,0,s,n),a.beginPath(),a.translate(s/2,n/2),a.fillStyle=t,a.font="bold 32px 宋体",a.textBaseline="middle",a.textAlign="center",a.fillText(e,0,0),o}createPlateSprite(i){return new Promise((e,t)=>{var r,p;const o=!i.plateNo||i.plateNo==="0"||i.plateNo==="000000";if(this.currentSpriteContent===d.EVehiclePlateState.None||this.currentSpriteContent===d.EVehiclePlateState.PlateNumber&&o){e(void 0);return}let s=new Image,n="",a="";if(this.currentSpriteContent===d.EVehiclePlateState.PlateNumber||this.currentSpriteContent===d.EVehiclePlateState.Mix)if(o)s=this.greyPlateBG,n=i.ptcId,a="#ffffff";else switch(n=((r=i.showName)==null?void 0:r.substring(0,2))+"•"+((p=i.showName)==null?void 0:p.substring(2)),i.plateColor){case 1:s=this.bluePlateBG,a="#ffffff";break;case 2:s=this.yellowPlateBG,a="#000000";break;case 3:s=this.whitePlateBG,a="#000000";break;case 4:s=this.blackPlateBG,a="#ffffff";break;case 5:s=this.neoYellowPlateBG,a="#000000";break;case 6:s=this.neoGreenPlateBG,a="#000000";break;default:s=this.greyPlateBG,n=i.plateNo,a="#ffffff";break}else this.currentSpriteContent===d.EVehiclePlateState.Id&&(s=this.greyPlateBG,n=i.ptcId,a="#ffffff");const h=this.createCanvas(s,n,a);if(h){const c=new l.CanvasTexture(h),g=new l.SpriteMaterial({map:c,transparent:!1}),f=new l.Sprite(g),P=.05,w=h.width*P,b=h.height*P;f.scale.set(w,b,1),f.name="VehiclePlate",e(f)}else{t("canvas创建失败");return}s.onerror=c=>{console.log(`号牌背景加载失败: ${s.src}`,c),t(c)}})}}exports.default=N;
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const d=require("@arcgis/core/core/promiseUtils.js"),M=require("three"),m=require("three/examples/jsm/loaders/GLTFLoader.js");function u(h){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(h){for(const a in h)if(a!=="default"){const s=Object.getOwnPropertyDescriptor(h,a);Object.defineProperty(e,a,s.get?s:{enumerable:!0,get:()=>h[a]})}}return e.default=h,Object.freeze(e)}const g=u(d),i=u(M);class P{constructor(){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.carPool=new Map,this.vanPool=new Map,this.truckPool=new Map,this.busPool=new Map,this.bicyclePool=[],this.ballPool=[],this.poolSize=20,this.cameraHeightThreshold=1e3}createCarMaterial(e){return new i.MeshPhongMaterial({color:e})}async initPool(e,a){this.view=a;const s=new m.GLTFLoader;await g.eachAlways([new Promise(o=>{s.load(`${e}/3DModels/car.glb`,l=>{const t=l.scene;t.rotation.x=i.MathUtils.degToRad(90),t.userData={status:"unused"},this.materialMap.forEach((n,c)=>{const r=t.clone();this.materialModel(r,n),this.carPool.set(c,Array.from({length:this.poolSize},()=>r.clone()))}),o()})}),new Promise(o=>{s.load(`${e}/3DModels/van.glb`,l=>{const t=l.scene;t.rotation.x=i.MathUtils.degToRad(90),t.userData={status:"unused"},this.materialMap.forEach((n,c)=>{const r=t.clone();this.materialModel(r,n),this.vanPool.set(c,Array.from({length:this.poolSize},()=>r.clone()))}),o()})}),new Promise(o=>{s.load(`${e}/3DModels/truck.glb`,l=>{const t=l.scene;t.scale.set(1.2,1,1.5),t.rotation.x=i.MathUtils.degToRad(90),t.userData={status:"unused"},this.materialMap.forEach((n,c)=>{const r=t.clone();this.materialModel(r,n),this.truckPool.set(c,Array.from({length:this.poolSize},()=>r.clone()))}),o()})}),new Promise(o=>{s.load(`${e}/3DModels/bus.glb`,l=>{const t=l.scene;t.rotation.x=i.MathUtils.degToRad(90),t.userData={status:"unused"},this.materialMap.forEach((n,c)=>{const r=t.clone();r.userData={status:"unused"},this.materialModel(r,n),this.busPool.set(c,Array.from({length:this.poolSize},()=>r.clone()))}),o()})}),new Promise(o=>{s.load(`${e}/3DModels/bicycle.glb`,l=>{const t=l.scene;t.userData={status:"unused"},t.rotation.x=i.MathUtils.degToRad(90),t.rotation.y=i.MathUtils.degToRad(180),t.userData={status:"unused"},this.bicyclePool=Array.from({length:this.poolSize},()=>t.clone()),o()})}),new Promise(o=>{const l=new i.SphereGeometry(5,32,32),t=new i.MeshPhysicalMaterial({color:325253,emissive:0,roughness:.2,metalness:.8});this.ballPool=Array.from({length:100},()=>{const n=new i.Mesh(l,t);return n.userData={status:"unused"},n}),o()})])}getInstance(e){if(console.log(e),this.view.camera.position.z>=this.cameraHeightThreshold)return this.getInstanceFromList(this.ballPool);{const a=e.vehicleColor;if(e.ptcType===2)return this.getInstanceFromList(this.bicyclePool);switch(e.vehicleType){case 1:case 10:return this.getInstanceFromPool(a,this.carPool);case 20:return this.getInstanceFromPool(a,this.vanPool);case 25:return this.getInstanceFromPool(a,this.truckPool);case 50:return this.getInstanceFromPool(a,this.busPool);default:return this.getInstanceFromPool(a,this.carPool)}}}recycleInstance(e){e.visible=!1,e.userData.status="unused"}getInstanceFromPool(e,a){let s=a.get(e);return s||(s=a.get(99)),this.getInstanceFromList(s)}getInstanceFromList(e){let a=e.find(s=>s.userData.status==="unused");return a||(a=e[0].clone(),e.push(a),console.log("increase pool. pool size:",e.length)),a.userData.status="used",a}materialModel(e,a){let s=!1;e.traverse(o=>{!s&&o instanceof i.Mesh&&(o.material=a,s=!0)})}}exports.default=P;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const d=require("@arcgis/core/core/promiseUtils.js"),M=require("three"),m=require("three/examples/jsm/loaders/GLTFLoader.js");function u(h){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(h){for(const a in h)if(a!=="default"){const s=Object.getOwnPropertyDescriptor(h,a);Object.defineProperty(e,a,s.get?s:{enumerable:!0,get:()=>h[a]})}}return e.default=h,Object.freeze(e)}const g=u(d),i=u(M);class P{constructor(){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.carPool=new Map,this.vanPool=new Map,this.truckPool=new Map,this.busPool=new Map,this.bicyclePool=[],this.ballPool=[],this.poolSize=20,this.cameraHeightThreshold=1e3}createCarMaterial(e){return new i.MeshPhongMaterial({color:e})}async initPool(e,a){this.view=a;const s=new m.GLTFLoader;await g.eachAlways([new Promise(o=>{s.load(`${e}/3DModels/car.glb`,l=>{const t=l.scene;t.rotation.x=i.MathUtils.degToRad(90),t.userData={status:"unused"},this.materialMap.forEach((n,c)=>{const r=t.clone();this.materialModel(r,n),this.carPool.set(c,Array.from({length:this.poolSize},()=>r.clone()))}),o()})}),new Promise(o=>{s.load(`${e}/3DModels/van.glb`,l=>{const t=l.scene;t.rotation.x=i.MathUtils.degToRad(90),t.userData={status:"unused"},this.materialMap.forEach((n,c)=>{const r=t.clone();this.materialModel(r,n),this.vanPool.set(c,Array.from({length:this.poolSize},()=>r.clone()))}),o()})}),new Promise(o=>{s.load(`${e}/3DModels/truck.glb`,l=>{const t=l.scene;t.scale.set(1.2,1,1.5),t.rotation.x=i.MathUtils.degToRad(90),t.userData={status:"unused"},this.materialMap.forEach((n,c)=>{const r=t.clone();this.materialModel(r,n),this.truckPool.set(c,Array.from({length:this.poolSize},()=>r.clone()))}),o()})}),new Promise(o=>{s.load(`${e}/3DModels/bus.glb`,l=>{const t=l.scene;t.rotation.x=i.MathUtils.degToRad(90),t.userData={status:"unused"},this.materialMap.forEach((n,c)=>{const r=t.clone();r.userData={status:"unused"},this.materialModel(r,n),this.busPool.set(c,Array.from({length:this.poolSize},()=>r.clone()))}),o()})}),new Promise(o=>{s.load(`${e}/3DModels/bicycle.glb`,l=>{const t=l.scene;t.userData={status:"unused"},t.rotation.x=i.MathUtils.degToRad(90),t.rotation.y=i.MathUtils.degToRad(180),t.userData={status:"unused"},this.bicyclePool=Array.from({length:this.poolSize},()=>t.clone()),o()})}),new Promise(o=>{const l=new i.SphereGeometry(5,32,32),t=new i.MeshPhysicalMaterial({color:325253,emissive:0,roughness:.2,metalness:.8});this.ballPool=Array.from({length:100},()=>{const n=new i.Mesh(l,t);return n.userData={status:"unused"},n}),o()})])}getInstance(e){if(this.view.camera.position.z>=this.cameraHeightThreshold)return this.getInstanceFromList(this.ballPool);{const a=e.vehicleColor;if(e.ptcType===2)return this.getInstanceFromList(this.bicyclePool);switch(e.vehicleType){case 1:case 10:return this.getInstanceFromPool(a,this.carPool);case 20:return this.getInstanceFromPool(a,this.vanPool);case 25:return this.getInstanceFromPool(a,this.truckPool);case 50:return this.getInstanceFromPool(a,this.busPool);default:return this.getInstanceFromPool(a,this.carPool)}}}recycleInstance(e){e.visible=!1,e.userData.status="unused"}getInstanceFromPool(e,a){let s=a.get(e);return s||(s=a.get(99)),this.getInstanceFromList(s)}getInstanceFromList(e){let a=e.find(s=>s.userData.status==="unused");return a||(a=e[0].clone(),e.push(a),console.log("increase pool. pool size:",e.length)),a.userData.status="used",a}materialModel(e,a){let s=!1;e.traverse(o=>{!s&&o instanceof i.Mesh&&(o.material=a,s=!0)})}}exports.default=P;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gisviewer-vue3-arcgis",
3
- "version": "1.0.112",
3
+ "version": "1.0.113",
4
4
  "main": "lib/index.js",
5
5
  "module": "es/index.mjs",
6
6
  "files": [