gisviewer-vue3-arcgis 1.0.135 → 1.0.137
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/src/gis-map/utils/holo-flow/trace-renderer-external.mjs +183 -177
- package/es/src/gis-map/utils/signal-control-area-controller/index.mjs +46 -25
- package/es/src/types/index.d.ts +1 -1
- package/lib/src/gis-map/utils/holo-flow/trace-renderer-external.js +1 -1
- package/lib/src/gis-map/utils/signal-control-area-controller/index.js +1 -1
- package/lib/src/types/index.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import * as
|
|
1
|
+
import * as M from "@arcgis/core/core/promiseUtils.js";
|
|
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 a from "three";
|
|
6
6
|
import { GLTFLoader as y } from "three/examples/jsm/loaders/GLTFLoader";
|
|
7
7
|
import { EVehiclePlateState as m } from "../../../types/index.mjs";
|
|
8
8
|
import T from "../../stores/index.mjs";
|
|
9
|
-
class
|
|
10
|
-
constructor(
|
|
11
|
-
this.cameraHeightThreshold = 1e3, this.roughness = 0.2, this.metalness = 0.8, this.defaultMaterial = new
|
|
9
|
+
class R {
|
|
10
|
+
constructor(s) {
|
|
11
|
+
this.cameraHeightThreshold = 1e3, this.roughness = 0.2, this.metalness = 0.8, this.defaultMaterial = new a.MeshPhongMaterial({
|
|
12
12
|
color: 16777215
|
|
13
13
|
}), this.materialMap = /* @__PURE__ */ new Map([
|
|
14
14
|
[1, this.createCarMaterial(16777215)],
|
|
@@ -45,7 +45,7 @@ class I {
|
|
|
45
45
|
]
|
|
46
46
|
], this.assetsRoot = JSON.parse(
|
|
47
47
|
JSON.stringify(this.appDataStore.mapConfig)
|
|
48
|
-
).assetsRoot, this.view =
|
|
48
|
+
).assetsRoot, this.view = s, P.watch(
|
|
49
49
|
() => this.view.camera.position.z,
|
|
50
50
|
(e, t) => {
|
|
51
51
|
(t <= this.cameraHeightThreshold && e > this.cameraHeightThreshold || t > this.cameraHeightThreshold && e <= this.cameraHeightThreshold) && (this.updateModel = !0);
|
|
@@ -53,9 +53,9 @@ class I {
|
|
|
53
53
|
);
|
|
54
54
|
}
|
|
55
55
|
// private readonly vehiclePool = new VehiclePool();
|
|
56
|
-
createCarMaterial(
|
|
57
|
-
return new
|
|
58
|
-
color:
|
|
56
|
+
createCarMaterial(s) {
|
|
57
|
+
return new a.MeshPhongMaterial({
|
|
58
|
+
color: s
|
|
59
59
|
// // emissive: 0xc3c3c3,
|
|
60
60
|
// roughness: this.roughness,
|
|
61
61
|
// metalness: this.metalness
|
|
@@ -65,31 +65,37 @@ class I {
|
|
|
65
65
|
return this.logTable;
|
|
66
66
|
}
|
|
67
67
|
async init() {
|
|
68
|
-
const
|
|
69
|
-
await
|
|
68
|
+
const s = new y();
|
|
69
|
+
await M.eachAlways([
|
|
70
70
|
new Promise((e) => {
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
s.load(`${this.assetsRoot}/3DModels/car.glb`, (t) => {
|
|
72
|
+
const i = t.scene, n = new a.Box3().setFromObject(i).getSize(new a.Vector3());
|
|
73
|
+
this.carModel = new a.Object3D(), this.carModel.rotation.x = a.MathUtils.degToRad(90), this.carModel.add(i), i.position.set(0, 0, n.z / 2), e();
|
|
73
74
|
});
|
|
74
75
|
}),
|
|
75
76
|
new Promise((e) => {
|
|
76
|
-
|
|
77
|
-
|
|
77
|
+
s.load(`${this.assetsRoot}/3DModels/van.glb`, (t) => {
|
|
78
|
+
const i = t.scene, n = new a.Box3().setFromObject(i).getSize(new a.Vector3());
|
|
79
|
+
this.vanModel = new a.Object3D(), this.vanModel.rotation.x = a.MathUtils.degToRad(90), this.vanModel.add(i), i.position.set(0, 0, n.z / 2), e();
|
|
78
80
|
});
|
|
79
81
|
}),
|
|
80
82
|
new Promise((e) => {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
+
s.load(`${this.assetsRoot}/3DModels/truck.glb`, (t) => {
|
|
84
|
+
const i = t.scene;
|
|
85
|
+
i.scale.set(1.2, 1, 1.5);
|
|
86
|
+
const n = new a.Box3().setFromObject(i).getSize(new a.Vector3());
|
|
87
|
+
this.truckModel = new a.Object3D(), this.truckModel.rotation.x = a.MathUtils.degToRad(90), this.truckModel.add(i), i.position.set(0, 0, n.z / 2), e();
|
|
83
88
|
});
|
|
84
89
|
}),
|
|
85
90
|
new Promise((e) => {
|
|
86
|
-
|
|
87
|
-
|
|
91
|
+
s.load(`${this.assetsRoot}/3DModels/bus.glb`, (t) => {
|
|
92
|
+
const i = t.scene, n = new a.Box3().setFromObject(i).getSize(new a.Vector3());
|
|
93
|
+
this.busModel = new a.Object3D(), this.busModel.rotation.x = a.MathUtils.degToRad(90), this.busModel.add(i), i.position.set(0, 0, n.z / 2), e();
|
|
88
94
|
});
|
|
89
95
|
}),
|
|
90
96
|
new Promise((e) => {
|
|
91
|
-
|
|
92
|
-
this.bicycleModel = t.scene, this.bicycleModel.rotation.x =
|
|
97
|
+
s.load(`${this.assetsRoot}/3DModels/bicycle.glb`, (t) => {
|
|
98
|
+
this.bicycleModel = t.scene, this.bicycleModel.rotation.x = a.MathUtils.degToRad(90), this.bicycleModel.rotation.y = a.MathUtils.degToRad(180), e();
|
|
93
99
|
});
|
|
94
100
|
}),
|
|
95
101
|
new Promise((e) => {
|
|
@@ -129,12 +135,12 @@ class I {
|
|
|
129
135
|
})
|
|
130
136
|
]), this.isInitialized = !0;
|
|
131
137
|
}
|
|
132
|
-
setInterpolate(
|
|
133
|
-
this.clearVehicles(), this.needInterpolate =
|
|
138
|
+
setInterpolate(s) {
|
|
139
|
+
this.clearVehicles(), this.needInterpolate = s;
|
|
134
140
|
}
|
|
135
|
-
async setup(
|
|
136
|
-
this.context =
|
|
137
|
-
context:
|
|
141
|
+
async setup(s) {
|
|
142
|
+
this.context = s, this.renderer = new a.WebGLRenderer({
|
|
143
|
+
context: s.gl,
|
|
138
144
|
premultipliedAlpha: !0,
|
|
139
145
|
logarithmicDepthBuffer: !0,
|
|
140
146
|
antialias: !0,
|
|
@@ -143,52 +149,52 @@ class I {
|
|
|
143
149
|
const e = this.renderer.setRenderTarget.bind(
|
|
144
150
|
this.renderer
|
|
145
151
|
);
|
|
146
|
-
this.renderer.setRenderTarget = (
|
|
147
|
-
e(
|
|
148
|
-
}, this.scene = new
|
|
149
|
-
const { camera: t } =
|
|
150
|
-
this.camera = new
|
|
152
|
+
this.renderer.setRenderTarget = (i) => {
|
|
153
|
+
e(i), i == null && s.bindRenderTarget();
|
|
154
|
+
}, this.scene = new a.Scene();
|
|
155
|
+
const { camera: t } = s;
|
|
156
|
+
this.camera = new a.PerspectiveCamera(
|
|
151
157
|
t.fovY,
|
|
152
158
|
t.aspect,
|
|
153
159
|
0.1,
|
|
154
160
|
1e5
|
|
155
|
-
), this.ambient = new
|
|
161
|
+
), this.ambient = new a.AmbientLight(16777215, 2), this.scene.add(this.ambient), this.sun = new a.DirectionalLight(16777215, 2), this.scene.add(this.sun), s.resetWebGLState();
|
|
156
162
|
}
|
|
157
|
-
async render(
|
|
158
|
-
var
|
|
159
|
-
const e =
|
|
163
|
+
async render(s) {
|
|
164
|
+
var i;
|
|
165
|
+
const e = s.camera;
|
|
160
166
|
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(
|
|
161
|
-
new
|
|
167
|
+
new a.Vector3(e.center[0], e.center[1], e.center[2])
|
|
162
168
|
), this.camera.projectionMatrix.fromArray(e.projectionMatrix), !this.isPaused && this.needInterpolate)
|
|
163
|
-
for (const
|
|
164
|
-
const n = (
|
|
169
|
+
for (const o of this.vehicleObjectMap.keys()) {
|
|
170
|
+
const n = (i = this.vehicleObjectMap.get(o)) == null ? void 0 : i.model;
|
|
165
171
|
if (!n)
|
|
166
172
|
continue;
|
|
167
|
-
const
|
|
168
|
-
if (
|
|
169
|
-
const d = this.toRenderCoordinates(
|
|
170
|
-
n.position.set(d[0], d[1], d[2]), n.rotation.y =
|
|
173
|
+
const r = this.computeVehiclePosition(o);
|
|
174
|
+
if (r) {
|
|
175
|
+
const d = this.toRenderCoordinates(r);
|
|
176
|
+
n.position.set(d[0], d[1], d[2]), n.rotation.y = a.MathUtils.degToRad(-r[3]);
|
|
171
177
|
}
|
|
172
178
|
}
|
|
173
|
-
const t =
|
|
174
|
-
this.sun.position.set(t.direction[0], t.direction[1], t.direction[2]), this.sun.intensity = t.diffuse.intensity, this.sun.color = new
|
|
179
|
+
const t = s.sunLight;
|
|
180
|
+
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(
|
|
175
181
|
t.diffuse.color[0],
|
|
176
182
|
t.diffuse.color[1],
|
|
177
183
|
t.diffuse.color[2]
|
|
178
|
-
), this.ambient.intensity = t.ambient.intensity, this.ambient.color = new
|
|
184
|
+
), this.ambient.intensity = t.ambient.intensity, this.ambient.color = new a.Color(
|
|
179
185
|
t.ambient.color[0],
|
|
180
186
|
t.ambient.color[1],
|
|
181
187
|
t.ambient.color[2]
|
|
182
|
-
), this.renderer.resetState(),
|
|
188
|
+
), this.renderer.resetState(), s.bindRenderTarget(), this.renderer.render(this.scene, this.camera), u.requestRender(this.view), s.resetWebGLState();
|
|
183
189
|
}
|
|
184
190
|
/**
|
|
185
191
|
* 新增车辆
|
|
186
192
|
* */
|
|
187
|
-
async addVehicles(
|
|
193
|
+
async addVehicles(s) {
|
|
188
194
|
if (this.isPaused || !this.isInitialized)
|
|
189
195
|
return;
|
|
190
196
|
const e = Date.now();
|
|
191
|
-
for (const t of
|
|
197
|
+
for (const t of s) {
|
|
192
198
|
this.appDataStore.saveTrackLog && this.logTable.push([
|
|
193
199
|
t.ptcId,
|
|
194
200
|
t.plateNo,
|
|
@@ -209,19 +215,19 @@ class I {
|
|
|
209
215
|
0,
|
|
210
216
|
0
|
|
211
217
|
]);
|
|
212
|
-
const { vehicleId:
|
|
213
|
-
this.historyPositionMap.set(
|
|
214
|
-
{ pos: [n,
|
|
218
|
+
const { vehicleId: i, localTimestamp: o } = t, n = Number(t.x), r = Number(t.y), d = Number(t.heading);
|
|
219
|
+
this.historyPositionMap.set(i, [
|
|
220
|
+
{ pos: [n, r, 0], heading: d, time: o }
|
|
215
221
|
]);
|
|
216
222
|
const h = this.getVehicleModel(t);
|
|
217
|
-
h.name =
|
|
223
|
+
h.name = i, h.visible = !1;
|
|
218
224
|
try {
|
|
219
|
-
const
|
|
220
|
-
|
|
221
|
-
} catch (
|
|
222
|
-
console.log("createPlateSprite error:",
|
|
225
|
+
const l = await this.createPlateSprite(t);
|
|
226
|
+
l && (h.add(l), l.position.set(0, 5, -4));
|
|
227
|
+
} catch (l) {
|
|
228
|
+
console.log("createPlateSprite error:", l);
|
|
223
229
|
}
|
|
224
|
-
this.scene.add(h), this.vehicleObjectMap.set(
|
|
230
|
+
this.scene.add(h), this.vehicleObjectMap.set(i, {
|
|
225
231
|
model: h,
|
|
226
232
|
data: t,
|
|
227
233
|
waitForDelete: !1,
|
|
@@ -232,73 +238,73 @@ class I {
|
|
|
232
238
|
/**
|
|
233
239
|
* 更新车辆
|
|
234
240
|
* */
|
|
235
|
-
async updateVehicles(
|
|
241
|
+
async updateVehicles(s) {
|
|
236
242
|
if (this.isPaused || !this.isInitialized)
|
|
237
243
|
return;
|
|
238
244
|
const e = [], t = Date.now();
|
|
239
|
-
for (const
|
|
240
|
-
const { vehicleId:
|
|
241
|
-
let h = Number(
|
|
242
|
-
const
|
|
243
|
-
|
|
245
|
+
for (const i of s) {
|
|
246
|
+
const { vehicleId: o, localTimestamp: n } = i, r = Number(i.x), d = Number(i.y);
|
|
247
|
+
let h = Number(i.heading);
|
|
248
|
+
const l = this.vehicleObjectMap.get(o), p = this.historyPositionMap.get(
|
|
249
|
+
o
|
|
244
250
|
);
|
|
245
|
-
if (!
|
|
246
|
-
e.push(
|
|
251
|
+
if (!l || !p)
|
|
252
|
+
e.push(i);
|
|
247
253
|
else {
|
|
248
254
|
if (this.appDataStore.saveTrackLog && this.logTable.push([
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
255
|
+
i.ptcId,
|
|
256
|
+
i.plateNo,
|
|
257
|
+
i.timestamp,
|
|
258
|
+
i.localTimestamp,
|
|
259
|
+
i.speed,
|
|
260
|
+
i.x,
|
|
261
|
+
i.y,
|
|
262
|
+
i.ptcType,
|
|
263
|
+
i.vehicleType,
|
|
264
|
+
i.vehicleColor,
|
|
265
|
+
i.plateColor,
|
|
266
|
+
i.heading,
|
|
267
|
+
i.fixAngle,
|
|
268
|
+
i.roadLayer,
|
|
269
|
+
i.step,
|
|
264
270
|
t,
|
|
265
271
|
p.length,
|
|
266
272
|
1
|
|
267
|
-
]), this.updateModel ||
|
|
268
|
-
this.scene.remove(
|
|
269
|
-
const c = await this.createPlateSprite(
|
|
270
|
-
c && (
|
|
273
|
+
]), this.updateModel || l.data.vehicleColor !== i.vehicleColor || l.data.vehicleType !== i.vehicleType) {
|
|
274
|
+
this.scene.remove(l.model), this.disposeModel(l.model), l.model = this.getVehicleModel(i), l.model.visible = !0;
|
|
275
|
+
const c = await this.createPlateSprite(i);
|
|
276
|
+
c && (l.model.add(c), c.position.set(0, 5, -4)), this.scene.add(l.model);
|
|
271
277
|
}
|
|
272
|
-
if (
|
|
273
|
-
const c =
|
|
274
|
-
c && (
|
|
275
|
-
const g = await this.createPlateSprite(
|
|
276
|
-
g && (
|
|
278
|
+
if (l.data.showName !== i.showName || l.data.plateColor !== i.plateColor) {
|
|
279
|
+
const c = l.model.getObjectByName("VehiclePlate");
|
|
280
|
+
c && (l.model.remove(c), this.disposeModel(c));
|
|
281
|
+
const g = await this.createPlateSprite(i);
|
|
282
|
+
g && (l.model.add(g), g.position.set(0, 5, -4));
|
|
277
283
|
}
|
|
278
|
-
if (
|
|
284
|
+
if (l.data = i, this.needInterpolate) {
|
|
279
285
|
const c = p[p.length - 1];
|
|
280
286
|
Math.abs(h - c.heading) >= 180 && (h > c.heading ? c.heading += 360 : h += 360), p.push({
|
|
281
|
-
pos: [
|
|
287
|
+
pos: [r, d, 0],
|
|
282
288
|
heading: h,
|
|
283
289
|
time: n
|
|
284
290
|
});
|
|
285
291
|
} else {
|
|
286
|
-
this.historyPositionMap.set(
|
|
287
|
-
{ pos: [
|
|
292
|
+
this.historyPositionMap.set(o, [
|
|
293
|
+
{ pos: [r, d, 0], heading: h, time: n }
|
|
288
294
|
]);
|
|
289
|
-
const c = this.toRenderCoordinates([
|
|
290
|
-
|
|
295
|
+
const c = this.toRenderCoordinates([r, d, 0]);
|
|
296
|
+
l.model.position.set(c[0], c[1], c[2]), l.model.rotation.y = a.MathUtils.degToRad(-h);
|
|
291
297
|
}
|
|
292
298
|
}
|
|
293
299
|
}
|
|
294
300
|
await this.addVehicles(e), this.updateModel = !1, this.needInterpolate || this.render(this.context);
|
|
295
301
|
}
|
|
296
|
-
toRenderCoordinates(
|
|
302
|
+
toRenderCoordinates(s) {
|
|
297
303
|
const e = [0, 0, 0];
|
|
298
304
|
return u.toRenderCoordinates(
|
|
299
305
|
// @ts-ignore
|
|
300
306
|
this.view,
|
|
301
|
-
|
|
307
|
+
s,
|
|
302
308
|
0,
|
|
303
309
|
v.WGS84,
|
|
304
310
|
e,
|
|
@@ -309,13 +315,13 @@ class I {
|
|
|
309
315
|
/**
|
|
310
316
|
* 删除车辆
|
|
311
317
|
* */
|
|
312
|
-
deleteVehicles(
|
|
318
|
+
deleteVehicles(s) {
|
|
313
319
|
if (this.isPaused)
|
|
314
320
|
return;
|
|
315
321
|
const e = Date.now();
|
|
316
|
-
|
|
322
|
+
s.forEach((t) => {
|
|
317
323
|
if (this.appDataStore.saveTrackLog) {
|
|
318
|
-
const
|
|
324
|
+
const o = this.historyPositionMap.get(t);
|
|
319
325
|
this.logTable.push([
|
|
320
326
|
t,
|
|
321
327
|
"",
|
|
@@ -333,33 +339,33 @@ class I {
|
|
|
333
339
|
"",
|
|
334
340
|
"",
|
|
335
341
|
e,
|
|
336
|
-
|
|
342
|
+
o ? o.length : 0,
|
|
337
343
|
2
|
|
338
344
|
]);
|
|
339
345
|
}
|
|
340
|
-
const
|
|
341
|
-
|
|
346
|
+
const i = this.vehicleObjectMap.get(t);
|
|
347
|
+
i && (this.needInterpolate ? i.isMoving ? i.waitForDelete = !0 : this.deleteVehicle(i) : this.deleteVehicle(i));
|
|
342
348
|
});
|
|
343
349
|
}
|
|
344
|
-
deleteVehicle(
|
|
345
|
-
this.scene.remove(
|
|
346
|
-
const e =
|
|
350
|
+
deleteVehicle(s) {
|
|
351
|
+
this.scene.remove(s.model), this.disposeModel(s.model);
|
|
352
|
+
const e = s.data.vehicleId;
|
|
347
353
|
this.vehicleObjectMap.delete(e), this.historyPositionMap.delete(e);
|
|
348
354
|
}
|
|
349
|
-
async toggleTrafficInfo(
|
|
350
|
-
|
|
351
|
-
|
|
355
|
+
async toggleTrafficInfo(s) {
|
|
356
|
+
s.name === "vehiclePlate" && (s.visible === !0 && this.currentSpriteContent === m.None ? await this.updatePanelContent(m.PlateNumber) : await this.updatePanelContent(
|
|
357
|
+
s.visible ? this.currentSpriteContent : m.None
|
|
352
358
|
));
|
|
353
359
|
}
|
|
354
|
-
togglePause(
|
|
355
|
-
this.isPaused =
|
|
360
|
+
togglePause(s) {
|
|
361
|
+
this.isPaused = s;
|
|
356
362
|
}
|
|
357
363
|
/**
|
|
358
364
|
* 清除全部车辆
|
|
359
365
|
* */
|
|
360
366
|
clearVehicles() {
|
|
361
|
-
for (const
|
|
362
|
-
const e = this.vehicleObjectMap.get(
|
|
367
|
+
for (const s of this.vehicleObjectMap.keys()) {
|
|
368
|
+
const e = this.vehicleObjectMap.get(s);
|
|
363
369
|
e && (this.scene.remove(e.model), this.disposeModel(e.model));
|
|
364
370
|
}
|
|
365
371
|
this.vehicleObjectMap.clear(), this.historyPositionMap.clear();
|
|
@@ -369,81 +375,81 @@ class I {
|
|
|
369
375
|
* @param contentType
|
|
370
376
|
* @returns
|
|
371
377
|
*/
|
|
372
|
-
async updatePanelContent(
|
|
373
|
-
if (
|
|
374
|
-
this.currentSpriteContent =
|
|
378
|
+
async updatePanelContent(s) {
|
|
379
|
+
if (s !== this.currentSpriteContent) {
|
|
380
|
+
this.currentSpriteContent = s;
|
|
375
381
|
for (const e of this.vehicleObjectMap.keys()) {
|
|
376
382
|
const t = this.vehicleObjectMap.get(e);
|
|
377
383
|
if (t) {
|
|
378
|
-
const
|
|
379
|
-
if (
|
|
380
|
-
const
|
|
381
|
-
|
|
384
|
+
const i = t.model.getObjectByName("VehiclePlate");
|
|
385
|
+
if (i && (t.model.remove(i), this.disposeModel(i)), s !== m.None) {
|
|
386
|
+
const o = await this.createPlateSprite(t.data);
|
|
387
|
+
o && (t.model.add(o), o.position.set(0, 5, -4));
|
|
382
388
|
}
|
|
383
389
|
}
|
|
384
390
|
}
|
|
385
391
|
}
|
|
386
392
|
}
|
|
387
|
-
toggleGroundVehicle(
|
|
388
|
-
console.log("toggleGroundVehicle",
|
|
393
|
+
toggleGroundVehicle(s) {
|
|
394
|
+
console.log("toggleGroundVehicle", s), this.showGroundVehicle = s;
|
|
389
395
|
}
|
|
390
|
-
toggleElevatedVehicle(
|
|
391
|
-
this.showElevatedVehicle =
|
|
396
|
+
toggleElevatedVehicle(s) {
|
|
397
|
+
this.showElevatedVehicle = s;
|
|
392
398
|
}
|
|
393
399
|
/**
|
|
394
400
|
* 释放模型资源
|
|
395
401
|
* */
|
|
396
|
-
disposeModel(
|
|
397
|
-
|
|
398
|
-
e instanceof
|
|
402
|
+
disposeModel(s) {
|
|
403
|
+
s.traverse((e) => {
|
|
404
|
+
e instanceof a.Mesh && (e.geometry.dispose(), e.material.dispose());
|
|
399
405
|
});
|
|
400
406
|
}
|
|
401
407
|
/**
|
|
402
408
|
* 计算车辆位置
|
|
403
409
|
* */
|
|
404
|
-
computeVehiclePosition(
|
|
405
|
-
const e = this.historyPositionMap.get(
|
|
410
|
+
computeVehiclePosition(s) {
|
|
411
|
+
const e = this.historyPositionMap.get(s), t = this.vehicleObjectMap.get(s);
|
|
406
412
|
if (!t || !e || !t.isMoving && e.length <= 2)
|
|
407
413
|
return;
|
|
408
|
-
const
|
|
409
|
-
t.isMoving = !0, t.data.roadLayer === "1" ? t.model.visible = this.showGroundVehicle : t.model.visible = this.showElevatedVehicle, t.segmentStartTime || (t.segmentStartTime =
|
|
410
|
-
const
|
|
411
|
-
|
|
414
|
+
const i = Date.now();
|
|
415
|
+
t.isMoving = !0, t.data.roadLayer === "1" ? t.model.visible = this.showGroundVehicle : t.model.visible = this.showElevatedVehicle, t.segmentStartTime || (t.segmentStartTime = i, t.segmentTotalTime = e[1].time - e[0].time);
|
|
416
|
+
const o = i - t.segmentStartTime, n = Math.min(
|
|
417
|
+
o / t.segmentTotalTime,
|
|
412
418
|
1
|
|
413
419
|
);
|
|
414
420
|
if (n === 1)
|
|
415
421
|
if (e.shift(), e.length === 1) {
|
|
416
|
-
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",
|
|
422
|
+
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", s));
|
|
417
423
|
return;
|
|
418
424
|
} else {
|
|
419
425
|
t.segmentStartTime = Date.now();
|
|
420
|
-
const
|
|
421
|
-
return t.segmentTotalTime = e[1].time - e[0].time -
|
|
426
|
+
const r = o - t.segmentTotalTime;
|
|
427
|
+
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);
|
|
422
428
|
}
|
|
423
429
|
else if (e.length >= 2) {
|
|
424
|
-
const
|
|
425
|
-
return [
|
|
430
|
+
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;
|
|
431
|
+
return [r, d, 0, h];
|
|
426
432
|
} else
|
|
427
433
|
return;
|
|
428
434
|
}
|
|
429
435
|
/**
|
|
430
436
|
* 根据车辆类型、车身颜色获取模型
|
|
431
437
|
* */
|
|
432
|
-
getVehicleModel(
|
|
438
|
+
getVehicleModel(s) {
|
|
433
439
|
if (this.view.camera.position.z >= this.cameraHeightThreshold) {
|
|
434
|
-
const e = new
|
|
440
|
+
const e = new a.SphereGeometry(5, 32, 32), t = new a.MeshPhysicalMaterial({
|
|
435
441
|
color: 325253,
|
|
436
442
|
emissive: 0,
|
|
437
443
|
roughness: this.roughness,
|
|
438
444
|
metalness: this.metalness
|
|
439
445
|
});
|
|
440
|
-
return new
|
|
446
|
+
return new a.Mesh(e, t);
|
|
441
447
|
} else {
|
|
442
448
|
let e;
|
|
443
|
-
if (
|
|
449
|
+
if (s.ptcType === 2)
|
|
444
450
|
e = this.bicycleModel.clone();
|
|
445
451
|
else {
|
|
446
|
-
switch (
|
|
452
|
+
switch (s.vehicleType) {
|
|
447
453
|
case 10:
|
|
448
454
|
e = this.carModel.clone();
|
|
449
455
|
break;
|
|
@@ -460,10 +466,10 @@ class I {
|
|
|
460
466
|
e = this.carModel.clone();
|
|
461
467
|
break;
|
|
462
468
|
}
|
|
463
|
-
const t = this.materialMap.get(
|
|
464
|
-
let
|
|
465
|
-
e.traverse((
|
|
466
|
-
!
|
|
469
|
+
const t = this.materialMap.get(s.vehicleColor) || this.defaultMaterial;
|
|
470
|
+
let i = !1;
|
|
471
|
+
e.traverse((o) => {
|
|
472
|
+
!i && o instanceof a.Mesh && (o.material = t, i = !0);
|
|
467
473
|
});
|
|
468
474
|
}
|
|
469
475
|
return e;
|
|
@@ -472,71 +478,71 @@ class I {
|
|
|
472
478
|
/**
|
|
473
479
|
* 创建号牌canvas
|
|
474
480
|
* */
|
|
475
|
-
createCanvas(
|
|
476
|
-
const
|
|
477
|
-
|
|
478
|
-
const
|
|
479
|
-
if (!
|
|
481
|
+
createCanvas(s, e, t) {
|
|
482
|
+
const i = document.createElement("canvas"), o = s.width, n = s.height;
|
|
483
|
+
i.width = o, i.height = n;
|
|
484
|
+
const r = i.getContext("2d");
|
|
485
|
+
if (!r) {
|
|
480
486
|
console.log("canvas创建失败");
|
|
481
487
|
return;
|
|
482
488
|
}
|
|
483
|
-
return
|
|
489
|
+
return r.fillStyle = "rgba(0,0,0,0.0)", r.fillRect(0, 0, o, n), r.drawImage(s, 0, 0, o, n), r.beginPath(), r.translate(o / 2, n / 2), r.fillStyle = t, r.font = "bold 32px 宋体", r.textBaseline = "middle", r.textAlign = "center", r.fillText(e, 0, 0), i;
|
|
484
490
|
}
|
|
485
|
-
createPlateSprite(
|
|
491
|
+
createPlateSprite(s) {
|
|
486
492
|
return new Promise((e, t) => {
|
|
487
|
-
var h,
|
|
488
|
-
const
|
|
489
|
-
if (this.currentSpriteContent === m.None || this.currentSpriteContent === m.PlateNumber &&
|
|
493
|
+
var h, l;
|
|
494
|
+
const i = !s.plateNo || s.plateNo === "0" || s.plateNo === "000000";
|
|
495
|
+
if (this.currentSpriteContent === m.None || this.currentSpriteContent === m.PlateNumber && i) {
|
|
490
496
|
e(void 0);
|
|
491
497
|
return;
|
|
492
498
|
}
|
|
493
|
-
let
|
|
499
|
+
let o = new Image(), n = "", r = "";
|
|
494
500
|
if (this.currentSpriteContent === m.PlateNumber || this.currentSpriteContent === m.Mix)
|
|
495
|
-
if (
|
|
496
|
-
|
|
501
|
+
if (i)
|
|
502
|
+
o = this.greyPlateBG, n = s.ptcId, r = "#ffffff";
|
|
497
503
|
else
|
|
498
|
-
switch (n = ((h =
|
|
504
|
+
switch (n = ((h = s.showName) == null ? void 0 : h.substring(0, 2)) + "•" + ((l = s.showName) == null ? void 0 : l.substring(2)), s.plateColor) {
|
|
499
505
|
case 1:
|
|
500
|
-
|
|
506
|
+
o = this.bluePlateBG, r = "#ffffff";
|
|
501
507
|
break;
|
|
502
508
|
case 2:
|
|
503
|
-
|
|
509
|
+
o = this.yellowPlateBG, r = "#000000";
|
|
504
510
|
break;
|
|
505
511
|
case 3:
|
|
506
|
-
|
|
512
|
+
o = this.whitePlateBG, r = "#000000";
|
|
507
513
|
break;
|
|
508
514
|
case 4:
|
|
509
|
-
|
|
515
|
+
o = this.blackPlateBG, r = "#ffffff";
|
|
510
516
|
break;
|
|
511
517
|
case 5:
|
|
512
|
-
|
|
518
|
+
o = this.neoYellowPlateBG, r = "#000000";
|
|
513
519
|
break;
|
|
514
520
|
case 6:
|
|
515
|
-
|
|
521
|
+
o = this.neoGreenPlateBG, r = "#000000";
|
|
516
522
|
break;
|
|
517
523
|
default:
|
|
518
|
-
|
|
524
|
+
o = this.greyPlateBG, n = s.plateNo, r = "#ffffff";
|
|
519
525
|
break;
|
|
520
526
|
}
|
|
521
527
|
else
|
|
522
|
-
this.currentSpriteContent === m.Id && (
|
|
523
|
-
const d = this.createCanvas(
|
|
528
|
+
this.currentSpriteContent === m.Id && (o = this.greyPlateBG, n = s.ptcId, r = "#ffffff");
|
|
529
|
+
const d = this.createCanvas(o, n, r);
|
|
524
530
|
if (d) {
|
|
525
|
-
const p = new
|
|
531
|
+
const p = new a.CanvasTexture(d), c = new a.SpriteMaterial({
|
|
526
532
|
map: p,
|
|
527
533
|
transparent: !1
|
|
528
|
-
}), g = new
|
|
529
|
-
g.scale.set(w,
|
|
534
|
+
}), g = new a.Sprite(c), f = 0.05, w = d.width * f, b = d.height * f;
|
|
535
|
+
g.scale.set(w, b, 1), g.name = "VehiclePlate", e(g);
|
|
530
536
|
} else {
|
|
531
537
|
t("canvas创建失败");
|
|
532
538
|
return;
|
|
533
539
|
}
|
|
534
|
-
|
|
535
|
-
console.log(`号牌背景加载失败: ${
|
|
540
|
+
o.onerror = (p) => {
|
|
541
|
+
console.log(`号牌背景加载失败: ${o.src}`, p), t(p);
|
|
536
542
|
};
|
|
537
543
|
});
|
|
538
544
|
}
|
|
539
545
|
}
|
|
540
546
|
export {
|
|
541
|
-
|
|
547
|
+
R as default
|
|
542
548
|
};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as m from "@arcgis/core/core/reactiveUtils.js";
|
|
2
2
|
import n from "@arcgis/core/Graphic";
|
|
3
3
|
import a from "@arcgis/core/layers/GraphicsLayer";
|
|
4
|
-
import
|
|
4
|
+
import u from "@turf/buffer";
|
|
5
5
|
import d from "@turf/convex";
|
|
6
6
|
import * as c from "@turf/helpers";
|
|
7
7
|
import p from "./district-controller.mjs";
|
|
8
8
|
class C {
|
|
9
9
|
constructor(e) {
|
|
10
|
-
this.crossScale =
|
|
10
|
+
this.crossScale = 3e3, this.view = e, this.view.popup.visibleElements = {
|
|
11
11
|
closeButton: !0,
|
|
12
12
|
collapseButton: !1,
|
|
13
13
|
actionBar: !0
|
|
@@ -38,28 +38,45 @@ class C {
|
|
|
38
38
|
const r = new p(t);
|
|
39
39
|
this.drawArea(r, !0);
|
|
40
40
|
}
|
|
41
|
-
return this.watchHandle =
|
|
41
|
+
return this.watchHandle = m.watch(
|
|
42
42
|
() => this.view.scale,
|
|
43
43
|
(t, r) => {
|
|
44
|
-
t > this.crossScale && r <= this.crossScale
|
|
45
|
-
s
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
s
|
|
44
|
+
if (t > this.crossScale && r <= this.crossScale)
|
|
45
|
+
this.crossLayer.graphics.forEach((s) => {
|
|
46
|
+
s.symbol = {
|
|
47
|
+
type: "simple-marker",
|
|
48
|
+
color: s.getAttribute("color"),
|
|
49
|
+
size: 8,
|
|
50
|
+
outline: {
|
|
51
|
+
color: "white",
|
|
52
|
+
width: 1
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}), this.highlightLayer.graphics.forEach((s) => {
|
|
56
|
+
s.getAttribute("type") === "cross" && (s.symbol = {
|
|
57
|
+
type: "simple-marker",
|
|
58
|
+
color: s.getAttribute("color"),
|
|
59
|
+
size: 8,
|
|
60
|
+
outline: {
|
|
61
|
+
color: "white",
|
|
62
|
+
width: 1
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
else if (t <= this.crossScale && r > this.crossScale) {
|
|
67
|
+
const s = {
|
|
56
68
|
type: "picture-marker",
|
|
57
|
-
url: "/GisViewerAssets/
|
|
69
|
+
url: "/GisViewerAssets/Images/xhj_1.png",
|
|
58
70
|
width: "37px",
|
|
59
71
|
height: "57px",
|
|
60
72
|
yoffset: "25px"
|
|
61
73
|
};
|
|
62
|
-
|
|
74
|
+
this.crossLayer.graphics.forEach((i) => {
|
|
75
|
+
i.symbol = s;
|
|
76
|
+
}), this.highlightLayer.graphics.forEach((i) => {
|
|
77
|
+
i.getAttribute("type") === "cross" && (i.symbol = s);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
63
80
|
}
|
|
64
81
|
), { status: 0, message: "ok" };
|
|
65
82
|
}
|
|
@@ -70,7 +87,10 @@ class C {
|
|
|
70
87
|
async locateSignalControlArea(e) {
|
|
71
88
|
const t = this.findAreaGraphic(e.id);
|
|
72
89
|
if (t) {
|
|
73
|
-
t.attributes.type === "cross" ? await this.view.goTo({
|
|
90
|
+
t.attributes.type === "cross" ? await this.view.goTo({
|
|
91
|
+
target: t.geometry,
|
|
92
|
+
scale: 1500
|
|
93
|
+
}) : await this.view.goTo(t.geometry);
|
|
74
94
|
const r = t.geometry.type === "point" ? t.geometry : t.geometry.centroid;
|
|
75
95
|
return this.view.openPopup({
|
|
76
96
|
features: [t],
|
|
@@ -86,9 +106,10 @@ class C {
|
|
|
86
106
|
).toArray().map((i) => i.clone()), s = this.crossLayer.graphics.filter(
|
|
87
107
|
(i) => i.getAttribute("id") === e.id || i.getAttribute("districtId") === e.id || i.getAttribute("subDistrictId") === e.id
|
|
88
108
|
).toArray().map((i) => i.clone());
|
|
89
|
-
return t.length > 0 && this.highlightLayer.addMany(t), r.length > 0 && this.highlightLayer.addMany(r), s.length > 0 && this.highlightLayer.addMany(s), this.highlightLayer.graphics.length === 0 ? { status: 1, message: "未找到" } : (await this.view.goTo(
|
|
90
|
-
|
|
91
|
-
|
|
109
|
+
return t.length > 0 && this.highlightLayer.addMany(t), r.length > 0 && this.highlightLayer.addMany(r), s.length > 0 && this.highlightLayer.addMany(s), this.highlightLayer.graphics.length === 0 ? { status: 1, message: "未找到" } : (t.length > 0 ? await this.view.goTo(t) : r.length > 0 ? await this.view.goTo(r) : s.length > 1 ? await this.view.goTo(s) : await this.view.goTo({
|
|
110
|
+
target: s[0].geometry,
|
|
111
|
+
scale: 1500
|
|
112
|
+
}), { status: 0, message: "ok" });
|
|
92
113
|
}
|
|
93
114
|
resetHighlight() {
|
|
94
115
|
return this.highlightLayer.removeAll(), this.districtControllerLayer.visible = !0, this.subDistrictControllerLayer.visible = !0, this.crossLayer.visible = !0, { status: 0, message: "ok" };
|
|
@@ -116,11 +137,11 @@ class C {
|
|
|
116
137
|
const r = e.getAllCrossCoordinates();
|
|
117
138
|
if (r.length > 2) {
|
|
118
139
|
const i = c.featureCollection(
|
|
119
|
-
r.map((
|
|
140
|
+
r.map((y) => c.point(y))
|
|
120
141
|
), l = d(i);
|
|
121
142
|
if (!l)
|
|
122
143
|
return;
|
|
123
|
-
const
|
|
144
|
+
const g = u(
|
|
124
145
|
l.geometry,
|
|
125
146
|
// 区控面积更大,需要更大的缓冲半径
|
|
126
147
|
t ? 200 : 30,
|
|
@@ -159,7 +180,7 @@ class C {
|
|
|
159
180
|
const h = new n({
|
|
160
181
|
geometry: {
|
|
161
182
|
type: "polygon",
|
|
162
|
-
rings:
|
|
183
|
+
rings: g.geometry.coordinates
|
|
163
184
|
},
|
|
164
185
|
symbol: {
|
|
165
186
|
type: "simple-fill",
|
package/es/src/types/index.d.ts
CHANGED
|
@@ -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"),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),I=f(y),M=f(S),l=f(C);class V{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=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.assetsRoot=JSON.parse(JSON.stringify(this.appDataStore.mapConfig)).assetsRoot,this.view=i,I.watch(()=>this.view.camera.position.z,(e,t)=>{(t<=this.cameraHeightThreshold&&e>this.cameraHeightThreshold||t>this.cameraHeightThreshold&&e<=this.cameraHeightThreshold)&&(this.updateModel=!0)})}createCarMaterial(i){return new l.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=>{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 d=this.toRenderCoordinates(o);n.position.set(d[0],d[1],d[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)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),o=Number(t.y),d=Number(t.heading);this.historyPositionMap.set(s,[{pos:[n,o,0],heading:d,time:a}]);const h=this.getVehicleModel(t);h.name=s,h.visible=!1;try{const r=await this.createPlateSprite(t);r&&(h.add(r),r.position.set(0,5,-4))}catch(r){console.log("createPlateSprite error:",r)}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,o=Number(s.x),d=Number(s.y);let h=Number(s.heading);const r=this.vehicleObjectMap.get(a),p=this.historyPositionMap.get(a);if(!r||!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||r.data.vehicleColor!==s.vehicleColor||r.data.vehicleType!==s.vehicleType){this.scene.remove(r.model),this.disposeModel(r.model),r.model=this.getVehicleModel(s),r.model.visible=!0;const c=await this.createPlateSprite(s);c&&(r.model.add(c),c.position.set(0,5,-4)),this.scene.add(r.model)}if(r.data.showName!==s.showName||r.data.plateColor!==s.plateColor){const c=r.model.getObjectByName("VehiclePlate");c&&(r.model.remove(c),this.disposeModel(c));const g=await this.createPlateSprite(s);g&&(r.model.add(g),g.position.set(0,5,-4))}if(r.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:[o,d,0],heading:h,time:n})}else{this.historyPositionMap.set(a,[{pos:[o,d,0],heading:h,time:n}]);const c=this.toRenderCoordinates([o,d,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,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===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.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!==m.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{t.segmentStartTime=Date.now();const o=a-t.segmentTotalTime;return t.segmentTotalTime=e[1].time-e[0].time-o,(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,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[o,d,0,h]}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 h,r;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 a=new Image,n="",o="";if(this.currentSpriteContent===m.EVehiclePlateState.PlateNumber||this.currentSpriteContent===m.EVehiclePlateState.Mix)if(s)a=this.greyPlateBG,n=i.ptcId,o="#ffffff";else switch(n=((h=i.showName)==null?void 0:h.substring(0,2))+"•"+((r=i.showName)==null?void 0:r.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===m.EVehiclePlateState.Id&&(a=this.greyPlateBG,n=i.ptcId,o="#ffffff");const d=this.createCanvas(a,n,o);if(d){const p=new l.CanvasTexture(d),c=new l.SpriteMaterial({map:p,transparent:!1}),g=new l.Sprite(c),P=.05,w=d.width*P,b=d.height*P;g.scale.set(w,b,1),g.name="VehiclePlate",e(g)}else{t("canvas创建失败");return}a.onerror=p=>{console.log(`号牌背景加载失败: ${a.src}`,p),t(p)}})}}exports.default=V;
|
|
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"),m=require("../../../types/index.js"),B=require("../../stores/index.js");function f(u){const s=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(s,e,t.get?t:{enumerable:!0,get:()=>u[e]})}}return s.default=u,Object.freeze(s)}const x=f(v),V=f(y),w=f(S),o=f(C);class R{constructor(s){this.cameraHeightThreshold=1e3,this.roughness=.2,this.metalness=.8,this.defaultMaterial=new o.MeshPhongMaterial({color:16777215}),this.materialMap=new Map([[1,this.createCarMaterial(16777215)],[2,this.createCarMaterial(7833753)],[3,this.createCarMaterial(16766720)],[4,this.createCarMaterial(16758465)],[5,this.createCarMaterial(14423100)],[6,this.createCarMaterial(3329330)],[7,this.createCarMaterial(2003183)],[8,this.createCarMaterial(16032864)],[9,this.createCarMaterial(2105376)],[10,this.createCarMaterial(9662683)],[99,this.createCarMaterial(6908265)]]),this.isInitialized=!1,this.showGroundVehicle=!0,this.showElevatedVehicle=!0,this.isPaused=!1,this.currentSpriteContent=m.EVehiclePlateState.None,this.historyPositionMap=new Map,this.vehicleObjectMap=new Map,this.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.assetsRoot=JSON.parse(JSON.stringify(this.appDataStore.mapConfig)).assetsRoot,this.view=s,V.watch(()=>this.view.camera.position.z,(e,t)=>{(t<=this.cameraHeightThreshold&&e>this.cameraHeightThreshold||t>this.cameraHeightThreshold&&e<=this.cameraHeightThreshold)&&(this.updateModel=!0)})}createCarMaterial(s){return new o.MeshPhongMaterial({color:s})}getLog(){return this.logTable}async init(){const s=new G.GLTFLoader;await x.eachAlways([new Promise(e=>{s.load(`${this.assetsRoot}/3DModels/car.glb`,t=>{const i=t.scene,n=new o.Box3().setFromObject(i).getSize(new o.Vector3);this.carModel=new o.Object3D,this.carModel.rotation.x=o.MathUtils.degToRad(90),this.carModel.add(i),i.position.set(0,0,n.z/2),e()})}),new Promise(e=>{s.load(`${this.assetsRoot}/3DModels/van.glb`,t=>{const i=t.scene,n=new o.Box3().setFromObject(i).getSize(new o.Vector3);this.vanModel=new o.Object3D,this.vanModel.rotation.x=o.MathUtils.degToRad(90),this.vanModel.add(i),i.position.set(0,0,n.z/2),e()})}),new Promise(e=>{s.load(`${this.assetsRoot}/3DModels/truck.glb`,t=>{const i=t.scene;i.scale.set(1.2,1,1.5);const n=new o.Box3().setFromObject(i).getSize(new o.Vector3);this.truckModel=new o.Object3D,this.truckModel.rotation.x=o.MathUtils.degToRad(90),this.truckModel.add(i),i.position.set(0,0,n.z/2),e()})}),new Promise(e=>{s.load(`${this.assetsRoot}/3DModels/bus.glb`,t=>{const i=t.scene,n=new o.Box3().setFromObject(i).getSize(new o.Vector3);this.busModel=new o.Object3D,this.busModel.rotation.x=o.MathUtils.degToRad(90),this.busModel.add(i),i.position.set(0,0,n.z/2),e()})}),new Promise(e=>{s.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=>{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(s){this.clearVehicles(),this.needInterpolate=s}async setup(s){this.context=s,this.renderer=new o.WebGLRenderer({context:s.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=i=>{e(i),i==null&&s.bindRenderTarget()},this.scene=new o.Scene;const{camera:t}=s;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),s.resetWebGLState()}async render(s){var i;const e=s.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=(i=this.vehicleObjectMap.get(a))==null?void 0:i.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=s.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(),s.bindRenderTarget(),this.renderer.render(this.scene,this.camera),w.requestRender(this.view),s.resetWebGLState()}async addVehicles(s){if(this.isPaused||!this.isInitialized)return;const e=Date.now();for(const t of s){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:i,localTimestamp:a}=t,n=Number(t.x),r=Number(t.y),d=Number(t.heading);this.historyPositionMap.set(i,[{pos:[n,r,0],heading:d,time:a}]);const h=this.getVehicleModel(t);h.name=i,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(i,{model:h,data:t,waitForDelete:!1,isMoving:!1})}}async updateVehicles(s){if(this.isPaused||!this.isInitialized)return;const e=[],t=Date.now();for(const i of s){const{vehicleId:a,localTimestamp:n}=i,r=Number(i.x),d=Number(i.y);let h=Number(i.heading);const l=this.vehicleObjectMap.get(a),p=this.historyPositionMap.get(a);if(!l||!p)e.push(i);else{if(this.appDataStore.saveTrackLog&&this.logTable.push([i.ptcId,i.plateNo,i.timestamp,i.localTimestamp,i.speed,i.x,i.y,i.ptcType,i.vehicleType,i.vehicleColor,i.plateColor,i.heading,i.fixAngle,i.roadLayer,i.step,t,p.length,1]),this.updateModel||l.data.vehicleColor!==i.vehicleColor||l.data.vehicleType!==i.vehicleType){this.scene.remove(l.model),this.disposeModel(l.model),l.model=this.getVehicleModel(i),l.model.visible=!0;const c=await this.createPlateSprite(i);c&&(l.model.add(c),c.position.set(0,5,-4)),this.scene.add(l.model)}if(l.data.showName!==i.showName||l.data.plateColor!==i.plateColor){const c=l.model.getObjectByName("VehiclePlate");c&&(l.model.remove(c),this.disposeModel(c));const g=await this.createPlateSprite(i);g&&(l.model.add(g),g.position.set(0,5,-4))}if(l.data=i,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(s){const e=[0,0,0];return w.toRenderCoordinates(this.view,s,0,T.WGS84,e,0,1),e}deleteVehicles(s){if(this.isPaused)return;const e=Date.now();s.forEach(t=>{if(this.appDataStore.saveTrackLog){const a=this.historyPositionMap.get(t);this.logTable.push([t,"","","","","","","","","","","","","","",e,a?a.length:0,2])}const i=this.vehicleObjectMap.get(t);i&&(this.needInterpolate?i.isMoving?i.waitForDelete=!0:this.deleteVehicle(i):this.deleteVehicle(i))})}deleteVehicle(s){this.scene.remove(s.model),this.disposeModel(s.model);const e=s.data.vehicleId;this.vehicleObjectMap.delete(e),this.historyPositionMap.delete(e)}async toggleTrafficInfo(s){s.name==="vehiclePlate"&&(s.visible===!0&&this.currentSpriteContent===m.EVehiclePlateState.None?await this.updatePanelContent(m.EVehiclePlateState.PlateNumber):await this.updatePanelContent(s.visible?this.currentSpriteContent:m.EVehiclePlateState.None))}togglePause(s){this.isPaused=s}clearVehicles(){for(const s of this.vehicleObjectMap.keys()){const e=this.vehicleObjectMap.get(s);e&&(this.scene.remove(e.model),this.disposeModel(e.model))}this.vehicleObjectMap.clear(),this.historyPositionMap.clear()}async updatePanelContent(s){if(s!==this.currentSpriteContent){this.currentSpriteContent=s;for(const e of this.vehicleObjectMap.keys()){const t=this.vehicleObjectMap.get(e);if(t){const i=t.model.getObjectByName("VehiclePlate");if(i&&(t.model.remove(i),this.disposeModel(i)),s!==m.EVehiclePlateState.None){const a=await this.createPlateSprite(t.data);a&&(t.model.add(a),a.position.set(0,5,-4))}}}}}toggleGroundVehicle(s){console.log("toggleGroundVehicle",s),this.showGroundVehicle=s}toggleElevatedVehicle(s){this.showElevatedVehicle=s}disposeModel(s){s.traverse(e=>{e instanceof o.Mesh&&(e.geometry.dispose(),e.material.dispose())})}computeVehiclePosition(s){const e=this.historyPositionMap.get(s),t=this.vehicleObjectMap.get(s);if(!t||!e||!t.isMoving&&e.length<=2)return;const i=Date.now();t.isMoving=!0,t.data.roadLayer==="1"?t.model.visible=this.showGroundVehicle:t.model.visible=this.showElevatedVehicle,t.segmentStartTime||(t.segmentStartTime=i,t.segmentTotalTime=e[1].time-e[0].time);const a=i-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",s));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(s){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(s.ptcType===2)e=this.bicycleModel.clone();else{switch(s.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(s.vehicleColor)||this.defaultMaterial;let i=!1;e.traverse(a=>{!i&&a instanceof o.Mesh&&(a.material=t,i=!0)})}return e}}createCanvas(s,e,t){const i=document.createElement("canvas"),a=s.width,n=s.height;i.width=a,i.height=n;const r=i.getContext("2d");if(!r){console.log("canvas创建失败");return}return r.fillStyle="rgba(0,0,0,0.0)",r.fillRect(0,0,a,n),r.drawImage(s,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),i}createPlateSprite(s){return new Promise((e,t)=>{var h,l;const i=!s.plateNo||s.plateNo==="0"||s.plateNo==="000000";if(this.currentSpriteContent===m.EVehiclePlateState.None||this.currentSpriteContent===m.EVehiclePlateState.PlateNumber&&i){e(void 0);return}let a=new Image,n="",r="";if(this.currentSpriteContent===m.EVehiclePlateState.PlateNumber||this.currentSpriteContent===m.EVehiclePlateState.Mix)if(i)a=this.greyPlateBG,n=s.ptcId,r="#ffffff";else switch(n=((h=s.showName)==null?void 0:h.substring(0,2))+"•"+((l=s.showName)==null?void 0:l.substring(2)),s.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=s.plateNo,r="#ffffff";break}else this.currentSpriteContent===m.EVehiclePlateState.Id&&(a=this.greyPlateBG,n=s.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}),g=new o.Sprite(c),b=.05,M=d.width*b,P=d.height*b;g.scale.set(M,P,1),g.name="VehiclePlate",e(g)}else{t("canvas创建失败");return}a.onerror=p=>{console.log(`号牌背景加载失败: ${a.src}`,p),t(p)}})}}exports.default=R;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const m=require("@arcgis/core/core/reactiveUtils.js"),
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const m=require("@arcgis/core/core/reactiveUtils.js"),c=require("@arcgis/core/Graphic"),o=require("@arcgis/core/layers/GraphicsLayer"),p=require("@turf/buffer"),f=require("@turf/convex"),b=require("@turf/helpers"),L=require("./district-controller.js");function g(a){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(a){for(const t in a)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(a,t);Object.defineProperty(e,t,r.get?r:{enumerable:!0,get:()=>a[t]})}}return e.default=a,Object.freeze(e)}const w=g(m),u=g(b);class v{constructor(e){this.crossScale=3e3,this.view=e,this.view.popup.visibleElements={closeButton:!0,collapseButton:!1,actionBar:!0},this.districtControllerLayer=new o({id:"districtControllerLayer",maxScale:144447,minScale:1155582}),this.subDistrictControllerLayer=new o({id:"subDistrictControllerLayer",maxScale:0,minScale:144447}),this.crossLayer=new o({id:"crossLayer",maxScale:0,minScale:36112}),this.highlightLayer=new o({id:"highlightLayer"}),this.view.map.addMany([this.districtControllerLayer,this.subDistrictControllerLayer,this.crossLayer,this.highlightLayer])}showSignalControlArea(e){this.districtControllerLayer.removeAll(),this.subDistrictControllerLayer.removeAll(),this.crossLayer.removeAll(),this.highlightLayer.removeAll(),this.districtControllerLayer.visible=!0,this.subDistrictControllerLayer.visible=!0;for(const t of e){const r=new L.default(t);this.drawArea(r,!0)}return this.watchHandle=w.watch(()=>this.view.scale,(t,r)=>{if(t>this.crossScale&&r<=this.crossScale)this.crossLayer.graphics.forEach(s=>{s.symbol={type:"simple-marker",color:s.getAttribute("color"),size:8,outline:{color:"white",width:1}}}),this.highlightLayer.graphics.forEach(s=>{s.getAttribute("type")==="cross"&&(s.symbol={type:"simple-marker",color:s.getAttribute("color"),size:8,outline:{color:"white",width:1}})});else if(t<=this.crossScale&&r>this.crossScale){const s={type:"picture-marker",url:"/GisViewerAssets/Images/xhj_1.png",width:"37px",height:"57px",yoffset:"25px"};this.crossLayer.graphics.forEach(i=>{i.symbol=s}),this.highlightLayer.graphics.forEach(i=>{i.getAttribute("type")==="cross"&&(i.symbol=s)})}}),{status:0,message:"ok"}}clearSignalControlArea(){var e;return this.districtControllerLayer.removeAll(),this.subDistrictControllerLayer.removeAll(),this.crossLayer.removeAll(),this.highlightLayer.removeAll(),(e=this.watchHandle)==null||e.remove(),this.view.closePopup(),{status:0,message:"ok"}}async locateSignalControlArea(e){const t=this.findAreaGraphic(e.id);if(t){t.attributes.type==="cross"?await this.view.goTo({target:t.geometry,scale:1500}):await this.view.goTo(t.geometry);const r=t.geometry.type==="point"?t.geometry:t.geometry.centroid;return this.view.openPopup({features:[t],location:r}),{status:0,message:"ok"}}else return{status:1,message:"未找到"}}async highlightSignalControlArea(e){this.highlightLayer.removeAll(),this.districtControllerLayer.visible=!1,this.subDistrictControllerLayer.visible=!1,this.crossLayer.visible=!1;const t=this.districtControllerLayer.graphics.filter(i=>i.getAttribute("id")===e.id).toArray().map(i=>i.clone()),r=this.subDistrictControllerLayer.graphics.filter(i=>i.getAttribute("id")===e.id||i.getAttribute("parentId")===e.id).toArray().map(i=>i.clone()),s=this.crossLayer.graphics.filter(i=>i.getAttribute("id")===e.id||i.getAttribute("districtId")===e.id||i.getAttribute("subDistrictId")===e.id).toArray().map(i=>i.clone());return t.length>0&&this.highlightLayer.addMany(t),r.length>0&&this.highlightLayer.addMany(r),s.length>0&&this.highlightLayer.addMany(s),this.highlightLayer.graphics.length===0?{status:1,message:"未找到"}:(t.length>0?await this.view.goTo(t):r.length>0?await this.view.goTo(r):s.length>1?await this.view.goTo(s):await this.view.goTo({target:s[0].geometry,scale:1500}),{status:0,message:"ok"})}resetHighlight(){return this.highlightLayer.removeAll(),this.districtControllerLayer.visible=!0,this.subDistrictControllerLayer.visible=!0,this.crossLayer.visible=!0,{status:0,message:"ok"}}findAreaGraphic(e){let t=this.districtControllerLayer.graphics.find(r=>r.attributes.id===e);return t||(t=this.subDistrictControllerLayer.graphics.find(r=>r.attributes.id===e)),t||(t=this.crossLayer.graphics.find(r=>r.attributes.id===e)),t}drawArea(e,t){const r=e.getAllCrossCoordinates();if(r.length>2){const i=u.featureCollection(r.map(d=>u.point(d))),n=f(i);if(!n)return;const y=p(n.geometry,t?200:30,{units:"meters"});let l;t?l=[{fieldName:"id",label:"区控编号"},{fieldName:"crossCount",label:"路口数量"},{fieldName:"subDistrictCount",label:"子区数量"}]:l=[{fieldName:"parentName",label:"区控名称"},{fieldName:"id",label:"子区编号"},{fieldName:"crossCount",label:"路口数量"}];const h=new c({geometry:{type:"polygon",rings:y.geometry.coordinates},symbol:{type:"simple-fill",color:[...e.areaColor,t?.6:.8],outline:{color:e.areaColor,width:2,style:t?"solid":"long-dash"}},attributes:{type:"signalControlArea",id:e.id,name:e.name,parentId:e.parentId,parentName:e.parentName,crossCount:e.crossCount,subDistrictCount:e.subDistrictCount},popupTemplate:{title:e.name,content:[{type:"fields",fieldInfos:l}]}});t?this.districtControllerLayer.add(h):this.subDistrictControllerLayer.add(h)}for(const i of e.subDistricts)this.drawArea(i,!1);const s=e.crosses.map(i=>new c({geometry:{type:"point",x:i.longitude,y:i.latitude},symbol:{type:"simple-marker",color:e.areaColor,size:8,outline:{color:"white",width:1}},attributes:{type:"cross",id:i.id,name:i.name,color:e.areaColor,signalId:i.signalId,districtId:t?e.id:e.parentId,districtName:t?e.name:e.parentName,subDistrictId:t?"":e.id,subDistrictName:t?"":e.name},popupTemplate:{title:i.name,content:[{type:"fields",fieldInfos:[{fieldName:"districtName",label:"区控名称"},{fieldName:"subDistrictName",label:"子区名称"},{fieldName:"id",label:"路口编号"},{fieldName:"signalId",label:"信号机编号"}]}]}}));this.crossLayer.addMany(s)}}exports.default=v;
|
package/lib/src/types/index.d.ts
CHANGED