gisviewer-vue3-arcgis 1.0.111 → 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.
- package/es/src/gis-map/utils/holo-flow/trace-holo-flow.mjs +47 -42
- package/es/src/gis-map/utils/holo-flow/trace-renderer-external.d.ts +1 -0
- package/es/src/gis-map/utils/holo-flow/trace-renderer-external.mjs +69 -68
- package/es/src/gis-map/utils/holo-flow/vehicle-pool.d.ts +41 -0
- package/es/src/gis-map/utils/holo-flow/vehicle-pool.mjs +180 -0
- package/es/src/types/index.d.ts +10 -0
- package/lib/src/gis-map/utils/holo-flow/trace-holo-flow.js +2 -2
- package/lib/src/gis-map/utils/holo-flow/trace-renderer-external.d.ts +1 -0
- package/lib/src/gis-map/utils/holo-flow/trace-renderer-external.js +1 -1
- package/lib/src/gis-map/utils/holo-flow/vehicle-pool.d.ts +41 -0
- package/lib/src/gis-map/utils/holo-flow/vehicle-pool.js +1 -0
- package/lib/src/types/index.d.ts +10 -0
- package/package.json +1 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import
|
|
1
|
+
import * as m from "@arcgis/core/views/3d/externalRenderers";
|
|
2
|
+
import u from "../../stores/index.mjs";
|
|
3
3
|
import g from "./trace-renderer-external.mjs";
|
|
4
4
|
import T from "./trace-renderer-layer.mjs";
|
|
5
5
|
class L {
|
|
6
6
|
constructor(t) {
|
|
7
|
-
this.appDataStore =
|
|
7
|
+
this.appDataStore = u.useAppDataStore, this.logTable = [
|
|
8
8
|
[
|
|
9
9
|
"uuid",
|
|
10
10
|
"ptcId",
|
|
@@ -27,9 +27,10 @@ class L {
|
|
|
27
27
|
"fixAngle",
|
|
28
28
|
"roadLayer",
|
|
29
29
|
"status",
|
|
30
|
-
"step"
|
|
30
|
+
"step",
|
|
31
|
+
"receiveTimestamp"
|
|
31
32
|
]
|
|
32
|
-
], t.type === "3d" ? (this.traceRenderer = new g(t),
|
|
33
|
+
], t.type === "3d" ? (this.traceRenderer = new g(t), m.add(
|
|
33
34
|
t,
|
|
34
35
|
this.traceRenderer
|
|
35
36
|
)) : this.traceRenderer = new T(t);
|
|
@@ -46,12 +47,10 @@ class L {
|
|
|
46
47
|
* 处理全息流轨迹数据
|
|
47
48
|
* */
|
|
48
49
|
async handleVehicleTraceData(t) {
|
|
49
|
-
const { newVehList: r, updateVehList: l, deleteVehList: a, jgsj: s } = t, i = t.crossId || "", c = [], n = [];
|
|
50
|
+
const { newVehList: r, updateVehList: l, deleteVehList: a, jgsj: s } = t, i = t.crossId || "", c = [], n = [], d = Date.now();
|
|
50
51
|
if (r && r.length > 0) {
|
|
51
52
|
for (const e of r) {
|
|
52
|
-
e.localTimestamp || (e.localTimestamp = s || Date.now())
|
|
53
|
-
const o = this.buildVehicleTrackData(e, i);
|
|
54
|
-
this.appDataStore.saveTrackLog && this.logTable.push([
|
|
53
|
+
e.localTimestamp || (e.localTimestamp = s || Date.now()), this.appDataStore.saveTrackLog && this.logTable.push([
|
|
55
54
|
e.uuid,
|
|
56
55
|
e.ptcId,
|
|
57
56
|
e.plateno,
|
|
@@ -73,38 +72,44 @@ class L {
|
|
|
73
72
|
e.fixAngle,
|
|
74
73
|
e.roadLayer,
|
|
75
74
|
e.status,
|
|
76
|
-
e.step
|
|
77
|
-
|
|
75
|
+
e.step,
|
|
76
|
+
d
|
|
77
|
+
]);
|
|
78
|
+
const o = this.buildVehicleTrackData(e, i);
|
|
79
|
+
o && c.push(o);
|
|
78
80
|
}
|
|
79
81
|
await this.traceRenderer.addVehicles(c);
|
|
80
82
|
}
|
|
81
83
|
if (l && l.length > 0) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
+
const e = Date.now();
|
|
85
|
+
for (const o of l) {
|
|
84
86
|
this.appDataStore.saveTrackLog && this.logTable.push([
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
87
|
+
o.uuid,
|
|
88
|
+
o.ptcId,
|
|
89
|
+
o.plateno,
|
|
90
|
+
o.timestamp,
|
|
91
|
+
o.localTimestamp,
|
|
92
|
+
o.timestamp_str,
|
|
93
|
+
o.speed,
|
|
94
|
+
o.laneNo,
|
|
95
|
+
o.objHeight,
|
|
96
|
+
o.objLength,
|
|
97
|
+
o.latitude,
|
|
98
|
+
o.longitude,
|
|
99
|
+
o.ptcType,
|
|
100
|
+
o.vehicleType,
|
|
101
|
+
o.vehicleColor,
|
|
102
|
+
o.plateColor,
|
|
103
|
+
o.sbdm,
|
|
104
|
+
o.heading,
|
|
105
|
+
o.fixAngle,
|
|
106
|
+
o.roadLayer,
|
|
107
|
+
o.status,
|
|
108
|
+
o.step,
|
|
109
|
+
e
|
|
110
|
+
]);
|
|
111
|
+
const p = this.buildVehicleTrackData(o, i);
|
|
112
|
+
p && n.push(p);
|
|
108
113
|
}
|
|
109
114
|
await this.traceRenderer.updateVehicles(n);
|
|
110
115
|
}
|
|
@@ -147,7 +152,7 @@ class L {
|
|
|
147
152
|
this.traceRenderer.setInterpolate(t);
|
|
148
153
|
}
|
|
149
154
|
buildVehicleTrackData(t, r) {
|
|
150
|
-
const l = t.longitude, a = t.latitude, s = t.ptcId, i = Number(t.ptcType), c = t.heading, n = Number(t.vehicleType),
|
|
155
|
+
const l = t.longitude, a = t.latitude, s = t.ptcId, i = Number(t.ptcType), c = t.heading, n = Number(t.vehicleType), d = Number(t.vehicleColor), e = t.plateNo || t.plateno, o = Number(t.plateColor), p = t.timestamp, h = t.roadLayer ? String(t.roadLayer) : "1";
|
|
151
156
|
if (!(i < 0 || i > 8))
|
|
152
157
|
return {
|
|
153
158
|
ptcId: s,
|
|
@@ -158,11 +163,11 @@ class L {
|
|
|
158
163
|
ptcType: i,
|
|
159
164
|
vehicleType: n,
|
|
160
165
|
heading: i === 2 ? -c : c,
|
|
161
|
-
vehicleColor:
|
|
162
|
-
showName:
|
|
163
|
-
plateNo:
|
|
164
|
-
plateColor:
|
|
165
|
-
timestamp:
|
|
166
|
+
vehicleColor: d,
|
|
167
|
+
showName: e && e !== "" && e !== "0" && e !== "000000" ? e : "",
|
|
168
|
+
plateNo: e,
|
|
169
|
+
plateColor: o,
|
|
170
|
+
timestamp: p,
|
|
166
171
|
localTimestamp: Date.now(),
|
|
167
172
|
roadLayer: h
|
|
168
173
|
};
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as w from "@arcgis/core/core/promiseUtils.js";
|
|
2
2
|
import * as b from "@arcgis/core/core/reactiveUtils.js";
|
|
3
3
|
import v from "@arcgis/core/geometry/SpatialReference";
|
|
4
4
|
import * as u from "@arcgis/core/views/3d/externalRenderers";
|
|
5
5
|
import * as l from "three";
|
|
6
|
-
import { GLTFLoader as y } from "three/examples/jsm/loaders/GLTFLoader
|
|
6
|
+
import { GLTFLoader as y } from "three/examples/jsm/loaders/GLTFLoader";
|
|
7
7
|
import { EVehiclePlateState as d } from "../../../types/index.mjs";
|
|
8
8
|
import G from "../../stores/index.mjs";
|
|
9
|
-
|
|
9
|
+
import C from "./vehicle-pool.mjs";
|
|
10
|
+
class N {
|
|
10
11
|
constructor(i) {
|
|
11
12
|
this.cameraHeightThreshold = 1e3, this.roughness = 0.2, this.metalness = 0.8, this.defaultMaterial = new l.MeshPhongMaterial({
|
|
12
13
|
color: 16777215
|
|
13
|
-
}), 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)],
|
|
@@ -28,8 +29,8 @@ class I {
|
|
|
28
29
|
JSON.stringify(e.mapConfig)
|
|
29
30
|
).assetsRoot, this.view = i, b.watch(
|
|
30
31
|
() => this.view.camera.position.z,
|
|
31
|
-
(t,
|
|
32
|
-
(
|
|
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
|
}
|
|
@@ -43,7 +44,7 @@ class I {
|
|
|
43
44
|
}
|
|
44
45
|
async init() {
|
|
45
46
|
const i = new y();
|
|
46
|
-
await
|
|
47
|
+
await w.eachAlways([
|
|
47
48
|
new Promise((e) => {
|
|
48
49
|
i.load(`${this.assetsRoot}/3DModels/car.glb`, (t) => {
|
|
49
50
|
this.carModel = t.scene, this.carModel.rotation.x = l.MathUtils.degToRad(90), e();
|
|
@@ -120,8 +121,8 @@ class I {
|
|
|
120
121
|
const e = this.renderer.setRenderTarget.bind(
|
|
121
122
|
this.renderer
|
|
122
123
|
);
|
|
123
|
-
this.renderer.setRenderTarget = (
|
|
124
|
-
e(
|
|
124
|
+
this.renderer.setRenderTarget = (o) => {
|
|
125
|
+
e(o), o == null && i.bindRenderTarget();
|
|
125
126
|
}, this.scene = new l.Scene();
|
|
126
127
|
const { camera: t } = i;
|
|
127
128
|
this.camera = new l.PerspectiveCamera(
|
|
@@ -132,19 +133,19 @@ class I {
|
|
|
132
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();
|
|
133
134
|
}
|
|
134
135
|
async render(i) {
|
|
135
|
-
var
|
|
136
|
+
var o;
|
|
136
137
|
const e = i.camera;
|
|
137
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(
|
|
138
139
|
new l.Vector3(e.center[0], e.center[1], e.center[2])
|
|
139
140
|
), this.camera.projectionMatrix.fromArray(e.projectionMatrix), !this.isPaused && this.needInterpolate)
|
|
140
|
-
for (const
|
|
141
|
-
const n = (
|
|
141
|
+
for (const s of this.vehicleObjectMap.keys()) {
|
|
142
|
+
const n = (o = this.vehicleObjectMap.get(s)) == null ? void 0 : o.model;
|
|
142
143
|
if (!n)
|
|
143
144
|
continue;
|
|
144
|
-
const
|
|
145
|
-
if (
|
|
146
|
-
const h = this.toRenderCoordinates(
|
|
147
|
-
n.position.set(h[0], h[1], h[2]), n.rotation.y = l.MathUtils.degToRad(-
|
|
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]);
|
|
148
149
|
}
|
|
149
150
|
}
|
|
150
151
|
const t = i.sunLight;
|
|
@@ -164,12 +165,12 @@ class I {
|
|
|
164
165
|
async addVehicles(i) {
|
|
165
166
|
if (!(this.isPaused || !this.isInitialized))
|
|
166
167
|
for (const e of i) {
|
|
167
|
-
const { vehicleId: t, localTimestamp:
|
|
168
|
+
const { vehicleId: t, localTimestamp: o } = e, s = Number(e.x), n = Number(e.y), a = Number(e.heading);
|
|
168
169
|
this.historyPositionMap.set(t, [
|
|
169
|
-
{ pos: [
|
|
170
|
+
{ pos: [s, n, 0], heading: a, time: o }
|
|
170
171
|
]);
|
|
171
172
|
const h = this.getVehicleModel(e);
|
|
172
|
-
h.name = t, h.visible = !
|
|
173
|
+
h.name = t, h.visible = !1;
|
|
173
174
|
try {
|
|
174
175
|
const r = await this.createPlateSprite(e);
|
|
175
176
|
r && (h.add(r), r.position.set(0, 5, -4));
|
|
@@ -192,16 +193,16 @@ class I {
|
|
|
192
193
|
return;
|
|
193
194
|
const e = [];
|
|
194
195
|
for (const t of i) {
|
|
195
|
-
const { vehicleId:
|
|
196
|
+
const { vehicleId: o, timestamp: s } = t, n = Number(t.x), a = Number(t.y);
|
|
196
197
|
let h = Number(t.heading);
|
|
197
|
-
const r = this.vehicleObjectMap.get(
|
|
198
|
-
|
|
198
|
+
const r = this.vehicleObjectMap.get(o), m = this.historyPositionMap.get(
|
|
199
|
+
o
|
|
199
200
|
);
|
|
200
201
|
if (!r || !m)
|
|
201
202
|
e.push(t);
|
|
202
203
|
else {
|
|
203
|
-
if (
|
|
204
|
-
this.
|
|
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;
|
|
205
206
|
const c = await this.createPlateSprite(t);
|
|
206
207
|
c && (r.model.add(c), c.position.set(0, 5, -4)), this.scene.add(r.model);
|
|
207
208
|
}
|
|
@@ -214,15 +215,15 @@ class I {
|
|
|
214
215
|
if (r.data = t, this.needInterpolate) {
|
|
215
216
|
const c = m[m.length - 1];
|
|
216
217
|
Math.abs(h - c.heading) >= 180 && (h > c.heading ? c.heading += 360 : h += 360), m.push({
|
|
217
|
-
pos: [n,
|
|
218
|
+
pos: [n, a, 0],
|
|
218
219
|
heading: h,
|
|
219
|
-
time:
|
|
220
|
+
time: s
|
|
220
221
|
});
|
|
221
222
|
} else {
|
|
222
|
-
this.historyPositionMap.set(
|
|
223
|
-
{ pos: [n,
|
|
223
|
+
this.historyPositionMap.set(o, [
|
|
224
|
+
{ pos: [n, a, 0], heading: h, time: s }
|
|
224
225
|
]);
|
|
225
|
-
const c = this.toRenderCoordinates([n,
|
|
226
|
+
const c = this.toRenderCoordinates([n, a, 0]);
|
|
226
227
|
r.model.position.set(c[0], c[1], c[2]), r.model.rotation.y = l.MathUtils.degToRad(-h);
|
|
227
228
|
}
|
|
228
229
|
}
|
|
@@ -252,7 +253,7 @@ class I {
|
|
|
252
253
|
});
|
|
253
254
|
}
|
|
254
255
|
deleteVehicle(i) {
|
|
255
|
-
this.
|
|
256
|
+
this.vehiclePool.recycleInstance(i.model);
|
|
256
257
|
const e = i.data.vehicleId;
|
|
257
258
|
this.vehicleObjectMap.delete(e), this.historyPositionMap.delete(e);
|
|
258
259
|
}
|
|
@@ -270,7 +271,7 @@ class I {
|
|
|
270
271
|
clearVehicles() {
|
|
271
272
|
for (const i of this.vehicleObjectMap.keys()) {
|
|
272
273
|
const e = this.vehicleObjectMap.get(i);
|
|
273
|
-
e &&
|
|
274
|
+
e && this.vehiclePool.recycleInstance(e.model);
|
|
274
275
|
}
|
|
275
276
|
this.vehicleObjectMap.clear(), this.historyPositionMap.clear();
|
|
276
277
|
}
|
|
@@ -285,10 +286,10 @@ class I {
|
|
|
285
286
|
for (const e of this.vehicleObjectMap.keys()) {
|
|
286
287
|
const t = this.vehicleObjectMap.get(e);
|
|
287
288
|
if (t) {
|
|
288
|
-
const
|
|
289
|
-
if (
|
|
290
|
-
const
|
|
291
|
-
|
|
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));
|
|
292
293
|
}
|
|
293
294
|
}
|
|
294
295
|
}
|
|
@@ -315,10 +316,10 @@ class I {
|
|
|
315
316
|
const e = this.historyPositionMap.get(i), t = this.vehicleObjectMap.get(i);
|
|
316
317
|
if (!t || !e || !t.isMoving && e.length <= 2)
|
|
317
318
|
return;
|
|
318
|
-
const
|
|
319
|
-
t.isMoving = !0, t.data.roadLayer === "1" ? t.model.visible = this.showGroundVehicle : t.model.visible = this.showElevatedVehicle, t.segmentStartTime || (t.segmentStartTime =
|
|
320
|
-
const
|
|
321
|
-
|
|
319
|
+
const o = Date.now();
|
|
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,
|
|
322
323
|
1
|
|
323
324
|
);
|
|
324
325
|
if (n === 1)
|
|
@@ -328,8 +329,8 @@ class I {
|
|
|
328
329
|
} else
|
|
329
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);
|
|
330
331
|
else if (e.length >= 2) {
|
|
331
|
-
const
|
|
332
|
-
return [
|
|
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];
|
|
333
334
|
} else
|
|
334
335
|
return;
|
|
335
336
|
}
|
|
@@ -368,9 +369,9 @@ class I {
|
|
|
368
369
|
break;
|
|
369
370
|
}
|
|
370
371
|
const t = this.materialMap.get(i.vehicleColor) || this.defaultMaterial;
|
|
371
|
-
let
|
|
372
|
-
e.traverse((
|
|
373
|
-
!
|
|
372
|
+
let o = !1;
|
|
373
|
+
e.traverse((s) => {
|
|
374
|
+
!o && s instanceof l.Mesh && (s.material = t, o = !0);
|
|
374
375
|
});
|
|
375
376
|
}
|
|
376
377
|
return e;
|
|
@@ -380,70 +381,70 @@ class I {
|
|
|
380
381
|
* 创建号牌canvas
|
|
381
382
|
* */
|
|
382
383
|
createCanvas(i, e, t) {
|
|
383
|
-
const
|
|
384
|
-
|
|
385
|
-
const
|
|
386
|
-
if (!
|
|
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) {
|
|
387
388
|
console.log("canvas创建失败");
|
|
388
389
|
return;
|
|
389
390
|
}
|
|
390
|
-
return
|
|
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;
|
|
391
392
|
}
|
|
392
393
|
createPlateSprite(i) {
|
|
393
394
|
return new Promise((e, t) => {
|
|
394
395
|
var r, m;
|
|
395
|
-
const
|
|
396
|
-
if (this.currentSpriteContent === d.None || this.currentSpriteContent === d.PlateNumber &&
|
|
396
|
+
const o = !i.plateNo || i.plateNo === "0" || i.plateNo === "000000";
|
|
397
|
+
if (this.currentSpriteContent === d.None || this.currentSpriteContent === d.PlateNumber && o) {
|
|
397
398
|
e(void 0);
|
|
398
399
|
return;
|
|
399
400
|
}
|
|
400
|
-
let
|
|
401
|
+
let s = new Image(), n = "", a = "";
|
|
401
402
|
if (this.currentSpriteContent === d.PlateNumber || this.currentSpriteContent === d.Mix)
|
|
402
|
-
if (
|
|
403
|
-
|
|
403
|
+
if (o)
|
|
404
|
+
s = this.greyPlateBG, n = i.ptcId, a = "#ffffff";
|
|
404
405
|
else
|
|
405
406
|
switch (n = ((r = i.showName) == null ? void 0 : r.substring(0, 2)) + "•" + ((m = i.showName) == null ? void 0 : m.substring(2)), i.plateColor) {
|
|
406
407
|
case 1:
|
|
407
|
-
|
|
408
|
+
s = this.bluePlateBG, a = "#ffffff";
|
|
408
409
|
break;
|
|
409
410
|
case 2:
|
|
410
|
-
|
|
411
|
+
s = this.yellowPlateBG, a = "#000000";
|
|
411
412
|
break;
|
|
412
413
|
case 3:
|
|
413
|
-
|
|
414
|
+
s = this.whitePlateBG, a = "#000000";
|
|
414
415
|
break;
|
|
415
416
|
case 4:
|
|
416
|
-
|
|
417
|
+
s = this.blackPlateBG, a = "#ffffff";
|
|
417
418
|
break;
|
|
418
419
|
case 5:
|
|
419
|
-
|
|
420
|
+
s = this.neoYellowPlateBG, a = "#000000";
|
|
420
421
|
break;
|
|
421
422
|
case 6:
|
|
422
|
-
|
|
423
|
+
s = this.neoGreenPlateBG, a = "#000000";
|
|
423
424
|
break;
|
|
424
425
|
default:
|
|
425
|
-
|
|
426
|
+
s = this.greyPlateBG, n = i.plateNo, a = "#ffffff";
|
|
426
427
|
break;
|
|
427
428
|
}
|
|
428
429
|
else
|
|
429
|
-
this.currentSpriteContent === d.Id && (
|
|
430
|
-
const h = this.createCanvas(
|
|
430
|
+
this.currentSpriteContent === d.Id && (s = this.greyPlateBG, n = i.ptcId, a = "#ffffff");
|
|
431
|
+
const h = this.createCanvas(s, n, a);
|
|
431
432
|
if (h) {
|
|
432
433
|
const c = new l.CanvasTexture(h), p = new l.SpriteMaterial({
|
|
433
434
|
map: c,
|
|
434
435
|
transparent: !1
|
|
435
|
-
}), g = new l.Sprite(p), f = 0.05, M = h.width * f,
|
|
436
|
-
g.scale.set(M,
|
|
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);
|
|
437
438
|
} else {
|
|
438
439
|
t("canvas创建失败");
|
|
439
440
|
return;
|
|
440
441
|
}
|
|
441
|
-
|
|
442
|
-
console.log(`号牌背景加载失败: ${
|
|
442
|
+
s.onerror = (c) => {
|
|
443
|
+
console.log(`号牌背景加载失败: ${s.src}`, c), t(c);
|
|
443
444
|
};
|
|
444
445
|
});
|
|
445
446
|
}
|
|
446
447
|
}
|
|
447
448
|
export {
|
|
448
|
-
|
|
449
|
+
N as default
|
|
449
450
|
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import * as Three from 'three';
|
|
2
|
+
import { IVehicleTrack } from '../../../types';
|
|
3
|
+
export declare enum EModelStatus {
|
|
4
|
+
/** 未使用 */
|
|
5
|
+
UNUSED = "unused",
|
|
6
|
+
/** 使用中 */
|
|
7
|
+
USED = "used",
|
|
8
|
+
/** 已销毁 */
|
|
9
|
+
DESTROYED = "destroyed"
|
|
10
|
+
}
|
|
11
|
+
declare type VehicleModelType = Three.Group | Three.Mesh;
|
|
12
|
+
export default class VehiclePool {
|
|
13
|
+
private createCarMaterial;
|
|
14
|
+
/** 车身颜色材质 */
|
|
15
|
+
private materialMap;
|
|
16
|
+
private readonly carPool;
|
|
17
|
+
private readonly vanPool;
|
|
18
|
+
private readonly truckPool;
|
|
19
|
+
private readonly busPool;
|
|
20
|
+
private bicyclePool;
|
|
21
|
+
private ballPool;
|
|
22
|
+
private readonly poolSize;
|
|
23
|
+
private view;
|
|
24
|
+
/** 车辆模型变化的阈值 */
|
|
25
|
+
private readonly cameraHeightThreshold;
|
|
26
|
+
initPool(assetsRoot: string, view: __esri.SceneView): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* 获取实例
|
|
29
|
+
* @param data
|
|
30
|
+
*/
|
|
31
|
+
getInstance(data: IVehicleTrack): VehicleModelType;
|
|
32
|
+
/**
|
|
33
|
+
* 回收实例
|
|
34
|
+
* @param instance
|
|
35
|
+
*/
|
|
36
|
+
recycleInstance(instance: VehicleModelType): void;
|
|
37
|
+
private getInstanceFromPool;
|
|
38
|
+
private getInstanceFromList;
|
|
39
|
+
private materialModel;
|
|
40
|
+
}
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import * as h from "@arcgis/core/core/promiseUtils.js";
|
|
2
|
+
import * as i from "three";
|
|
3
|
+
import { GLTFLoader as u } from "three/examples/jsm/loaders/GLTFLoader.js";
|
|
4
|
+
class d {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.materialMap = /* @__PURE__ */ new Map([
|
|
7
|
+
[1, this.createCarMaterial(16777215)],
|
|
8
|
+
[2, this.createCarMaterial(7833753)],
|
|
9
|
+
[3, this.createCarMaterial(16766720)],
|
|
10
|
+
[4, this.createCarMaterial(16758465)],
|
|
11
|
+
[5, this.createCarMaterial(14423100)],
|
|
12
|
+
[6, this.createCarMaterial(3329330)],
|
|
13
|
+
[7, this.createCarMaterial(2003183)],
|
|
14
|
+
[8, this.createCarMaterial(16032864)],
|
|
15
|
+
[9, this.createCarMaterial(2105376)],
|
|
16
|
+
[10, this.createCarMaterial(9662683)],
|
|
17
|
+
[99, this.createCarMaterial(6908265)]
|
|
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
|
+
}
|
|
20
|
+
createCarMaterial(t) {
|
|
21
|
+
return new i.MeshPhongMaterial({
|
|
22
|
+
color: t
|
|
23
|
+
// // emissive: 0xc3c3c3,
|
|
24
|
+
// roughness: this.roughness,
|
|
25
|
+
// metalness: this.metalness
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
async initPool(t, a) {
|
|
29
|
+
this.view = a;
|
|
30
|
+
const s = new u();
|
|
31
|
+
await h.eachAlways([
|
|
32
|
+
new Promise((o) => {
|
|
33
|
+
s.load(`${t}/3DModels/car.glb`, (l) => {
|
|
34
|
+
const e = l.scene;
|
|
35
|
+
e.rotation.x = i.MathUtils.degToRad(90), e.userData = {
|
|
36
|
+
status: "unused"
|
|
37
|
+
/* UNUSED */
|
|
38
|
+
}, this.materialMap.forEach((n, c) => {
|
|
39
|
+
const r = e.clone();
|
|
40
|
+
this.materialModel(r, n), this.carPool.set(
|
|
41
|
+
c,
|
|
42
|
+
Array.from({ length: this.poolSize }, () => r.clone())
|
|
43
|
+
);
|
|
44
|
+
}), o();
|
|
45
|
+
});
|
|
46
|
+
}),
|
|
47
|
+
new Promise((o) => {
|
|
48
|
+
s.load(`${t}/3DModels/van.glb`, (l) => {
|
|
49
|
+
const e = l.scene;
|
|
50
|
+
e.rotation.x = i.MathUtils.degToRad(90), e.userData = {
|
|
51
|
+
status: "unused"
|
|
52
|
+
/* UNUSED */
|
|
53
|
+
}, this.materialMap.forEach((n, c) => {
|
|
54
|
+
const r = e.clone();
|
|
55
|
+
this.materialModel(r, n), this.vanPool.set(
|
|
56
|
+
c,
|
|
57
|
+
Array.from({ length: this.poolSize }, () => r.clone())
|
|
58
|
+
);
|
|
59
|
+
}), o();
|
|
60
|
+
});
|
|
61
|
+
}),
|
|
62
|
+
new Promise((o) => {
|
|
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
|
+
status: "unused"
|
|
67
|
+
/* UNUSED */
|
|
68
|
+
}, this.materialMap.forEach((n, c) => {
|
|
69
|
+
const r = e.clone();
|
|
70
|
+
this.materialModel(r, n), this.truckPool.set(
|
|
71
|
+
c,
|
|
72
|
+
Array.from({ length: this.poolSize }, () => r.clone())
|
|
73
|
+
);
|
|
74
|
+
}), o();
|
|
75
|
+
});
|
|
76
|
+
}),
|
|
77
|
+
new Promise((o) => {
|
|
78
|
+
s.load(`${t}/3DModels/bus.glb`, (l) => {
|
|
79
|
+
const e = l.scene;
|
|
80
|
+
e.rotation.x = i.MathUtils.degToRad(90), e.userData = {
|
|
81
|
+
status: "unused"
|
|
82
|
+
/* UNUSED */
|
|
83
|
+
}, this.materialMap.forEach((n, c) => {
|
|
84
|
+
const r = e.clone();
|
|
85
|
+
r.userData = {
|
|
86
|
+
status: "unused"
|
|
87
|
+
/* UNUSED */
|
|
88
|
+
}, this.materialModel(r, n), this.busPool.set(
|
|
89
|
+
c,
|
|
90
|
+
Array.from({ length: this.poolSize }, () => r.clone())
|
|
91
|
+
);
|
|
92
|
+
}), o();
|
|
93
|
+
});
|
|
94
|
+
}),
|
|
95
|
+
new Promise((o) => {
|
|
96
|
+
s.load(`${t}/3DModels/bicycle.glb`, (l) => {
|
|
97
|
+
const e = l.scene;
|
|
98
|
+
e.userData = {
|
|
99
|
+
status: "unused"
|
|
100
|
+
/* UNUSED */
|
|
101
|
+
}, e.rotation.x = i.MathUtils.degToRad(90), e.rotation.y = i.MathUtils.degToRad(180), e.userData = {
|
|
102
|
+
status: "unused"
|
|
103
|
+
/* UNUSED */
|
|
104
|
+
}, this.bicyclePool = Array.from(
|
|
105
|
+
{ length: this.poolSize },
|
|
106
|
+
() => e.clone()
|
|
107
|
+
), o();
|
|
108
|
+
});
|
|
109
|
+
}),
|
|
110
|
+
new Promise((o) => {
|
|
111
|
+
const l = new i.SphereGeometry(5, 32, 32), e = new i.MeshPhysicalMaterial({
|
|
112
|
+
color: 325253,
|
|
113
|
+
emissive: 0,
|
|
114
|
+
roughness: 0.2,
|
|
115
|
+
metalness: 0.8
|
|
116
|
+
});
|
|
117
|
+
this.ballPool = Array.from({ length: 100 }, () => {
|
|
118
|
+
const n = new i.Mesh(l, e);
|
|
119
|
+
return n.userData = {
|
|
120
|
+
status: "unused"
|
|
121
|
+
/* UNUSED */
|
|
122
|
+
}, n;
|
|
123
|
+
}), o();
|
|
124
|
+
})
|
|
125
|
+
]);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* 获取实例
|
|
129
|
+
* @param data
|
|
130
|
+
*/
|
|
131
|
+
getInstance(t) {
|
|
132
|
+
if (this.view.camera.position.z >= this.cameraHeightThreshold)
|
|
133
|
+
return this.getInstanceFromList(this.ballPool);
|
|
134
|
+
{
|
|
135
|
+
const a = t.vehicleColor;
|
|
136
|
+
if (t.ptcType === 2)
|
|
137
|
+
return this.getInstanceFromList(this.bicyclePool);
|
|
138
|
+
switch (t.vehicleType) {
|
|
139
|
+
case 1:
|
|
140
|
+
case 10:
|
|
141
|
+
return this.getInstanceFromPool(a, this.carPool);
|
|
142
|
+
case 20:
|
|
143
|
+
return this.getInstanceFromPool(a, this.vanPool);
|
|
144
|
+
case 25:
|
|
145
|
+
return this.getInstanceFromPool(a, this.truckPool);
|
|
146
|
+
case 50:
|
|
147
|
+
return this.getInstanceFromPool(a, this.busPool);
|
|
148
|
+
default:
|
|
149
|
+
return this.getInstanceFromPool(a, this.carPool);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* 回收实例
|
|
155
|
+
* @param instance
|
|
156
|
+
*/
|
|
157
|
+
recycleInstance(t) {
|
|
158
|
+
t.visible = !1, t.userData.status = "unused";
|
|
159
|
+
}
|
|
160
|
+
getInstanceFromPool(t, a) {
|
|
161
|
+
let s = a.get(t);
|
|
162
|
+
return s || (s = a.get(99)), this.getInstanceFromList(s);
|
|
163
|
+
}
|
|
164
|
+
getInstanceFromList(t) {
|
|
165
|
+
let a = t.find(
|
|
166
|
+
(s) => s.userData.status === "unused"
|
|
167
|
+
/* UNUSED */
|
|
168
|
+
);
|
|
169
|
+
return a || (a = t[0].clone(), t.push(a), console.log("increase pool. pool size:", t.length)), a.userData.status = "used", a;
|
|
170
|
+
}
|
|
171
|
+
materialModel(t, a) {
|
|
172
|
+
let s = !1;
|
|
173
|
+
t.traverse((o) => {
|
|
174
|
+
!s && o instanceof i.Mesh && (o.material = a, s = !0);
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
export {
|
|
179
|
+
d as default
|
|
180
|
+
};
|
package/es/src/types/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* 45° ~ 135°:东象限。
|
|
6
6
|
* 135° ~ 225°:南象限。
|
|
7
7
|
*/
|
|
8
|
+
import Three from 'three';
|
|
8
9
|
export declare enum QuadrantCode {
|
|
9
10
|
West = "1",
|
|
10
11
|
North = "2",
|
|
@@ -37,6 +38,15 @@ export interface IVehicleTrack {
|
|
|
37
38
|
plateNo?: string;
|
|
38
39
|
roadLayer?: string;
|
|
39
40
|
}
|
|
41
|
+
export interface IVehicleRecord {
|
|
42
|
+
model: Three.Group | Three.Mesh;
|
|
43
|
+
data: IVehicleTrack;
|
|
44
|
+
segmentStartTime?: number;
|
|
45
|
+
segmentTotalTime?: number;
|
|
46
|
+
waitForDelete: boolean;
|
|
47
|
+
isMoving: boolean;
|
|
48
|
+
currentPos?: number[];
|
|
49
|
+
}
|
|
40
50
|
export interface ILaneNumberParams {
|
|
41
51
|
lanes: {
|
|
42
52
|
crossId: string;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const g=require("@arcgis/core/views/3d/externalRenderers"),m=require("../../stores/index.js"),b=require("./trace-renderer-external.js"),f=require("./trace-renderer-layer.js");function T(
|
|
2
|
-
`).replace(/null/g,""),r=new Blob([
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const g=require("@arcgis/core/views/3d/externalRenderers"),m=require("../../stores/index.js"),b=require("./trace-renderer-external.js"),f=require("./trace-renderer-layer.js");function T(l){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(l){for(const r in l)if(r!=="default"){const n=Object.getOwnPropertyDescriptor(l,r);Object.defineProperty(e,r,n.get?n:{enumerable:!0,get:()=>l[r]})}}return e.default=l,Object.freeze(e)}const y=T(g);class v{constructor(e){this.appDataStore=m.default.useAppDataStore,this.logTable=[["uuid","ptcId","plateno","timestamp","localTimestamp","timestamp_str","speed","laneNo","objHeight","objLength","latitude","longitude","ptcType","vehicleType","vehicleColor","plateColor","sbdm","heading","fixAngle","roadLayer","status","step","receiveTimestamp"]],e.type==="3d"?(this.traceRenderer=new b.default(e),y.add(e,this.traceRenderer)):this.traceRenderer=new f.default(e)}async init(){await this.traceRenderer.init()}downloadLog(){const e=this.logTable.map(c=>c.join(",")).join(`
|
|
2
|
+
`).replace(/null/g,""),r=new Blob([e],{type:"text/csv;charset=utf-8;"}),n=URL.createObjectURL(r),a=document.createElement("a");a.setAttribute("href",n),a.setAttribute("download","trace-log.csv"),a.style.visibility="hidden",document.body.appendChild(a),a.click(),document.body.removeChild(a)}async handleVehicleTraceData(e){const{newVehList:r,updateVehList:n,deleteVehList:a,jgsj:c}=e,i=e.crossId||"",s=[],d=[],h=Date.now();if(r&&r.length>0){for(const t of r){t.localTimestamp||(t.localTimestamp=c||Date.now()),this.appDataStore.saveTrackLog&&this.logTable.push([t.uuid,t.ptcId,t.plateno,t.timestamp,t.localTimestamp,t.timestamp_str,t.speed,t.laneNo,t.objHeight,t.objLength,t.latitude,t.longitude,t.ptcType,t.vehicleType,t.vehicleColor,t.plateColor,t.sbdm,t.heading,t.fixAngle,t.roadLayer,t.status,t.step,h]);const o=this.buildVehicleTrackData(t,i);o&&s.push(o)}await this.traceRenderer.addVehicles(s)}if(n&&n.length>0){const t=Date.now();for(const o of n){this.appDataStore.saveTrackLog&&this.logTable.push([o.uuid,o.ptcId,o.plateno,o.timestamp,o.localTimestamp,o.timestamp_str,o.speed,o.laneNo,o.objHeight,o.objLength,o.latitude,o.longitude,o.ptcType,o.vehicleType,o.vehicleColor,o.plateColor,o.sbdm,o.heading,o.fixAngle,o.roadLayer,o.status,o.step,t]);const p=this.buildVehicleTrackData(o,i);p&&d.push(p)}await this.traceRenderer.updateVehicles(d)}if(a&&a.length>0){const t=a.map(o=>i+"-"+(o.ptcId||o.vehno||o.vehNo));this.traceRenderer.deleteVehicles(t)}}toggleTrafficInfo(e){this.traceRenderer.toggleTrafficInfo(e)}clearTrace(){this.traceRenderer.clearVehicles()}togglePause(e){this.traceRenderer.togglePause(e)}updatePanelContent(e){this.traceRenderer.updatePanelContent(e)}toggleGroundVehicle(e){this.traceRenderer.toggleGroundVehicle(e)}toggleElevatedVehicle(e){this.traceRenderer.toggleElevatedVehicle(e)}setInterpolate(e){this.traceRenderer.setInterpolate(e)}buildVehicleTrackData(e,r){const n=e.longitude,a=e.latitude,c=e.ptcId,i=Number(e.ptcType),s=e.heading,d=Number(e.vehicleType),h=Number(e.vehicleColor),t=e.plateNo||e.plateno,o=Number(e.plateColor),p=e.timestamp,u=e.roadLayer?String(e.roadLayer):"1";if(!(i<0||i>8))return{ptcId:c,crossId:r,vehicleId:r+"-"+c,x:n,y:a,ptcType:i,vehicleType:d,heading:i===2?-s:s,vehicleColor:h,showName:t&&t!==""&&t!=="0"&&t!=="000000"?t:"",plateNo:t,plateColor:o,timestamp:p,localTimestamp:Date.now(),roadLayer:u}}}exports.default=v;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const v=require("@arcgis/core/core/promiseUtils.js"),y=require("@arcgis/core/core/reactiveUtils.js"),S=require("@arcgis/core/geometry/SpatialReference"),G=require("@arcgis/core/views/3d/externalRenderers"),C=require("three"),T=require("three/examples/jsm/loaders/GLTFLoader.js"),d=require("../../../types/index.js"),B=require("../../stores/index.js");function u(m){const i=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(m){for(const e in m)if(e!=="default"){const t=Object.getOwnPropertyDescriptor(m,e);Object.defineProperty(i,e,t.get?t:{enumerable:!0,get:()=>m[e]})}}return i.default=m,Object.freeze(i)}const R=u(v),V=u(y),M=u(G),l=u(C);class I{constructor(i){this.cameraHeightThreshold=1e3,this.roughness=.2,this.metalness=.8,this.defaultMaterial=new l.MeshPhongMaterial({color:16777215}),this.materialMap=new Map([[1,this.createCarMaterial(16777215)],[2,this.createCarMaterial(7833753)],[3,this.createCarMaterial(16766720)],[4,this.createCarMaterial(16758465)],[5,this.createCarMaterial(14423100)],[6,this.createCarMaterial(3329330)],[7,this.createCarMaterial(2003183)],[8,this.createCarMaterial(16032864)],[9,this.createCarMaterial(2105376)],[10,this.createCarMaterial(9662683)],[99,this.createCarMaterial(6908265)]]),this.isInitialized=!1,this.showGroundVehicle=!0,this.showElevatedVehicle=!0,this.isPaused=!1,this.currentSpriteContent=d.EVehiclePlateState.None,this.historyPositionMap=new Map,this.vehicleObjectMap=new Map,this.needInterpolate=!0,this.updateModel=!1;const e=B.default.useAppDataStore;this.assetsRoot=JSON.parse(JSON.stringify(e.mapConfig)).assetsRoot,this.view=i,V.watch(()=>this.view.camera.position.z,(t,s)=>{(s<=this.cameraHeightThreshold&&t>this.cameraHeightThreshold||s>this.cameraHeightThreshold&&t<=this.cameraHeightThreshold)&&(this.updateModel=!0)})}createCarMaterial(i){return new l.MeshPhongMaterial({color:i})}async init(){const i=new T.GLTFLoader;await R.eachAlways([new Promise(e=>{i.load(`${this.assetsRoot}/3DModels/car.glb`,t=>{this.carModel=t.scene,this.carModel.rotation.x=l.MathUtils.degToRad(90),e()})}),new Promise(e=>{i.load(`${this.assetsRoot}/3DModels/van.glb`,t=>{this.vanModel=t.scene,this.vanModel.rotation.x=l.MathUtils.degToRad(90),e()})}),new Promise(e=>{i.load(`${this.assetsRoot}/3DModels/truck.glb`,t=>{this.truckModel=t.scene,this.truckModel.scale.set(1.2,1,1.5),this.truckModel.rotation.x=l.MathUtils.degToRad(90),e()})}),new Promise(e=>{i.load(`${this.assetsRoot}/3DModels/bus.glb`,t=>{this.busModel=t.scene,this.busModel.rotation.x=l.MathUtils.degToRad(90),e()})}),new Promise(e=>{i.load(`${this.assetsRoot}/3DModels/bicycle.glb`,t=>{this.bicycleModel=t.scene,this.bicycleModel.rotation.x=l.MathUtils.degToRad(90),this.bicycleModel.rotation.y=l.MathUtils.degToRad(180),e()})}),new Promise(e=>{this.bluePlateBG=new Image,this.bluePlateBG.src=`${this.assetsRoot}/Images/PlateBG/blue.png`,this.bluePlateBG.onload=()=>{e()}}),new Promise(e=>{this.yellowPlateBG=new Image,this.yellowPlateBG.src=`${this.assetsRoot}/Images/PlateBG/yellow.png`,this.yellowPlateBG.onload=()=>{e()}}),new Promise(e=>{this.whitePlateBG=new Image,this.whitePlateBG.src=`${this.assetsRoot}/Images/PlateBG/white.png`,this.whitePlateBG.onload=()=>{e()}}),new Promise(e=>{this.blackPlateBG=new Image,this.blackPlateBG.src=`${this.assetsRoot}/Images/PlateBG/black.png`,this.blackPlateBG.onload=()=>{e()}}),new Promise(e=>{this.neoYellowPlateBG=new Image,this.neoYellowPlateBG.src=`${this.assetsRoot}/Images/PlateBG/neo_yellow.png`,this.neoYellowPlateBG.onload=()=>{e()}}),new Promise(e=>{this.neoGreenPlateBG=new Image,this.neoGreenPlateBG.src=`${this.assetsRoot}/Images/PlateBG/neo_green.png`,this.neoGreenPlateBG.onload=()=>{e()}}),new Promise(e=>{this.greyPlateBG=new Image,this.greyPlateBG.src=`${this.assetsRoot}/Images/PlateBG/grey.png`,this.greyPlateBG.onload=()=>{e()}})]),this.isInitialized=!0}setInterpolate(i){this.clearVehicles(),this.needInterpolate=i}async setup(i){this.context=i,this.renderer=new l.WebGLRenderer({context:i.gl,premultipliedAlpha:!0,logarithmicDepthBuffer:!0,antialias:!0,powerPreference:"high-performance"}),this.renderer.shadowMap.enabled=!0,this.renderer.setPixelRatio(window.devicePixelRatio),this.renderer.setViewport(0,0,this.view.width,this.view.height),this.renderer.autoClearDepth=!1,this.renderer.autoClearStencil=!1,this.renderer.autoClearColor=!1;const e=this.renderer.setRenderTarget.bind(this.renderer);this.renderer.setRenderTarget=s=>{e(s),s==null&&i.bindRenderTarget()},this.scene=new l.Scene;const{camera:t}=i;this.camera=new l.PerspectiveCamera(t.fovY,t.aspect,.1,1e5),this.ambient=new l.AmbientLight(16777215,2),this.scene.add(this.ambient),this.sun=new l.DirectionalLight(16777215,2),this.scene.add(this.sun),i.resetWebGLState()}async render(i){var s;const e=i.camera;if(this.camera.position.set(e.eye[0],e.eye[1],e.eye[2]),this.camera.up.set(e.up[0],e.up[1],e.up[2]),this.camera.lookAt(new l.Vector3(e.center[0],e.center[1],e.center[2])),this.camera.projectionMatrix.fromArray(e.projectionMatrix),!this.isPaused&&this.needInterpolate)for(const a of this.vehicleObjectMap.keys()){const n=(s=this.vehicleObjectMap.get(a))==null?void 0:s.model;if(!n)continue;const o=this.computeVehiclePosition(a);if(o){const h=this.toRenderCoordinates(o);n.position.set(h[0],h[1],h[2]),n.rotation.y=l.MathUtils.degToRad(-o[3])}}const t=i.sunLight;this.sun.position.set(t.direction[0],t.direction[1],t.direction[2]),this.sun.intensity=t.diffuse.intensity,this.sun.color=new l.Color(t.diffuse.color[0],t.diffuse.color[1],t.diffuse.color[2]),this.ambient.intensity=t.ambient.intensity,this.ambient.color=new l.Color(t.ambient.color[0],t.ambient.color[1],t.ambient.color[2]),this.renderer.resetState(),i.bindRenderTarget(),this.renderer.render(this.scene,this.camera),M.requestRender(this.view),i.resetWebGLState()}async addVehicles(i){if(!(this.isPaused||!this.isInitialized))for(const e of i){const{vehicleId:t,localTimestamp:s}=e,a=Number(e.x),n=Number(e.y),o=Number(e.heading);this.historyPositionMap.set(t,[{pos:[a,n,0],heading:o,time:s}]);const h=this.getVehicleModel(e);h.name=t,h.visible=!this.needInterpolate;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:s,timestamp:a}=t,n=Number(t.x),o=Number(t.y);let h=Number(t.heading);const r=this.vehicleObjectMap.get(s),p=this.historyPositionMap.get(s);if(!r||!p)e.push(t);else{if(p.length>=5&&console.log(s,p.length),this.updateModel||r.data.vehicleColor!==t.vehicleColor||r.data.vehicleType!==t.vehicleType){this.scene.remove(r.model),this.disposeModel(r.model),r.model=this.getVehicleModel(t);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,o,0],heading:h,time:a})}else{this.historyPositionMap.set(s,[{pos:[n,o,0],heading:h,time:a}]);const c=this.toRenderCoordinates([n,o,0]);r.model.position.set(c[0],c[1],c[2]),r.model.rotation.y=l.MathUtils.degToRad(-h)}}}await this.addVehicles(e),this.updateModel=!1,this.needInterpolate||this.render(this.context)}toRenderCoordinates(i){const e=[0,0,0];return M.toRenderCoordinates(this.view,i,0,S.WGS84,e,0,1),e}deleteVehicles(i){this.isPaused||i.forEach(e=>{const t=this.vehicleObjectMap.get(e);t&&(this.needInterpolate?t.isMoving?t.waitForDelete=!0:this.deleteVehicle(t):this.deleteVehicle(t))})}deleteVehicle(i){this.scene.remove(i.model),this.disposeModel(i.model);const e=i.data.vehicleId;this.vehicleObjectMap.delete(e),this.historyPositionMap.delete(e)}async toggleTrafficInfo(i){i.name==="vehiclePlate"&&(i.visible===!0&&this.currentSpriteContent===d.EVehiclePlateState.None?await this.updatePanelContent(d.EVehiclePlateState.PlateNumber):await this.updatePanelContent(i.visible?this.currentSpriteContent:d.EVehiclePlateState.None))}togglePause(i){this.isPaused=i}clearVehicles(){for(const i of this.vehicleObjectMap.keys()){const e=this.vehicleObjectMap.get(i);e&&(this.disposeModel(e.model),this.scene.remove(e.model))}this.vehicleObjectMap.clear(),this.historyPositionMap.clear()}async updatePanelContent(i){if(i!==this.currentSpriteContent){this.currentSpriteContent=i;for(const e of this.vehicleObjectMap.keys()){const t=this.vehicleObjectMap.get(e);if(t){const s=t.model.getObjectByName("VehiclePlate");if(s&&(t.model.remove(s),this.disposeModel(s)),i!==d.EVehiclePlateState.None){const a=await this.createPlateSprite(t.data);a&&(t.model.add(a),a.position.set(0,5,-4))}}}}}toggleGroundVehicle(i){console.log("toggleGroundVehicle",i),this.showGroundVehicle=i}toggleElevatedVehicle(i){this.showElevatedVehicle=i}disposeModel(i){i.traverse(e=>{e instanceof l.Mesh&&(e.geometry.dispose(),e.material.dispose())})}computeVehiclePosition(i){const e=this.historyPositionMap.get(i),t=this.vehicleObjectMap.get(i);if(!t||!e||!t.isMoving&&e.length<=2)return;const s=Date.now();t.isMoving=!0,t.data.roadLayer==="1"?t.model.visible=this.showGroundVehicle:t.model.visible=this.showElevatedVehicle,t.segmentStartTime||(t.segmentStartTime=s,t.segmentTotalTime=e[1].time-e[0].time);const a=s-t.segmentStartTime,n=Math.min(a/t.segmentTotalTime,1);if(n===1)if(e.shift(),e.length===1){t.waitForDelete===!0?this.deleteVehicle(t):(t.segmentStartTime=void 0,t.segmentTotalTime=void 0,t.model.visible=!1,t.isMoving=!1,console.log("hide vehicle",i));return}else 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 o=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[o,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 s=!1;e.traverse(a=>{!s&&a instanceof l.Mesh&&(a.material=t,s=!0)})}return e}}createCanvas(i,e,t){const s=document.createElement("canvas"),a=i.width,n=i.height;s.width=a,s.height=n;const o=s.getContext("2d");if(!o){console.log("canvas创建失败");return}return o.fillStyle="rgba(0,0,0,0.0)",o.fillRect(0,0,a,n),o.drawImage(i,0,0,a,n),o.beginPath(),o.translate(a/2,n/2),o.fillStyle=t,o.font="bold 32px 宋体",o.textBaseline="middle",o.textAlign="center",o.fillText(e,0,0),s}createPlateSprite(i){return new Promise((e,t)=>{var r,p;const s=!i.plateNo||i.plateNo==="0"||i.plateNo==="000000";if(this.currentSpriteContent===d.EVehiclePlateState.None||this.currentSpriteContent===d.EVehiclePlateState.PlateNumber&&s){e(void 0);return}let a=new Image,n="",o="";if(this.currentSpriteContent===d.EVehiclePlateState.PlateNumber||this.currentSpriteContent===d.EVehiclePlateState.Mix)if(s)a=this.greyPlateBG,n=i.ptcId,o="#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:a=this.bluePlateBG,o="#ffffff";break;case 2:a=this.yellowPlateBG,o="#000000";break;case 3:a=this.whitePlateBG,o="#000000";break;case 4:a=this.blackPlateBG,o="#ffffff";break;case 5:a=this.neoYellowPlateBG,o="#000000";break;case 6:a=this.neoGreenPlateBG,o="#000000";break;default:a=this.greyPlateBG,n=i.plateNo,o="#ffffff";break}else this.currentSpriteContent===d.EVehiclePlateState.Id&&(a=this.greyPlateBG,n=i.ptcId,o="#ffffff");const h=this.createCanvas(a,n,o);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}a.onerror=c=>{console.log(`号牌背景加载失败: ${a.src}`,c),t(c)}})}}exports.default=I;
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const v=require("@arcgis/core/core/promiseUtils.js"),y=require("@arcgis/core/core/reactiveUtils.js"),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;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import * as Three from 'three';
|
|
2
|
+
import { IVehicleTrack } from '../../../types';
|
|
3
|
+
export declare enum EModelStatus {
|
|
4
|
+
/** 未使用 */
|
|
5
|
+
UNUSED = "unused",
|
|
6
|
+
/** 使用中 */
|
|
7
|
+
USED = "used",
|
|
8
|
+
/** 已销毁 */
|
|
9
|
+
DESTROYED = "destroyed"
|
|
10
|
+
}
|
|
11
|
+
declare type VehicleModelType = Three.Group | Three.Mesh;
|
|
12
|
+
export default class VehiclePool {
|
|
13
|
+
private createCarMaterial;
|
|
14
|
+
/** 车身颜色材质 */
|
|
15
|
+
private materialMap;
|
|
16
|
+
private readonly carPool;
|
|
17
|
+
private readonly vanPool;
|
|
18
|
+
private readonly truckPool;
|
|
19
|
+
private readonly busPool;
|
|
20
|
+
private bicyclePool;
|
|
21
|
+
private ballPool;
|
|
22
|
+
private readonly poolSize;
|
|
23
|
+
private view;
|
|
24
|
+
/** 车辆模型变化的阈值 */
|
|
25
|
+
private readonly cameraHeightThreshold;
|
|
26
|
+
initPool(assetsRoot: string, view: __esri.SceneView): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* 获取实例
|
|
29
|
+
* @param data
|
|
30
|
+
*/
|
|
31
|
+
getInstance(data: IVehicleTrack): VehicleModelType;
|
|
32
|
+
/**
|
|
33
|
+
* 回收实例
|
|
34
|
+
* @param instance
|
|
35
|
+
*/
|
|
36
|
+
recycleInstance(instance: VehicleModelType): void;
|
|
37
|
+
private getInstanceFromPool;
|
|
38
|
+
private getInstanceFromList;
|
|
39
|
+
private materialModel;
|
|
40
|
+
}
|
|
41
|
+
export {};
|
|
@@ -0,0 +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(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/lib/src/types/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* 45° ~ 135°:东象限。
|
|
6
6
|
* 135° ~ 225°:南象限。
|
|
7
7
|
*/
|
|
8
|
+
import Three from 'three';
|
|
8
9
|
export declare enum QuadrantCode {
|
|
9
10
|
West = "1",
|
|
10
11
|
North = "2",
|
|
@@ -37,6 +38,15 @@ export interface IVehicleTrack {
|
|
|
37
38
|
plateNo?: string;
|
|
38
39
|
roadLayer?: string;
|
|
39
40
|
}
|
|
41
|
+
export interface IVehicleRecord {
|
|
42
|
+
model: Three.Group | Three.Mesh;
|
|
43
|
+
data: IVehicleTrack;
|
|
44
|
+
segmentStartTime?: number;
|
|
45
|
+
segmentTotalTime?: number;
|
|
46
|
+
waitForDelete: boolean;
|
|
47
|
+
isMoving: boolean;
|
|
48
|
+
currentPos?: number[];
|
|
49
|
+
}
|
|
40
50
|
export interface ILaneNumberParams {
|
|
41
51
|
lanes: {
|
|
42
52
|
crossId: string;
|