gisviewer-vue3-arcgis 1.0.102 → 1.0.103
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/GreenWaveline.d.ts +68 -0
- package/es/src/gis-map/utils/holo-flow/signal-holo-flow.mjs +1 -1
- package/es/src/gis-map/utils/holo-flow/trace-holo-flow.mjs +26 -26
- package/es/src/gis-map/utils/holo-flow/{trace-renderer-webgl.d.ts → trace-renderer-external.d.ts} +8 -6
- package/es/src/gis-map/utils/holo-flow/trace-renderer-external.mjs +381 -0
- package/lib/src/gis-map/utils/GreenWaveline.d.ts +68 -0
- package/lib/src/gis-map/utils/holo-flow/signal-holo-flow.js +1 -1
- package/lib/src/gis-map/utils/holo-flow/trace-holo-flow.js +1 -1
- package/lib/src/gis-map/utils/holo-flow/{trace-renderer-webgl.d.ts → trace-renderer-external.d.ts} +8 -6
- package/lib/src/gis-map/utils/holo-flow/trace-renderer-external.js +1 -0
- package/package.json +1 -1
- package/es/src/gis-map/utils/holo-flow/trace-renderer-webgl.mjs +0 -343
- package/lib/src/gis-map/utils/holo-flow/trace-renderer-webgl.js +0 -1
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import Graphic from '@arcgis/core/Graphic';
|
|
2
|
+
import GraphicsLayer from '@arcgis/core/layers/GraphicsLayer';
|
|
3
|
+
import MapView from '@arcgis/core/views/MapView';
|
|
4
|
+
import SceneView from '@arcgis/core/views/SceneView';
|
|
5
|
+
interface GreenWaveLineOptions {
|
|
6
|
+
viewer: MapView | SceneView;
|
|
7
|
+
graphicsLayerOptions: {
|
|
8
|
+
id: string;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
interface roadPath {
|
|
12
|
+
paths: [number, number][];
|
|
13
|
+
symbol: any;
|
|
14
|
+
attributes: any;
|
|
15
|
+
visible?: boolean;
|
|
16
|
+
}
|
|
17
|
+
interface animationOptions {
|
|
18
|
+
isAnimation: boolean;
|
|
19
|
+
positive?: boolean;
|
|
20
|
+
positiveColor?: number[];
|
|
21
|
+
negative?: boolean;
|
|
22
|
+
negativeColor?: number[];
|
|
23
|
+
}
|
|
24
|
+
export default class GreenWaveLine {
|
|
25
|
+
private viewer;
|
|
26
|
+
overlayLayer: GraphicsLayer;
|
|
27
|
+
customGreenWaveLineView: any;
|
|
28
|
+
material: THREE.ShaderMaterial;
|
|
29
|
+
renderer: THREE.WebGLRenderer;
|
|
30
|
+
threeScene: THREE.Scene;
|
|
31
|
+
camera: THREE.PerspectiveCamera;
|
|
32
|
+
private defaultAnimationOptions;
|
|
33
|
+
constructor(options: GreenWaveLineOptions);
|
|
34
|
+
addGreenWaveLine(paths: roadPath[], options?: animationOptions): void;
|
|
35
|
+
getAnimationPath(paths: [number, number][], options?: animationOptions): any;
|
|
36
|
+
createLine(paths: any, symbol: any, attributes: any, visible: boolean): Graphic;
|
|
37
|
+
addPointText(points: any[]): void;
|
|
38
|
+
createPointText(point: any, symbol: any, attributes: any, visible: boolean): Graphic;
|
|
39
|
+
/**
|
|
40
|
+
* 隐藏覆盖物
|
|
41
|
+
*
|
|
42
|
+
* @param {string[]} [ids]
|
|
43
|
+
* @memberof GreenWaveLine
|
|
44
|
+
*/
|
|
45
|
+
hideWaveLine(ids?: string[]): void;
|
|
46
|
+
/**
|
|
47
|
+
* 显示覆盖物
|
|
48
|
+
*
|
|
49
|
+
* @param {string[]} [ids]
|
|
50
|
+
* @memberof GreenWaveLine
|
|
51
|
+
*/
|
|
52
|
+
showWaveLine(ids?: string[]): void;
|
|
53
|
+
/**
|
|
54
|
+
* 隐藏图层
|
|
55
|
+
*
|
|
56
|
+
* @memberof GreenWaveLine
|
|
57
|
+
*/
|
|
58
|
+
hideLayer(): void;
|
|
59
|
+
/**
|
|
60
|
+
* 显示图层
|
|
61
|
+
*
|
|
62
|
+
* @memberof Overlay
|
|
63
|
+
*/
|
|
64
|
+
showLayer(): void;
|
|
65
|
+
clearGreenWaveLine(): void;
|
|
66
|
+
destroy(): void;
|
|
67
|
+
}
|
|
68
|
+
export {};
|
|
@@ -216,7 +216,7 @@ class f {
|
|
|
216
216
|
createCountdownCanvas() {
|
|
217
217
|
return new Promise((e, a) => {
|
|
218
218
|
const i = new Image();
|
|
219
|
-
i.src = `${this.mapConfig.assetsRoot}/Images/timeboard/CountdownBG.png`,
|
|
219
|
+
i.src = `${this.mapConfig.assetsRoot}/Images/timeboard/CountdownBG.png`, i.onload = () => {
|
|
220
220
|
const n = document.createElement("canvas");
|
|
221
221
|
n.width = this.canvasWidth, n.height = this.canvasHeight, n.style.position = "absolute", n.style.transform = "translate(-50%, -50%)", n.getContext(
|
|
222
222
|
"2d"
|
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
class
|
|
1
|
+
import * as f from "@arcgis/core/views/3d/externalRenderers";
|
|
2
|
+
import g from "../../stores/index.mjs";
|
|
3
|
+
import u from "./trace-renderer-external.mjs";
|
|
4
|
+
import T from "./trace-renderer-layer.mjs";
|
|
5
|
+
class b {
|
|
6
6
|
constructor(e) {
|
|
7
7
|
this.lastDataTime = 0, this.view = e;
|
|
8
|
-
const
|
|
9
|
-
this.mapConfig = JSON.parse(JSON.stringify(
|
|
8
|
+
const c = g.useAppDataStore;
|
|
9
|
+
this.mapConfig = JSON.parse(JSON.stringify(c.mapConfig)), e.type === "3d" ? (this.traceRenderer = new u(e), f.add(
|
|
10
10
|
e,
|
|
11
11
|
this.traceRenderer
|
|
12
|
-
)) : this.traceRenderer = new
|
|
12
|
+
)) : this.traceRenderer = new T(e);
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
15
|
* 处理全息流轨迹数据
|
|
16
16
|
* */
|
|
17
17
|
handleVehicleTraceData(e) {
|
|
18
|
-
const
|
|
18
|
+
const c = new Date().getTime(), { newVehList: s, updateVehList: l, deleteVehList: o, jgsj: i } = e, n = e.crossId || "", a = [], h = [];
|
|
19
19
|
if (s && s.length > 0) {
|
|
20
20
|
for (const t of s) {
|
|
21
|
-
t.localTimestamp || (t.localTimestamp = i ||
|
|
21
|
+
t.localTimestamp || (t.localTimestamp = i || c);
|
|
22
22
|
const r = this.buildVehicleTrackData(t, n);
|
|
23
|
-
r &&
|
|
23
|
+
r && a.push(r);
|
|
24
24
|
}
|
|
25
|
-
this.traceRenderer.addVehicles(
|
|
25
|
+
this.traceRenderer.addVehicles(a);
|
|
26
26
|
}
|
|
27
|
-
if (
|
|
28
|
-
for (const t of
|
|
27
|
+
if (l && l.length > 0) {
|
|
28
|
+
for (const t of l) {
|
|
29
29
|
const r = this.buildVehicleTrackData(t, n);
|
|
30
30
|
r && h.push(r);
|
|
31
31
|
}
|
|
32
32
|
this.traceRenderer.updateVehicles(h);
|
|
33
33
|
}
|
|
34
|
-
if (
|
|
35
|
-
const t =
|
|
34
|
+
if (o && o.length > 0) {
|
|
35
|
+
const t = o.map(
|
|
36
36
|
(r) => n + "-" + (r.ptcId || r.vehno || r.vehNo)
|
|
37
37
|
);
|
|
38
38
|
this.traceRenderer.deleteVehicles(t);
|
|
@@ -63,28 +63,28 @@ class y {
|
|
|
63
63
|
setInterpolate(e) {
|
|
64
64
|
this.traceRenderer.setInterpolate(e);
|
|
65
65
|
}
|
|
66
|
-
buildVehicleTrackData(e,
|
|
67
|
-
const s = e.longitude,
|
|
66
|
+
buildVehicleTrackData(e, c) {
|
|
67
|
+
const s = e.longitude, l = e.latitude, o = e.ptcId, i = Number(e.ptcType), n = e.heading, a = Number(e.vehicleType), h = Number(e.vehicleColor), t = e.plateNo || e.plateno, r = Number(e.plateColor), p = e.timestamp, d = e.localTimestamp, m = String(e.roadLayer) || "1";
|
|
68
68
|
if (!(i < 0 || i > 8))
|
|
69
69
|
return {
|
|
70
|
-
ptcId:
|
|
71
|
-
crossId:
|
|
72
|
-
vehicleId:
|
|
70
|
+
ptcId: o,
|
|
71
|
+
crossId: c,
|
|
72
|
+
vehicleId: c + "-" + o,
|
|
73
73
|
x: s,
|
|
74
|
-
y:
|
|
74
|
+
y: l,
|
|
75
75
|
ptcType: i,
|
|
76
|
-
vehicleType:
|
|
76
|
+
vehicleType: a,
|
|
77
77
|
heading: i === 2 ? -n : n,
|
|
78
78
|
vehicleColor: h,
|
|
79
79
|
showName: t && t !== "" && t !== "0" && t !== "000000" ? t : "",
|
|
80
80
|
plateNo: t,
|
|
81
81
|
plateColor: r,
|
|
82
82
|
timestamp: p,
|
|
83
|
-
localTimestamp:
|
|
84
|
-
roadLayer:
|
|
83
|
+
localTimestamp: d,
|
|
84
|
+
roadLayer: m
|
|
85
85
|
};
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
export {
|
|
89
|
-
|
|
89
|
+
b as default
|
|
90
90
|
};
|
package/es/src/gis-map/utils/holo-flow/{trace-renderer-webgl.d.ts → trace-renderer-external.d.ts}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EVehiclePlateState, IToggleTrafficInfoParams, ITraceRendererInterface, IVehicleTrack } from '../../../types';
|
|
2
|
-
export default class
|
|
2
|
+
export default class TraceRendererExternal implements ITraceRendererInterface {
|
|
3
3
|
private renderer;
|
|
4
4
|
private scene;
|
|
5
5
|
private camera;
|
|
@@ -25,27 +25,29 @@ export default class TraceRendererWebgl implements ITraceRendererInterface {
|
|
|
25
25
|
private historyPositionMap;
|
|
26
26
|
private vehicleObjectMap;
|
|
27
27
|
private needInterpolate;
|
|
28
|
+
private mesh;
|
|
29
|
+
private sprite;
|
|
28
30
|
constructor(view: __esri.SceneView);
|
|
29
31
|
setInterpolate(needInterpolate: boolean): void;
|
|
30
32
|
private context;
|
|
31
33
|
setup(context: any): Promise<void>;
|
|
32
|
-
private
|
|
34
|
+
private geometryTest;
|
|
33
35
|
render(context: any): Promise<void>;
|
|
34
36
|
/**
|
|
35
37
|
* 新增车辆
|
|
36
38
|
* */
|
|
37
|
-
addVehicles(objects: IVehicleTrack[]): void
|
|
39
|
+
addVehicles(objects: IVehicleTrack[]): Promise<void>;
|
|
38
40
|
/**
|
|
39
41
|
* 更新车辆
|
|
40
42
|
* */
|
|
41
|
-
updateVehicles(objects: IVehicleTrack[]): void
|
|
43
|
+
updateVehicles(objects: IVehicleTrack[]): Promise<void>;
|
|
42
44
|
private toRenderCoordinates;
|
|
43
45
|
/**
|
|
44
46
|
* 删除车辆
|
|
45
47
|
* */
|
|
46
48
|
deleteVehicles(idList: string[]): void;
|
|
47
49
|
private deleteVehicle;
|
|
48
|
-
toggleTrafficInfo(params: IToggleTrafficInfoParams): void
|
|
50
|
+
toggleTrafficInfo(params: IToggleTrafficInfoParams): Promise<void>;
|
|
49
51
|
/**
|
|
50
52
|
* 清除全部车辆
|
|
51
53
|
* */
|
|
@@ -55,7 +57,7 @@ export default class TraceRendererWebgl implements ITraceRendererInterface {
|
|
|
55
57
|
* @param contentType
|
|
56
58
|
* @returns
|
|
57
59
|
*/
|
|
58
|
-
updatePanelContent(contentType: EVehiclePlateState): void
|
|
60
|
+
updatePanelContent(contentType: EVehiclePlateState): Promise<void>;
|
|
59
61
|
toggleGroundVehicle(visible: boolean): void;
|
|
60
62
|
toggleElevatedVehicle(visible: boolean): void;
|
|
61
63
|
/**
|
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
import w from "@arcgis/core/geometry/SpatialReference";
|
|
2
|
+
import * as g from "@arcgis/core/views/3d/externalRenderers";
|
|
3
|
+
import * as o from "three";
|
|
4
|
+
import { GLTFLoader as u } from "three/examples/jsm/loaders/GLTFLoader.js";
|
|
5
|
+
import { EVehiclePlateState as p } from "../../../types/index.mjs";
|
|
6
|
+
import R from "../../stores/index.mjs";
|
|
7
|
+
class k {
|
|
8
|
+
constructor(i) {
|
|
9
|
+
this.defaultMaterial = new o.MeshBasicMaterial({
|
|
10
|
+
color: 6908265
|
|
11
|
+
}), this.materialMap = /* @__PURE__ */ new Map([
|
|
12
|
+
[1, new o.MeshBasicMaterial({ color: 16777215 })],
|
|
13
|
+
[2, new o.MeshBasicMaterial({ color: 7833753 })],
|
|
14
|
+
[3, new o.MeshBasicMaterial({ color: 16766720 })],
|
|
15
|
+
[4, new o.MeshBasicMaterial({ color: 16758465 })],
|
|
16
|
+
[5, new o.MeshBasicMaterial({ color: 14423100 })],
|
|
17
|
+
[6, new o.MeshBasicMaterial({ color: 3329330 })],
|
|
18
|
+
[7, new o.MeshBasicMaterial({ color: 2003183 })],
|
|
19
|
+
[8, new o.MeshBasicMaterial({ color: 16032864 })],
|
|
20
|
+
[9, new o.MeshBasicMaterial({ color: 2105376 })],
|
|
21
|
+
[10, new o.MeshBasicMaterial({ color: 9662683 })],
|
|
22
|
+
[99, new o.MeshBasicMaterial({ color: 6908265 })]
|
|
23
|
+
]), this.carModelReady = !1, this.vanModelReady = !1, this.truckModelReady = !1, this.busModelReady = !1, this.bicycleModelReady = !1, this.currentSpriteContent = p.None, this.historyPositionMap = /* @__PURE__ */ new Map(), this.vehicleObjectMap = /* @__PURE__ */ new Map(), this.needInterpolate = !0;
|
|
24
|
+
const e = R.useAppDataStore;
|
|
25
|
+
this.assetsRoot = JSON.parse(
|
|
26
|
+
JSON.stringify(e.mapConfig)
|
|
27
|
+
).assetsRoot, this.view = i;
|
|
28
|
+
const t = new u();
|
|
29
|
+
t.load(`${this.assetsRoot}/3DModels/car.glb`, (s) => {
|
|
30
|
+
this.carModel = s.scene, this.carModel.rotation.x = o.MathUtils.degToRad(90), this.carModelReady = !0;
|
|
31
|
+
}), t.load(`${this.assetsRoot}/3DModels/van.glb`, (s) => {
|
|
32
|
+
this.vanModel = s.scene, this.vanModel.rotation.x = o.MathUtils.degToRad(90), this.vanModelReady = !0;
|
|
33
|
+
}), t.load(`${this.assetsRoot}/3DModels/truck.glb`, (s) => {
|
|
34
|
+
this.truckModel = s.scene, this.truckModel.scale.set(1.2, 1, 1.5), this.truckModel.rotation.x = o.MathUtils.degToRad(90), this.truckModelReady = !0;
|
|
35
|
+
}), t.load(`${this.assetsRoot}/3DModels/bus.glb`, (s) => {
|
|
36
|
+
this.busModel = s.scene, this.busModel.rotation.x = o.MathUtils.degToRad(90), this.busModelReady = !0;
|
|
37
|
+
}), t.load(`${this.assetsRoot}/3DModels/bicycle.glb`, (s) => {
|
|
38
|
+
this.bicycleModel = s.scene, this.bicycleModel.rotation.x = o.MathUtils.degToRad(90), this.bicycleModel.rotation.y = o.MathUtils.degToRad(180), this.bicycleModelReady = !0;
|
|
39
|
+
}), document.addEventListener(
|
|
40
|
+
"visibilitychange",
|
|
41
|
+
() => {
|
|
42
|
+
this.clearVehicles(), this.needInterpolate = !document.hidden;
|
|
43
|
+
},
|
|
44
|
+
!1
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
setInterpolate(i) {
|
|
48
|
+
this.clearVehicles(), this.needInterpolate = i;
|
|
49
|
+
}
|
|
50
|
+
async setup(i) {
|
|
51
|
+
this.context = i, this.renderer = new o.WebGLRenderer({
|
|
52
|
+
context: i.gl,
|
|
53
|
+
premultipliedAlpha: !0,
|
|
54
|
+
logarithmicDepthBuffer: !0,
|
|
55
|
+
antialias: !0,
|
|
56
|
+
powerPreference: "high-performance"
|
|
57
|
+
}), 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;
|
|
58
|
+
const e = this.renderer.setRenderTarget.bind(
|
|
59
|
+
this.renderer
|
|
60
|
+
);
|
|
61
|
+
this.renderer.setRenderTarget = (t) => {
|
|
62
|
+
e(t), t == null && i.bindRenderTarget();
|
|
63
|
+
}, this.scene = new o.Scene(), this.camera = new o.PerspectiveCamera(), this.ambient = new o.AmbientLight(16777215, 0.5), this.scene.add(this.ambient), this.sun = new o.DirectionalLight(16777215, 0.5), this.scene.add(this.sun), i.resetWebGLState();
|
|
64
|
+
}
|
|
65
|
+
geometryTest() {
|
|
66
|
+
new u().load(`${this.assetsRoot}/3DModels/car.glb`, (e) => {
|
|
67
|
+
this.mesh = e.scene, this.mesh.rotation.x = o.MathUtils.degToRad(90);
|
|
68
|
+
const t = [121.46892831020403, 31.239681632841354, 0], s = this.toRenderCoordinates(t);
|
|
69
|
+
this.mesh.position.set(s[0], s[1], s[2]), this.scene.add(this.mesh), new o.TextureLoader().load(
|
|
70
|
+
`${this.assetsRoot}/Images/PlateBG/grey.png`,
|
|
71
|
+
(r) => {
|
|
72
|
+
const n = new o.SpriteMaterial({
|
|
73
|
+
map: r,
|
|
74
|
+
transparent: !1
|
|
75
|
+
}), a = new o.Sprite(n);
|
|
76
|
+
a.scale.set(5, 2.5, 1), a.position.set(0, 5, -4), this.mesh.add(a), console.log(this.mesh.visible, a.visible);
|
|
77
|
+
}
|
|
78
|
+
);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
async render(i) {
|
|
82
|
+
var s;
|
|
83
|
+
const e = i.camera;
|
|
84
|
+
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(
|
|
85
|
+
new o.Vector3(e.center[0], e.center[1], e.center[2])
|
|
86
|
+
), this.camera.projectionMatrix.fromArray(e.projectionMatrix), this.needInterpolate)
|
|
87
|
+
for (const l of this.vehicleObjectMap.keys()) {
|
|
88
|
+
const r = (s = this.vehicleObjectMap.get(l)) == null ? void 0 : s.model;
|
|
89
|
+
if (!r)
|
|
90
|
+
continue;
|
|
91
|
+
const n = this.computeVehiclePosition(l);
|
|
92
|
+
if (n) {
|
|
93
|
+
const a = this.toRenderCoordinates(n);
|
|
94
|
+
r.position.set(a[0], a[1], a[2]), r.rotation.y = o.MathUtils.degToRad(-n[3]);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const t = i.sunLight;
|
|
98
|
+
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(
|
|
99
|
+
t.diffuse.color[0],
|
|
100
|
+
t.diffuse.color[1],
|
|
101
|
+
t.diffuse.color[2]
|
|
102
|
+
), this.ambient.intensity = t.ambient.intensity, this.ambient.color = new o.Color(
|
|
103
|
+
t.ambient.color[0],
|
|
104
|
+
t.ambient.color[1],
|
|
105
|
+
t.ambient.color[2]
|
|
106
|
+
), this.renderer.resetState(), i.bindRenderTarget(), this.renderer.render(this.scene, this.camera), g.requestRender(this.view), i.resetWebGLState();
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* 新增车辆
|
|
110
|
+
* */
|
|
111
|
+
async addVehicles(i) {
|
|
112
|
+
if (!(!this.carModelReady || !this.vanModelReady || !this.truckModelReady || !this.busModelReady || !this.bicycleModelReady))
|
|
113
|
+
for (const e of i) {
|
|
114
|
+
const { vehicleId: t, localTimestamp: s } = e, l = Number(e.x), r = Number(e.y), n = Number(e.heading);
|
|
115
|
+
this.historyPositionMap.set(t, [
|
|
116
|
+
{ pos: [l, r, 0], heading: n, time: s }
|
|
117
|
+
]);
|
|
118
|
+
const a = this.getVehicleModel(e);
|
|
119
|
+
a.name = t, a.visible = !this.needInterpolate;
|
|
120
|
+
try {
|
|
121
|
+
const c = await this.createPlateSprite(e);
|
|
122
|
+
c && (a.add(c), c.position.set(0, 5, -4)), this.scene.add(a), this.vehicleObjectMap.set(t, {
|
|
123
|
+
model: a,
|
|
124
|
+
data: e,
|
|
125
|
+
waitForDelete: !1,
|
|
126
|
+
isMoving: !1
|
|
127
|
+
});
|
|
128
|
+
} catch (c) {
|
|
129
|
+
console.log("createPlateSprite error:", c);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* 更新车辆
|
|
135
|
+
* */
|
|
136
|
+
async updateVehicles(i) {
|
|
137
|
+
if (!this.carModelReady || !this.vanModelReady || !this.truckModelReady || !this.busModelReady || !this.bicycleModelReady)
|
|
138
|
+
return;
|
|
139
|
+
const e = [];
|
|
140
|
+
for (const t of i) {
|
|
141
|
+
const { vehicleId: s, localTimestamp: l } = t, r = Number(t.x), n = Number(t.y);
|
|
142
|
+
let a = Number(t.heading);
|
|
143
|
+
const c = this.vehicleObjectMap.get(s);
|
|
144
|
+
if (!c)
|
|
145
|
+
e.push(t);
|
|
146
|
+
else {
|
|
147
|
+
if (c.data.vehicleColor !== t.vehicleColor || c.data.vehicleType !== t.vehicleType) {
|
|
148
|
+
this.scene.remove(c.model), this.disposeModel(c.model), c.model = this.getVehicleModel(t);
|
|
149
|
+
const h = await this.createPlateSprite(t);
|
|
150
|
+
h && (c.model.add(h), h.position.set(0, 5, -4)), this.scene.add(c.model);
|
|
151
|
+
}
|
|
152
|
+
if (c.data.showName !== t.showName || c.data.plateColor !== t.plateColor) {
|
|
153
|
+
const h = c.model.getObjectByName("VehiclePlate");
|
|
154
|
+
h && (c.model.remove(h), this.disposeModel(h));
|
|
155
|
+
const d = await this.createPlateSprite(t);
|
|
156
|
+
d && (c.model.add(d), d.position.set(0, 5, -4));
|
|
157
|
+
}
|
|
158
|
+
if (c.data = t, this.needInterpolate) {
|
|
159
|
+
const h = this.historyPositionMap.get(
|
|
160
|
+
s
|
|
161
|
+
), d = h[h.length - 1];
|
|
162
|
+
Math.abs(a - d.heading) >= 180 && (a > d.heading ? d.heading += 360 : a += 360), h.push({
|
|
163
|
+
pos: [r, n, 0],
|
|
164
|
+
heading: a,
|
|
165
|
+
time: l
|
|
166
|
+
});
|
|
167
|
+
} else {
|
|
168
|
+
this.historyPositionMap.set(s, [
|
|
169
|
+
{ pos: [r, n, 0], heading: a, time: l }
|
|
170
|
+
]);
|
|
171
|
+
const h = this.toRenderCoordinates([r, n, 0]);
|
|
172
|
+
c.model.position.set(h[0], h[1], h[2]), c.model.rotation.y = o.MathUtils.degToRad(-a);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
this.addVehicles(e), this.needInterpolate || this.render(this.context);
|
|
177
|
+
}
|
|
178
|
+
toRenderCoordinates(i) {
|
|
179
|
+
const e = [0, 0, 0];
|
|
180
|
+
return g.toRenderCoordinates(
|
|
181
|
+
// @ts-ignore
|
|
182
|
+
this.view,
|
|
183
|
+
i,
|
|
184
|
+
0,
|
|
185
|
+
w.WGS84,
|
|
186
|
+
e,
|
|
187
|
+
0,
|
|
188
|
+
1
|
|
189
|
+
), e;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* 删除车辆
|
|
193
|
+
* */
|
|
194
|
+
deleteVehicles(i) {
|
|
195
|
+
i.forEach((e) => {
|
|
196
|
+
const t = this.vehicleObjectMap.get(e);
|
|
197
|
+
t && (this.needInterpolate ? t.isMoving ? t.waitForDelete = !0 : this.deleteVehicle(t) : this.deleteVehicle(t));
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
deleteVehicle(i) {
|
|
201
|
+
this.scene.remove(i.model), this.disposeModel(i.model);
|
|
202
|
+
const e = i.data.vehicleId;
|
|
203
|
+
this.vehicleObjectMap.delete(e), this.historyPositionMap.delete(e);
|
|
204
|
+
}
|
|
205
|
+
async toggleTrafficInfo(i) {
|
|
206
|
+
i.name === "vehiclePlate" && (i.visible === !0 && this.currentSpriteContent === p.None ? await this.updatePanelContent(p.Id) : await this.updatePanelContent(
|
|
207
|
+
i.visible ? this.currentSpriteContent : p.None
|
|
208
|
+
));
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* 清除全部车辆
|
|
212
|
+
* */
|
|
213
|
+
clearVehicles() {
|
|
214
|
+
for (const i of this.vehicleObjectMap.keys()) {
|
|
215
|
+
const e = this.vehicleObjectMap.get(i);
|
|
216
|
+
e && (this.disposeModel(e.model), this.scene.remove(e.model));
|
|
217
|
+
}
|
|
218
|
+
this.vehicleObjectMap.clear(), this.historyPositionMap.clear();
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* 设置号牌显示状态
|
|
222
|
+
* @param contentType
|
|
223
|
+
* @returns
|
|
224
|
+
*/
|
|
225
|
+
async updatePanelContent(i) {
|
|
226
|
+
if (i !== this.currentSpriteContent) {
|
|
227
|
+
this.currentSpriteContent = i;
|
|
228
|
+
for (const e of this.vehicleObjectMap.keys()) {
|
|
229
|
+
const t = this.vehicleObjectMap.get(e);
|
|
230
|
+
if (t) {
|
|
231
|
+
const s = t.model.getObjectByName("VehiclePlate");
|
|
232
|
+
if (s && (t.model.remove(s), this.disposeModel(s)), i !== p.None) {
|
|
233
|
+
const l = await this.createPlateSprite(t.data);
|
|
234
|
+
l && (t.model.add(l), l.position.set(0, 5, -4));
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
toggleGroundVehicle(i) {
|
|
241
|
+
}
|
|
242
|
+
toggleElevatedVehicle(i) {
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* 释放模型资源
|
|
246
|
+
* */
|
|
247
|
+
disposeModel(i) {
|
|
248
|
+
i.traverse((e) => {
|
|
249
|
+
e instanceof o.Mesh && (e.geometry.dispose(), e.material.dispose());
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* 计算车辆位置
|
|
254
|
+
* */
|
|
255
|
+
computeVehiclePosition(i) {
|
|
256
|
+
const e = this.historyPositionMap.get(i), t = this.vehicleObjectMap.get(i);
|
|
257
|
+
if (!t || !e || !t.isMoving && e.length <= 2)
|
|
258
|
+
return;
|
|
259
|
+
const s = Date.now();
|
|
260
|
+
t.model.visible = !0, t.isMoving = !0, t.segmentStartTime || (t.segmentStartTime = s, t.segmentTotalTime = e[1].time - e[0].time);
|
|
261
|
+
const l = s - t.segmentStartTime, r = Math.min(
|
|
262
|
+
l / t.segmentTotalTime,
|
|
263
|
+
1
|
|
264
|
+
);
|
|
265
|
+
if (r === 1)
|
|
266
|
+
if (e.shift(), e.length === 1) {
|
|
267
|
+
t.waitForDelete === !0 ? this.deleteVehicle(t) : (t.segmentStartTime = void 0, t.segmentTotalTime = void 0, t.model.visible = !1, t.isMoving = !1, console.log("pause vehicle", i));
|
|
268
|
+
return;
|
|
269
|
+
} else
|
|
270
|
+
return t.segmentStartTime = Date.now(), t.segmentTotalTime = e[1].time - e[0].time, (e[1].heading >= 270 && e[0].heading <= 90 || e[1].heading <= 90 && e[0].heading >= 270) && (e[1].heading > e[0].heading ? e[0].heading += 360 : e[1].heading += 360), e[0].pos.concat(e[0].heading);
|
|
271
|
+
else {
|
|
272
|
+
const n = e[0].pos[0] + (e[1].pos[0] - e[0].pos[0]) * r, a = e[0].pos[1] + (e[1].pos[1] - e[0].pos[1]) * r, c = e[0].heading + (e[1].heading - e[0].heading) * r;
|
|
273
|
+
return [n, a, 0, c];
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* 根据车辆类型、车身颜色获取模型
|
|
278
|
+
* */
|
|
279
|
+
getVehicleModel(i) {
|
|
280
|
+
let e;
|
|
281
|
+
if (i.ptcType === 2)
|
|
282
|
+
e = this.bicycleModel.clone();
|
|
283
|
+
else {
|
|
284
|
+
switch (i.vehicleType) {
|
|
285
|
+
case 10:
|
|
286
|
+
e = this.carModel.clone();
|
|
287
|
+
break;
|
|
288
|
+
case 20:
|
|
289
|
+
e = this.vanModel.clone();
|
|
290
|
+
break;
|
|
291
|
+
case 25:
|
|
292
|
+
e = this.truckModel.clone();
|
|
293
|
+
break;
|
|
294
|
+
case 50:
|
|
295
|
+
e = this.busModel.clone();
|
|
296
|
+
break;
|
|
297
|
+
default:
|
|
298
|
+
e = this.carModel.clone();
|
|
299
|
+
break;
|
|
300
|
+
}
|
|
301
|
+
const t = this.materialMap.get(i.vehicleColor) || this.defaultMaterial;
|
|
302
|
+
let s = !1;
|
|
303
|
+
e.traverse((l) => {
|
|
304
|
+
!s && l instanceof o.Mesh && (l.material = t, s = !0);
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
return e;
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* 创建号牌canvas
|
|
311
|
+
* */
|
|
312
|
+
createCanvas(i, e, t) {
|
|
313
|
+
const s = document.createElement("canvas"), l = i.width, r = i.height;
|
|
314
|
+
s.width = l, s.height = r;
|
|
315
|
+
const n = s.getContext("2d");
|
|
316
|
+
if (!n) {
|
|
317
|
+
console.log("canvas创建失败");
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
return n.fillStyle = "rgba(0,0,0,0.0)", n.fillRect(0, 0, l, r), n.drawImage(i, 0, 0, l, r), n.beginPath(), n.translate(l / 2, r / 2), n.fillStyle = t, n.font = "bold 32px 宋体", n.textBaseline = "middle", n.textAlign = "center", n.fillText(e, 0, 0), s;
|
|
321
|
+
}
|
|
322
|
+
createPlateSprite(i) {
|
|
323
|
+
return new Promise((e, t) => {
|
|
324
|
+
var c, h;
|
|
325
|
+
const s = !i.plateNo || i.plateNo === "0" || i.plateNo === "000000";
|
|
326
|
+
if (this.currentSpriteContent === p.None || this.currentSpriteContent === p.PlateNumber && s) {
|
|
327
|
+
e(void 0);
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
const l = new Image();
|
|
331
|
+
let r = "", n = "", a = "";
|
|
332
|
+
if (this.currentSpriteContent === p.PlateNumber || this.currentSpriteContent === p.Mix)
|
|
333
|
+
if (s)
|
|
334
|
+
r = "grey", n = i.ptcId, a = "#ffffff";
|
|
335
|
+
else
|
|
336
|
+
switch (n = ((c = i.showName) == null ? void 0 : c.substring(0, 2)) + "•" + ((h = i.showName) == null ? void 0 : h.substring(2)), i.plateColor) {
|
|
337
|
+
case 1:
|
|
338
|
+
r = "blue", a = "#ffffff";
|
|
339
|
+
break;
|
|
340
|
+
case 2:
|
|
341
|
+
r = "yellow", a = "#000000";
|
|
342
|
+
break;
|
|
343
|
+
case 3:
|
|
344
|
+
r = "white", a = "#000000";
|
|
345
|
+
break;
|
|
346
|
+
case 4:
|
|
347
|
+
r = "black";
|
|
348
|
+
break;
|
|
349
|
+
case 5:
|
|
350
|
+
r = "neo_yellow", a = "#000000";
|
|
351
|
+
break;
|
|
352
|
+
case 6:
|
|
353
|
+
r = "neo_green", a = "#000000";
|
|
354
|
+
break;
|
|
355
|
+
default:
|
|
356
|
+
r = "grey", n = i.plateNo, a = "#ffffff";
|
|
357
|
+
break;
|
|
358
|
+
}
|
|
359
|
+
else
|
|
360
|
+
this.currentSpriteContent === p.Id && (r = "grey", n = i.ptcId, a = "#ffffff");
|
|
361
|
+
l.src = `${this.assetsRoot}/Images/PlateBG/${r}.png`, l.onload = () => {
|
|
362
|
+
const d = this.createCanvas(l, n, a);
|
|
363
|
+
if (!d)
|
|
364
|
+
t("canvas创建失败");
|
|
365
|
+
else {
|
|
366
|
+
const f = new o.CanvasTexture(d), b = new o.SpriteMaterial({
|
|
367
|
+
map: f,
|
|
368
|
+
transparent: !1
|
|
369
|
+
}), m = new o.Sprite(b), M = 0.05, y = d.width * M, v = d.height * M;
|
|
370
|
+
m.scale.set(y, v, 1), m.name = "VehiclePlate", e(m);
|
|
371
|
+
}
|
|
372
|
+
l.onerror = (f) => {
|
|
373
|
+
console.log(`号牌背景加载失败: ${l.src}`, f), t(f);
|
|
374
|
+
};
|
|
375
|
+
};
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
export {
|
|
380
|
+
k as default
|
|
381
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import Graphic from '@arcgis/core/Graphic';
|
|
2
|
+
import GraphicsLayer from '@arcgis/core/layers/GraphicsLayer';
|
|
3
|
+
import MapView from '@arcgis/core/views/MapView';
|
|
4
|
+
import SceneView from '@arcgis/core/views/SceneView';
|
|
5
|
+
interface GreenWaveLineOptions {
|
|
6
|
+
viewer: MapView | SceneView;
|
|
7
|
+
graphicsLayerOptions: {
|
|
8
|
+
id: string;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
interface roadPath {
|
|
12
|
+
paths: [number, number][];
|
|
13
|
+
symbol: any;
|
|
14
|
+
attributes: any;
|
|
15
|
+
visible?: boolean;
|
|
16
|
+
}
|
|
17
|
+
interface animationOptions {
|
|
18
|
+
isAnimation: boolean;
|
|
19
|
+
positive?: boolean;
|
|
20
|
+
positiveColor?: number[];
|
|
21
|
+
negative?: boolean;
|
|
22
|
+
negativeColor?: number[];
|
|
23
|
+
}
|
|
24
|
+
export default class GreenWaveLine {
|
|
25
|
+
private viewer;
|
|
26
|
+
overlayLayer: GraphicsLayer;
|
|
27
|
+
customGreenWaveLineView: any;
|
|
28
|
+
material: THREE.ShaderMaterial;
|
|
29
|
+
renderer: THREE.WebGLRenderer;
|
|
30
|
+
threeScene: THREE.Scene;
|
|
31
|
+
camera: THREE.PerspectiveCamera;
|
|
32
|
+
private defaultAnimationOptions;
|
|
33
|
+
constructor(options: GreenWaveLineOptions);
|
|
34
|
+
addGreenWaveLine(paths: roadPath[], options?: animationOptions): void;
|
|
35
|
+
getAnimationPath(paths: [number, number][], options?: animationOptions): any;
|
|
36
|
+
createLine(paths: any, symbol: any, attributes: any, visible: boolean): Graphic;
|
|
37
|
+
addPointText(points: any[]): void;
|
|
38
|
+
createPointText(point: any, symbol: any, attributes: any, visible: boolean): Graphic;
|
|
39
|
+
/**
|
|
40
|
+
* 隐藏覆盖物
|
|
41
|
+
*
|
|
42
|
+
* @param {string[]} [ids]
|
|
43
|
+
* @memberof GreenWaveLine
|
|
44
|
+
*/
|
|
45
|
+
hideWaveLine(ids?: string[]): void;
|
|
46
|
+
/**
|
|
47
|
+
* 显示覆盖物
|
|
48
|
+
*
|
|
49
|
+
* @param {string[]} [ids]
|
|
50
|
+
* @memberof GreenWaveLine
|
|
51
|
+
*/
|
|
52
|
+
showWaveLine(ids?: string[]): void;
|
|
53
|
+
/**
|
|
54
|
+
* 隐藏图层
|
|
55
|
+
*
|
|
56
|
+
* @memberof GreenWaveLine
|
|
57
|
+
*/
|
|
58
|
+
hideLayer(): void;
|
|
59
|
+
/**
|
|
60
|
+
* 显示图层
|
|
61
|
+
*
|
|
62
|
+
* @memberof Overlay
|
|
63
|
+
*/
|
|
64
|
+
showLayer(): void;
|
|
65
|
+
clearGreenWaveLine(): void;
|
|
66
|
+
destroy(): void;
|
|
67
|
+
}
|
|
68
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const d=require("@arcgis/core/core/reactiveUtils"),u=require("@arcgis/core/geometry"),p=require("@arcgis/core/layers/FeatureLayer"),g=require("../../stores/index.js");function y(l){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(l){for(const t in l)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(l,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>l[t]})}}return e.default=l,Object.freeze(e)}const w=y(d);class m{constructor(e){this.currentPhaseMap=new Map,this.countdownCanvasMap=new Map,this.lastDataTime=0,this.isDeletingCanvas=!1,this.canvasWidth=80,this.canvasHeight=40,this.view=(e.type==="2d",e);const t=g.default.useAppDataStore;this.mapConfig=JSON.parse(JSON.stringify(t.mapConfig))}async initializeLayer(){if(this.mapConfig.phaseLineLayer)if(this.phaseLineLayer)this.phaseLineLayer.visible||(this.phaseLineLayer.visible=!0);else{const e=`${this.mapConfig.assetsRoot}/${this.mapConfig.phaseLineLayer}`,i=(await(await fetch(e)).json()).features.map((s,a)=>({geometry:{type:"polyline",paths:[s.geometry.coordinates]},attributes:{ObjectID:a+1,id:s.properties.id,color:"hide"}}));this.phaseLineLayer=new p({source:i,geometryType:"polyline",objectIdField:"ObjectID",outFields:["*"],fields:[{name:"ObjectID",alias:"ObjectID",type:"oid"},{name:"color",alias:"color",type:"string"}],renderer:{type:"unique-value",field:"color",defaultSymbol:{type:"simple-line",color:"lightblue",width:"2px",style:"none"},uniqueValueInfos:[{value:"green",symbol:{type:"line-3d",symbolLayers:[{type:"path",profile:"quad",material:{color:[19,255,69,.8]},width:1,height:.5}]}},{value:"red",symbol:{type:"line-3d",symbolLayers:[{type:"path",profile:"quad",material:{color:[254,5,9,.8]},width:1,height:.5}]}},{value:"yellow",symbol:{type:"line-3d",symbolLayers:[{type:"path",profile:"quad",material:{color:[255,215,0,.8]},width:1,height:.5}]}}]}}),this.view.map.add(this.phaseLineLayer)}}async handleSignalData(e){const{crossId:t,lat:n,lon:i,rtStage:s,channelsConfig:a}=e;await this.updateCountdown(t,n,i,s),!(!this.phaseLineLayer||!a)&&((!this.currentPhaseMap.has(t)||this.currentPhaseMap.get(t)!==s.stagePhase)&&await this.updatePhaseLine(t,s.channelsConfig,a),this.currentPhaseMap.set(t,s.stagePhase))}clearSignal(){this.phaseLineLayer&&(this.phaseLineLayer.visible=!1),this.countdownWatchHandel&&(this.countdownWatchHandel.remove(),this.countdownWatchHandel=void 0),this.countdownCanvasMap.forEach(e=>{this.view.container.removeChild(e.backgroundCanvas),this.view.container.removeChild(e.countdownCanvas)}),this.countdownCanvasMap.clear()}async updateCountdown(e,t,n,i){if(this.isDeletingCanvas)return;const s=this.countdownCanvasMap.get(e);if(s)this.drawCountdownText(s.countdownCanvas,i);else try{const a=new u.Point({longitude:n,latitude:t,z:10}),o=this.view.toScreen(a),r=await this.createCountdownCanvas(),c=r[0],h=r[1];c.style.left=o.x+"px",c.style.top=o.y+"px",h.style.left=o.x+"px",h.style.top=o.y+"px",this.countdownCanvasMap.set(e,{backgroundCanvas:c,countdownCanvas:h,mapPoint:a}),this.drawCountdownText(h,i)}catch(a){console.log("倒计时canvas创建失败",e,a)}this.countdownWatchHandel||(this.countdownWatchHandel=w.watch(()=>this.view.extent,()=>{this.countdownCanvasMap.forEach(a=>{const o=this.view.toScreen(a.mapPoint);a.backgroundCanvas.style.left=o.x+"px",a.backgroundCanvas.style.top=o.y+"px",a.countdownCanvas.style.left=o.x+"px",a.countdownCanvas.style.top=o.y+"px"})}))}drawCountdownText(e,t){const n=e.getContext("2d");n.clearRect(0,0,e.width,e.height),n.font="24px Digital",n.textBaseline="middle",n.textAlign="center",n.fillStyle=t.stageRemainingTime<=t.stageAllRedTime?"red":t.stageRemainingTime<=t.stageAllRedTime+t.stageYellowTime?"yellow":"lime",n.fillText(`${t.stageID} ${t.stageRemainingTime.toFixed(0)}`,e.width/2,e.height/2)}drawCircle(e,t){console.log(t);const n=e.getContext("2d");n.clearRect(0,0,e.width,e.height),this.ctxDraw(n,"lime",e.width/2,e.height/2,20,-Math.PI/2,-Math.PI/2+2*.6*Math.PI)}ctxDraw(e,t,n,i,s,a,o){e.save,e.beginPath(),e.lineWidth=4,e.strokeStyle=t,e.arc(n,i,s,a,o),e.stroke(),e.closePath(),e.font="26px Digital",e.textBaseline="middle",e.textAlign="center",e.fillText("A",n,i),e.restore()}async updatePhaseLine(e,t,n){const i=this.phaseLineLayer.source.filter(s=>s.getAttribute("id").includes(e));i.forEach(s=>{const a=s.getAttribute("id");this.isLaneInChannels(a,t)?s.setAttribute("color","green"):this.isLaneInChannels(a,n)?s.setAttribute("color","red"):s.setAttribute("color","green")}),await this.phaseLineLayer.applyEdits({updateFeatures:i})}isLaneInChannels(e,t){const n=e.split("+"),i=n[1],s=n[2];for(let a=0;a<t.length;a++)for(let o=0;o<t[a].laneSnList.length;o++){const r=t[a].laneSnList[o].toFixed(0);if(i===r[0]&&s===r[1])return!0}return!1}createCountdownCanvas(){return new Promise((e,t)=>{const n=new Image;n.src=`${this.mapConfig.assetsRoot}/Images/timeboard/CountdownBG.png`,
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const d=require("@arcgis/core/core/reactiveUtils"),u=require("@arcgis/core/geometry"),p=require("@arcgis/core/layers/FeatureLayer"),g=require("../../stores/index.js");function y(l){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(l){for(const t in l)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(l,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>l[t]})}}return e.default=l,Object.freeze(e)}const w=y(d);class m{constructor(e){this.currentPhaseMap=new Map,this.countdownCanvasMap=new Map,this.lastDataTime=0,this.isDeletingCanvas=!1,this.canvasWidth=80,this.canvasHeight=40,this.view=(e.type==="2d",e);const t=g.default.useAppDataStore;this.mapConfig=JSON.parse(JSON.stringify(t.mapConfig))}async initializeLayer(){if(this.mapConfig.phaseLineLayer)if(this.phaseLineLayer)this.phaseLineLayer.visible||(this.phaseLineLayer.visible=!0);else{const e=`${this.mapConfig.assetsRoot}/${this.mapConfig.phaseLineLayer}`,i=(await(await fetch(e)).json()).features.map((s,a)=>({geometry:{type:"polyline",paths:[s.geometry.coordinates]},attributes:{ObjectID:a+1,id:s.properties.id,color:"hide"}}));this.phaseLineLayer=new p({source:i,geometryType:"polyline",objectIdField:"ObjectID",outFields:["*"],fields:[{name:"ObjectID",alias:"ObjectID",type:"oid"},{name:"color",alias:"color",type:"string"}],renderer:{type:"unique-value",field:"color",defaultSymbol:{type:"simple-line",color:"lightblue",width:"2px",style:"none"},uniqueValueInfos:[{value:"green",symbol:{type:"line-3d",symbolLayers:[{type:"path",profile:"quad",material:{color:[19,255,69,.8]},width:1,height:.5}]}},{value:"red",symbol:{type:"line-3d",symbolLayers:[{type:"path",profile:"quad",material:{color:[254,5,9,.8]},width:1,height:.5}]}},{value:"yellow",symbol:{type:"line-3d",symbolLayers:[{type:"path",profile:"quad",material:{color:[255,215,0,.8]},width:1,height:.5}]}}]}}),this.view.map.add(this.phaseLineLayer)}}async handleSignalData(e){const{crossId:t,lat:n,lon:i,rtStage:s,channelsConfig:a}=e;await this.updateCountdown(t,n,i,s),!(!this.phaseLineLayer||!a)&&((!this.currentPhaseMap.has(t)||this.currentPhaseMap.get(t)!==s.stagePhase)&&await this.updatePhaseLine(t,s.channelsConfig,a),this.currentPhaseMap.set(t,s.stagePhase))}clearSignal(){this.phaseLineLayer&&(this.phaseLineLayer.visible=!1),this.countdownWatchHandel&&(this.countdownWatchHandel.remove(),this.countdownWatchHandel=void 0),this.countdownCanvasMap.forEach(e=>{this.view.container.removeChild(e.backgroundCanvas),this.view.container.removeChild(e.countdownCanvas)}),this.countdownCanvasMap.clear()}async updateCountdown(e,t,n,i){if(this.isDeletingCanvas)return;const s=this.countdownCanvasMap.get(e);if(s)this.drawCountdownText(s.countdownCanvas,i);else try{const a=new u.Point({longitude:n,latitude:t,z:10}),o=this.view.toScreen(a),r=await this.createCountdownCanvas(),c=r[0],h=r[1];c.style.left=o.x+"px",c.style.top=o.y+"px",h.style.left=o.x+"px",h.style.top=o.y+"px",this.countdownCanvasMap.set(e,{backgroundCanvas:c,countdownCanvas:h,mapPoint:a}),this.drawCountdownText(h,i)}catch(a){console.log("倒计时canvas创建失败",e,a)}this.countdownWatchHandel||(this.countdownWatchHandel=w.watch(()=>this.view.extent,()=>{this.countdownCanvasMap.forEach(a=>{const o=this.view.toScreen(a.mapPoint);a.backgroundCanvas.style.left=o.x+"px",a.backgroundCanvas.style.top=o.y+"px",a.countdownCanvas.style.left=o.x+"px",a.countdownCanvas.style.top=o.y+"px"})}))}drawCountdownText(e,t){const n=e.getContext("2d");n.clearRect(0,0,e.width,e.height),n.font="24px Digital",n.textBaseline="middle",n.textAlign="center",n.fillStyle=t.stageRemainingTime<=t.stageAllRedTime?"red":t.stageRemainingTime<=t.stageAllRedTime+t.stageYellowTime?"yellow":"lime",n.fillText(`${t.stageID} ${t.stageRemainingTime.toFixed(0)}`,e.width/2,e.height/2)}drawCircle(e,t){console.log(t);const n=e.getContext("2d");n.clearRect(0,0,e.width,e.height),this.ctxDraw(n,"lime",e.width/2,e.height/2,20,-Math.PI/2,-Math.PI/2+2*.6*Math.PI)}ctxDraw(e,t,n,i,s,a,o){e.save,e.beginPath(),e.lineWidth=4,e.strokeStyle=t,e.arc(n,i,s,a,o),e.stroke(),e.closePath(),e.font="26px Digital",e.textBaseline="middle",e.textAlign="center",e.fillText("A",n,i),e.restore()}async updatePhaseLine(e,t,n){const i=this.phaseLineLayer.source.filter(s=>s.getAttribute("id").includes(e));i.forEach(s=>{const a=s.getAttribute("id");this.isLaneInChannels(a,t)?s.setAttribute("color","green"):this.isLaneInChannels(a,n)?s.setAttribute("color","red"):s.setAttribute("color","green")}),await this.phaseLineLayer.applyEdits({updateFeatures:i})}isLaneInChannels(e,t){const n=e.split("+"),i=n[1],s=n[2];for(let a=0;a<t.length;a++)for(let o=0;o<t[a].laneSnList.length;o++){const r=t[a].laneSnList[o].toFixed(0);if(i===r[0]&&s===r[1])return!0}return!1}createCountdownCanvas(){return new Promise((e,t)=>{const n=new Image;n.src=`${this.mapConfig.assetsRoot}/Images/timeboard/CountdownBG.png`,n.onload=()=>{const i=document.createElement("canvas");i.width=this.canvasWidth,i.height=this.canvasHeight,i.style.position="absolute",i.style.transform="translate(-50%, -50%)",i.getContext("2d").drawImage(n,0,0,this.canvasWidth,this.canvasHeight),this.view.container.appendChild(i);const a=document.createElement("canvas");a.width=this.canvasWidth-10,a.height=this.canvasHeight-10,a.style.position="absolute",a.style.transform="translate(-50%, -50%)",this.view.container.appendChild(a),e([i,a])},n.onerror=i=>{t(i)}})}}exports.default=m;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const g=require("@arcgis/core/views/3d/externalRenderers"),m=require("../../stores/index.js"),T=require("./trace-renderer-external.js"),b=require("./trace-renderer-layer.js");function R(o){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(o){for(const r in o)if(r!=="default"){const n=Object.getOwnPropertyDescriptor(o,r);Object.defineProperty(e,r,n.get?n:{enumerable:!0,get:()=>o[r]})}}return e.default=o,Object.freeze(e)}const V=R(g);class y{constructor(e){this.lastDataTime=0,this.view=e;const r=m.default.useAppDataStore;this.mapConfig=JSON.parse(JSON.stringify(r.mapConfig)),e.type==="3d"?(this.traceRenderer=new T.default(e),V.add(e,this.traceRenderer)):this.traceRenderer=new b.default(e)}handleVehicleTraceData(e){const r=new Date().getTime(),{newVehList:n,updateVehList:a,deleteVehList:i,jgsj:s}=e,l=e.crossId||"",d=[],h=[];if(n&&n.length>0){for(const t of n){t.localTimestamp||(t.localTimestamp=s||r);const c=this.buildVehicleTrackData(t,l);c&&d.push(c)}this.traceRenderer.addVehicles(d)}if(a&&a.length>0){for(const t of a){const c=this.buildVehicleTrackData(t,l);c&&h.push(c)}this.traceRenderer.updateVehicles(h)}if(i&&i.length>0){const t=i.map(c=>l+"-"+(c.ptcId||c.vehno||c.vehNo));this.traceRenderer.deleteVehicles(t)}}toggleTrafficInfo(e){this.traceRenderer.toggleTrafficInfo(e)}clearTrace(){this.traceRenderer.clearVehicles()}updatePanelContent(e){this.traceRenderer.updatePanelContent(e)}toggleGroundVehicle(e){this.traceRenderer.toggleGroundVehicle(e)}toggleElevatedVehicle(e){this.traceRenderer.toggleElevatedVehicle(e)}setInterpolate(e){this.traceRenderer.setInterpolate(e)}buildVehicleTrackData(e,r){const n=e.longitude,a=e.latitude,i=e.ptcId,s=Number(e.ptcType),l=e.heading,d=Number(e.vehicleType),h=Number(e.vehicleColor),t=e.plateNo||e.plateno,c=Number(e.plateColor),u=e.timestamp,p=e.localTimestamp,f=String(e.roadLayer)||"1";if(!(s<0||s>8))return{ptcId:i,crossId:r,vehicleId:r+"-"+i,x:n,y:a,ptcType:s,vehicleType:d,heading:s===2?-l:l,vehicleColor:h,showName:t&&t!==""&&t!=="0"&&t!=="000000"?t:"",plateNo:t,plateColor:c,timestamp:u,localTimestamp:p,roadLayer:f}}}exports.default=y;
|
package/lib/src/gis-map/utils/holo-flow/{trace-renderer-webgl.d.ts → trace-renderer-external.d.ts}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EVehiclePlateState, IToggleTrafficInfoParams, ITraceRendererInterface, IVehicleTrack } from '../../../types';
|
|
2
|
-
export default class
|
|
2
|
+
export default class TraceRendererExternal implements ITraceRendererInterface {
|
|
3
3
|
private renderer;
|
|
4
4
|
private scene;
|
|
5
5
|
private camera;
|
|
@@ -25,27 +25,29 @@ export default class TraceRendererWebgl implements ITraceRendererInterface {
|
|
|
25
25
|
private historyPositionMap;
|
|
26
26
|
private vehicleObjectMap;
|
|
27
27
|
private needInterpolate;
|
|
28
|
+
private mesh;
|
|
29
|
+
private sprite;
|
|
28
30
|
constructor(view: __esri.SceneView);
|
|
29
31
|
setInterpolate(needInterpolate: boolean): void;
|
|
30
32
|
private context;
|
|
31
33
|
setup(context: any): Promise<void>;
|
|
32
|
-
private
|
|
34
|
+
private geometryTest;
|
|
33
35
|
render(context: any): Promise<void>;
|
|
34
36
|
/**
|
|
35
37
|
* 新增车辆
|
|
36
38
|
* */
|
|
37
|
-
addVehicles(objects: IVehicleTrack[]): void
|
|
39
|
+
addVehicles(objects: IVehicleTrack[]): Promise<void>;
|
|
38
40
|
/**
|
|
39
41
|
* 更新车辆
|
|
40
42
|
* */
|
|
41
|
-
updateVehicles(objects: IVehicleTrack[]): void
|
|
43
|
+
updateVehicles(objects: IVehicleTrack[]): Promise<void>;
|
|
42
44
|
private toRenderCoordinates;
|
|
43
45
|
/**
|
|
44
46
|
* 删除车辆
|
|
45
47
|
* */
|
|
46
48
|
deleteVehicles(idList: string[]): void;
|
|
47
49
|
private deleteVehicle;
|
|
48
|
-
toggleTrafficInfo(params: IToggleTrafficInfoParams): void
|
|
50
|
+
toggleTrafficInfo(params: IToggleTrafficInfoParams): Promise<void>;
|
|
49
51
|
/**
|
|
50
52
|
* 清除全部车辆
|
|
51
53
|
* */
|
|
@@ -55,7 +57,7 @@ export default class TraceRendererWebgl implements ITraceRendererInterface {
|
|
|
55
57
|
* @param contentType
|
|
56
58
|
* @returns
|
|
57
59
|
*/
|
|
58
|
-
updatePanelContent(contentType: EVehiclePlateState): void
|
|
60
|
+
updatePanelContent(contentType: EVehiclePlateState): Promise<void>;
|
|
59
61
|
toggleGroundVehicle(visible: boolean): void;
|
|
60
62
|
toggleElevatedVehicle(visible: boolean): void;
|
|
61
63
|
/**
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const S=require("@arcgis/core/geometry/SpatialReference"),P=require("@arcgis/core/views/3d/externalRenderers"),T=require("three"),g=require("three/examples/jsm/loaders/GLTFLoader.js"),p=require("../../../types/index.js"),C=require("../../stores/index.js");function y(f){const i=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(f){for(const e in f)if(e!=="default"){const t=Object.getOwnPropertyDescriptor(f,e);Object.defineProperty(i,e,t.get?t:{enumerable:!0,get:()=>f[e]})}}return i.default=f,Object.freeze(i)}const b=y(P),o=y(T);class V{constructor(i){this.defaultMaterial=new o.MeshBasicMaterial({color:6908265}),this.materialMap=new Map([[1,new o.MeshBasicMaterial({color:16777215})],[2,new o.MeshBasicMaterial({color:7833753})],[3,new o.MeshBasicMaterial({color:16766720})],[4,new o.MeshBasicMaterial({color:16758465})],[5,new o.MeshBasicMaterial({color:14423100})],[6,new o.MeshBasicMaterial({color:3329330})],[7,new o.MeshBasicMaterial({color:2003183})],[8,new o.MeshBasicMaterial({color:16032864})],[9,new o.MeshBasicMaterial({color:2105376})],[10,new o.MeshBasicMaterial({color:9662683})],[99,new o.MeshBasicMaterial({color:6908265})]]),this.carModelReady=!1,this.vanModelReady=!1,this.truckModelReady=!1,this.busModelReady=!1,this.bicycleModelReady=!1,this.currentSpriteContent=p.EVehiclePlateState.None,this.historyPositionMap=new Map,this.vehicleObjectMap=new Map,this.needInterpolate=!0;const e=C.default.useAppDataStore;this.assetsRoot=JSON.parse(JSON.stringify(e.mapConfig)).assetsRoot,this.view=i;const t=new g.GLTFLoader;t.load(`${this.assetsRoot}/3DModels/car.glb`,s=>{this.carModel=s.scene,this.carModel.rotation.x=o.MathUtils.degToRad(90),this.carModelReady=!0}),t.load(`${this.assetsRoot}/3DModels/van.glb`,s=>{this.vanModel=s.scene,this.vanModel.rotation.x=o.MathUtils.degToRad(90),this.vanModelReady=!0}),t.load(`${this.assetsRoot}/3DModels/truck.glb`,s=>{this.truckModel=s.scene,this.truckModel.scale.set(1.2,1,1.5),this.truckModel.rotation.x=o.MathUtils.degToRad(90),this.truckModelReady=!0}),t.load(`${this.assetsRoot}/3DModels/bus.glb`,s=>{this.busModel=s.scene,this.busModel.rotation.x=o.MathUtils.degToRad(90),this.busModelReady=!0}),t.load(`${this.assetsRoot}/3DModels/bicycle.glb`,s=>{this.bicycleModel=s.scene,this.bicycleModel.rotation.x=o.MathUtils.degToRad(90),this.bicycleModel.rotation.y=o.MathUtils.degToRad(180),this.bicycleModelReady=!0}),document.addEventListener("visibilitychange",()=>{this.clearVehicles(),this.needInterpolate=!document.hidden},!1)}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.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=t=>{e(t),t==null&&i.bindRenderTarget()},this.scene=new o.Scene,this.camera=new o.PerspectiveCamera,this.ambient=new o.AmbientLight(16777215,.5),this.scene.add(this.ambient),this.sun=new o.DirectionalLight(16777215,.5),this.scene.add(this.sun),i.resetWebGLState()}geometryTest(){new g.GLTFLoader().load(`${this.assetsRoot}/3DModels/car.glb`,e=>{this.mesh=e.scene,this.mesh.rotation.x=o.MathUtils.degToRad(90);const t=[121.46892831020403,31.239681632841354,0],s=this.toRenderCoordinates(t);this.mesh.position.set(s[0],s[1],s[2]),this.scene.add(this.mesh),new o.TextureLoader().load(`${this.assetsRoot}/Images/PlateBG/grey.png`,r=>{const n=new o.SpriteMaterial({map:r,transparent:!1}),a=new o.Sprite(n);a.scale.set(5,2.5,1),a.position.set(0,5,-4),this.mesh.add(a),console.log(this.mesh.visible,a.visible)})})}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.needInterpolate)for(const l of this.vehicleObjectMap.keys()){const r=(s=this.vehicleObjectMap.get(l))==null?void 0:s.model;if(!r)continue;const n=this.computeVehiclePosition(l);if(n){const a=this.toRenderCoordinates(n);r.position.set(a[0],a[1],a[2]),r.rotation.y=o.MathUtils.degToRad(-n[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),b.requestRender(this.view),i.resetWebGLState()}async addVehicles(i){if(!(!this.carModelReady||!this.vanModelReady||!this.truckModelReady||!this.busModelReady||!this.bicycleModelReady))for(const e of i){const{vehicleId:t,localTimestamp:s}=e,l=Number(e.x),r=Number(e.y),n=Number(e.heading);this.historyPositionMap.set(t,[{pos:[l,r,0],heading:n,time:s}]);const a=this.getVehicleModel(e);a.name=t,a.visible=!this.needInterpolate;try{const c=await this.createPlateSprite(e);c&&(a.add(c),c.position.set(0,5,-4)),this.scene.add(a),this.vehicleObjectMap.set(t,{model:a,data:e,waitForDelete:!1,isMoving:!1})}catch(c){console.log("createPlateSprite error:",c)}}}async updateVehicles(i){if(!this.carModelReady||!this.vanModelReady||!this.truckModelReady||!this.busModelReady||!this.bicycleModelReady)return;const e=[];for(const t of i){const{vehicleId:s,localTimestamp:l}=t,r=Number(t.x),n=Number(t.y);let a=Number(t.heading);const c=this.vehicleObjectMap.get(s);if(!c)e.push(t);else{if(c.data.vehicleColor!==t.vehicleColor||c.data.vehicleType!==t.vehicleType){this.scene.remove(c.model),this.disposeModel(c.model),c.model=this.getVehicleModel(t);const h=await this.createPlateSprite(t);h&&(c.model.add(h),h.position.set(0,5,-4)),this.scene.add(c.model)}if(c.data.showName!==t.showName||c.data.plateColor!==t.plateColor){const h=c.model.getObjectByName("VehiclePlate");h&&(c.model.remove(h),this.disposeModel(h));const d=await this.createPlateSprite(t);d&&(c.model.add(d),d.position.set(0,5,-4))}if(c.data=t,this.needInterpolate){const h=this.historyPositionMap.get(s),d=h[h.length-1];Math.abs(a-d.heading)>=180&&(a>d.heading?d.heading+=360:a+=360),h.push({pos:[r,n,0],heading:a,time:l})}else{this.historyPositionMap.set(s,[{pos:[r,n,0],heading:a,time:l}]);const h=this.toRenderCoordinates([r,n,0]);c.model.position.set(h[0],h[1],h[2]),c.model.rotation.y=o.MathUtils.degToRad(-a)}}}this.addVehicles(e),this.needInterpolate||this.render(this.context)}toRenderCoordinates(i){const e=[0,0,0];return b.toRenderCoordinates(this.view,i,0,S.WGS84,e,0,1),e}deleteVehicles(i){i.forEach(e=>{const t=this.vehicleObjectMap.get(e);t&&(this.needInterpolate?t.isMoving?t.waitForDelete=!0:this.deleteVehicle(t):this.deleteVehicle(t))})}deleteVehicle(i){this.scene.remove(i.model),this.disposeModel(i.model);const e=i.data.vehicleId;this.vehicleObjectMap.delete(e),this.historyPositionMap.delete(e)}async toggleTrafficInfo(i){i.name==="vehiclePlate"&&(i.visible===!0&&this.currentSpriteContent===p.EVehiclePlateState.None?await this.updatePanelContent(p.EVehiclePlateState.Id):await this.updatePanelContent(i.visible?this.currentSpriteContent:p.EVehiclePlateState.None))}clearVehicles(){for(const i of this.vehicleObjectMap.keys()){const e=this.vehicleObjectMap.get(i);e&&(this.disposeModel(e.model),this.scene.remove(e.model))}this.vehicleObjectMap.clear(),this.historyPositionMap.clear()}async updatePanelContent(i){if(i!==this.currentSpriteContent){this.currentSpriteContent=i;for(const e of this.vehicleObjectMap.keys()){const t=this.vehicleObjectMap.get(e);if(t){const s=t.model.getObjectByName("VehiclePlate");if(s&&(t.model.remove(s),this.disposeModel(s)),i!==p.EVehiclePlateState.None){const l=await this.createPlateSprite(t.data);l&&(t.model.add(l),l.position.set(0,5,-4))}}}}}toggleGroundVehicle(i){}toggleElevatedVehicle(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.model.visible=!0,t.isMoving=!0,t.segmentStartTime||(t.segmentStartTime=s,t.segmentTotalTime=e[1].time-e[0].time);const l=s-t.segmentStartTime,r=Math.min(l/t.segmentTotalTime,1);if(r===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("pause vehicle",i));return}else return t.segmentStartTime=Date.now(),t.segmentTotalTime=e[1].time-e[0].time,(e[1].heading>=270&&e[0].heading<=90||e[1].heading<=90&&e[0].heading>=270)&&(e[1].heading>e[0].heading?e[0].heading+=360:e[1].heading+=360),e[0].pos.concat(e[0].heading);else{const n=e[0].pos[0]+(e[1].pos[0]-e[0].pos[0])*r,a=e[0].pos[1]+(e[1].pos[1]-e[0].pos[1])*r,c=e[0].heading+(e[1].heading-e[0].heading)*r;return[n,a,0,c]}}getVehicleModel(i){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(l=>{!s&&l instanceof o.Mesh&&(l.material=t,s=!0)})}return e}createCanvas(i,e,t){const s=document.createElement("canvas"),l=i.width,r=i.height;s.width=l,s.height=r;const n=s.getContext("2d");if(!n){console.log("canvas创建失败");return}return n.fillStyle="rgba(0,0,0,0.0)",n.fillRect(0,0,l,r),n.drawImage(i,0,0,l,r),n.beginPath(),n.translate(l/2,r/2),n.fillStyle=t,n.font="bold 32px 宋体",n.textBaseline="middle",n.textAlign="center",n.fillText(e,0,0),s}createPlateSprite(i){return new Promise((e,t)=>{var c,h;const s=!i.plateNo||i.plateNo==="0"||i.plateNo==="000000";if(this.currentSpriteContent===p.EVehiclePlateState.None||this.currentSpriteContent===p.EVehiclePlateState.PlateNumber&&s){e(void 0);return}const l=new Image;let r="",n="",a="";if(this.currentSpriteContent===p.EVehiclePlateState.PlateNumber||this.currentSpriteContent===p.EVehiclePlateState.Mix)if(s)r="grey",n=i.ptcId,a="#ffffff";else switch(n=((c=i.showName)==null?void 0:c.substring(0,2))+"•"+((h=i.showName)==null?void 0:h.substring(2)),i.plateColor){case 1:r="blue",a="#ffffff";break;case 2:r="yellow",a="#000000";break;case 3:r="white",a="#000000";break;case 4:r="black";break;case 5:r="neo_yellow",a="#000000";break;case 6:r="neo_green",a="#000000";break;default:r="grey",n=i.plateNo,a="#ffffff";break}else this.currentSpriteContent===p.EVehiclePlateState.Id&&(r="grey",n=i.ptcId,a="#ffffff");l.src=`${this.assetsRoot}/Images/PlateBG/${r}.png`,l.onload=()=>{const d=this.createCanvas(l,n,a);if(!d)t("canvas创建失败");else{const u=new o.CanvasTexture(d),v=new o.SpriteMaterial({map:u,transparent:!1}),M=new o.Sprite(v),m=.05,w=d.width*m,R=d.height*m;M.scale.set(w,R,1),M.name="VehiclePlate",e(M)}l.onerror=u=>{console.log(`号牌背景加载失败: ${l.src}`,u),t(u)}}})}}exports.default=V;
|
package/package.json
CHANGED
|
@@ -1,343 +0,0 @@
|
|
|
1
|
-
import y from "@arcgis/core/geometry/SpatialReference";
|
|
2
|
-
import * as g from "@arcgis/core/views/3d/externalRenderers";
|
|
3
|
-
import * as a from "three";
|
|
4
|
-
import { GLTFLoader as b } from "three/examples/jsm/loaders/GLTFLoader.js";
|
|
5
|
-
import { EVehiclePlateState as d } from "../../../types/index.mjs";
|
|
6
|
-
import w from "../../stores/index.mjs";
|
|
7
|
-
class k {
|
|
8
|
-
constructor(i) {
|
|
9
|
-
this.defaultMaterial = new a.MeshBasicMaterial({
|
|
10
|
-
color: 6908265
|
|
11
|
-
}), this.materialMap = /* @__PURE__ */ new Map([
|
|
12
|
-
[1, new a.MeshBasicMaterial({ color: 16777215 })],
|
|
13
|
-
[2, new a.MeshBasicMaterial({ color: 7833753 })],
|
|
14
|
-
[3, new a.MeshBasicMaterial({ color: 16766720 })],
|
|
15
|
-
[4, new a.MeshBasicMaterial({ color: 16758465 })],
|
|
16
|
-
[5, new a.MeshBasicMaterial({ color: 14423100 })],
|
|
17
|
-
[6, new a.MeshBasicMaterial({ color: 3329330 })],
|
|
18
|
-
[7, new a.MeshBasicMaterial({ color: 2003183 })],
|
|
19
|
-
[8, new a.MeshBasicMaterial({ color: 16032864 })],
|
|
20
|
-
[9, new a.MeshBasicMaterial({ color: 2105376 })],
|
|
21
|
-
[10, new a.MeshBasicMaterial({ color: 9662683 })],
|
|
22
|
-
[99, new a.MeshBasicMaterial({ color: 6908265 })]
|
|
23
|
-
]), this.carModelReady = !1, this.vanModelReady = !1, this.truckModelReady = !1, this.busModelReady = !1, this.bicycleModelReady = !1, this.currentSpriteContent = d.None, this.historyPositionMap = /* @__PURE__ */ new Map(), this.vehicleObjectMap = /* @__PURE__ */ new Map(), this.needInterpolate = !0, this.lastRenderTime = Date.now();
|
|
24
|
-
const e = w.useAppDataStore;
|
|
25
|
-
this.assetsRoot = JSON.parse(
|
|
26
|
-
JSON.stringify(e.mapConfig)
|
|
27
|
-
).assetsRoot, this.view = i;
|
|
28
|
-
const t = new b();
|
|
29
|
-
t.load(`${this.assetsRoot}/3DModels/car.glb`, (s) => {
|
|
30
|
-
this.carModel = s.scene, this.carModel.rotation.x = a.MathUtils.degToRad(90), this.carModelReady = !0;
|
|
31
|
-
}), t.load(`${this.assetsRoot}/3DModels/van.glb`, (s) => {
|
|
32
|
-
this.vanModel = s.scene, this.vanModel.rotation.x = a.MathUtils.degToRad(90), this.vanModelReady = !0;
|
|
33
|
-
}), t.load(`${this.assetsRoot}/3DModels/truck.glb`, (s) => {
|
|
34
|
-
this.truckModel = s.scene, this.truckModel.scale.set(1.2, 1, 1.5), this.truckModel.rotation.x = a.MathUtils.degToRad(90), this.truckModelReady = !0;
|
|
35
|
-
}), t.load(`${this.assetsRoot}/3DModels/bus.glb`, (s) => {
|
|
36
|
-
this.busModel = s.scene, this.busModel.rotation.x = a.MathUtils.degToRad(90), this.busModelReady = !0;
|
|
37
|
-
}), t.load(`${this.assetsRoot}/3DModels/bicycle.glb`, (s) => {
|
|
38
|
-
this.bicycleModel = s.scene, this.bicycleModel.rotation.x = a.MathUtils.degToRad(90), this.bicycleModel.rotation.y = a.MathUtils.degToRad(180), this.bicycleModelReady = !0;
|
|
39
|
-
}), document.addEventListener(
|
|
40
|
-
"visibilitychange",
|
|
41
|
-
() => {
|
|
42
|
-
this.clearVehicles(), this.needInterpolate = !document.hidden;
|
|
43
|
-
},
|
|
44
|
-
!1
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
setInterpolate(i) {
|
|
48
|
-
this.clearVehicles(), this.needInterpolate = i;
|
|
49
|
-
}
|
|
50
|
-
async setup(i) {
|
|
51
|
-
this.context = i, this.renderer = new a.WebGLRenderer({
|
|
52
|
-
context: i.gl,
|
|
53
|
-
premultipliedAlpha: !1,
|
|
54
|
-
antialias: !0,
|
|
55
|
-
powerPreference: "high-performance"
|
|
56
|
-
}), 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;
|
|
57
|
-
const e = this.renderer.setRenderTarget.bind(
|
|
58
|
-
this.renderer
|
|
59
|
-
);
|
|
60
|
-
this.renderer.setRenderTarget = (t) => {
|
|
61
|
-
e(t), t == null && i.bindRenderTarget();
|
|
62
|
-
}, this.scene = new a.Scene(), this.camera = new a.PerspectiveCamera(), this.ambient = new a.AmbientLight(16777215, 0.5), this.scene.add(this.ambient), this.sun = new a.DirectionalLight(16777215, 0.5), this.scene.add(this.sun), i.resetWebGLState();
|
|
63
|
-
}
|
|
64
|
-
async render(i) {
|
|
65
|
-
var n;
|
|
66
|
-
const e = Date.now();
|
|
67
|
-
this.lastRenderTime = e;
|
|
68
|
-
const t = i.camera;
|
|
69
|
-
if (this.camera.position.set(t.eye[0], t.eye[1], t.eye[2]), this.camera.up.set(t.up[0], t.up[1], t.up[2]), this.camera.lookAt(
|
|
70
|
-
new a.Vector3(t.center[0], t.center[1], t.center[2])
|
|
71
|
-
), this.camera.projectionMatrix.fromArray(t.projectionMatrix), this.needInterpolate)
|
|
72
|
-
for (const l of this.vehicleObjectMap.keys()) {
|
|
73
|
-
const o = (n = this.vehicleObjectMap.get(l)) == null ? void 0 : n.model;
|
|
74
|
-
if (!o)
|
|
75
|
-
continue;
|
|
76
|
-
const h = this.computeVehiclePosition(l);
|
|
77
|
-
if (h) {
|
|
78
|
-
const r = this.toRenderCoordinates(h);
|
|
79
|
-
o.position.set(r[0], r[1], r[2]), o.rotation.y = a.MathUtils.degToRad(-h[3]);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
const s = i.sunLight;
|
|
83
|
-
this.sun.position.set(s.direction[0], s.direction[1], s.direction[2]), this.sun.intensity = s.diffuse.intensity, this.sun.color = new a.Color(
|
|
84
|
-
s.diffuse.color[0],
|
|
85
|
-
s.diffuse.color[1],
|
|
86
|
-
s.diffuse.color[2]
|
|
87
|
-
), this.ambient.intensity = s.ambient.intensity, this.ambient.color = new a.Color(
|
|
88
|
-
s.ambient.color[0],
|
|
89
|
-
s.ambient.color[1],
|
|
90
|
-
s.ambient.color[2]
|
|
91
|
-
), this.renderer.resetState(), i.bindRenderTarget(), this.renderer.render(this.scene, this.camera), g.requestRender(this.view), i.resetWebGLState();
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* 新增车辆
|
|
95
|
-
* */
|
|
96
|
-
addVehicles(i) {
|
|
97
|
-
!this.carModelReady || !this.vanModelReady || !this.truckModelReady || !this.busModelReady || !this.bicycleModelReady || i.forEach((e) => {
|
|
98
|
-
const { vehicleId: t, localTimestamp: s } = e, n = Number(e.x), l = Number(e.y), o = Number(e.heading);
|
|
99
|
-
this.historyPositionMap.set(t, [
|
|
100
|
-
{ pos: [n, l, 0], heading: o, time: s }
|
|
101
|
-
]);
|
|
102
|
-
const h = this.getVehicleModel(e);
|
|
103
|
-
h.name = t, h.visible = !this.needInterpolate, this.createPlateSprite(e, (r) => {
|
|
104
|
-
h.add(r), r.position.set(0, 5, -4);
|
|
105
|
-
}), this.scene.add(h), this.vehicleObjectMap.set(t, {
|
|
106
|
-
model: h,
|
|
107
|
-
data: e,
|
|
108
|
-
waitForDelete: !1,
|
|
109
|
-
isMoving: !1
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* 更新车辆
|
|
115
|
-
* */
|
|
116
|
-
updateVehicles(i) {
|
|
117
|
-
if (!this.carModelReady || !this.vanModelReady || !this.truckModelReady || !this.busModelReady || !this.bicycleModelReady)
|
|
118
|
-
return;
|
|
119
|
-
const e = [];
|
|
120
|
-
i.forEach((t) => {
|
|
121
|
-
const { vehicleId: s, localTimestamp: n } = t, l = Number(t.x), o = Number(t.y);
|
|
122
|
-
let h = Number(t.heading);
|
|
123
|
-
const r = this.vehicleObjectMap.get(s);
|
|
124
|
-
if (!r)
|
|
125
|
-
e.push(t);
|
|
126
|
-
else {
|
|
127
|
-
if ((r.data.vehicleColor !== t.vehicleColor || r.data.vehicleType !== t.vehicleType) && (this.scene.remove(r.model), this.disposeModel(r.model), r.model = this.getVehicleModel(t), this.scene.add(r.model)), r.data.showName !== t.showName || r.data.plateColor !== t.plateColor) {
|
|
128
|
-
const c = r.model.getObjectByName("VehiclePlate");
|
|
129
|
-
c && (r.model.remove(c), this.disposeModel(c)), this.createPlateSprite(t, (p) => {
|
|
130
|
-
r.model.add(p), p.position.set(0, 5, -4);
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
if (r.data = t, this.needInterpolate) {
|
|
134
|
-
const c = this.historyPositionMap.get(
|
|
135
|
-
s
|
|
136
|
-
), p = c[c.length - 1];
|
|
137
|
-
Math.abs(h - p.heading) >= 180 && (h > p.heading ? p.heading += 360 : h += 360), c.push({
|
|
138
|
-
pos: [l, o, 0],
|
|
139
|
-
heading: h,
|
|
140
|
-
time: n
|
|
141
|
-
});
|
|
142
|
-
} else {
|
|
143
|
-
this.historyPositionMap.set(s, [
|
|
144
|
-
{ pos: [l, o, 0], heading: h, time: n }
|
|
145
|
-
]);
|
|
146
|
-
const c = this.toRenderCoordinates([l, o, 0]);
|
|
147
|
-
r.model.position.set(c[0], c[1], c[2]), r.model.rotation.y = a.MathUtils.degToRad(-h);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}), this.addVehicles(e), this.needInterpolate || this.render(this.context);
|
|
151
|
-
}
|
|
152
|
-
toRenderCoordinates(i) {
|
|
153
|
-
const e = [0, 0, 0];
|
|
154
|
-
return g.toRenderCoordinates(
|
|
155
|
-
this.view,
|
|
156
|
-
i,
|
|
157
|
-
0,
|
|
158
|
-
y.WGS84,
|
|
159
|
-
e,
|
|
160
|
-
0,
|
|
161
|
-
1
|
|
162
|
-
), e;
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* 删除车辆
|
|
166
|
-
* */
|
|
167
|
-
deleteVehicles(i) {
|
|
168
|
-
i.forEach((e) => {
|
|
169
|
-
const t = this.vehicleObjectMap.get(e);
|
|
170
|
-
t && (this.needInterpolate ? t.isMoving ? t.waitForDelete = !0 : this.deleteVehicle(t) : this.deleteVehicle(t));
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
deleteVehicle(i) {
|
|
174
|
-
this.scene.remove(i.model), this.disposeModel(i.model);
|
|
175
|
-
const e = i.data.vehicleId;
|
|
176
|
-
this.vehicleObjectMap.delete(e), this.historyPositionMap.delete(e);
|
|
177
|
-
}
|
|
178
|
-
toggleTrafficInfo(i) {
|
|
179
|
-
i.name === "vehiclePlate" && (i.visible === !0 && this.currentSpriteContent === d.None ? this.updatePanelContent(d.Id) : this.updatePanelContent(
|
|
180
|
-
i.visible ? this.currentSpriteContent : d.None
|
|
181
|
-
));
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* 清除全部车辆
|
|
185
|
-
* */
|
|
186
|
-
clearVehicles() {
|
|
187
|
-
for (const i of this.vehicleObjectMap.keys()) {
|
|
188
|
-
const e = this.vehicleObjectMap.get(i);
|
|
189
|
-
e && (this.disposeModel(e.model), this.scene.remove(e.model));
|
|
190
|
-
}
|
|
191
|
-
this.vehicleObjectMap.clear(), this.historyPositionMap.clear();
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* 设置号牌显示状态
|
|
195
|
-
* @param contentType
|
|
196
|
-
* @returns
|
|
197
|
-
*/
|
|
198
|
-
updatePanelContent(i) {
|
|
199
|
-
if (i !== this.currentSpriteContent) {
|
|
200
|
-
this.currentSpriteContent = i;
|
|
201
|
-
for (const e of this.vehicleObjectMap.keys()) {
|
|
202
|
-
const t = this.vehicleObjectMap.get(e);
|
|
203
|
-
if (t) {
|
|
204
|
-
const s = t.model.getObjectByName("VehiclePlate");
|
|
205
|
-
s && (t.model.remove(s), this.disposeModel(s)), i !== d.None && this.createPlateSprite(t.data, (n) => {
|
|
206
|
-
t.model.add(n), n.position.set(0, 5, -4);
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
toggleGroundVehicle(i) {
|
|
213
|
-
}
|
|
214
|
-
toggleElevatedVehicle(i) {
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* 释放模型资源
|
|
218
|
-
* */
|
|
219
|
-
disposeModel(i) {
|
|
220
|
-
i.traverse((e) => {
|
|
221
|
-
e instanceof a.Mesh && (e.geometry.dispose(), e.material.dispose());
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
/**
|
|
225
|
-
* 计算车辆位置
|
|
226
|
-
* */
|
|
227
|
-
computeVehiclePosition(i) {
|
|
228
|
-
const e = this.historyPositionMap.get(i), t = this.vehicleObjectMap.get(i);
|
|
229
|
-
if (!t || !e || !t.isMoving && e.length <= 2)
|
|
230
|
-
return;
|
|
231
|
-
const s = Date.now();
|
|
232
|
-
t.model.visible = !0, t.isMoving = !0, t.segmentStartTime || (t.segmentStartTime = s, t.segmentTotalTime = e[1].time - e[0].time);
|
|
233
|
-
const n = s - t.segmentStartTime, l = Math.min(
|
|
234
|
-
n / t.segmentTotalTime,
|
|
235
|
-
1
|
|
236
|
-
);
|
|
237
|
-
if (l === 1)
|
|
238
|
-
if (e.shift(), e.length === 1) {
|
|
239
|
-
t.waitForDelete === !0 ? (this.deleteVehicle(t), console.log("delete vehicle", i)) : (t.segmentStartTime = void 0, t.segmentTotalTime = void 0, t.model.visible = !1, t.isMoving = !1, console.log("pause vehicle", i));
|
|
240
|
-
return;
|
|
241
|
-
} else
|
|
242
|
-
return t.segmentStartTime = Date.now(), t.segmentTotalTime = e[1].time - e[0].time, (e[1].heading >= 270 && e[0].heading <= 90 || e[1].heading <= 90 && e[0].heading >= 270) && (e[1].heading > e[0].heading ? e[0].heading += 360 : e[1].heading += 360), e[0].pos.concat(e[0].heading);
|
|
243
|
-
else {
|
|
244
|
-
const o = e[0].pos[0] + (e[1].pos[0] - e[0].pos[0]) * l, h = e[0].pos[1] + (e[1].pos[1] - e[0].pos[1]) * l, r = e[0].heading + (e[1].heading - e[0].heading) * l;
|
|
245
|
-
return [o, h, 0, r];
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* 根据车辆类型、车身颜色获取模型
|
|
250
|
-
* */
|
|
251
|
-
getVehicleModel(i) {
|
|
252
|
-
let e;
|
|
253
|
-
if (i.ptcType === 2)
|
|
254
|
-
e = this.bicycleModel.clone();
|
|
255
|
-
else {
|
|
256
|
-
switch (i.vehicleType) {
|
|
257
|
-
case 10:
|
|
258
|
-
e = this.carModel.clone();
|
|
259
|
-
break;
|
|
260
|
-
case 20:
|
|
261
|
-
e = this.vanModel.clone();
|
|
262
|
-
break;
|
|
263
|
-
case 25:
|
|
264
|
-
e = this.truckModel.clone();
|
|
265
|
-
break;
|
|
266
|
-
case 50:
|
|
267
|
-
e = this.busModel.clone();
|
|
268
|
-
break;
|
|
269
|
-
default:
|
|
270
|
-
e = this.carModel.clone();
|
|
271
|
-
break;
|
|
272
|
-
}
|
|
273
|
-
const t = this.materialMap.get(i.vehicleColor) || this.defaultMaterial;
|
|
274
|
-
let s = !1;
|
|
275
|
-
e.traverse((n) => {
|
|
276
|
-
!s && n instanceof a.Mesh && (n.material = t, s = !0);
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
return e;
|
|
280
|
-
}
|
|
281
|
-
/**
|
|
282
|
-
* 创建号牌canvas
|
|
283
|
-
* */
|
|
284
|
-
createCanvas(i, e, t) {
|
|
285
|
-
const s = document.createElement("canvas"), n = i.width, l = i.height;
|
|
286
|
-
s.width = n, s.height = l;
|
|
287
|
-
const o = s.getContext("2d");
|
|
288
|
-
if (!o) {
|
|
289
|
-
console.log("canvas创建失败");
|
|
290
|
-
return;
|
|
291
|
-
}
|
|
292
|
-
return o.fillStyle = "rgba(0,0,0,0.0)", o.fillRect(0, 0, n, l), o.drawImage(i, 0, 0, n, l), o.beginPath(), o.translate(n / 2, l / 2), o.fillStyle = t, o.font = "bold 32px 宋体", o.textBaseline = "middle", o.textAlign = "center", o.fillText(e, 0, 0), s;
|
|
293
|
-
}
|
|
294
|
-
createPlateSprite(i, e) {
|
|
295
|
-
var h, r;
|
|
296
|
-
const t = !i.plateNo || i.plateNo === "0" || i.plateNo === "000000";
|
|
297
|
-
if (this.currentSpriteContent === d.None || this.currentSpriteContent === d.PlateNumber && t)
|
|
298
|
-
return;
|
|
299
|
-
const s = new Image();
|
|
300
|
-
let n = "", l = "", o = "";
|
|
301
|
-
if (this.currentSpriteContent === d.PlateNumber || this.currentSpriteContent === d.Mix)
|
|
302
|
-
if (t)
|
|
303
|
-
n = "grey", l = i.ptcId, o = "#ffffff";
|
|
304
|
-
else
|
|
305
|
-
switch (l = ((h = i.showName) == null ? void 0 : h.substring(0, 2)) + "•" + ((r = i.showName) == null ? void 0 : r.substring(2)), i.plateColor) {
|
|
306
|
-
case 1:
|
|
307
|
-
n = "blue", o = "#ffffff";
|
|
308
|
-
break;
|
|
309
|
-
case 2:
|
|
310
|
-
n = "yellow", o = "#000000";
|
|
311
|
-
break;
|
|
312
|
-
case 3:
|
|
313
|
-
n = "white", o = "#000000";
|
|
314
|
-
break;
|
|
315
|
-
case 4:
|
|
316
|
-
n = "black";
|
|
317
|
-
break;
|
|
318
|
-
case 5:
|
|
319
|
-
n = "neo_yellow", o = "#000000";
|
|
320
|
-
break;
|
|
321
|
-
case 6:
|
|
322
|
-
n = "neo_green", o = "#000000";
|
|
323
|
-
break;
|
|
324
|
-
default:
|
|
325
|
-
n = "grey", l = i.plateNo, o = "#ffffff";
|
|
326
|
-
break;
|
|
327
|
-
}
|
|
328
|
-
else
|
|
329
|
-
this.currentSpriteContent === d.Id && (n = "grey", l = i.ptcId, o = "#ffffff");
|
|
330
|
-
s.src = `${this.assetsRoot}/Images/PlateBG/${n}.png`, s.onload = () => {
|
|
331
|
-
const c = this.createCanvas(s, l, o);
|
|
332
|
-
if (!c)
|
|
333
|
-
return;
|
|
334
|
-
const p = new a.CanvasTexture(c), m = new a.SpriteMaterial({
|
|
335
|
-
map: p
|
|
336
|
-
}), f = new a.Sprite(m), M = 0.05, u = c.width * M, v = c.height * M;
|
|
337
|
-
f.scale.set(u, v, 1), f.name = "VehiclePlate", e(f);
|
|
338
|
-
};
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
export {
|
|
342
|
-
k as default
|
|
343
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const w=require("@arcgis/core/geometry/SpatialReference"),R=require("@arcgis/core/views/3d/externalRenderers"),P=require("three"),S=require("three/examples/jsm/loaders/GLTFLoader.js"),d=require("../../../types/index.js"),T=require("../../stores/index.js");function v(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 g=v(R),o=v(P);class C{constructor(i){this.defaultMaterial=new o.MeshBasicMaterial({color:6908265}),this.materialMap=new Map([[1,new o.MeshBasicMaterial({color:16777215})],[2,new o.MeshBasicMaterial({color:7833753})],[3,new o.MeshBasicMaterial({color:16766720})],[4,new o.MeshBasicMaterial({color:16758465})],[5,new o.MeshBasicMaterial({color:14423100})],[6,new o.MeshBasicMaterial({color:3329330})],[7,new o.MeshBasicMaterial({color:2003183})],[8,new o.MeshBasicMaterial({color:16032864})],[9,new o.MeshBasicMaterial({color:2105376})],[10,new o.MeshBasicMaterial({color:9662683})],[99,new o.MeshBasicMaterial({color:6908265})]]),this.carModelReady=!1,this.vanModelReady=!1,this.truckModelReady=!1,this.busModelReady=!1,this.bicycleModelReady=!1,this.currentSpriteContent=d.EVehiclePlateState.None,this.historyPositionMap=new Map,this.vehicleObjectMap=new Map,this.needInterpolate=!0,this.lastRenderTime=Date.now();const e=T.default.useAppDataStore;this.assetsRoot=JSON.parse(JSON.stringify(e.mapConfig)).assetsRoot,this.view=i;const t=new S.GLTFLoader;t.load(`${this.assetsRoot}/3DModels/car.glb`,s=>{this.carModel=s.scene,this.carModel.rotation.x=o.MathUtils.degToRad(90),this.carModelReady=!0}),t.load(`${this.assetsRoot}/3DModels/van.glb`,s=>{this.vanModel=s.scene,this.vanModel.rotation.x=o.MathUtils.degToRad(90),this.vanModelReady=!0}),t.load(`${this.assetsRoot}/3DModels/truck.glb`,s=>{this.truckModel=s.scene,this.truckModel.scale.set(1.2,1,1.5),this.truckModel.rotation.x=o.MathUtils.degToRad(90),this.truckModelReady=!0}),t.load(`${this.assetsRoot}/3DModels/bus.glb`,s=>{this.busModel=s.scene,this.busModel.rotation.x=o.MathUtils.degToRad(90),this.busModelReady=!0}),t.load(`${this.assetsRoot}/3DModels/bicycle.glb`,s=>{this.bicycleModel=s.scene,this.bicycleModel.rotation.x=o.MathUtils.degToRad(90),this.bicycleModel.rotation.y=o.MathUtils.degToRad(180),this.bicycleModelReady=!0}),document.addEventListener("visibilitychange",()=>{this.clearVehicles(),this.needInterpolate=!document.hidden},!1)}setInterpolate(i){this.clearVehicles(),this.needInterpolate=i}async setup(i){this.context=i,this.renderer=new o.WebGLRenderer({context:i.gl,premultipliedAlpha:!1,antialias:!0,powerPreference:"high-performance"}),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=t=>{e(t),t==null&&i.bindRenderTarget()},this.scene=new o.Scene,this.camera=new o.PerspectiveCamera,this.ambient=new o.AmbientLight(16777215,.5),this.scene.add(this.ambient),this.sun=new o.DirectionalLight(16777215,.5),this.scene.add(this.sun),i.resetWebGLState()}async render(i){var n;const e=Date.now();this.lastRenderTime=e;const t=i.camera;if(this.camera.position.set(t.eye[0],t.eye[1],t.eye[2]),this.camera.up.set(t.up[0],t.up[1],t.up[2]),this.camera.lookAt(new o.Vector3(t.center[0],t.center[1],t.center[2])),this.camera.projectionMatrix.fromArray(t.projectionMatrix),this.needInterpolate)for(const r of this.vehicleObjectMap.keys()){const a=(n=this.vehicleObjectMap.get(r))==null?void 0:n.model;if(!a)continue;const c=this.computeVehiclePosition(r);if(c){const l=this.toRenderCoordinates(c);a.position.set(l[0],l[1],l[2]),a.rotation.y=o.MathUtils.degToRad(-c[3])}}const s=i.sunLight;this.sun.position.set(s.direction[0],s.direction[1],s.direction[2]),this.sun.intensity=s.diffuse.intensity,this.sun.color=new o.Color(s.diffuse.color[0],s.diffuse.color[1],s.diffuse.color[2]),this.ambient.intensity=s.ambient.intensity,this.ambient.color=new o.Color(s.ambient.color[0],s.ambient.color[1],s.ambient.color[2]),this.renderer.resetState(),i.bindRenderTarget(),this.renderer.render(this.scene,this.camera),g.requestRender(this.view),i.resetWebGLState()}addVehicles(i){!this.carModelReady||!this.vanModelReady||!this.truckModelReady||!this.busModelReady||!this.bicycleModelReady||i.forEach(e=>{const{vehicleId:t,localTimestamp:s}=e,n=Number(e.x),r=Number(e.y),a=Number(e.heading);this.historyPositionMap.set(t,[{pos:[n,r,0],heading:a,time:s}]);const c=this.getVehicleModel(e);c.name=t,c.visible=!this.needInterpolate,this.createPlateSprite(e,l=>{c.add(l),l.position.set(0,5,-4)}),this.scene.add(c),this.vehicleObjectMap.set(t,{model:c,data:e,waitForDelete:!1,isMoving:!1})})}updateVehicles(i){if(!this.carModelReady||!this.vanModelReady||!this.truckModelReady||!this.busModelReady||!this.bicycleModelReady)return;const e=[];i.forEach(t=>{const{vehicleId:s,localTimestamp:n}=t,r=Number(t.x),a=Number(t.y);let c=Number(t.heading);const l=this.vehicleObjectMap.get(s);if(!l)e.push(t);else{if((l.data.vehicleColor!==t.vehicleColor||l.data.vehicleType!==t.vehicleType)&&(this.scene.remove(l.model),this.disposeModel(l.model),l.model=this.getVehicleModel(t),this.scene.add(l.model)),l.data.showName!==t.showName||l.data.plateColor!==t.plateColor){const h=l.model.getObjectByName("VehiclePlate");h&&(l.model.remove(h),this.disposeModel(h)),this.createPlateSprite(t,p=>{l.model.add(p),p.position.set(0,5,-4)})}if(l.data=t,this.needInterpolate){const h=this.historyPositionMap.get(s),p=h[h.length-1];Math.abs(c-p.heading)>=180&&(c>p.heading?p.heading+=360:c+=360),h.push({pos:[r,a,0],heading:c,time:n})}else{this.historyPositionMap.set(s,[{pos:[r,a,0],heading:c,time:n}]);const h=this.toRenderCoordinates([r,a,0]);l.model.position.set(h[0],h[1],h[2]),l.model.rotation.y=o.MathUtils.degToRad(-c)}}}),this.addVehicles(e),this.needInterpolate||this.render(this.context)}toRenderCoordinates(i){const e=[0,0,0];return g.toRenderCoordinates(this.view,i,0,w.WGS84,e,0,1),e}deleteVehicles(i){i.forEach(e=>{const t=this.vehicleObjectMap.get(e);t&&(this.needInterpolate?t.isMoving?t.waitForDelete=!0:this.deleteVehicle(t):this.deleteVehicle(t))})}deleteVehicle(i){this.scene.remove(i.model),this.disposeModel(i.model);const e=i.data.vehicleId;this.vehicleObjectMap.delete(e),this.historyPositionMap.delete(e)}toggleTrafficInfo(i){i.name==="vehiclePlate"&&(i.visible===!0&&this.currentSpriteContent===d.EVehiclePlateState.None?this.updatePanelContent(d.EVehiclePlateState.Id):this.updatePanelContent(i.visible?this.currentSpriteContent:d.EVehiclePlateState.None))}clearVehicles(){for(const i of this.vehicleObjectMap.keys()){const e=this.vehicleObjectMap.get(i);e&&(this.disposeModel(e.model),this.scene.remove(e.model))}this.vehicleObjectMap.clear(),this.historyPositionMap.clear()}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");s&&(t.model.remove(s),this.disposeModel(s)),i!==d.EVehiclePlateState.None&&this.createPlateSprite(t.data,n=>{t.model.add(n),n.position.set(0,5,-4)})}}}}toggleGroundVehicle(i){}toggleElevatedVehicle(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.model.visible=!0,t.isMoving=!0,t.segmentStartTime||(t.segmentStartTime=s,t.segmentTotalTime=e[1].time-e[0].time);const n=s-t.segmentStartTime,r=Math.min(n/t.segmentTotalTime,1);if(r===1)if(e.shift(),e.length===1){t.waitForDelete===!0?(this.deleteVehicle(t),console.log("delete vehicle",i)):(t.segmentStartTime=void 0,t.segmentTotalTime=void 0,t.model.visible=!1,t.isMoving=!1,console.log("pause vehicle",i));return}else return t.segmentStartTime=Date.now(),t.segmentTotalTime=e[1].time-e[0].time,(e[1].heading>=270&&e[0].heading<=90||e[1].heading<=90&&e[0].heading>=270)&&(e[1].heading>e[0].heading?e[0].heading+=360:e[1].heading+=360),e[0].pos.concat(e[0].heading);else{const a=e[0].pos[0]+(e[1].pos[0]-e[0].pos[0])*r,c=e[0].pos[1]+(e[1].pos[1]-e[0].pos[1])*r,l=e[0].heading+(e[1].heading-e[0].heading)*r;return[a,c,0,l]}}getVehicleModel(i){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(n=>{!s&&n instanceof o.Mesh&&(n.material=t,s=!0)})}return e}createCanvas(i,e,t){const s=document.createElement("canvas"),n=i.width,r=i.height;s.width=n,s.height=r;const a=s.getContext("2d");if(!a){console.log("canvas创建失败");return}return a.fillStyle="rgba(0,0,0,0.0)",a.fillRect(0,0,n,r),a.drawImage(i,0,0,n,r),a.beginPath(),a.translate(n/2,r/2),a.fillStyle=t,a.font="bold 32px 宋体",a.textBaseline="middle",a.textAlign="center",a.fillText(e,0,0),s}createPlateSprite(i,e){var c,l;const t=!i.plateNo||i.plateNo==="0"||i.plateNo==="000000";if(this.currentSpriteContent===d.EVehiclePlateState.None||this.currentSpriteContent===d.EVehiclePlateState.PlateNumber&&t)return;const s=new Image;let n="",r="",a="";if(this.currentSpriteContent===d.EVehiclePlateState.PlateNumber||this.currentSpriteContent===d.EVehiclePlateState.Mix)if(t)n="grey",r=i.ptcId,a="#ffffff";else switch(r=((c=i.showName)==null?void 0:c.substring(0,2))+"•"+((l=i.showName)==null?void 0:l.substring(2)),i.plateColor){case 1:n="blue",a="#ffffff";break;case 2:n="yellow",a="#000000";break;case 3:n="white",a="#000000";break;case 4:n="black";break;case 5:n="neo_yellow",a="#000000";break;case 6:n="neo_green",a="#000000";break;default:n="grey",r=i.plateNo,a="#ffffff";break}else this.currentSpriteContent===d.EVehiclePlateState.Id&&(n="grey",r=i.ptcId,a="#ffffff");s.src=`${this.assetsRoot}/Images/PlateBG/${n}.png`,s.onload=()=>{const h=this.createCanvas(s,r,a);if(!h)return;const p=new o.CanvasTexture(h),M=new o.SpriteMaterial({map:p}),f=new o.Sprite(M),m=.05,b=h.width*m,y=h.height*m;f.scale.set(b,y,1),f.name="VehiclePlate",e(f)}}}exports.default=C;
|