gisviewer-vue3-arcgis 1.0.102 → 1.0.104
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/signal-holo-flow.mjs +1 -1
- package/es/src/gis-map/utils/holo-flow/trace-holo-flow.mjs +19 -19
- package/es/src/gis-map/utils/holo-flow/{trace-renderer-webgl.d.ts → trace-renderer-external.d.ts} +13 -6
- package/es/src/gis-map/utils/holo-flow/trace-renderer-external.mjs +407 -0
- package/es/src/gis-map/utils/map-initializer.mjs +4 -3
- 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} +13 -6
- package/lib/src/gis-map/utils/holo-flow/trace-renderer-external.js +1 -0
- package/lib/src/gis-map/utils/map-initializer.js +1 -1
- 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
|
@@ -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,31 +1,31 @@
|
|
|
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 N {
|
|
6
6
|
constructor(e) {
|
|
7
7
|
this.lastDataTime = 0, this.view = e;
|
|
8
|
-
const o =
|
|
9
|
-
this.mapConfig = JSON.parse(JSON.stringify(o.mapConfig)), e.type === "3d" ? (this.traceRenderer = new u(e),
|
|
8
|
+
const o = g.useAppDataStore;
|
|
9
|
+
this.mapConfig = JSON.parse(JSON.stringify(o.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 o = new Date().getTime(), { newVehList: s, updateVehList:
|
|
18
|
+
const o = new Date().getTime(), { newVehList: s, updateVehList: l, deleteVehList: c, jgsj: i } = e, n = e.crossId || "", a = [], h = [];
|
|
19
19
|
if (s && s.length > 0) {
|
|
20
20
|
for (const t of s) {
|
|
21
21
|
t.localTimestamp || (t.localTimestamp = i || o);
|
|
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
|
}
|
|
@@ -64,27 +64,27 @@ class y {
|
|
|
64
64
|
this.traceRenderer.setInterpolate(e);
|
|
65
65
|
}
|
|
66
66
|
buildVehicleTrackData(e, o) {
|
|
67
|
-
const s = e.longitude,
|
|
67
|
+
const s = e.longitude, l = e.latitude, c = 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 = e.roadLayer ? String(e.roadLayer) : "1";
|
|
68
68
|
if (!(i < 0 || i > 8))
|
|
69
69
|
return {
|
|
70
70
|
ptcId: c,
|
|
71
71
|
crossId: o,
|
|
72
72
|
vehicleId: o + "-" + c,
|
|
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
|
+
N as default
|
|
90
90
|
};
|
package/es/src/gis-map/utils/holo-flow/{trace-renderer-webgl.d.ts → trace-renderer-external.d.ts}
RENAMED
|
@@ -1,12 +1,17 @@
|
|
|
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;
|
|
6
6
|
private ambient;
|
|
7
7
|
private sun;
|
|
8
|
+
/** 车辆模型变化的阈值 */
|
|
9
|
+
private readonly zoomThreshold;
|
|
10
|
+
private readonly roughness;
|
|
11
|
+
private readonly metalness;
|
|
8
12
|
/** 默认车身材质 */
|
|
9
13
|
private defaultMaterial;
|
|
14
|
+
private createCarMaterial;
|
|
10
15
|
/** 车身颜色材质 */
|
|
11
16
|
private materialMap;
|
|
12
17
|
private readonly view;
|
|
@@ -21,31 +26,33 @@ export default class TraceRendererWebgl implements ITraceRendererInterface {
|
|
|
21
26
|
private busModelReady;
|
|
22
27
|
private bicycleModel;
|
|
23
28
|
private bicycleModelReady;
|
|
29
|
+
private showGroundVehicle;
|
|
30
|
+
private showElevatedVehicle;
|
|
24
31
|
private currentSpriteContent;
|
|
25
32
|
private historyPositionMap;
|
|
26
33
|
private vehicleObjectMap;
|
|
27
34
|
private needInterpolate;
|
|
35
|
+
private updateModel;
|
|
28
36
|
constructor(view: __esri.SceneView);
|
|
29
37
|
setInterpolate(needInterpolate: boolean): void;
|
|
30
38
|
private context;
|
|
31
39
|
setup(context: any): Promise<void>;
|
|
32
|
-
private lastRenderTime;
|
|
33
40
|
render(context: any): Promise<void>;
|
|
34
41
|
/**
|
|
35
42
|
* 新增车辆
|
|
36
43
|
* */
|
|
37
|
-
addVehicles(objects: IVehicleTrack[]): void
|
|
44
|
+
addVehicles(objects: IVehicleTrack[]): Promise<void>;
|
|
38
45
|
/**
|
|
39
46
|
* 更新车辆
|
|
40
47
|
* */
|
|
41
|
-
updateVehicles(objects: IVehicleTrack[]): void
|
|
48
|
+
updateVehicles(objects: IVehicleTrack[]): Promise<void>;
|
|
42
49
|
private toRenderCoordinates;
|
|
43
50
|
/**
|
|
44
51
|
* 删除车辆
|
|
45
52
|
* */
|
|
46
53
|
deleteVehicles(idList: string[]): void;
|
|
47
54
|
private deleteVehicle;
|
|
48
|
-
toggleTrafficInfo(params: IToggleTrafficInfoParams): void
|
|
55
|
+
toggleTrafficInfo(params: IToggleTrafficInfoParams): Promise<void>;
|
|
49
56
|
/**
|
|
50
57
|
* 清除全部车辆
|
|
51
58
|
* */
|
|
@@ -55,7 +62,7 @@ export default class TraceRendererWebgl implements ITraceRendererInterface {
|
|
|
55
62
|
* @param contentType
|
|
56
63
|
* @returns
|
|
57
64
|
*/
|
|
58
|
-
updatePanelContent(contentType: EVehiclePlateState): void
|
|
65
|
+
updatePanelContent(contentType: EVehiclePlateState): Promise<void>;
|
|
59
66
|
toggleGroundVehicle(visible: boolean): void;
|
|
60
67
|
toggleElevatedVehicle(visible: boolean): void;
|
|
61
68
|
/**
|
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
import * as y from "@arcgis/core/core/reactiveUtils.js";
|
|
2
|
+
import w from "@arcgis/core/geometry/SpatialReference";
|
|
3
|
+
import * as M from "@arcgis/core/views/3d/externalRenderers";
|
|
4
|
+
import * as h from "three";
|
|
5
|
+
import { GLTFLoader as R } from "three/examples/jsm/loaders/GLTFLoader.js";
|
|
6
|
+
import { EVehiclePlateState as p } from "../../../types/index.mjs";
|
|
7
|
+
import C from "../../stores/index.mjs";
|
|
8
|
+
class N {
|
|
9
|
+
constructor(i) {
|
|
10
|
+
this.zoomThreshold = 18.5, this.roughness = 0.4, this.metalness = 0.5, this.defaultMaterial = new h.MeshPhysicalMaterial({
|
|
11
|
+
color: 16777215,
|
|
12
|
+
emissive: 0,
|
|
13
|
+
roughness: this.roughness,
|
|
14
|
+
metalness: this.metalness
|
|
15
|
+
}), this.materialMap = /* @__PURE__ */ new Map([
|
|
16
|
+
[1, this.createCarMaterial(16777215)],
|
|
17
|
+
[2, this.createCarMaterial(7833753)],
|
|
18
|
+
[3, this.createCarMaterial(16766720)],
|
|
19
|
+
[4, this.createCarMaterial(16758465)],
|
|
20
|
+
[5, this.createCarMaterial(14423100)],
|
|
21
|
+
[6, this.createCarMaterial(3329330)],
|
|
22
|
+
[7, this.createCarMaterial(2003183)],
|
|
23
|
+
[8, this.createCarMaterial(16032864)],
|
|
24
|
+
[9, this.createCarMaterial(2105376)],
|
|
25
|
+
[10, this.createCarMaterial(9662683)],
|
|
26
|
+
[99, this.createCarMaterial(6908265)]
|
|
27
|
+
]), this.carModelReady = !1, this.vanModelReady = !1, this.truckModelReady = !1, this.busModelReady = !1, this.bicycleModelReady = !1, this.showGroundVehicle = !0, this.showElevatedVehicle = !0, this.currentSpriteContent = p.None, this.historyPositionMap = /* @__PURE__ */ new Map(), this.vehicleObjectMap = /* @__PURE__ */ new Map(), this.needInterpolate = !0, this.updateModel = !1;
|
|
28
|
+
const e = C.useAppDataStore;
|
|
29
|
+
this.assetsRoot = JSON.parse(
|
|
30
|
+
JSON.stringify(e.mapConfig)
|
|
31
|
+
).assetsRoot, this.view = i;
|
|
32
|
+
const t = new R();
|
|
33
|
+
t.load(`${this.assetsRoot}/3DModels/car.glb`, (s) => {
|
|
34
|
+
this.carModel = s.scene, this.carModel.rotation.x = h.MathUtils.degToRad(90), this.carModelReady = !0;
|
|
35
|
+
}), t.load(`${this.assetsRoot}/3DModels/van.glb`, (s) => {
|
|
36
|
+
this.vanModel = s.scene, this.vanModel.rotation.x = h.MathUtils.degToRad(90), this.vanModelReady = !0;
|
|
37
|
+
}), t.load(`${this.assetsRoot}/3DModels/truck.glb`, (s) => {
|
|
38
|
+
this.truckModel = s.scene, this.truckModel.scale.set(1.2, 1, 1.5), this.truckModel.rotation.x = h.MathUtils.degToRad(90), this.truckModelReady = !0;
|
|
39
|
+
}), t.load(`${this.assetsRoot}/3DModels/bus.glb`, (s) => {
|
|
40
|
+
this.busModel = s.scene, this.busModel.rotation.x = h.MathUtils.degToRad(90), this.busModelReady = !0;
|
|
41
|
+
}), t.load(`${this.assetsRoot}/3DModels/bicycle.glb`, (s) => {
|
|
42
|
+
this.bicycleModel = s.scene, this.bicycleModel.rotation.x = h.MathUtils.degToRad(90), this.bicycleModel.rotation.y = h.MathUtils.degToRad(180), this.bicycleModelReady = !0;
|
|
43
|
+
}), document.addEventListener(
|
|
44
|
+
"visibilitychange",
|
|
45
|
+
() => {
|
|
46
|
+
this.clearVehicles(), this.needInterpolate = !document.hidden;
|
|
47
|
+
},
|
|
48
|
+
!1
|
|
49
|
+
), y.watch(
|
|
50
|
+
() => this.view.zoom,
|
|
51
|
+
(s, o) => {
|
|
52
|
+
(o <= this.zoomThreshold && s > this.zoomThreshold || o > this.zoomThreshold && s <= this.zoomThreshold) && (this.updateModel = !0);
|
|
53
|
+
}
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
createCarMaterial(i) {
|
|
57
|
+
return new h.MeshPhysicalMaterial({
|
|
58
|
+
color: i,
|
|
59
|
+
emissive: 0,
|
|
60
|
+
roughness: this.roughness,
|
|
61
|
+
metalness: this.metalness
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
setInterpolate(i) {
|
|
65
|
+
this.clearVehicles(), this.needInterpolate = i;
|
|
66
|
+
}
|
|
67
|
+
async setup(i) {
|
|
68
|
+
this.context = i, this.renderer = new h.WebGLRenderer({
|
|
69
|
+
context: i.gl,
|
|
70
|
+
premultipliedAlpha: !0,
|
|
71
|
+
logarithmicDepthBuffer: !0,
|
|
72
|
+
antialias: !0,
|
|
73
|
+
powerPreference: "high-performance"
|
|
74
|
+
}), 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;
|
|
75
|
+
const e = this.renderer.setRenderTarget.bind(
|
|
76
|
+
this.renderer
|
|
77
|
+
);
|
|
78
|
+
this.renderer.setRenderTarget = (a) => {
|
|
79
|
+
e(a), a == null && i.bindRenderTarget();
|
|
80
|
+
}, this.scene = new h.Scene();
|
|
81
|
+
const { camera: t } = i;
|
|
82
|
+
this.camera = new h.PerspectiveCamera(
|
|
83
|
+
t.fovY,
|
|
84
|
+
t.aspect,
|
|
85
|
+
0.1,
|
|
86
|
+
1e5
|
|
87
|
+
), this.ambient = new h.AmbientLight(16777215, 2e4), this.scene.add(this.ambient), this.sun = new h.DirectionalLight(16777215, 2e4);
|
|
88
|
+
const s = [121.46790813287619, 31.239514870157972, 1e3], o = this.toRenderCoordinates(s);
|
|
89
|
+
this.sun.position.set(
|
|
90
|
+
o[0],
|
|
91
|
+
o[1],
|
|
92
|
+
o[2]
|
|
93
|
+
), this.scene.add(this.sun), i.resetWebGLState();
|
|
94
|
+
}
|
|
95
|
+
async render(i) {
|
|
96
|
+
var s;
|
|
97
|
+
const e = i.camera;
|
|
98
|
+
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(
|
|
99
|
+
new h.Vector3(e.center[0], e.center[1], e.center[2])
|
|
100
|
+
), this.camera.projectionMatrix.fromArray(e.projectionMatrix), this.needInterpolate)
|
|
101
|
+
for (const o of this.vehicleObjectMap.keys()) {
|
|
102
|
+
const a = (s = this.vehicleObjectMap.get(o)) == null ? void 0 : s.model;
|
|
103
|
+
if (!a)
|
|
104
|
+
continue;
|
|
105
|
+
const r = this.computeVehiclePosition(o);
|
|
106
|
+
if (r) {
|
|
107
|
+
const n = this.toRenderCoordinates(r);
|
|
108
|
+
a.position.set(n[0], n[1], n[2]), a.rotation.y = h.MathUtils.degToRad(-r[3]);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const t = i.sunLight;
|
|
112
|
+
this.sun.position.set(t.direction[0], t.direction[1], t.direction[2]), this.sun.intensity = t.diffuse.intensity, this.sun.color = new h.Color(
|
|
113
|
+
t.diffuse.color[0],
|
|
114
|
+
t.diffuse.color[1],
|
|
115
|
+
t.diffuse.color[2]
|
|
116
|
+
), this.ambient.intensity = t.ambient.intensity, this.ambient.color = new h.Color(
|
|
117
|
+
t.ambient.color[0],
|
|
118
|
+
t.ambient.color[1],
|
|
119
|
+
t.ambient.color[2]
|
|
120
|
+
), this.renderer.resetState(), i.bindRenderTarget(), this.renderer.render(this.scene, this.camera), M.requestRender(this.view), i.resetWebGLState();
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* 新增车辆
|
|
124
|
+
* */
|
|
125
|
+
async addVehicles(i) {
|
|
126
|
+
if (!(!this.carModelReady || !this.vanModelReady || !this.truckModelReady || !this.busModelReady || !this.bicycleModelReady))
|
|
127
|
+
for (const e of i) {
|
|
128
|
+
const { vehicleId: t, localTimestamp: s } = e, o = Number(e.x), a = Number(e.y), r = Number(e.heading);
|
|
129
|
+
this.historyPositionMap.set(t, [
|
|
130
|
+
{ pos: [o, a, 0], heading: r, time: s }
|
|
131
|
+
]);
|
|
132
|
+
const n = this.getVehicleModel(e);
|
|
133
|
+
n.name = t, n.visible = !this.needInterpolate;
|
|
134
|
+
try {
|
|
135
|
+
const l = await this.createPlateSprite(e);
|
|
136
|
+
l && (n.add(l), l.position.set(0, 5, -4)), this.scene.add(n), this.vehicleObjectMap.set(t, {
|
|
137
|
+
model: n,
|
|
138
|
+
data: e,
|
|
139
|
+
waitForDelete: !1,
|
|
140
|
+
isMoving: !1
|
|
141
|
+
});
|
|
142
|
+
} catch (l) {
|
|
143
|
+
console.log("createPlateSprite error:", l);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* 更新车辆
|
|
149
|
+
* */
|
|
150
|
+
async updateVehicles(i) {
|
|
151
|
+
if (!this.carModelReady || !this.vanModelReady || !this.truckModelReady || !this.busModelReady || !this.bicycleModelReady)
|
|
152
|
+
return;
|
|
153
|
+
const e = [];
|
|
154
|
+
for (const t of i) {
|
|
155
|
+
const { vehicleId: s, localTimestamp: o } = t, a = Number(t.x), r = Number(t.y);
|
|
156
|
+
let n = Number(t.heading);
|
|
157
|
+
const l = this.vehicleObjectMap.get(s);
|
|
158
|
+
if (!l)
|
|
159
|
+
e.push(t);
|
|
160
|
+
else {
|
|
161
|
+
if (this.updateModel || l.data.vehicleColor !== t.vehicleColor || l.data.vehicleType !== t.vehicleType) {
|
|
162
|
+
this.scene.remove(l.model), this.disposeModel(l.model), l.model = this.getVehicleModel(t);
|
|
163
|
+
const c = await this.createPlateSprite(t);
|
|
164
|
+
c && (l.model.add(c), c.position.set(0, 5, -4)), this.scene.add(l.model);
|
|
165
|
+
}
|
|
166
|
+
if (l.data.showName !== t.showName || l.data.plateColor !== t.plateColor) {
|
|
167
|
+
const c = l.model.getObjectByName("VehiclePlate");
|
|
168
|
+
c && (l.model.remove(c), this.disposeModel(c));
|
|
169
|
+
const d = await this.createPlateSprite(t);
|
|
170
|
+
d && (l.model.add(d), d.position.set(0, 5, -4));
|
|
171
|
+
}
|
|
172
|
+
if (l.data = t, this.needInterpolate) {
|
|
173
|
+
const c = this.historyPositionMap.get(
|
|
174
|
+
s
|
|
175
|
+
), d = c[c.length - 1];
|
|
176
|
+
Math.abs(n - d.heading) >= 180 && (n > d.heading ? d.heading += 360 : n += 360), c.push({
|
|
177
|
+
pos: [a, r, 0],
|
|
178
|
+
heading: n,
|
|
179
|
+
time: o
|
|
180
|
+
});
|
|
181
|
+
} else {
|
|
182
|
+
this.historyPositionMap.set(s, [
|
|
183
|
+
{ pos: [a, r, 0], heading: n, time: o }
|
|
184
|
+
]);
|
|
185
|
+
const c = this.toRenderCoordinates([a, r, 0]);
|
|
186
|
+
l.model.position.set(c[0], c[1], c[2]), l.model.rotation.y = h.MathUtils.degToRad(-n);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
this.addVehicles(e), this.updateModel = !1, this.needInterpolate || this.render(this.context);
|
|
191
|
+
}
|
|
192
|
+
toRenderCoordinates(i) {
|
|
193
|
+
const e = [0, 0, 0];
|
|
194
|
+
return M.toRenderCoordinates(
|
|
195
|
+
// @ts-ignore
|
|
196
|
+
this.view,
|
|
197
|
+
i,
|
|
198
|
+
0,
|
|
199
|
+
w.WGS84,
|
|
200
|
+
e,
|
|
201
|
+
0,
|
|
202
|
+
1
|
|
203
|
+
), e;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* 删除车辆
|
|
207
|
+
* */
|
|
208
|
+
deleteVehicles(i) {
|
|
209
|
+
i.forEach((e) => {
|
|
210
|
+
const t = this.vehicleObjectMap.get(e);
|
|
211
|
+
t && (this.needInterpolate ? t.isMoving ? t.waitForDelete = !0 : this.deleteVehicle(t) : this.deleteVehicle(t));
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
deleteVehicle(i) {
|
|
215
|
+
this.scene.remove(i.model), this.disposeModel(i.model);
|
|
216
|
+
const e = i.data.vehicleId;
|
|
217
|
+
this.vehicleObjectMap.delete(e), this.historyPositionMap.delete(e);
|
|
218
|
+
}
|
|
219
|
+
async toggleTrafficInfo(i) {
|
|
220
|
+
i.name === "vehiclePlate" && (i.visible === !0 && this.currentSpriteContent === p.None ? await this.updatePanelContent(p.Id) : await this.updatePanelContent(
|
|
221
|
+
i.visible ? this.currentSpriteContent : p.None
|
|
222
|
+
));
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* 清除全部车辆
|
|
226
|
+
* */
|
|
227
|
+
clearVehicles() {
|
|
228
|
+
for (const i of this.vehicleObjectMap.keys()) {
|
|
229
|
+
const e = this.vehicleObjectMap.get(i);
|
|
230
|
+
e && (this.disposeModel(e.model), this.scene.remove(e.model));
|
|
231
|
+
}
|
|
232
|
+
this.vehicleObjectMap.clear(), this.historyPositionMap.clear();
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* 设置号牌显示状态
|
|
236
|
+
* @param contentType
|
|
237
|
+
* @returns
|
|
238
|
+
*/
|
|
239
|
+
async updatePanelContent(i) {
|
|
240
|
+
if (i !== this.currentSpriteContent) {
|
|
241
|
+
this.currentSpriteContent = i;
|
|
242
|
+
for (const e of this.vehicleObjectMap.keys()) {
|
|
243
|
+
const t = this.vehicleObjectMap.get(e);
|
|
244
|
+
if (t) {
|
|
245
|
+
const s = t.model.getObjectByName("VehiclePlate");
|
|
246
|
+
if (s && (t.model.remove(s), this.disposeModel(s)), i !== p.None) {
|
|
247
|
+
const o = await this.createPlateSprite(t.data);
|
|
248
|
+
o && (t.model.add(o), o.position.set(0, 5, -4));
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
toggleGroundVehicle(i) {
|
|
255
|
+
console.log("toggleGroundVehicle", i), this.showGroundVehicle = i;
|
|
256
|
+
}
|
|
257
|
+
toggleElevatedVehicle(i) {
|
|
258
|
+
this.showElevatedVehicle = i;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* 释放模型资源
|
|
262
|
+
* */
|
|
263
|
+
disposeModel(i) {
|
|
264
|
+
i.traverse((e) => {
|
|
265
|
+
e instanceof h.Mesh && (e.geometry.dispose(), e.material.dispose());
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* 计算车辆位置
|
|
270
|
+
* */
|
|
271
|
+
computeVehiclePosition(i) {
|
|
272
|
+
const e = this.historyPositionMap.get(i), t = this.vehicleObjectMap.get(i);
|
|
273
|
+
if (!t || !e || !t.isMoving && e.length <= 2)
|
|
274
|
+
return;
|
|
275
|
+
const s = Date.now();
|
|
276
|
+
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);
|
|
277
|
+
const o = s - t.segmentStartTime, a = Math.min(
|
|
278
|
+
o / t.segmentTotalTime,
|
|
279
|
+
1
|
|
280
|
+
);
|
|
281
|
+
if (a === 1)
|
|
282
|
+
if (e.shift(), e.length === 1) {
|
|
283
|
+
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));
|
|
284
|
+
return;
|
|
285
|
+
} else
|
|
286
|
+
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);
|
|
287
|
+
else {
|
|
288
|
+
const r = e[0].pos[0] + (e[1].pos[0] - e[0].pos[0]) * a, n = e[0].pos[1] + (e[1].pos[1] - e[0].pos[1]) * a, l = e[0].heading + (e[1].heading - e[0].heading) * a;
|
|
289
|
+
return [r, n, 0, l];
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* 根据车辆类型、车身颜色获取模型
|
|
294
|
+
* */
|
|
295
|
+
getVehicleModel(i) {
|
|
296
|
+
if (this.view.zoom <= this.zoomThreshold) {
|
|
297
|
+
const e = new h.SphereGeometry(5, 32, 32), t = new h.MeshPhysicalMaterial({
|
|
298
|
+
color: 325253,
|
|
299
|
+
emissive: 0,
|
|
300
|
+
roughness: this.roughness,
|
|
301
|
+
metalness: this.metalness
|
|
302
|
+
});
|
|
303
|
+
return new h.Mesh(e, t);
|
|
304
|
+
} else {
|
|
305
|
+
let e;
|
|
306
|
+
if (i.ptcType === 2)
|
|
307
|
+
e = this.bicycleModel.clone();
|
|
308
|
+
else {
|
|
309
|
+
switch (i.vehicleType) {
|
|
310
|
+
case 10:
|
|
311
|
+
e = this.carModel.clone();
|
|
312
|
+
break;
|
|
313
|
+
case 20:
|
|
314
|
+
e = this.vanModel.clone();
|
|
315
|
+
break;
|
|
316
|
+
case 25:
|
|
317
|
+
e = this.truckModel.clone();
|
|
318
|
+
break;
|
|
319
|
+
case 50:
|
|
320
|
+
e = this.busModel.clone();
|
|
321
|
+
break;
|
|
322
|
+
default:
|
|
323
|
+
e = this.carModel.clone();
|
|
324
|
+
break;
|
|
325
|
+
}
|
|
326
|
+
const t = this.materialMap.get(i.vehicleColor) || this.defaultMaterial;
|
|
327
|
+
let s = !1;
|
|
328
|
+
e.traverse((o) => {
|
|
329
|
+
!s && o instanceof h.Mesh && (o.material = t, s = !0);
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
return e;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* 创建号牌canvas
|
|
337
|
+
* */
|
|
338
|
+
createCanvas(i, e, t) {
|
|
339
|
+
const s = document.createElement("canvas"), o = i.width, a = i.height;
|
|
340
|
+
s.width = o, s.height = a;
|
|
341
|
+
const r = s.getContext("2d");
|
|
342
|
+
if (!r) {
|
|
343
|
+
console.log("canvas创建失败");
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
return r.fillStyle = "rgba(0,0,0,0.0)", r.fillRect(0, 0, o, a), r.drawImage(i, 0, 0, o, a), r.beginPath(), r.translate(o / 2, a / 2), r.fillStyle = t, r.font = "bold 32px 宋体", r.textBaseline = "middle", r.textAlign = "center", r.fillText(e, 0, 0), s;
|
|
347
|
+
}
|
|
348
|
+
createPlateSprite(i) {
|
|
349
|
+
return new Promise((e, t) => {
|
|
350
|
+
var l, c;
|
|
351
|
+
const s = !i.plateNo || i.plateNo === "0" || i.plateNo === "000000";
|
|
352
|
+
if (this.currentSpriteContent === p.None || this.currentSpriteContent === p.PlateNumber && s) {
|
|
353
|
+
e(void 0);
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
const o = new Image();
|
|
357
|
+
let a = "", r = "", n = "";
|
|
358
|
+
if (this.currentSpriteContent === p.PlateNumber || this.currentSpriteContent === p.Mix)
|
|
359
|
+
if (s)
|
|
360
|
+
a = "grey", r = i.ptcId, n = "#ffffff";
|
|
361
|
+
else
|
|
362
|
+
switch (r = ((l = i.showName) == null ? void 0 : l.substring(0, 2)) + "•" + ((c = i.showName) == null ? void 0 : c.substring(2)), i.plateColor) {
|
|
363
|
+
case 1:
|
|
364
|
+
a = "blue", n = "#ffffff";
|
|
365
|
+
break;
|
|
366
|
+
case 2:
|
|
367
|
+
a = "yellow", n = "#000000";
|
|
368
|
+
break;
|
|
369
|
+
case 3:
|
|
370
|
+
a = "white", n = "#000000";
|
|
371
|
+
break;
|
|
372
|
+
case 4:
|
|
373
|
+
a = "black";
|
|
374
|
+
break;
|
|
375
|
+
case 5:
|
|
376
|
+
a = "neo_yellow", n = "#000000";
|
|
377
|
+
break;
|
|
378
|
+
case 6:
|
|
379
|
+
a = "neo_green", n = "#000000";
|
|
380
|
+
break;
|
|
381
|
+
default:
|
|
382
|
+
a = "grey", r = i.plateNo, n = "#ffffff";
|
|
383
|
+
break;
|
|
384
|
+
}
|
|
385
|
+
else
|
|
386
|
+
this.currentSpriteContent === p.Id && (a = "grey", r = i.ptcId, n = "#ffffff");
|
|
387
|
+
o.src = `${this.assetsRoot}/Images/PlateBG/${a}.png`, o.onload = () => {
|
|
388
|
+
const d = this.createCanvas(o, r, n);
|
|
389
|
+
if (!d)
|
|
390
|
+
t("canvas创建失败");
|
|
391
|
+
else {
|
|
392
|
+
const m = new h.CanvasTexture(d), g = new h.SpriteMaterial({
|
|
393
|
+
map: m,
|
|
394
|
+
transparent: !1
|
|
395
|
+
}), f = new h.Sprite(g), u = 0.05, b = d.width * u, v = d.height * u;
|
|
396
|
+
f.scale.set(b, v, 1), f.name = "VehiclePlate", e(f);
|
|
397
|
+
}
|
|
398
|
+
o.onerror = (m) => {
|
|
399
|
+
console.log(`号牌背景加载失败: ${o.src}`, m), t(m);
|
|
400
|
+
};
|
|
401
|
+
};
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
export {
|
|
406
|
+
N as default
|
|
407
|
+
};
|
|
@@ -39,7 +39,7 @@ class Q {
|
|
|
39
39
|
container: a,
|
|
40
40
|
...e == null ? void 0 : e.mapOptions
|
|
41
41
|
}), this.view.on("click", async (s) => {
|
|
42
|
-
var
|
|
42
|
+
var v, b;
|
|
43
43
|
if (d) {
|
|
44
44
|
let o = s.mapPoint;
|
|
45
45
|
o.spatialReference.isWebMercator && (o = f.webMercatorToGeographic(
|
|
@@ -60,9 +60,10 @@ class Q {
|
|
|
60
60
|
tilt: o.tilt,
|
|
61
61
|
position: l.toJSON()
|
|
62
62
|
};
|
|
63
|
-
console.log(w), (
|
|
63
|
+
console.log(w), (v = navigator.clipboard) == null || v.writeText(JSON.stringify(w));
|
|
64
64
|
} else
|
|
65
65
|
console.log(o.toJSON());
|
|
66
|
+
console.log(this.view.zoom, this.view.scale);
|
|
66
67
|
} else {
|
|
67
68
|
let o = this.view.center;
|
|
68
69
|
this.view.spatialReference.isWebMercator && (o = f.webMercatorToGeographic(
|
|
@@ -72,7 +73,7 @@ class Q {
|
|
|
72
73
|
zoom: this.view.zoom
|
|
73
74
|
});
|
|
74
75
|
}
|
|
75
|
-
const h = (
|
|
76
|
+
const h = (b = (await this.view.hitTest(s)).results) == null ? void 0 : b.filter(
|
|
76
77
|
(o) => o.type === "graphic"
|
|
77
78
|
);
|
|
78
79
|
h.length > 0 && h.forEach((o) => {
|
|
@@ -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 y=R(g);class V{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),y.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=e.roadLayer?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=V;
|
package/lib/src/gis-map/utils/holo-flow/{trace-renderer-webgl.d.ts → trace-renderer-external.d.ts}
RENAMED
|
@@ -1,12 +1,17 @@
|
|
|
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;
|
|
6
6
|
private ambient;
|
|
7
7
|
private sun;
|
|
8
|
+
/** 车辆模型变化的阈值 */
|
|
9
|
+
private readonly zoomThreshold;
|
|
10
|
+
private readonly roughness;
|
|
11
|
+
private readonly metalness;
|
|
8
12
|
/** 默认车身材质 */
|
|
9
13
|
private defaultMaterial;
|
|
14
|
+
private createCarMaterial;
|
|
10
15
|
/** 车身颜色材质 */
|
|
11
16
|
private materialMap;
|
|
12
17
|
private readonly view;
|
|
@@ -21,31 +26,33 @@ export default class TraceRendererWebgl implements ITraceRendererInterface {
|
|
|
21
26
|
private busModelReady;
|
|
22
27
|
private bicycleModel;
|
|
23
28
|
private bicycleModelReady;
|
|
29
|
+
private showGroundVehicle;
|
|
30
|
+
private showElevatedVehicle;
|
|
24
31
|
private currentSpriteContent;
|
|
25
32
|
private historyPositionMap;
|
|
26
33
|
private vehicleObjectMap;
|
|
27
34
|
private needInterpolate;
|
|
35
|
+
private updateModel;
|
|
28
36
|
constructor(view: __esri.SceneView);
|
|
29
37
|
setInterpolate(needInterpolate: boolean): void;
|
|
30
38
|
private context;
|
|
31
39
|
setup(context: any): Promise<void>;
|
|
32
|
-
private lastRenderTime;
|
|
33
40
|
render(context: any): Promise<void>;
|
|
34
41
|
/**
|
|
35
42
|
* 新增车辆
|
|
36
43
|
* */
|
|
37
|
-
addVehicles(objects: IVehicleTrack[]): void
|
|
44
|
+
addVehicles(objects: IVehicleTrack[]): Promise<void>;
|
|
38
45
|
/**
|
|
39
46
|
* 更新车辆
|
|
40
47
|
* */
|
|
41
|
-
updateVehicles(objects: IVehicleTrack[]): void
|
|
48
|
+
updateVehicles(objects: IVehicleTrack[]): Promise<void>;
|
|
42
49
|
private toRenderCoordinates;
|
|
43
50
|
/**
|
|
44
51
|
* 删除车辆
|
|
45
52
|
* */
|
|
46
53
|
deleteVehicles(idList: string[]): void;
|
|
47
54
|
private deleteVehicle;
|
|
48
|
-
toggleTrafficInfo(params: IToggleTrafficInfoParams): void
|
|
55
|
+
toggleTrafficInfo(params: IToggleTrafficInfoParams): Promise<void>;
|
|
49
56
|
/**
|
|
50
57
|
* 清除全部车辆
|
|
51
58
|
* */
|
|
@@ -55,7 +62,7 @@ export default class TraceRendererWebgl implements ITraceRendererInterface {
|
|
|
55
62
|
* @param contentType
|
|
56
63
|
* @returns
|
|
57
64
|
*/
|
|
58
|
-
updatePanelContent(contentType: EVehiclePlateState): void
|
|
65
|
+
updatePanelContent(contentType: EVehiclePlateState): Promise<void>;
|
|
59
66
|
toggleGroundVehicle(visible: boolean): void;
|
|
60
67
|
toggleElevatedVehicle(visible: boolean): void;
|
|
61
68
|
/**
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const R=require("@arcgis/core/core/reactiveUtils.js"),P=require("@arcgis/core/geometry/SpatialReference"),S=require("@arcgis/core/views/3d/externalRenderers"),C=require("three"),T=require("three/examples/jsm/loaders/GLTFLoader.js"),p=require("../../../types/index.js"),V=require("../../stores/index.js");function g(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 k=g(R),b=g(S),h=g(C);class x{constructor(i){this.zoomThreshold=18.5,this.roughness=.4,this.metalness=.5,this.defaultMaterial=new h.MeshPhysicalMaterial({color:16777215,emissive:0,roughness:this.roughness,metalness:this.metalness}),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.carModelReady=!1,this.vanModelReady=!1,this.truckModelReady=!1,this.busModelReady=!1,this.bicycleModelReady=!1,this.showGroundVehicle=!0,this.showElevatedVehicle=!0,this.currentSpriteContent=p.EVehiclePlateState.None,this.historyPositionMap=new Map,this.vehicleObjectMap=new Map,this.needInterpolate=!0,this.updateModel=!1;const e=V.default.useAppDataStore;this.assetsRoot=JSON.parse(JSON.stringify(e.mapConfig)).assetsRoot,this.view=i;const t=new T.GLTFLoader;t.load(`${this.assetsRoot}/3DModels/car.glb`,s=>{this.carModel=s.scene,this.carModel.rotation.x=h.MathUtils.degToRad(90),this.carModelReady=!0}),t.load(`${this.assetsRoot}/3DModels/van.glb`,s=>{this.vanModel=s.scene,this.vanModel.rotation.x=h.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=h.MathUtils.degToRad(90),this.truckModelReady=!0}),t.load(`${this.assetsRoot}/3DModels/bus.glb`,s=>{this.busModel=s.scene,this.busModel.rotation.x=h.MathUtils.degToRad(90),this.busModelReady=!0}),t.load(`${this.assetsRoot}/3DModels/bicycle.glb`,s=>{this.bicycleModel=s.scene,this.bicycleModel.rotation.x=h.MathUtils.degToRad(90),this.bicycleModel.rotation.y=h.MathUtils.degToRad(180),this.bicycleModelReady=!0}),document.addEventListener("visibilitychange",()=>{this.clearVehicles(),this.needInterpolate=!document.hidden},!1),k.watch(()=>this.view.zoom,(s,a)=>{(a<=this.zoomThreshold&&s>this.zoomThreshold||a>this.zoomThreshold&&s<=this.zoomThreshold)&&(this.updateModel=!0)})}createCarMaterial(i){return new h.MeshPhysicalMaterial({color:i,emissive:0,roughness:this.roughness,metalness:this.metalness})}setInterpolate(i){this.clearVehicles(),this.needInterpolate=i}async setup(i){this.context=i,this.renderer=new h.WebGLRenderer({context:i.gl,premultipliedAlpha:!0,logarithmicDepthBuffer:!0,antialias:!0,powerPreference:"high-performance"}),this.renderer.shadowMap.enabled=!0,this.renderer.setPixelRatio(window.devicePixelRatio),this.renderer.setViewport(0,0,this.view.width,this.view.height),this.renderer.autoClearDepth=!1,this.renderer.autoClearStencil=!1,this.renderer.autoClearColor=!1;const e=this.renderer.setRenderTarget.bind(this.renderer);this.renderer.setRenderTarget=o=>{e(o),o==null&&i.bindRenderTarget()},this.scene=new h.Scene;const{camera:t}=i;this.camera=new h.PerspectiveCamera(t.fovY,t.aspect,.1,1e5),this.ambient=new h.AmbientLight(16777215,2e4),this.scene.add(this.ambient),this.sun=new h.DirectionalLight(16777215,2e4);const s=[121.46790813287619,31.239514870157972,1e3],a=this.toRenderCoordinates(s);this.sun.position.set(a[0],a[1],a[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 h.Vector3(e.center[0],e.center[1],e.center[2])),this.camera.projectionMatrix.fromArray(e.projectionMatrix),this.needInterpolate)for(const a of this.vehicleObjectMap.keys()){const o=(s=this.vehicleObjectMap.get(a))==null?void 0:s.model;if(!o)continue;const r=this.computeVehiclePosition(a);if(r){const n=this.toRenderCoordinates(r);o.position.set(n[0],n[1],n[2]),o.rotation.y=h.MathUtils.degToRad(-r[3])}}const t=i.sunLight;this.sun.position.set(t.direction[0],t.direction[1],t.direction[2]),this.sun.intensity=t.diffuse.intensity,this.sun.color=new h.Color(t.diffuse.color[0],t.diffuse.color[1],t.diffuse.color[2]),this.ambient.intensity=t.ambient.intensity,this.ambient.color=new h.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,a=Number(e.x),o=Number(e.y),r=Number(e.heading);this.historyPositionMap.set(t,[{pos:[a,o,0],heading:r,time:s}]);const n=this.getVehicleModel(e);n.name=t,n.visible=!this.needInterpolate;try{const l=await this.createPlateSprite(e);l&&(n.add(l),l.position.set(0,5,-4)),this.scene.add(n),this.vehicleObjectMap.set(t,{model:n,data:e,waitForDelete:!1,isMoving:!1})}catch(l){console.log("createPlateSprite error:",l)}}}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:a}=t,o=Number(t.x),r=Number(t.y);let n=Number(t.heading);const l=this.vehicleObjectMap.get(s);if(!l)e.push(t);else{if(this.updateModel||l.data.vehicleColor!==t.vehicleColor||l.data.vehicleType!==t.vehicleType){this.scene.remove(l.model),this.disposeModel(l.model),l.model=this.getVehicleModel(t);const c=await this.createPlateSprite(t);c&&(l.model.add(c),c.position.set(0,5,-4)),this.scene.add(l.model)}if(l.data.showName!==t.showName||l.data.plateColor!==t.plateColor){const c=l.model.getObjectByName("VehiclePlate");c&&(l.model.remove(c),this.disposeModel(c));const d=await this.createPlateSprite(t);d&&(l.model.add(d),d.position.set(0,5,-4))}if(l.data=t,this.needInterpolate){const c=this.historyPositionMap.get(s),d=c[c.length-1];Math.abs(n-d.heading)>=180&&(n>d.heading?d.heading+=360:n+=360),c.push({pos:[o,r,0],heading:n,time:a})}else{this.historyPositionMap.set(s,[{pos:[o,r,0],heading:n,time:a}]);const c=this.toRenderCoordinates([o,r,0]);l.model.position.set(c[0],c[1],c[2]),l.model.rotation.y=h.MathUtils.degToRad(-n)}}}this.addVehicles(e),this.updateModel=!1,this.needInterpolate||this.render(this.context)}toRenderCoordinates(i){const e=[0,0,0];return b.toRenderCoordinates(this.view,i,0,P.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 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 h.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,o=Math.min(a/t.segmentTotalTime,1);if(o===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 r=e[0].pos[0]+(e[1].pos[0]-e[0].pos[0])*o,n=e[0].pos[1]+(e[1].pos[1]-e[0].pos[1])*o,l=e[0].heading+(e[1].heading-e[0].heading)*o;return[r,n,0,l]}}getVehicleModel(i){if(this.view.zoom<=this.zoomThreshold){const e=new h.SphereGeometry(5,32,32),t=new h.MeshPhysicalMaterial({color:325253,emissive:0,roughness:this.roughness,metalness:this.metalness});return new h.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 h.Mesh&&(a.material=t,s=!0)})}return e}}createCanvas(i,e,t){const s=document.createElement("canvas"),a=i.width,o=i.height;s.width=a,s.height=o;const r=s.getContext("2d");if(!r){console.log("canvas创建失败");return}return r.fillStyle="rgba(0,0,0,0.0)",r.fillRect(0,0,a,o),r.drawImage(i,0,0,a,o),r.beginPath(),r.translate(a/2,o/2),r.fillStyle=t,r.font="bold 32px 宋体",r.textBaseline="middle",r.textAlign="center",r.fillText(e,0,0),s}createPlateSprite(i){return new Promise((e,t)=>{var l,c;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 a=new Image;let o="",r="",n="";if(this.currentSpriteContent===p.EVehiclePlateState.PlateNumber||this.currentSpriteContent===p.EVehiclePlateState.Mix)if(s)o="grey",r=i.ptcId,n="#ffffff";else switch(r=((l=i.showName)==null?void 0:l.substring(0,2))+"•"+((c=i.showName)==null?void 0:c.substring(2)),i.plateColor){case 1:o="blue",n="#ffffff";break;case 2:o="yellow",n="#000000";break;case 3:o="white",n="#000000";break;case 4:o="black";break;case 5:o="neo_yellow",n="#000000";break;case 6:o="neo_green",n="#000000";break;default:o="grey",r=i.plateNo,n="#ffffff";break}else this.currentSpriteContent===p.EVehiclePlateState.Id&&(o="grey",r=i.ptcId,n="#ffffff");a.src=`${this.assetsRoot}/Images/PlateBG/${o}.png`,a.onload=()=>{const d=this.createCanvas(a,r,n);if(!d)t("canvas创建失败");else{const f=new h.CanvasTexture(d),v=new h.SpriteMaterial({map:f,transparent:!1}),m=new h.Sprite(v),M=.05,y=d.width*M,w=d.height*M;m.scale.set(y,w,1),m.name="VehiclePlate",e(m)}a.onerror=f=>{console.log(`号牌背景加载失败: ${a.src}`,f),t(f)}}})}}exports.default=x;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const k=require("@arcgis/core/Basemap"),
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const k=require("@arcgis/core/Basemap"),z=require("@arcgis/core/Map"),b=require("@arcgis/core/config"),q=require("@arcgis/core/core/reactiveUtils"),g=require("@arcgis/core/geometry"),O=require("@arcgis/core/geometry/support/webMercatorUtils"),S=require("@arcgis/core/layers/GeoJSONLayer"),W=require("@arcgis/core/layers/TileLayer"),x=require("@arcgis/core/layers/WebTileLayer"),L=require("@arcgis/core/views/MapView"),R=require("@arcgis/core/views/SceneView"),H=require("@turf/destination"),I=require("@turf/helpers"),_=require("../stores/index.js");function v(r){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const i in r)if(i!=="default"){const t=Object.getOwnPropertyDescriptor(r,i);Object.defineProperty(e,i,t.get?t:{enumerable:!0,get:()=>r[i]})}}return e.default=r,Object.freeze(e)}const T=v(q),p=v(O),G=v(I);function y(r,e){return r.startsWith("http://")||r.startsWith("https://")?r:e+r}class N{constructor(){this.mapConfig={},this.watchHandleMap=new Map,this.handleIndex=0,this.zoomWatchHandle=null}async initialize(e){const i=_.default.useAppDataStore,t=JSON.parse(JSON.stringify(i.mapConfig));this.mapConfig=t;const{container:a,markerClickCallback:n,mapClickCallback:f}=e;b.assetsPath=`${t.assetsRoot}/ArcgisAssets`,b.fontsUrl=`${t.assetsRoot}/fonts`,b.apiKey="AAPKf5a3e1044d7a4faeb3b1ec7060f5c68equIrP2KbRyL-t_b40Kk4GTWUQ1BFCyttvyQPQnWpFmBd7kp9gkrVihjfmcKBwxjW";const l=new z;if((t==null?void 0:t.mapOptions.mode.toLowerCase())==="2d"?this.view=new L({map:l,container:a,...t.mapOptions}):this.view=new R({map:l,container:a,...t==null?void 0:t.mapOptions}),this.view.on("click",async s=>{var M,P;if(f){let o=s.mapPoint;o.spatialReference.isWebMercator&&(o=p.webMercatorToGeographic(o)),f([o.x,o.y],[s.screenPoint.x,s.screenPoint.y],s)}if(this.view.type==="3d"){const o=this.view.camera;if(this.view.spatialReference.isWebMercator){const u=p.webMercatorToGeographic(o.position),d={heading:o.heading,tilt:o.tilt,position:u.toJSON()};console.log(d),(M=navigator.clipboard)==null||M.writeText(JSON.stringify(d))}else console.log(o.toJSON());console.log(this.view.zoom,this.view.scale)}else{let o=this.view.center;this.view.spatialReference.isWebMercator&&(o=p.webMercatorToGeographic(o)),console.log({center:o.toJSON(),zoom:this.view.zoom})}const h=(P=(await this.view.hitTest(s)).results)==null?void 0:P.filter(o=>o.type==="graphic");h.length>0&&h.forEach(o=>{var d;const u=o.graphic;(d=u.attributes)!=null&&d.type&&n&&n(u.attributes.type,u.attributes.id,u.attributes,s)})}),t!=null&&t.baseLayers?t.baseLayers.forEach(s=>{switch(s.type.toLowerCase()){case"webTile".toLowerCase():{const c=y(s.url,t.assetsRoot),h=new x({urlTemplate:c,...s.options});l.add(h);break}case"tile":{const c=y(s.url,t.assetsRoot),h=new W({url:c,...s.options});l.add(h);break}case"arcgis":{const c=new k(s.options);l.basemap=c;break}}}):l.basemap=new k({style:{id:"arcgis/dark-gray",language:"zh-CN"}}),t!=null&&t.hdLayers){const s=t.hdLayers.map(c=>new S({url:y(c.url,t.assetsRoot),...c.options,title:c.options.id}));l.addMany(s)}this.view.ui.remove("attribution"),this.view.ui.add("compass","top-left"),await this.view.when();const w=this.mapConfig.camera;let m;if(this.view.type==="2d"){let s=this.view.center;this.view.spatialReference.isWebMercator&&(s=p.webMercatorToGeographic(s)),m={center:[s.x,s.y],zoom:this.view.zoom}}else{let s=this.view.camera.position;this.view.spatialReference.isWebMercator&&(s=p.webMercatorToGeographic(s)),m={position:s,heading:this.view.camera.heading,tilt:this.view.camera.tilt}}return w?w.home=m:this.mapConfig.camera={home:m},this.view}setLayerVisibility(e){const{id:i,visible:t}=e,a=this.view.map.findLayerById(i);return a?(a.visible=t,{status:0,message:"ok"}):{status:-1,message:"未找到图层"}}async setMapCenter(e){var i;if(!this.view)return{status:-1,message:"未初始化"};if(e.center||e.target){switch((i=e.target)==null?void 0:i.type){case"point":e.target=new g.Point(e.target);break;case"polyline":e.target=new g.Polyline(e.target);break;case"polygon":e.target=new g.Polygon(e.target);break}await this.view.goTo(e,{duration:(e.duration||0)*1e3})}return{status:0,message:"成功"}}async lookAt(e){if(this.view.type==="2d")return;const i=e.tilt||0,t=e.heading||0;if(i===0)await this.view.goTo({position:{x:e.center[0],y:e.center[1],z:e.height},heading:t,tilt:0},{duration:(e.duration||2)*1e3});else{const a=Math.tan(i*Math.PI/180)*e.height,n=H(G.point(e.center),a,t+180,{units:"meters"});await this.view.goTo({position:{x:n.geometry.coordinates[0],y:n.geometry.coordinates[1],z:e.height},heading:t,tilt:i},{duration:(e.duration||2)*1e3})}}async setMapCamera(e){if(!this.view)return{status:-1,message:"未初始化"};const{name:i,duration:t=0}=e,{camera:a}=this.mapConfig;if(!a)return{status:-1,message:"未配置camera"};const n=a[i];return n?(await this.view.goTo(n,{duration:t*1e3}),{status:0,message:"成功"}):{status:-1,message:"未配置camera"}}requestCoordinateTransform(e,i){let t=0;const n=1e3/30,f=T.watch(()=>this.view.center,()=>{const l=this.transformPoints(e),w=Date.now();w-t>n&&(i(l),t=w)});return this.handleIndex++,this.watchHandleMap.set(this.handleIndex,f),{handle:this.handleIndex,points:this.transformPoints(e)}}transformPoints(e){return e.map(i=>{const t=new g.Point({x:i[0],y:i[1]}),a=this.view.toScreen(t);return[a.x,a.y]})}cancelCoordinateTransform(e){const i=this.watchHandleMap.get(e);i&&(i.remove(),this.watchHandleMap.delete(e))}setMapZoomRange(e){const{min:i,max:t}=e;!i&&!t||(this.zoomWatchHandle&&this.zoomWatchHandle.remove(),this.zoomWatchHandle=T.watch(()=>this.view.zoom,a=>{i&&a<=i&&(this.view.zoom=i),t&&a>=t&&(this.view.zoom=t)}))}}exports.default=N;
|
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;
|