gisviewer-vue3-arcgis 1.0.175 → 1.0.177
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/gis-map.vue.mjs +1 -1
- package/es/src/gis-map/utils/holo-flow/trace-holo-flow.d.ts +1 -0
- package/es/src/gis-map/utils/holo-flow/trace-holo-flow.mjs +42 -44
- package/es/src/gis-map/utils/holo-flow/trace-renderer-external.mjs +89 -96
- package/lib/src/gis-map/gis-map.vue.js +1 -1
- package/lib/src/gis-map/utils/holo-flow/trace-holo-flow.d.ts +1 -0
- package/lib/src/gis-map/utils/holo-flow/trace-holo-flow.js +2 -2
- package/lib/src/gis-map/utils/holo-flow/trace-renderer-external.js +1 -1
- package/package.json +1 -1
|
@@ -10,7 +10,7 @@ import Re from "./utils/queue-length.mjs";
|
|
|
10
10
|
import T from "./utils/road-config-tool/index.mjs";
|
|
11
11
|
import I from "./utils/signal-control-area-controller/index.mjs";
|
|
12
12
|
import We from "./utils/traffic-flow.mjs";
|
|
13
|
-
const Xe = { class: "gis-viewer" }, Ye = { style: { position: "absolute", bottom: "
|
|
13
|
+
const Xe = { class: "gis-viewer" }, Ye = { style: { position: "absolute", bottom: "80px", left: "10px", "z-index": "9999" } }, mt = /* @__PURE__ */ Pe({
|
|
14
14
|
__name: "gis-map",
|
|
15
15
|
props: {
|
|
16
16
|
config: {},
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import
|
|
1
|
+
import * as g from "@arcgis/core/views/3d/externalRenderers";
|
|
2
|
+
import f from "./trace-renderer-external.mjs";
|
|
3
3
|
import R from "./trace-renderer-layer.mjs";
|
|
4
|
-
class
|
|
4
|
+
class V {
|
|
5
5
|
constructor(e) {
|
|
6
|
-
this.nullDataCount = 0, e.type === "3d" ? (this.traceRenderer = new
|
|
6
|
+
this.nullDataCount = 0, this.clearTraceTimer = null, e.type === "3d" ? (this.traceRenderer = new f(e), g.add(
|
|
7
7
|
e,
|
|
8
8
|
this.traceRenderer
|
|
9
9
|
)) : this.traceRenderer = new R(e);
|
|
@@ -12,40 +12,38 @@ class L {
|
|
|
12
12
|
await this.traceRenderer.init();
|
|
13
13
|
}
|
|
14
14
|
downloadLog() {
|
|
15
|
-
const e = this.traceRenderer.getLog().map((
|
|
16
|
-
`).replace(/null/g, ""),
|
|
17
|
-
r.setAttribute("href",
|
|
15
|
+
const e = this.traceRenderer.getLog().map((o) => o.join(",")).join(`
|
|
16
|
+
`).replace(/null/g, ""), n = new Blob([e], { type: "text/csv;charset=utf-8;" }), i = URL.createObjectURL(n), r = document.createElement("a");
|
|
17
|
+
r.setAttribute("href", i), r.setAttribute("download", "trace-log.csv"), r.style.visibility = "hidden", document.body.appendChild(r), r.click(), document.body.removeChild(r);
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
20
|
* 处理全息流轨迹数据
|
|
21
21
|
* */
|
|
22
22
|
async handleVehicleTraceData(e) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const t = this.buildVehicleTrackData(n, i);
|
|
33
|
-
t && l.push(t);
|
|
23
|
+
this.clearTraceTimer || (this.clearTraceTimer = setInterval(() => {
|
|
24
|
+
this.nullDataCount++, this.nullDataCount >= 5 && (console.log("clear trace data"), this.clearTrace(), this.nullDataCount = 0);
|
|
25
|
+
}, 1e3)), this.nullDataCount = 0;
|
|
26
|
+
const { newVehList: n, updateVehList: i, deleteVehList: r, jgsj: o } = e, l = e.crossId || "", a = [], s = [];
|
|
27
|
+
if (n && n.length > 0) {
|
|
28
|
+
for (const c of n) {
|
|
29
|
+
c.localTimestamp || (c.localTimestamp = o || Date.now());
|
|
30
|
+
const t = this.buildVehicleTrackData(c, l);
|
|
31
|
+
t && a.push(t);
|
|
34
32
|
}
|
|
35
|
-
await this.traceRenderer.addVehicles(
|
|
33
|
+
await this.traceRenderer.addVehicles(a);
|
|
36
34
|
}
|
|
37
|
-
if (
|
|
38
|
-
for (const
|
|
39
|
-
const t = this.buildVehicleTrackData(
|
|
40
|
-
t &&
|
|
35
|
+
if (i && i.length > 0) {
|
|
36
|
+
for (const c of i) {
|
|
37
|
+
const t = this.buildVehicleTrackData(c, l);
|
|
38
|
+
t && s.push(t);
|
|
41
39
|
}
|
|
42
|
-
await this.traceRenderer.updateVehicles(
|
|
40
|
+
await this.traceRenderer.updateVehicles(s);
|
|
43
41
|
}
|
|
44
42
|
if (r && r.length > 0) {
|
|
45
|
-
const
|
|
46
|
-
(t) =>
|
|
43
|
+
const c = r.map(
|
|
44
|
+
(t) => l + "-" + (t.ptcId || t.vehno || t.vehNo)
|
|
47
45
|
);
|
|
48
|
-
this.traceRenderer.deleteVehicles(
|
|
46
|
+
this.traceRenderer.deleteVehicles(c);
|
|
49
47
|
}
|
|
50
48
|
}
|
|
51
49
|
/**
|
|
@@ -59,7 +57,7 @@ class L {
|
|
|
59
57
|
* 清除轨迹流
|
|
60
58
|
* */
|
|
61
59
|
clearTrace() {
|
|
62
|
-
this.traceRenderer.clearVehicles();
|
|
60
|
+
this.clearTraceTimer && (clearInterval(this.clearTraceTimer), this.clearTraceTimer = null), this.traceRenderer.clearVehicles();
|
|
63
61
|
}
|
|
64
62
|
/**
|
|
65
63
|
* 切换暂停
|
|
@@ -79,30 +77,30 @@ class L {
|
|
|
79
77
|
setInterpolate(e) {
|
|
80
78
|
this.traceRenderer.setInterpolate(e);
|
|
81
79
|
}
|
|
82
|
-
buildVehicleTrackData(e,
|
|
83
|
-
const
|
|
84
|
-
if (!(
|
|
80
|
+
buildVehicleTrackData(e, n) {
|
|
81
|
+
const i = e.longitude, r = e.latitude, o = e.ptcId, l = Number(e.ptcType), a = e.heading, s = Number(e.vehicleType), c = Number(e.vehicleColor), t = e.plateNo || e.plateno, h = Number(e.plateColor), d = e.timestamp, u = e.localTimestamp, p = e.roadLayer ? String(e.roadLayer) : "1", m = e.step, T = e.speed;
|
|
82
|
+
if (!(l < 0 || l > 8))
|
|
85
83
|
return {
|
|
86
|
-
ptcId:
|
|
87
|
-
crossId:
|
|
88
|
-
vehicleId:
|
|
89
|
-
x:
|
|
84
|
+
ptcId: o,
|
|
85
|
+
crossId: n,
|
|
86
|
+
vehicleId: n + "-" + o,
|
|
87
|
+
x: i,
|
|
90
88
|
y: r,
|
|
91
|
-
ptcType:
|
|
92
|
-
vehicleType:
|
|
93
|
-
heading:
|
|
94
|
-
vehicleColor:
|
|
89
|
+
ptcType: l,
|
|
90
|
+
vehicleType: s,
|
|
91
|
+
heading: l === 2 ? -a : a,
|
|
92
|
+
vehicleColor: c,
|
|
95
93
|
showName: t && t !== "" && t !== "0" && t !== "000000" ? t : "",
|
|
96
94
|
plateNo: t,
|
|
97
95
|
plateColor: h,
|
|
98
96
|
timestamp: d,
|
|
99
|
-
localTimestamp:
|
|
100
|
-
roadLayer:
|
|
101
|
-
step:
|
|
102
|
-
speed:
|
|
97
|
+
localTimestamp: u,
|
|
98
|
+
roadLayer: p,
|
|
99
|
+
step: m,
|
|
100
|
+
speed: T
|
|
103
101
|
};
|
|
104
102
|
}
|
|
105
103
|
}
|
|
106
104
|
export {
|
|
107
|
-
|
|
105
|
+
V as default
|
|
108
106
|
};
|
|
@@ -2,14 +2,14 @@ import * as b from "@arcgis/core/core/promiseUtils.js";
|
|
|
2
2
|
import * as P 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
|
-
import * as
|
|
5
|
+
import * as o from "three";
|
|
6
6
|
import { GLTFLoader as y } from "three/examples/jsm/loaders/GLTFLoader";
|
|
7
7
|
import { toRaw as T } from "vue";
|
|
8
8
|
import { EVehiclePlateState as m } from "../../../types/index.mjs";
|
|
9
9
|
import C from "../../stores/index.mjs";
|
|
10
10
|
class V {
|
|
11
11
|
constructor(i) {
|
|
12
|
-
this.cameraHeightThreshold = 1e3, this.roughness = 0.2, this.metalness = 0.8, this.defaultMaterial = new
|
|
12
|
+
this.cameraHeightThreshold = 1e3, this.roughness = 0.2, this.metalness = 0.8, this.defaultMaterial = new o.MeshPhongMaterial({
|
|
13
13
|
color: 16777215
|
|
14
14
|
}), this.materialMap = /* @__PURE__ */ new Map([
|
|
15
15
|
[1, this.createCarMaterial(16777215)],
|
|
@@ -55,7 +55,7 @@ class V {
|
|
|
55
55
|
}
|
|
56
56
|
// private readonly vehiclePool = new VehiclePool();
|
|
57
57
|
createCarMaterial(i) {
|
|
58
|
-
return new
|
|
58
|
+
return new o.MeshPhongMaterial({
|
|
59
59
|
color: i
|
|
60
60
|
// // emissive: 0xc3c3c3,
|
|
61
61
|
// roughness: this.roughness,
|
|
@@ -70,38 +70,38 @@ class V {
|
|
|
70
70
|
await b.eachAlways([
|
|
71
71
|
new Promise((e) => {
|
|
72
72
|
i.load(`${this.assetsRoot}/3DModels/car.glb`, (t) => {
|
|
73
|
-
const s = t.scene,
|
|
74
|
-
this.carModel = new
|
|
73
|
+
const s = t.scene, l = new o.Box3().setFromObject(s).getSize(new o.Vector3());
|
|
74
|
+
this.carModel = new o.Object3D(), this.carModel.rotation.x = o.MathUtils.degToRad(90), this.carModel.add(s), s.position.set(0, 0, l.z / 2), e();
|
|
75
75
|
});
|
|
76
76
|
}),
|
|
77
77
|
new Promise((e) => {
|
|
78
78
|
i.load(`${this.assetsRoot}/3DModels/van.glb`, (t) => {
|
|
79
|
-
const s = t.scene,
|
|
80
|
-
this.vanModel = new
|
|
79
|
+
const s = t.scene, l = new o.Box3().setFromObject(s).getSize(new o.Vector3());
|
|
80
|
+
this.vanModel = new o.Object3D(), this.vanModel.rotation.x = o.MathUtils.degToRad(90), this.vanModel.add(s), s.position.set(0, 0, l.z / 2), e();
|
|
81
81
|
});
|
|
82
82
|
}),
|
|
83
83
|
new Promise((e) => {
|
|
84
84
|
i.load(`${this.assetsRoot}/3DModels/truck.glb`, (t) => {
|
|
85
85
|
const s = t.scene;
|
|
86
86
|
s.scale.set(1.2, 1, 1.5);
|
|
87
|
-
const
|
|
88
|
-
this.truckModel = new
|
|
87
|
+
const l = new o.Box3().setFromObject(s).getSize(new o.Vector3());
|
|
88
|
+
this.truckModel = new o.Object3D(), this.truckModel.rotation.x = o.MathUtils.degToRad(90), this.truckModel.add(s), s.position.set(0, 0, l.z / 2), e();
|
|
89
89
|
});
|
|
90
90
|
}),
|
|
91
91
|
new Promise((e) => {
|
|
92
92
|
i.load(`${this.assetsRoot}/3DModels/bus.glb`, (t) => {
|
|
93
|
-
const s = t.scene,
|
|
94
|
-
this.busModel = new
|
|
93
|
+
const s = t.scene, l = new o.Box3().setFromObject(s).getSize(new o.Vector3());
|
|
94
|
+
this.busModel = new o.Object3D(), this.busModel.rotation.x = o.MathUtils.degToRad(90), this.busModel.add(s), s.position.set(0, 0, l.z / 2), e();
|
|
95
95
|
});
|
|
96
96
|
}),
|
|
97
97
|
new Promise((e) => {
|
|
98
98
|
i.load(`${this.assetsRoot}/3DModels/bicycle.glb`, (t) => {
|
|
99
|
-
this.bicycleModel = t.scene, this.bicycleModel.rotation.x =
|
|
99
|
+
this.bicycleModel = t.scene, this.bicycleModel.rotation.x = o.MathUtils.degToRad(90), this.bicycleModel.rotation.y = o.MathUtils.degToRad(180), e();
|
|
100
100
|
});
|
|
101
101
|
}),
|
|
102
102
|
new Promise((e) => {
|
|
103
103
|
i.load(`${this.assetsRoot}/3DModels/bicycle.glb`, (t) => {
|
|
104
|
-
this.passengerModel = t.scene, this.passengerModel.rotation.x =
|
|
104
|
+
this.passengerModel = t.scene, this.passengerModel.rotation.x = o.MathUtils.degToRad(90), this.passengerModel.rotation.y = o.MathUtils.degToRad(180), e();
|
|
105
105
|
});
|
|
106
106
|
}),
|
|
107
107
|
new Promise((e) => {
|
|
@@ -145,7 +145,7 @@ class V {
|
|
|
145
145
|
this.clearVehicles(), this.needInterpolate = i;
|
|
146
146
|
}
|
|
147
147
|
async setup(i) {
|
|
148
|
-
this.context = i, this.renderer = new
|
|
148
|
+
this.context = i, this.renderer = new o.WebGLRenderer({
|
|
149
149
|
context: i.gl,
|
|
150
150
|
premultipliedAlpha: !0,
|
|
151
151
|
logarithmicDepthBuffer: !0,
|
|
@@ -157,37 +157,37 @@ class V {
|
|
|
157
157
|
);
|
|
158
158
|
this.renderer.setRenderTarget = (s) => {
|
|
159
159
|
e(s), s == null && i.bindRenderTarget();
|
|
160
|
-
}, this.scene = new
|
|
160
|
+
}, this.scene = new o.Scene();
|
|
161
161
|
const { camera: t } = i;
|
|
162
|
-
this.camera = new
|
|
162
|
+
this.camera = new o.PerspectiveCamera(
|
|
163
163
|
t.fovY,
|
|
164
164
|
t.aspect,
|
|
165
165
|
0.1,
|
|
166
166
|
1e5
|
|
167
|
-
), this.ambient = new
|
|
167
|
+
), this.ambient = new o.AmbientLight(16777215, 2), this.scene.add(this.ambient), this.sun = new o.DirectionalLight(16777215, 2), this.scene.add(this.sun), i.resetWebGLState();
|
|
168
168
|
}
|
|
169
169
|
async render(i) {
|
|
170
170
|
var s;
|
|
171
171
|
const e = i.camera;
|
|
172
172
|
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(
|
|
173
|
-
new
|
|
173
|
+
new o.Vector3(e.center[0], e.center[1], e.center[2])
|
|
174
174
|
), this.camera.projectionMatrix.fromArray(e.projectionMatrix), !this.isPaused && this.needInterpolate)
|
|
175
|
-
for (const
|
|
176
|
-
const
|
|
177
|
-
if (!
|
|
175
|
+
for (const a of this.vehicleObjectMap.keys()) {
|
|
176
|
+
const l = (s = this.vehicleObjectMap.get(a)) == null ? void 0 : s.model;
|
|
177
|
+
if (!l)
|
|
178
178
|
continue;
|
|
179
|
-
const r = this.computeVehiclePosition(
|
|
179
|
+
const r = this.computeVehiclePosition(a);
|
|
180
180
|
if (r) {
|
|
181
181
|
const d = this.toRenderCoordinates(r);
|
|
182
|
-
|
|
182
|
+
l.position.set(d[0], d[1], d[2]), l.rotation.y = o.MathUtils.degToRad(-r[3]);
|
|
183
183
|
}
|
|
184
184
|
}
|
|
185
185
|
const t = i.sunLight;
|
|
186
|
-
this.sun.position.set(t.direction[0], t.direction[1], t.direction[2]), this.sun.intensity = t.diffuse.intensity, this.sun.color = new
|
|
186
|
+
this.sun.position.set(t.direction[0], t.direction[1], t.direction[2]), this.sun.intensity = t.diffuse.intensity, this.sun.color = new o.Color(
|
|
187
187
|
t.diffuse.color[0],
|
|
188
188
|
t.diffuse.color[1],
|
|
189
189
|
t.diffuse.color[2]
|
|
190
|
-
), this.ambient.intensity = t.ambient.intensity, this.ambient.color = new
|
|
190
|
+
), this.ambient.intensity = t.ambient.intensity, this.ambient.color = new o.Color(
|
|
191
191
|
t.ambient.color[0],
|
|
192
192
|
t.ambient.color[1],
|
|
193
193
|
t.ambient.color[2]
|
|
@@ -221,17 +221,17 @@ class V {
|
|
|
221
221
|
0,
|
|
222
222
|
0
|
|
223
223
|
]);
|
|
224
|
-
const { vehicleId: s, localTimestamp:
|
|
224
|
+
const { vehicleId: s, localTimestamp: a } = t, l = Number(t.x), r = Number(t.y), d = Number(t.heading);
|
|
225
225
|
this.historyPositionMap.set(s, [
|
|
226
|
-
{ pos: [
|
|
226
|
+
{ pos: [l, r, 0], heading: d, time: a }
|
|
227
227
|
]);
|
|
228
228
|
const h = this.getVehicleModel(t);
|
|
229
229
|
h.name = s, h.visible = !1;
|
|
230
230
|
try {
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
} catch (
|
|
234
|
-
console.log("createPlateSprite error:",
|
|
231
|
+
const n = await this.createPlateSprite(t);
|
|
232
|
+
n && (h.add(n), n.position.set(0, 5, -4));
|
|
233
|
+
} catch (n) {
|
|
234
|
+
console.log("createPlateSprite error:", n);
|
|
235
235
|
}
|
|
236
236
|
this.scene.add(h), this.vehicleObjectMap.set(s, {
|
|
237
237
|
model: h,
|
|
@@ -249,12 +249,12 @@ class V {
|
|
|
249
249
|
return;
|
|
250
250
|
const e = [], t = Date.now();
|
|
251
251
|
for (const s of i) {
|
|
252
|
-
const { vehicleId:
|
|
252
|
+
const { vehicleId: a, localTimestamp: l } = s, r = Number(s.x), d = Number(s.y);
|
|
253
253
|
let h = Number(s.heading);
|
|
254
|
-
const
|
|
255
|
-
|
|
254
|
+
const n = this.vehicleObjectMap.get(a), p = this.historyPositionMap.get(
|
|
255
|
+
a
|
|
256
256
|
);
|
|
257
|
-
if (!
|
|
257
|
+
if (!n || !p)
|
|
258
258
|
e.push(s);
|
|
259
259
|
else {
|
|
260
260
|
if (this.appDataStore.saveTrackLog && this.logTable.push([
|
|
@@ -276,30 +276,30 @@ class V {
|
|
|
276
276
|
t,
|
|
277
277
|
p.length,
|
|
278
278
|
1
|
|
279
|
-
]), this.updateModel ||
|
|
280
|
-
this.scene.remove(
|
|
279
|
+
]), this.updateModel || n.data.vehicleColor !== s.vehicleColor || n.data.vehicleType !== s.vehicleType) {
|
|
280
|
+
this.scene.remove(n.model), this.disposeModel(n.model), n.model = this.getVehicleModel(s), n.model.visible = !0;
|
|
281
281
|
const c = await this.createPlateSprite(s);
|
|
282
|
-
c && (
|
|
282
|
+
c && (n.model.add(c), c.position.set(0, 5, -4)), this.scene.add(n.model);
|
|
283
283
|
}
|
|
284
|
-
if (
|
|
285
|
-
const c =
|
|
286
|
-
c && (
|
|
284
|
+
if (n.data.showName !== s.showName || n.data.plateColor !== s.plateColor) {
|
|
285
|
+
const c = n.model.getObjectByName("VehiclePlate");
|
|
286
|
+
c && (n.model.remove(c), this.disposeModel(c));
|
|
287
287
|
const g = await this.createPlateSprite(s);
|
|
288
|
-
g && (
|
|
288
|
+
g && (n.model.add(g), g.position.set(0, 5, -4));
|
|
289
289
|
}
|
|
290
|
-
if (
|
|
290
|
+
if (n.data = s, this.needInterpolate) {
|
|
291
291
|
const c = p[p.length - 1];
|
|
292
292
|
Math.abs(h - c.heading) >= 180 && (h > c.heading ? c.heading += 360 : h += 360), p.push({
|
|
293
293
|
pos: [r, d, 0],
|
|
294
294
|
heading: h,
|
|
295
|
-
time:
|
|
295
|
+
time: l
|
|
296
296
|
});
|
|
297
297
|
} else {
|
|
298
|
-
this.historyPositionMap.set(
|
|
299
|
-
{ pos: [r, d, 0], heading: h, time:
|
|
298
|
+
this.historyPositionMap.set(a, [
|
|
299
|
+
{ pos: [r, d, 0], heading: h, time: l }
|
|
300
300
|
]);
|
|
301
301
|
const c = this.toRenderCoordinates([r, d, 0]);
|
|
302
|
-
|
|
302
|
+
n.model.position.set(c[0], c[1], c[2]), n.model.rotation.y = o.MathUtils.degToRad(-h);
|
|
303
303
|
}
|
|
304
304
|
}
|
|
305
305
|
}
|
|
@@ -327,7 +327,7 @@ class V {
|
|
|
327
327
|
const e = Date.now();
|
|
328
328
|
i.forEach((t) => {
|
|
329
329
|
if (this.appDataStore.saveTrackLog) {
|
|
330
|
-
const
|
|
330
|
+
const a = this.historyPositionMap.get(t);
|
|
331
331
|
this.logTable.push([
|
|
332
332
|
t,
|
|
333
333
|
"",
|
|
@@ -345,7 +345,7 @@ class V {
|
|
|
345
345
|
"",
|
|
346
346
|
"",
|
|
347
347
|
e,
|
|
348
|
-
|
|
348
|
+
a ? a.length : 0,
|
|
349
349
|
2
|
|
350
350
|
]);
|
|
351
351
|
}
|
|
@@ -354,7 +354,7 @@ class V {
|
|
|
354
354
|
});
|
|
355
355
|
}
|
|
356
356
|
deleteVehicle(i) {
|
|
357
|
-
this.
|
|
357
|
+
this.disposeModel(i.model), this.scene.remove(i.model);
|
|
358
358
|
const e = i.data.vehicleId;
|
|
359
359
|
this.vehicleObjectMap.delete(e), this.historyPositionMap.delete(e);
|
|
360
360
|
}
|
|
@@ -370,10 +370,8 @@ class V {
|
|
|
370
370
|
* 清除全部车辆
|
|
371
371
|
* */
|
|
372
372
|
clearVehicles() {
|
|
373
|
-
for (const i of this.vehicleObjectMap.
|
|
374
|
-
|
|
375
|
-
e && (this.scene.remove(e.model), this.disposeModel(e.model));
|
|
376
|
-
}
|
|
373
|
+
for (const i of this.vehicleObjectMap.values())
|
|
374
|
+
this.disposeModel(i.model), this.scene.remove(i.model);
|
|
377
375
|
this.vehicleObjectMap.clear(), this.historyPositionMap.clear();
|
|
378
376
|
}
|
|
379
377
|
/**
|
|
@@ -382,22 +380,17 @@ class V {
|
|
|
382
380
|
* @returns
|
|
383
381
|
*/
|
|
384
382
|
async updatePanelContent(i) {
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
if (s && (t.model.remove(s), this.disposeModel(s)), i !== m.None) {
|
|
392
|
-
const o = await this.createPlateSprite(t.data);
|
|
393
|
-
o && (t.model.add(o), o.position.set(0, 5, -4));
|
|
394
|
-
}
|
|
395
|
-
}
|
|
383
|
+
this.currentSpriteContent = i;
|
|
384
|
+
for (const e of this.vehicleObjectMap.values()) {
|
|
385
|
+
const t = e.model.getObjectByName("VehiclePlate");
|
|
386
|
+
if (t && (e.model.remove(t), this.disposeModel(t)), i !== m.None) {
|
|
387
|
+
const s = await this.createPlateSprite(e.data);
|
|
388
|
+
s && (e.model.add(s), s.position.set(0, 5, -4));
|
|
396
389
|
}
|
|
397
390
|
}
|
|
398
391
|
}
|
|
399
392
|
toggleGroundVehicle(i) {
|
|
400
|
-
|
|
393
|
+
this.showGroundVehicle = i;
|
|
401
394
|
}
|
|
402
395
|
toggleElevatedVehicle(i) {
|
|
403
396
|
this.showElevatedVehicle = i;
|
|
@@ -407,7 +400,7 @@ class V {
|
|
|
407
400
|
* */
|
|
408
401
|
disposeModel(i) {
|
|
409
402
|
i.traverse((e) => {
|
|
410
|
-
e instanceof
|
|
403
|
+
e instanceof o.Mesh && (e.geometry.dispose(), e.material.dispose());
|
|
411
404
|
});
|
|
412
405
|
}
|
|
413
406
|
/**
|
|
@@ -419,21 +412,21 @@ class V {
|
|
|
419
412
|
return;
|
|
420
413
|
const s = Date.now();
|
|
421
414
|
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);
|
|
422
|
-
const
|
|
423
|
-
|
|
415
|
+
const a = s - t.segmentStartTime, l = Math.min(
|
|
416
|
+
a / t.segmentTotalTime,
|
|
424
417
|
1
|
|
425
418
|
);
|
|
426
|
-
if (
|
|
419
|
+
if (l === 1)
|
|
427
420
|
if (e.shift(), e.length === 1) {
|
|
428
421
|
t.waitForDelete === !0 ? this.deleteVehicle(t) : (t.segmentStartTime = void 0, t.segmentTotalTime = void 0, t.model.visible = !1, t.isMoving = !1, console.log("hide vehicle", i));
|
|
429
422
|
return;
|
|
430
423
|
} else {
|
|
431
424
|
t.segmentStartTime = Date.now();
|
|
432
|
-
const r =
|
|
425
|
+
const r = a - t.segmentTotalTime;
|
|
433
426
|
return t.segmentTotalTime = e[1].time - e[0].time - r, (e[1].heading >= 270 && e[0].heading <= 90 || e[1].heading <= 90 && e[0].heading >= 270) && (e[1].heading > e[0].heading ? e[0].heading += 360 : e[1].heading += 360), e[0].pos.concat(e[0].heading);
|
|
434
427
|
}
|
|
435
428
|
else if (e.length >= 2) {
|
|
436
|
-
const r = e[0].pos[0] + (e[1].pos[0] - e[0].pos[0]) *
|
|
429
|
+
const r = e[0].pos[0] + (e[1].pos[0] - e[0].pos[0]) * l, d = e[0].pos[1] + (e[1].pos[1] - e[0].pos[1]) * l, h = e[0].heading + (e[1].heading - e[0].heading) * l;
|
|
437
430
|
return [r, d, 0, h];
|
|
438
431
|
} else
|
|
439
432
|
return;
|
|
@@ -443,13 +436,13 @@ class V {
|
|
|
443
436
|
* */
|
|
444
437
|
getVehicleModel(i) {
|
|
445
438
|
if (this.view.camera.position.z >= this.cameraHeightThreshold) {
|
|
446
|
-
const e = new
|
|
439
|
+
const e = new o.SphereGeometry(5, 32, 32), t = new o.MeshPhysicalMaterial({
|
|
447
440
|
color: 325253,
|
|
448
441
|
emissive: 0,
|
|
449
442
|
roughness: this.roughness,
|
|
450
443
|
metalness: this.metalness
|
|
451
444
|
});
|
|
452
|
-
return new
|
|
445
|
+
return new o.Mesh(e, t);
|
|
453
446
|
} else {
|
|
454
447
|
let e;
|
|
455
448
|
if (i.ptcType === 2)
|
|
@@ -476,8 +469,8 @@ class V {
|
|
|
476
469
|
}
|
|
477
470
|
const t = this.materialMap.get(i.vehicleColor) || this.defaultMaterial;
|
|
478
471
|
let s = !1;
|
|
479
|
-
e.traverse((
|
|
480
|
-
!s &&
|
|
472
|
+
e.traverse((a) => {
|
|
473
|
+
!s && a instanceof o.Mesh && (a.material = t, s = !0);
|
|
481
474
|
});
|
|
482
475
|
}
|
|
483
476
|
return e;
|
|
@@ -487,66 +480,66 @@ class V {
|
|
|
487
480
|
* 创建号牌canvas
|
|
488
481
|
* */
|
|
489
482
|
createCanvas(i, e, t) {
|
|
490
|
-
const s = document.createElement("canvas"),
|
|
491
|
-
s.width =
|
|
483
|
+
const s = document.createElement("canvas"), a = i.width, l = i.height;
|
|
484
|
+
s.width = a, s.height = l;
|
|
492
485
|
const r = s.getContext("2d");
|
|
493
486
|
if (!r) {
|
|
494
487
|
console.log("canvas创建失败");
|
|
495
488
|
return;
|
|
496
489
|
}
|
|
497
|
-
return r.fillStyle = "rgba(0,0,0,0.0)", r.fillRect(0, 0,
|
|
490
|
+
return r.fillStyle = "rgba(0,0,0,0.0)", r.fillRect(0, 0, a, l), r.drawImage(i, 0, 0, a, l), r.beginPath(), r.translate(a / 2, l / 2), r.fillStyle = t, r.font = "bold 32px 宋体", r.textBaseline = "middle", r.textAlign = "center", r.fillText(e, 0, 0), s;
|
|
498
491
|
}
|
|
499
492
|
createPlateSprite(i) {
|
|
500
493
|
return new Promise((e, t) => {
|
|
501
|
-
var h,
|
|
494
|
+
var h, n;
|
|
502
495
|
const s = !i.plateNo || i.plateNo === "0" || i.plateNo === "000000";
|
|
503
496
|
if (this.currentSpriteContent === m.None || this.currentSpriteContent === m.PlateNumber && s) {
|
|
504
497
|
e(void 0);
|
|
505
498
|
return;
|
|
506
499
|
}
|
|
507
|
-
let
|
|
500
|
+
let a = new Image(), l = "", r = "";
|
|
508
501
|
if (this.currentSpriteContent === m.PlateNumber || this.currentSpriteContent === m.Mix)
|
|
509
502
|
if (s)
|
|
510
|
-
|
|
503
|
+
a = this.greyPlateBG, l = i.ptcId, r = "#ffffff";
|
|
511
504
|
else
|
|
512
|
-
switch (
|
|
505
|
+
switch (l = ((h = i.showName) == null ? void 0 : h.substring(0, 2)) + "•" + ((n = i.showName) == null ? void 0 : n.substring(2)), i.plateColor) {
|
|
513
506
|
case 1:
|
|
514
|
-
|
|
507
|
+
a = this.bluePlateBG, r = "#ffffff";
|
|
515
508
|
break;
|
|
516
509
|
case 2:
|
|
517
|
-
|
|
510
|
+
a = this.yellowPlateBG, r = "#000000";
|
|
518
511
|
break;
|
|
519
512
|
case 3:
|
|
520
|
-
|
|
513
|
+
a = this.whitePlateBG, r = "#000000";
|
|
521
514
|
break;
|
|
522
515
|
case 4:
|
|
523
|
-
|
|
516
|
+
a = this.blackPlateBG, r = "#ffffff";
|
|
524
517
|
break;
|
|
525
518
|
case 5:
|
|
526
|
-
|
|
519
|
+
a = this.neoYellowPlateBG, r = "#000000";
|
|
527
520
|
break;
|
|
528
521
|
case 6:
|
|
529
|
-
|
|
522
|
+
a = this.neoGreenPlateBG, r = "#000000";
|
|
530
523
|
break;
|
|
531
524
|
default:
|
|
532
|
-
|
|
525
|
+
a = this.greyPlateBG, l = i.plateNo, r = "#ffffff";
|
|
533
526
|
break;
|
|
534
527
|
}
|
|
535
528
|
else
|
|
536
|
-
this.currentSpriteContent === m.Id && (
|
|
537
|
-
const d = this.createCanvas(
|
|
529
|
+
this.currentSpriteContent === m.Id && (a = this.greyPlateBG, l = i.ptcId, r = "#ffffff");
|
|
530
|
+
const d = this.createCanvas(a, l, r);
|
|
538
531
|
if (d) {
|
|
539
|
-
const p = new
|
|
532
|
+
const p = new o.CanvasTexture(d), c = new o.SpriteMaterial({
|
|
540
533
|
map: p,
|
|
541
534
|
transparent: !1
|
|
542
|
-
}), g = new
|
|
535
|
+
}), g = new o.Sprite(c), f = 0.05, w = d.width * f, M = d.height * f;
|
|
543
536
|
g.scale.set(w, M, 1), g.name = "VehiclePlate", e(g);
|
|
544
537
|
} else {
|
|
545
538
|
t("canvas创建失败");
|
|
546
539
|
return;
|
|
547
540
|
}
|
|
548
|
-
|
|
549
|
-
console.log(`号牌背景加载失败: ${
|
|
541
|
+
a.onerror = (p) => {
|
|
542
|
+
console.log(`号牌背景加载失败: ${a.src}`, p), t(p);
|
|
550
543
|
};
|
|
551
544
|
});
|
|
552
545
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const a=require("vue"),h=require("./stores/index.js");require("./style/index.css");const
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const a=require("vue"),h=require("./stores/index.js");require("./style/index.css");const xe=require("./utils/holo-flow/index.js"),qe=require("./utils/holo-flow/signal-countdown-panel.vue.js"),Me=require("./utils/map-initializer.js"),O=require("./utils/open-drive-renderer/index.js"),b=require("./utils/overlay.js"),Ve=require("./utils/queue-length.js"),A=require("./utils/road-config-tool/index.js"),L=require("./utils/signal-control-area-controller/index.js"),Ne=require("./utils/traffic-flow.js"),Be={class:"gis-viewer"},He={style:{position:"absolute",bottom:"80px",left:"10px","z-index":"9999"}},Pe=a.defineComponent({__name:"gis-map",props:{config:{},assetsRoot:{}},emits:["mapLoaded","markerClick","mapClick"],setup(D,{expose:T,emit:_}){const p=a.ref(null);let i,u,l,o,n,r,g,t,s;const f=a.ref(!1);h.registerStore();const I=h.default.useAppDataStore,C=a.reactive([]);a.onMounted(async()=>{if(!p.value)return;document.addEventListener("keydown",m=>{m.ctrlKey&&m.key==="i"&&(f.value=!f.value)});const e=a.getCurrentInstance(),{$gisviewerAssetsRoot:d}=e.appContext.config.globalProperties,c=await(await fetch(k.config)).json();c.assetsRoot=k.assetsRoot||d,I.mapConfig=c,u=new Me.default,i=await u.initialize({container:p.value,mapConfig:c,markerClickCallback:(m,v,w,Ie)=>{S("markerClick",m,v,w,Ie)},mapClickCallback:(m,v,w)=>{S("mapClick",m,v,w)}}),n=new xe.default(i,C),await n.init(),S("mapLoaded")}),a.onUnmounted(()=>{s==null||s.clearSignalControlArea(),t==null||t.clearOpenDrive(),n.clearHoloTrace(),n.clearHoloSignal(),o==null||o.disconnectTrafficFlow()});const x=a.computed(()=>i),q=()=>{const e=h.default.useAppDataStore;e.saveTrackLog=!0},M=()=>{n.downloadTrackLog()},V=()=>{y("vehicleId")},N=()=>{y("plateNumber")},B=async e=>await u.setMapCenter(e),H=async e=>await u.setMapCamera(e),P=async e=>await u.lookAt(e),E=e=>u.setLayerVisibility(e),z=(e,d)=>u.requestCoordinateTransform(e,d),j=e=>{u.cancelCoordinateTransform(e)},Q=e=>{u.setMapZoomRange(e)},Z=e=>(l||(l=new A.default(i)),l.showLaneNumber(e)),K=()=>{l==null||l.clearLaneNumber()},U=async e=>(l||(l=new A.default(i)),await l.initializeSearch(e)),G=async()=>l==null?void 0:l.calCrossIndicatorArea(),J=async()=>{},W=async(e,d)=>{o||(o=new Ne.default(i)),o.connectTrafficFlow(e,d)},X=()=>{o==null||o.disconnectTrafficFlow()},Y=async e=>{n.handleVehicleTraceData(e)},F=()=>{n.clearHoloTrace()},R=e=>{n.setInterpolate(e)},$=async e=>{await n.handleSignalData(e)},ee=()=>{n.clearHoloSignal()},te=e=>{o==null||o.toggleTrafficInfo(e),n==null||n.toggleTrafficInfo(e)},ae=e=>{n==null||n.togglePause(e)},ne=e=>{o==null||o.toggleTrafficObject(e),n==null||n.toggleTrafficObject(e)},y=e=>{n==null||n.updatePanelContent(e)},re=async e=>(r||(r=new b.default(i)),r.addOverlays(e)),se=e=>(r||(r=new b.default(i)),r.addMask(e)),oe=()=>{r==null||r.removeMask()},ie=e=>r==null?void 0:r.removeOverlaysByType(e),ce=e=>r==null?void 0:r.removeOverlaysById(e),le=()=>r==null?void 0:r.removeAllOverlays(),ue=()=>{r==null||r.showAllOverlays()},de=e=>{g||(g=new Ve.default(i)),g.updateQueueLength(e)},me=()=>{g==null||g.removeQueueLength()},ge=async(e,d)=>(t||(t=new O.default(i)),await t.showOpenDriveFromServer(e,d)),pe=async e=>(t||(t=new O.default(i)),await t.clearOpenDrive(),await t.showOpenDriveFromFile(e)),fe=async()=>await(t==null?void 0:t.clearOpenDrive()),ye=async e=>t?await(t==null?void 0:t.findSumo(e)):{status:-1,message:"未加载OpenDrive地图"},Se=async e=>t?t.selectSumo(e):{status:-1,message:"未加载OpenDrive地图"},ve=async e=>t?t.unselectSumo(e):{status:-1,message:"未加载OpenDrive地图"},we=async e=>t?await t.geometrySearch(e):{status:-1,message:"未加载OpenDrive地图"},he=async e=>t?await t.getSumoInfo(e):{status:-1,message:"未加载OpenDrive地图"},Ce=async e=>t?await(t==null?void 0:t.splitLane(e)):{status:-1,message:"未加载OpenDrive地图"},ke=async()=>t?t==null?void 0:t.clearSplitLane():{status:-1,message:"未加载OpenDrive地图"},Oe=e=>(s||(s=new L.default(i)),s.showSignalControlArea(e)),be=()=>{s==null||s.clearSignalControlArea()},Ae=async e=>s?await s.locateSignalControlArea(e):{status:-1,message:"未加载信号控制区"},Le=async e=>s?await s.highlightSignalControlArea(e):{status:-1,message:"未加载信号控制区"},De=()=>s?s.resetHighlight():{status:-1,message:"未加载信号控制区"},Te=e=>(s||(s=new L.default(i)),s.showSubSignalControlArea(e)),_e=()=>s?s.editSubSignalArea():{status:-1,message:"未加载信号控制区"},k=D,S=_;return T({mapViewer:x,setLayerVisibility:E,setMapCenter:B,lookAt:P,setMapCamera:H,setMapZoomRange:Q,requestCoordinateTransform:z,cancelCoordinateTransform:j,addOverlays:re,addMask:se,removeMask:oe,showAllOverlays:ue,removeOverlaysByType:ie,removeOverlaysById:ce,removeAllOverlays:le,showLaneNumber:Z,clearLaneNumber:K,initializeAreaTool:U,calCrossIndicatorArea:G,calRoadIndicatorArea:J,connectCarFlow:W,disconnectCarFlow:X,handleHoloVehicleTraceData:Y,clearHoloTrace:F,handleHoloSignalData:$,clearHoloSignal:ee,setInterpolate:R,toggleTrafficInfo:te,toggleTrafficObject:ne,toggleVehicleInfo:y,togglePause:ae,updateQueueLength:de,removeQueueLength:me,showOpenDriveFromServer:ge,showOpenDriveFromFile:pe,clearOpenDrive:fe,geometrySearchInOpenDrive:we,findSumoInOpenDrive:ye,selectSumoInOpenDrive:Se,unselectSumoInOpenDrive:ve,getSumoInfo:he,splitOpenDriveLane:Ce,clearSplitOpenDriveLane:ke,showSignalControlArea:Oe,clearSignalControlArea:be,locateSignalControlArea:Ae,highlightSignalControlArea:Le,resetHighlightSignalControlArea:De,showSubSignalControlArea:Te,editSubSignalControlArea:_e}),(e,d)=>(a.openBlock(),a.createElementBlock("div",Be,[a.createElementVNode("div",{class:"gis-viewer-main",ref_key:"mapContainer",ref:p},[a.withDirectives(a.createElementVNode("div",He,[a.createElementVNode("button",{style:{"margin-right":"10px"},onClick:q}," 开始记录 "),a.createElementVNode("button",{style:{"margin-right":"10px"},onClick:M}," 下载日志 "),a.createElementVNode("button",{style:{"margin-right":"10px"},onClick:V}," 显示车辆id "),a.createElementVNode("button",{onClick:N},"显示车辆号牌")],512),[[a.vShow,f.value]])],512),(a.openBlock(!0),a.createElementBlock(a.Fragment,null,a.renderList(C,(c,m)=>(a.openBlock(),a.createBlock(qe.default,{key:m,"display-mode":c.displayMode,"road-id":c.crossId,"cross-id":c.roadId,"map-point":c.mapPoint,"stop-line":c.stopLine,position:c.position,rotation:c.rotation,scale:c.scale,"lamp-status":c.lampStatus},null,8,["display-mode","road-id","cross-id","map-point","stop-line","position","rotation","scale","lamp-status"]))),128))]))}});exports.default=Pe;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const
|
|
2
|
-
`).replace(/null/g,""),r=new Blob([e],{type:"text/csv;charset=utf-8;"}),
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const T=require("@arcgis/core/views/3d/externalRenderers"),b=require("./trace-renderer-external.js"),y=require("./trace-renderer-layer.js");function R(i){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(i){for(const r in i)if(r!=="default"){const n=Object.getOwnPropertyDescriptor(i,r);Object.defineProperty(e,r,n.get?n:{enumerable:!0,get:()=>i[r]})}}return e.default=i,Object.freeze(e)}const v=R(T);class V{constructor(e){this.nullDataCount=0,this.clearTraceTimer=null,e.type==="3d"?(this.traceRenderer=new b.default(e),v.add(e,this.traceRenderer)):this.traceRenderer=new y.default(e)}async init(){await this.traceRenderer.init()}downloadLog(){const e=this.traceRenderer.getLog().map(a=>a.join(",")).join(`
|
|
2
|
+
`).replace(/null/g,""),r=new Blob([e],{type:"text/csv;charset=utf-8;"}),n=URL.createObjectURL(r),c=document.createElement("a");c.setAttribute("href",n),c.setAttribute("download","trace-log.csv"),c.style.visibility="hidden",document.body.appendChild(c),c.click(),document.body.removeChild(c)}async handleVehicleTraceData(e){this.clearTraceTimer||(this.clearTraceTimer=setInterval(()=>{this.nullDataCount++,this.nullDataCount>=5&&(console.log("clear trace data"),this.clearTrace(),this.nullDataCount=0)},1e3)),this.nullDataCount=0;const{newVehList:r,updateVehList:n,deleteVehList:c,jgsj:a}=e,o=e.crossId||"",s=[],h=[];if(r&&r.length>0){for(const l of r){l.localTimestamp||(l.localTimestamp=a||Date.now());const t=this.buildVehicleTrackData(l,o);t&&s.push(t)}await this.traceRenderer.addVehicles(s)}if(n&&n.length>0){for(const l of n){const t=this.buildVehicleTrackData(l,o);t&&h.push(t)}await this.traceRenderer.updateVehicles(h)}if(c&&c.length>0){const l=c.map(t=>o+"-"+(t.ptcId||t.vehno||t.vehNo));this.traceRenderer.deleteVehicles(l)}}toggleTrafficInfo(e){this.traceRenderer.toggleTrafficInfo(e)}clearTrace(){this.clearTraceTimer&&(clearInterval(this.clearTraceTimer),this.clearTraceTimer=null),this.traceRenderer.clearVehicles()}togglePause(e){this.traceRenderer.togglePause(e)}updatePanelContent(e){this.traceRenderer.updatePanelContent(e)}toggleGroundVehicle(e){this.traceRenderer.toggleGroundVehicle(e)}toggleElevatedVehicle(e){this.traceRenderer.toggleElevatedVehicle(e)}setInterpolate(e){this.traceRenderer.setInterpolate(e)}buildVehicleTrackData(e,r){const n=e.longitude,c=e.latitude,a=e.ptcId,o=Number(e.ptcType),s=e.heading,h=Number(e.vehicleType),l=Number(e.vehicleColor),t=e.plateNo||e.plateno,d=Number(e.plateColor),u=e.timestamp,p=e.localTimestamp,g=e.roadLayer?String(e.roadLayer):"1",f=e.step,m=e.speed;if(!(o<0||o>8))return{ptcId:a,crossId:r,vehicleId:r+"-"+a,x:n,y:c,ptcType:o,vehicleType:h,heading:o===2?-s:s,vehicleColor:l,showName:t&&t!==""&&t!=="0"&&t!=="000000"?t:"",plateNo:t,plateColor:d,timestamp:u,localTimestamp:p,roadLayer:g,step:f,speed:m}}}exports.default=V;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const v=require("@arcgis/core/core/promiseUtils.js"),y=require("@arcgis/core/core/reactiveUtils.js"),T=require("@arcgis/core/geometry/SpatialReference"),S=require("@arcgis/core/views/3d/externalRenderers"),C=require("three"),G=require("three/examples/jsm/loaders/GLTFLoader"),x=require("vue"),g=require("../../../types/index.js"),B=require("../../stores/index.js");function f(u){const i=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(u){for(const e in u)if(e!=="default"){const t=Object.getOwnPropertyDescriptor(u,e);Object.defineProperty(i,e,t.get?t:{enumerable:!0,get:()=>u[e]})}}return i.default=u,Object.freeze(i)}const R=f(v),V=f(y),w=f(S),o=f(C);class I{constructor(i){this.cameraHeightThreshold=1e3,this.roughness=.2,this.metalness=.8,this.defaultMaterial=new o.MeshPhongMaterial({color:16777215}),this.materialMap=new Map([[1,this.createCarMaterial(16777215)],[2,this.createCarMaterial(7833753)],[3,this.createCarMaterial(16766720)],[4,this.createCarMaterial(16758465)],[5,this.createCarMaterial(14423100)],[6,this.createCarMaterial(3329330)],[7,this.createCarMaterial(2003183)],[8,this.createCarMaterial(16032864)],[9,this.createCarMaterial(2105376)],[10,this.createCarMaterial(9662683)],[99,this.createCarMaterial(6908265)]]),this.isInitialized=!1,this.showGroundVehicle=!0,this.showElevatedVehicle=!0,this.isPaused=!1,this.currentSpriteContent=g.EVehiclePlateState.None,this.historyPositionMap=new Map,this.vehicleObjectMap=new Map,this.needInterpolate=!0,this.updateModel=!1,this.appDataStore=B.default.useAppDataStore,this.logTable=[["ptcId","plateno","timestamp","localTimestamp","speed","longitude","latitude","ptcType","vehicleType","vehicleColor","plateColor","heading","fixAngle","roadLayer","step","receiveTimestamp","queueLength","status"]],this.view=i;const e=x.toRaw(this.appDataStore.mapConfig);this.assetsRoot=e.assetsRoot,V.watch(()=>this.view.camera.position.z,(t,s)=>{(s<=this.cameraHeightThreshold&&t>this.cameraHeightThreshold||s>this.cameraHeightThreshold&&t<=this.cameraHeightThreshold)&&(this.updateModel=!0)})}createCarMaterial(i){return new o.MeshPhongMaterial({color:i})}getLog(){return this.logTable}async init(){const i=new G.GLTFLoader;await R.eachAlways([new Promise(e=>{i.load(`${this.assetsRoot}/3DModels/car.glb`,t=>{const s=t.scene,n=new o.Box3().setFromObject(s).getSize(new o.Vector3);this.carModel=new o.Object3D,this.carModel.rotation.x=o.MathUtils.degToRad(90),this.carModel.add(s),s.position.set(0,0,n.z/2),e()})}),new Promise(e=>{i.load(`${this.assetsRoot}/3DModels/van.glb`,t=>{const s=t.scene,n=new o.Box3().setFromObject(s).getSize(new o.Vector3);this.vanModel=new o.Object3D,this.vanModel.rotation.x=o.MathUtils.degToRad(90),this.vanModel.add(s),s.position.set(0,0,n.z/2),e()})}),new Promise(e=>{i.load(`${this.assetsRoot}/3DModels/truck.glb`,t=>{const s=t.scene;s.scale.set(1.2,1,1.5);const n=new o.Box3().setFromObject(s).getSize(new o.Vector3);this.truckModel=new o.Object3D,this.truckModel.rotation.x=o.MathUtils.degToRad(90),this.truckModel.add(s),s.position.set(0,0,n.z/2),e()})}),new Promise(e=>{i.load(`${this.assetsRoot}/3DModels/bus.glb`,t=>{const s=t.scene,n=new o.Box3().setFromObject(s).getSize(new o.Vector3);this.busModel=new o.Object3D,this.busModel.rotation.x=o.MathUtils.degToRad(90),this.busModel.add(s),s.position.set(0,0,n.z/2),e()})}),new Promise(e=>{i.load(`${this.assetsRoot}/3DModels/bicycle.glb`,t=>{this.bicycleModel=t.scene,this.bicycleModel.rotation.x=o.MathUtils.degToRad(90),this.bicycleModel.rotation.y=o.MathUtils.degToRad(180),e()})}),new Promise(e=>{i.load(`${this.assetsRoot}/3DModels/bicycle.glb`,t=>{this.passengerModel=t.scene,this.passengerModel.rotation.x=o.MathUtils.degToRad(90),this.passengerModel.rotation.y=o.MathUtils.degToRad(180),e()})}),new Promise(e=>{this.bluePlateBG=new Image,this.bluePlateBG.src=`${this.assetsRoot}/Images/PlateBG/blue.png`,this.bluePlateBG.onload=()=>{e()}}),new Promise(e=>{this.yellowPlateBG=new Image,this.yellowPlateBG.src=`${this.assetsRoot}/Images/PlateBG/yellow.png`,this.yellowPlateBG.onload=()=>{e()}}),new Promise(e=>{this.whitePlateBG=new Image,this.whitePlateBG.src=`${this.assetsRoot}/Images/PlateBG/white.png`,this.whitePlateBG.onload=()=>{e()}}),new Promise(e=>{this.blackPlateBG=new Image,this.blackPlateBG.src=`${this.assetsRoot}/Images/PlateBG/black.png`,this.blackPlateBG.onload=()=>{e()}}),new Promise(e=>{this.neoYellowPlateBG=new Image,this.neoYellowPlateBG.src=`${this.assetsRoot}/Images/PlateBG/neo_yellow.png`,this.neoYellowPlateBG.onload=()=>{e()}}),new Promise(e=>{this.neoGreenPlateBG=new Image,this.neoGreenPlateBG.src=`${this.assetsRoot}/Images/PlateBG/neo_green.png`,this.neoGreenPlateBG.onload=()=>{e()}}),new Promise(e=>{this.greyPlateBG=new Image,this.greyPlateBG.src=`${this.assetsRoot}/Images/PlateBG/grey.png`,this.greyPlateBG.onload=()=>{e()}})]),this.isInitialized=!0}setInterpolate(i){this.clearVehicles(),this.needInterpolate=i}async setup(i){this.context=i,this.renderer=new o.WebGLRenderer({context:i.gl,premultipliedAlpha:!0,logarithmicDepthBuffer:!0,antialias:!0,powerPreference:"high-performance"}),this.renderer.shadowMap.enabled=!0,this.renderer.setPixelRatio(window.devicePixelRatio),this.renderer.setViewport(0,0,this.view.width,this.view.height),this.renderer.autoClearDepth=!1,this.renderer.autoClearStencil=!1,this.renderer.autoClearColor=!1;const e=this.renderer.setRenderTarget.bind(this.renderer);this.renderer.setRenderTarget=s=>{e(s),s==null&&i.bindRenderTarget()},this.scene=new o.Scene;const{camera:t}=i;this.camera=new o.PerspectiveCamera(t.fovY,t.aspect,.1,1e5),this.ambient=new o.AmbientLight(16777215,2),this.scene.add(this.ambient),this.sun=new o.DirectionalLight(16777215,2),this.scene.add(this.sun),i.resetWebGLState()}async render(i){var s;const e=i.camera;if(this.camera.position.set(e.eye[0],e.eye[1],e.eye[2]),this.camera.up.set(e.up[0],e.up[1],e.up[2]),this.camera.lookAt(new o.Vector3(e.center[0],e.center[1],e.center[2])),this.camera.projectionMatrix.fromArray(e.projectionMatrix),!this.isPaused&&this.needInterpolate)for(const a of this.vehicleObjectMap.keys()){const n=(s=this.vehicleObjectMap.get(a))==null?void 0:s.model;if(!n)continue;const r=this.computeVehiclePosition(a);if(r){const d=this.toRenderCoordinates(r);n.position.set(d[0],d[1],d[2]),n.rotation.y=o.MathUtils.degToRad(-r[3])}}const t=i.sunLight;this.sun.position.set(t.direction[0],t.direction[1],t.direction[2]),this.sun.intensity=t.diffuse.intensity,this.sun.color=new o.Color(t.diffuse.color[0],t.diffuse.color[1],t.diffuse.color[2]),this.ambient.intensity=t.ambient.intensity,this.ambient.color=new o.Color(t.ambient.color[0],t.ambient.color[1],t.ambient.color[2]),this.renderer.resetState(),i.bindRenderTarget(),this.renderer.render(this.scene,this.camera),w.requestRender(this.view),i.resetWebGLState()}async addVehicles(i){if(this.isPaused||!this.isInitialized)return;const e=Date.now();for(const t of i){this.appDataStore.saveTrackLog&&this.logTable.push([t.ptcId,t.plateNo,t.timestamp,t.localTimestamp,t.speed,t.x,t.y,t.ptcType,t.vehicleType,t.vehicleColor,t.plateColor,t.heading,t.fixAngle,t.roadLayer,t.step,e,0,0]);const{vehicleId:s,localTimestamp:a}=t,n=Number(t.x),r=Number(t.y),d=Number(t.heading);this.historyPositionMap.set(s,[{pos:[n,r,0],heading:d,time:a}]);const h=this.getVehicleModel(t);h.name=s,h.visible=!1;try{const l=await this.createPlateSprite(t);l&&(h.add(l),l.position.set(0,5,-4))}catch(l){console.log("createPlateSprite error:",l)}this.scene.add(h),this.vehicleObjectMap.set(s,{model:h,data:t,waitForDelete:!1,isMoving:!1})}}async updateVehicles(i){if(this.isPaused||!this.isInitialized)return;const e=[],t=Date.now();for(const s of i){const{vehicleId:a,localTimestamp:n}=s,r=Number(s.x),d=Number(s.y);let h=Number(s.heading);const l=this.vehicleObjectMap.get(a),p=this.historyPositionMap.get(a);if(!l||!p)e.push(s);else{if(this.appDataStore.saveTrackLog&&this.logTable.push([s.ptcId,s.plateNo,s.timestamp,s.localTimestamp,s.speed,s.x,s.y,s.ptcType,s.vehicleType,s.vehicleColor,s.plateColor,s.heading,s.fixAngle,s.roadLayer,s.step,t,p.length,1]),this.updateModel||l.data.vehicleColor!==s.vehicleColor||l.data.vehicleType!==s.vehicleType){this.scene.remove(l.model),this.disposeModel(l.model),l.model=this.getVehicleModel(s),l.model.visible=!0;const c=await this.createPlateSprite(s);c&&(l.model.add(c),c.position.set(0,5,-4)),this.scene.add(l.model)}if(l.data.showName!==s.showName||l.data.plateColor!==s.plateColor){const c=l.model.getObjectByName("VehiclePlate");c&&(l.model.remove(c),this.disposeModel(c));const m=await this.createPlateSprite(s);m&&(l.model.add(m),m.position.set(0,5,-4))}if(l.data=s,this.needInterpolate){const c=p[p.length-1];Math.abs(h-c.heading)>=180&&(h>c.heading?c.heading+=360:h+=360),p.push({pos:[r,d,0],heading:h,time:n})}else{this.historyPositionMap.set(a,[{pos:[r,d,0],heading:h,time:n}]);const c=this.toRenderCoordinates([r,d,0]);l.model.position.set(c[0],c[1],c[2]),l.model.rotation.y=o.MathUtils.degToRad(-h)}}}await this.addVehicles(e),this.updateModel=!1,this.needInterpolate||this.render(this.context)}toRenderCoordinates(i){const e=[0,0,0];return w.toRenderCoordinates(this.view,i,0,T.WGS84,e,0,1),e}deleteVehicles(i){if(this.isPaused)return;const e=Date.now();i.forEach(t=>{if(this.appDataStore.saveTrackLog){const a=this.historyPositionMap.get(t);this.logTable.push([t,"","","","","","","","","","","","","","",e,a?a.length:0,2])}const s=this.vehicleObjectMap.get(t);s&&(this.needInterpolate?s.isMoving?s.waitForDelete=!0:this.deleteVehicle(s):this.deleteVehicle(s))})}deleteVehicle(i){this.scene.remove(i.model),this.disposeModel(i.model);const e=i.data.vehicleId;this.vehicleObjectMap.delete(e),this.historyPositionMap.delete(e)}async toggleTrafficInfo(i){i.name==="vehiclePlate"&&(i.visible===!0&&this.currentSpriteContent===g.EVehiclePlateState.None?await this.updatePanelContent(g.EVehiclePlateState.PlateNumber):await this.updatePanelContent(i.visible?this.currentSpriteContent:g.EVehiclePlateState.None))}togglePause(i){this.isPaused=i}clearVehicles(){for(const i of this.vehicleObjectMap.keys()){const e=this.vehicleObjectMap.get(i);e&&(this.scene.remove(e.model),this.disposeModel(e.model))}this.vehicleObjectMap.clear(),this.historyPositionMap.clear()}async updatePanelContent(i){if(i!==this.currentSpriteContent){this.currentSpriteContent=i;for(const e of this.vehicleObjectMap.keys()){const t=this.vehicleObjectMap.get(e);if(t){const s=t.model.getObjectByName("VehiclePlate");if(s&&(t.model.remove(s),this.disposeModel(s)),i!==g.EVehiclePlateState.None){const a=await this.createPlateSprite(t.data);a&&(t.model.add(a),a.position.set(0,5,-4))}}}}}toggleGroundVehicle(i){console.log("toggleGroundVehicle",i),this.showGroundVehicle=i}toggleElevatedVehicle(i){this.showElevatedVehicle=i}disposeModel(i){i.traverse(e=>{e instanceof o.Mesh&&(e.geometry.dispose(),e.material.dispose())})}computeVehiclePosition(i){const e=this.historyPositionMap.get(i),t=this.vehicleObjectMap.get(i);if(!t||!e||!t.isMoving&&e.length<=2)return;const s=Date.now();t.isMoving=!0,t.data.roadLayer==="1"?t.model.visible=this.showGroundVehicle:t.model.visible=this.showElevatedVehicle,t.segmentStartTime||(t.segmentStartTime=s,t.segmentTotalTime=e[1].time-e[0].time);const a=s-t.segmentStartTime,n=Math.min(a/t.segmentTotalTime,1);if(n===1)if(e.shift(),e.length===1){t.waitForDelete===!0?this.deleteVehicle(t):(t.segmentStartTime=void 0,t.segmentTotalTime=void 0,t.model.visible=!1,t.isMoving=!1,console.log("hide vehicle",i));return}else{t.segmentStartTime=Date.now();const r=a-t.segmentTotalTime;return t.segmentTotalTime=e[1].time-e[0].time-r,(e[1].heading>=270&&e[0].heading<=90||e[1].heading<=90&&e[0].heading>=270)&&(e[1].heading>e[0].heading?e[0].heading+=360:e[1].heading+=360),e[0].pos.concat(e[0].heading)}else if(e.length>=2){const r=e[0].pos[0]+(e[1].pos[0]-e[0].pos[0])*n,d=e[0].pos[1]+(e[1].pos[1]-e[0].pos[1])*n,h=e[0].heading+(e[1].heading-e[0].heading)*n;return[r,d,0,h]}else return}getVehicleModel(i){if(this.view.camera.position.z>=this.cameraHeightThreshold){const e=new o.SphereGeometry(5,32,32),t=new o.MeshPhysicalMaterial({color:325253,emissive:0,roughness:this.roughness,metalness:this.metalness});return new o.Mesh(e,t)}else{let e;if(i.ptcType===2)e=this.bicycleModel.clone();else if(i.ptcType===3)e=this.passengerModel.clone();else{switch(i.vehicleType){case 10:e=this.carModel.clone();break;case 20:e=this.vanModel.clone();break;case 25:e=this.truckModel.clone();break;case 50:e=this.busModel.clone();break;default:e=this.carModel.clone();break}const t=this.materialMap.get(i.vehicleColor)||this.defaultMaterial;let s=!1;e.traverse(a=>{!s&&a instanceof o.Mesh&&(a.material=t,s=!0)})}return e}}createCanvas(i,e,t){const s=document.createElement("canvas"),a=i.width,n=i.height;s.width=a,s.height=n;const r=s.getContext("2d");if(!r){console.log("canvas创建失败");return}return r.fillStyle="rgba(0,0,0,0.0)",r.fillRect(0,0,a,n),r.drawImage(i,0,0,a,n),r.beginPath(),r.translate(a/2,n/2),r.fillStyle=t,r.font="bold 32px 宋体",r.textBaseline="middle",r.textAlign="center",r.fillText(e,0,0),s}createPlateSprite(i){return new Promise((e,t)=>{var h,l;const s=!i.plateNo||i.plateNo==="0"||i.plateNo==="000000";if(this.currentSpriteContent===g.EVehiclePlateState.None||this.currentSpriteContent===g.EVehiclePlateState.PlateNumber&&s){e(void 0);return}let a=new Image,n="",r="";if(this.currentSpriteContent===g.EVehiclePlateState.PlateNumber||this.currentSpriteContent===g.EVehiclePlateState.Mix)if(s)a=this.greyPlateBG,n=i.ptcId,r="#ffffff";else switch(n=((h=i.showName)==null?void 0:h.substring(0,2))+"•"+((l=i.showName)==null?void 0:l.substring(2)),i.plateColor){case 1:a=this.bluePlateBG,r="#ffffff";break;case 2:a=this.yellowPlateBG,r="#000000";break;case 3:a=this.whitePlateBG,r="#000000";break;case 4:a=this.blackPlateBG,r="#ffffff";break;case 5:a=this.neoYellowPlateBG,r="#000000";break;case 6:a=this.neoGreenPlateBG,r="#000000";break;default:a=this.greyPlateBG,n=i.plateNo,r="#ffffff";break}else this.currentSpriteContent===g.EVehiclePlateState.Id&&(a=this.greyPlateBG,n=i.ptcId,r="#ffffff");const d=this.createCanvas(a,n,r);if(d){const p=new o.CanvasTexture(d),c=new o.SpriteMaterial({map:p,transparent:!1}),m=new o.Sprite(c),b=.05,M=d.width*b,P=d.height*b;m.scale.set(M,P,1),m.name="VehiclePlate",e(m)}else{t("canvas创建失败");return}a.onerror=p=>{console.log(`号牌背景加载失败: ${a.src}`,p),t(p)}})}}exports.default=I;
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const v=require("@arcgis/core/core/promiseUtils.js"),y=require("@arcgis/core/core/reactiveUtils.js"),T=require("@arcgis/core/geometry/SpatialReference"),S=require("@arcgis/core/views/3d/externalRenderers"),C=require("three"),G=require("three/examples/jsm/loaders/GLTFLoader"),x=require("vue"),m=require("../../../types/index.js"),B=require("../../stores/index.js");function f(u){const i=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(u){for(const e in u)if(e!=="default"){const t=Object.getOwnPropertyDescriptor(u,e);Object.defineProperty(i,e,t.get?t:{enumerable:!0,get:()=>u[e]})}}return i.default=u,Object.freeze(i)}const R=f(v),V=f(y),b=f(S),a=f(C);class I{constructor(i){this.cameraHeightThreshold=1e3,this.roughness=.2,this.metalness=.8,this.defaultMaterial=new a.MeshPhongMaterial({color:16777215}),this.materialMap=new Map([[1,this.createCarMaterial(16777215)],[2,this.createCarMaterial(7833753)],[3,this.createCarMaterial(16766720)],[4,this.createCarMaterial(16758465)],[5,this.createCarMaterial(14423100)],[6,this.createCarMaterial(3329330)],[7,this.createCarMaterial(2003183)],[8,this.createCarMaterial(16032864)],[9,this.createCarMaterial(2105376)],[10,this.createCarMaterial(9662683)],[99,this.createCarMaterial(6908265)]]),this.isInitialized=!1,this.showGroundVehicle=!0,this.showElevatedVehicle=!0,this.isPaused=!1,this.currentSpriteContent=m.EVehiclePlateState.None,this.historyPositionMap=new Map,this.vehicleObjectMap=new Map,this.needInterpolate=!0,this.updateModel=!1,this.appDataStore=B.default.useAppDataStore,this.logTable=[["ptcId","plateno","timestamp","localTimestamp","speed","longitude","latitude","ptcType","vehicleType","vehicleColor","plateColor","heading","fixAngle","roadLayer","step","receiveTimestamp","queueLength","status"]],this.view=i;const e=x.toRaw(this.appDataStore.mapConfig);this.assetsRoot=e.assetsRoot,V.watch(()=>this.view.camera.position.z,(t,s)=>{(s<=this.cameraHeightThreshold&&t>this.cameraHeightThreshold||s>this.cameraHeightThreshold&&t<=this.cameraHeightThreshold)&&(this.updateModel=!0)})}createCarMaterial(i){return new a.MeshPhongMaterial({color:i})}getLog(){return this.logTable}async init(){const i=new G.GLTFLoader;await R.eachAlways([new Promise(e=>{i.load(`${this.assetsRoot}/3DModels/car.glb`,t=>{const s=t.scene,l=new a.Box3().setFromObject(s).getSize(new a.Vector3);this.carModel=new a.Object3D,this.carModel.rotation.x=a.MathUtils.degToRad(90),this.carModel.add(s),s.position.set(0,0,l.z/2),e()})}),new Promise(e=>{i.load(`${this.assetsRoot}/3DModels/van.glb`,t=>{const s=t.scene,l=new a.Box3().setFromObject(s).getSize(new a.Vector3);this.vanModel=new a.Object3D,this.vanModel.rotation.x=a.MathUtils.degToRad(90),this.vanModel.add(s),s.position.set(0,0,l.z/2),e()})}),new Promise(e=>{i.load(`${this.assetsRoot}/3DModels/truck.glb`,t=>{const s=t.scene;s.scale.set(1.2,1,1.5);const l=new a.Box3().setFromObject(s).getSize(new a.Vector3);this.truckModel=new a.Object3D,this.truckModel.rotation.x=a.MathUtils.degToRad(90),this.truckModel.add(s),s.position.set(0,0,l.z/2),e()})}),new Promise(e=>{i.load(`${this.assetsRoot}/3DModels/bus.glb`,t=>{const s=t.scene,l=new a.Box3().setFromObject(s).getSize(new a.Vector3);this.busModel=new a.Object3D,this.busModel.rotation.x=a.MathUtils.degToRad(90),this.busModel.add(s),s.position.set(0,0,l.z/2),e()})}),new Promise(e=>{i.load(`${this.assetsRoot}/3DModels/bicycle.glb`,t=>{this.bicycleModel=t.scene,this.bicycleModel.rotation.x=a.MathUtils.degToRad(90),this.bicycleModel.rotation.y=a.MathUtils.degToRad(180),e()})}),new Promise(e=>{i.load(`${this.assetsRoot}/3DModels/bicycle.glb`,t=>{this.passengerModel=t.scene,this.passengerModel.rotation.x=a.MathUtils.degToRad(90),this.passengerModel.rotation.y=a.MathUtils.degToRad(180),e()})}),new Promise(e=>{this.bluePlateBG=new Image,this.bluePlateBG.src=`${this.assetsRoot}/Images/PlateBG/blue.png`,this.bluePlateBG.onload=()=>{e()}}),new Promise(e=>{this.yellowPlateBG=new Image,this.yellowPlateBG.src=`${this.assetsRoot}/Images/PlateBG/yellow.png`,this.yellowPlateBG.onload=()=>{e()}}),new Promise(e=>{this.whitePlateBG=new Image,this.whitePlateBG.src=`${this.assetsRoot}/Images/PlateBG/white.png`,this.whitePlateBG.onload=()=>{e()}}),new Promise(e=>{this.blackPlateBG=new Image,this.blackPlateBG.src=`${this.assetsRoot}/Images/PlateBG/black.png`,this.blackPlateBG.onload=()=>{e()}}),new Promise(e=>{this.neoYellowPlateBG=new Image,this.neoYellowPlateBG.src=`${this.assetsRoot}/Images/PlateBG/neo_yellow.png`,this.neoYellowPlateBG.onload=()=>{e()}}),new Promise(e=>{this.neoGreenPlateBG=new Image,this.neoGreenPlateBG.src=`${this.assetsRoot}/Images/PlateBG/neo_green.png`,this.neoGreenPlateBG.onload=()=>{e()}}),new Promise(e=>{this.greyPlateBG=new Image,this.greyPlateBG.src=`${this.assetsRoot}/Images/PlateBG/grey.png`,this.greyPlateBG.onload=()=>{e()}})]),this.isInitialized=!0}setInterpolate(i){this.clearVehicles(),this.needInterpolate=i}async setup(i){this.context=i,this.renderer=new a.WebGLRenderer({context:i.gl,premultipliedAlpha:!0,logarithmicDepthBuffer:!0,antialias:!0,powerPreference:"high-performance"}),this.renderer.shadowMap.enabled=!0,this.renderer.setPixelRatio(window.devicePixelRatio),this.renderer.setViewport(0,0,this.view.width,this.view.height),this.renderer.autoClearDepth=!1,this.renderer.autoClearStencil=!1,this.renderer.autoClearColor=!1;const e=this.renderer.setRenderTarget.bind(this.renderer);this.renderer.setRenderTarget=s=>{e(s),s==null&&i.bindRenderTarget()},this.scene=new a.Scene;const{camera:t}=i;this.camera=new a.PerspectiveCamera(t.fovY,t.aspect,.1,1e5),this.ambient=new a.AmbientLight(16777215,2),this.scene.add(this.ambient),this.sun=new a.DirectionalLight(16777215,2),this.scene.add(this.sun),i.resetWebGLState()}async render(i){var s;const e=i.camera;if(this.camera.position.set(e.eye[0],e.eye[1],e.eye[2]),this.camera.up.set(e.up[0],e.up[1],e.up[2]),this.camera.lookAt(new a.Vector3(e.center[0],e.center[1],e.center[2])),this.camera.projectionMatrix.fromArray(e.projectionMatrix),!this.isPaused&&this.needInterpolate)for(const o of this.vehicleObjectMap.keys()){const l=(s=this.vehicleObjectMap.get(o))==null?void 0:s.model;if(!l)continue;const r=this.computeVehiclePosition(o);if(r){const d=this.toRenderCoordinates(r);l.position.set(d[0],d[1],d[2]),l.rotation.y=a.MathUtils.degToRad(-r[3])}}const t=i.sunLight;this.sun.position.set(t.direction[0],t.direction[1],t.direction[2]),this.sun.intensity=t.diffuse.intensity,this.sun.color=new a.Color(t.diffuse.color[0],t.diffuse.color[1],t.diffuse.color[2]),this.ambient.intensity=t.ambient.intensity,this.ambient.color=new a.Color(t.ambient.color[0],t.ambient.color[1],t.ambient.color[2]),this.renderer.resetState(),i.bindRenderTarget(),this.renderer.render(this.scene,this.camera),b.requestRender(this.view),i.resetWebGLState()}async addVehicles(i){if(this.isPaused||!this.isInitialized)return;const e=Date.now();for(const t of i){this.appDataStore.saveTrackLog&&this.logTable.push([t.ptcId,t.plateNo,t.timestamp,t.localTimestamp,t.speed,t.x,t.y,t.ptcType,t.vehicleType,t.vehicleColor,t.plateColor,t.heading,t.fixAngle,t.roadLayer,t.step,e,0,0]);const{vehicleId:s,localTimestamp:o}=t,l=Number(t.x),r=Number(t.y),d=Number(t.heading);this.historyPositionMap.set(s,[{pos:[l,r,0],heading:d,time:o}]);const h=this.getVehicleModel(t);h.name=s,h.visible=!1;try{const n=await this.createPlateSprite(t);n&&(h.add(n),n.position.set(0,5,-4))}catch(n){console.log("createPlateSprite error:",n)}this.scene.add(h),this.vehicleObjectMap.set(s,{model:h,data:t,waitForDelete:!1,isMoving:!1})}}async updateVehicles(i){if(this.isPaused||!this.isInitialized)return;const e=[],t=Date.now();for(const s of i){const{vehicleId:o,localTimestamp:l}=s,r=Number(s.x),d=Number(s.y);let h=Number(s.heading);const n=this.vehicleObjectMap.get(o),p=this.historyPositionMap.get(o);if(!n||!p)e.push(s);else{if(this.appDataStore.saveTrackLog&&this.logTable.push([s.ptcId,s.plateNo,s.timestamp,s.localTimestamp,s.speed,s.x,s.y,s.ptcType,s.vehicleType,s.vehicleColor,s.plateColor,s.heading,s.fixAngle,s.roadLayer,s.step,t,p.length,1]),this.updateModel||n.data.vehicleColor!==s.vehicleColor||n.data.vehicleType!==s.vehicleType){this.scene.remove(n.model),this.disposeModel(n.model),n.model=this.getVehicleModel(s),n.model.visible=!0;const c=await this.createPlateSprite(s);c&&(n.model.add(c),c.position.set(0,5,-4)),this.scene.add(n.model)}if(n.data.showName!==s.showName||n.data.plateColor!==s.plateColor){const c=n.model.getObjectByName("VehiclePlate");c&&(n.model.remove(c),this.disposeModel(c));const g=await this.createPlateSprite(s);g&&(n.model.add(g),g.position.set(0,5,-4))}if(n.data=s,this.needInterpolate){const c=p[p.length-1];Math.abs(h-c.heading)>=180&&(h>c.heading?c.heading+=360:h+=360),p.push({pos:[r,d,0],heading:h,time:l})}else{this.historyPositionMap.set(o,[{pos:[r,d,0],heading:h,time:l}]);const c=this.toRenderCoordinates([r,d,0]);n.model.position.set(c[0],c[1],c[2]),n.model.rotation.y=a.MathUtils.degToRad(-h)}}}await this.addVehicles(e),this.updateModel=!1,this.needInterpolate||this.render(this.context)}toRenderCoordinates(i){const e=[0,0,0];return b.toRenderCoordinates(this.view,i,0,T.WGS84,e,0,1),e}deleteVehicles(i){if(this.isPaused)return;const e=Date.now();i.forEach(t=>{if(this.appDataStore.saveTrackLog){const o=this.historyPositionMap.get(t);this.logTable.push([t,"","","","","","","","","","","","","","",e,o?o.length:0,2])}const s=this.vehicleObjectMap.get(t);s&&(this.needInterpolate?s.isMoving?s.waitForDelete=!0:this.deleteVehicle(s):this.deleteVehicle(s))})}deleteVehicle(i){this.disposeModel(i.model),this.scene.remove(i.model);const e=i.data.vehicleId;this.vehicleObjectMap.delete(e),this.historyPositionMap.delete(e)}async toggleTrafficInfo(i){i.name==="vehiclePlate"&&(i.visible===!0&&this.currentSpriteContent===m.EVehiclePlateState.None?await this.updatePanelContent(m.EVehiclePlateState.PlateNumber):await this.updatePanelContent(i.visible?this.currentSpriteContent:m.EVehiclePlateState.None))}togglePause(i){this.isPaused=i}clearVehicles(){for(const i of this.vehicleObjectMap.values())this.disposeModel(i.model),this.scene.remove(i.model);this.vehicleObjectMap.clear(),this.historyPositionMap.clear()}async updatePanelContent(i){this.currentSpriteContent=i;for(const e of this.vehicleObjectMap.values()){const t=e.model.getObjectByName("VehiclePlate");if(t&&(e.model.remove(t),this.disposeModel(t)),i!==m.EVehiclePlateState.None){const s=await this.createPlateSprite(e.data);s&&(e.model.add(s),s.position.set(0,5,-4))}}}toggleGroundVehicle(i){this.showGroundVehicle=i}toggleElevatedVehicle(i){this.showElevatedVehicle=i}disposeModel(i){i.traverse(e=>{e instanceof a.Mesh&&(e.geometry.dispose(),e.material.dispose())})}computeVehiclePosition(i){const e=this.historyPositionMap.get(i),t=this.vehicleObjectMap.get(i);if(!t||!e||!t.isMoving&&e.length<=2)return;const s=Date.now();t.isMoving=!0,t.data.roadLayer==="1"?t.model.visible=this.showGroundVehicle:t.model.visible=this.showElevatedVehicle,t.segmentStartTime||(t.segmentStartTime=s,t.segmentTotalTime=e[1].time-e[0].time);const o=s-t.segmentStartTime,l=Math.min(o/t.segmentTotalTime,1);if(l===1)if(e.shift(),e.length===1){t.waitForDelete===!0?this.deleteVehicle(t):(t.segmentStartTime=void 0,t.segmentTotalTime=void 0,t.model.visible=!1,t.isMoving=!1,console.log("hide vehicle",i));return}else{t.segmentStartTime=Date.now();const r=o-t.segmentTotalTime;return t.segmentTotalTime=e[1].time-e[0].time-r,(e[1].heading>=270&&e[0].heading<=90||e[1].heading<=90&&e[0].heading>=270)&&(e[1].heading>e[0].heading?e[0].heading+=360:e[1].heading+=360),e[0].pos.concat(e[0].heading)}else if(e.length>=2){const r=e[0].pos[0]+(e[1].pos[0]-e[0].pos[0])*l,d=e[0].pos[1]+(e[1].pos[1]-e[0].pos[1])*l,h=e[0].heading+(e[1].heading-e[0].heading)*l;return[r,d,0,h]}else return}getVehicleModel(i){if(this.view.camera.position.z>=this.cameraHeightThreshold){const e=new a.SphereGeometry(5,32,32),t=new a.MeshPhysicalMaterial({color:325253,emissive:0,roughness:this.roughness,metalness:this.metalness});return new a.Mesh(e,t)}else{let e;if(i.ptcType===2)e=this.bicycleModel.clone();else if(i.ptcType===3)e=this.passengerModel.clone();else{switch(i.vehicleType){case 10:e=this.carModel.clone();break;case 20:e=this.vanModel.clone();break;case 25:e=this.truckModel.clone();break;case 50:e=this.busModel.clone();break;default:e=this.carModel.clone();break}const t=this.materialMap.get(i.vehicleColor)||this.defaultMaterial;let s=!1;e.traverse(o=>{!s&&o instanceof a.Mesh&&(o.material=t,s=!0)})}return e}}createCanvas(i,e,t){const s=document.createElement("canvas"),o=i.width,l=i.height;s.width=o,s.height=l;const r=s.getContext("2d");if(!r){console.log("canvas创建失败");return}return r.fillStyle="rgba(0,0,0,0.0)",r.fillRect(0,0,o,l),r.drawImage(i,0,0,o,l),r.beginPath(),r.translate(o/2,l/2),r.fillStyle=t,r.font="bold 32px 宋体",r.textBaseline="middle",r.textAlign="center",r.fillText(e,0,0),s}createPlateSprite(i){return new Promise((e,t)=>{var h,n;const s=!i.plateNo||i.plateNo==="0"||i.plateNo==="000000";if(this.currentSpriteContent===m.EVehiclePlateState.None||this.currentSpriteContent===m.EVehiclePlateState.PlateNumber&&s){e(void 0);return}let o=new Image,l="",r="";if(this.currentSpriteContent===m.EVehiclePlateState.PlateNumber||this.currentSpriteContent===m.EVehiclePlateState.Mix)if(s)o=this.greyPlateBG,l=i.ptcId,r="#ffffff";else switch(l=((h=i.showName)==null?void 0:h.substring(0,2))+"•"+((n=i.showName)==null?void 0:n.substring(2)),i.plateColor){case 1:o=this.bluePlateBG,r="#ffffff";break;case 2:o=this.yellowPlateBG,r="#000000";break;case 3:o=this.whitePlateBG,r="#000000";break;case 4:o=this.blackPlateBG,r="#ffffff";break;case 5:o=this.neoYellowPlateBG,r="#000000";break;case 6:o=this.neoGreenPlateBG,r="#000000";break;default:o=this.greyPlateBG,l=i.plateNo,r="#ffffff";break}else this.currentSpriteContent===m.EVehiclePlateState.Id&&(o=this.greyPlateBG,l=i.ptcId,r="#ffffff");const d=this.createCanvas(o,l,r);if(d){const p=new a.CanvasTexture(d),c=new a.SpriteMaterial({map:p,transparent:!1}),g=new a.Sprite(c),w=.05,M=d.width*w,P=d.height*w;g.scale.set(M,P,1),g.name="VehiclePlate",e(g)}else{t("canvas创建失败");return}o.onerror=p=>{console.log(`号牌背景加载失败: ${o.src}`,p),t(p)}})}}exports.default=I;
|