gisviewer-vue3-arcgis 1.0.106 → 1.0.107
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/src/gis-map/utils/holo-flow/trace-renderer-external.d.ts +1 -1
- package/es/src/gis-map/utils/holo-flow/trace-renderer-external.mjs +55 -58
- package/es/src/gis-map/utils/map-initializer.mjs +1 -1
- package/lib/src/gis-map/utils/holo-flow/trace-renderer-external.d.ts +1 -1
- package/lib/src/gis-map/utils/holo-flow/trace-renderer-external.js +1 -1
- package/lib/src/gis-map/utils/map-initializer.js +1 -1
- package/package.json +1 -1
|
@@ -6,7 +6,7 @@ export default class TraceRendererExternal implements ITraceRendererInterface {
|
|
|
6
6
|
private ambient;
|
|
7
7
|
private sun;
|
|
8
8
|
/** 车辆模型变化的阈值 */
|
|
9
|
-
private readonly
|
|
9
|
+
private readonly cameraHeightThreshold;
|
|
10
10
|
/** 车辆材质参数 */
|
|
11
11
|
private readonly roughness;
|
|
12
12
|
private readonly metalness;
|
|
@@ -7,11 +7,8 @@ import { EVehiclePlateState as d } from "../../../types/index.mjs";
|
|
|
7
7
|
import P from "../../stores/index.mjs";
|
|
8
8
|
class k {
|
|
9
9
|
constructor(i) {
|
|
10
|
-
this.
|
|
11
|
-
color: 16777215
|
|
12
|
-
emissive: 0,
|
|
13
|
-
roughness: this.roughness,
|
|
14
|
-
metalness: this.metalness
|
|
10
|
+
this.cameraHeightThreshold = 1e3, this.roughness = 0.2, this.metalness = 0.8, this.defaultMaterial = new h.MeshPhongMaterial({
|
|
11
|
+
color: 16777215
|
|
15
12
|
}), this.materialMap = /* @__PURE__ */ new Map([
|
|
16
13
|
[1, this.createCarMaterial(16777215)],
|
|
17
14
|
[2, this.createCarMaterial(7833753)],
|
|
@@ -48,17 +45,17 @@ class k {
|
|
|
48
45
|
!1
|
|
49
46
|
), y.watch(
|
|
50
47
|
() => this.view.camera.position.z,
|
|
51
|
-
(s,
|
|
52
|
-
(
|
|
48
|
+
(s, a) => {
|
|
49
|
+
(a <= this.cameraHeightThreshold && s > this.cameraHeightThreshold || a > this.cameraHeightThreshold && s <= this.cameraHeightThreshold) && (this.updateModel = !0);
|
|
53
50
|
}
|
|
54
51
|
);
|
|
55
52
|
}
|
|
56
53
|
createCarMaterial(i) {
|
|
57
|
-
return new h.
|
|
58
|
-
color: i
|
|
59
|
-
emissive:
|
|
60
|
-
roughness: this.roughness,
|
|
61
|
-
metalness: this.metalness
|
|
54
|
+
return new h.MeshPhongMaterial({
|
|
55
|
+
color: i
|
|
56
|
+
// emissive: 0xc3c3c3,
|
|
57
|
+
// roughness: this.roughness,
|
|
58
|
+
// metalness: this.metalness
|
|
62
59
|
});
|
|
63
60
|
}
|
|
64
61
|
setInterpolate(i) {
|
|
@@ -85,17 +82,17 @@ class k {
|
|
|
85
82
|
0.1,
|
|
86
83
|
1e5
|
|
87
84
|
), this.ambient = new h.AmbientLight(16777215, 2e4), this.scene.add(this.ambient), this.sun = new h.DirectionalLight(16777215, 2e4);
|
|
88
|
-
const s = [121.51925377934634, 31.893973071723785, 1e4],
|
|
85
|
+
const s = [121.51925377934634, 31.893973071723785, 1e4], a = this.toRenderCoordinates(s);
|
|
89
86
|
this.sun.position.set(
|
|
90
|
-
o[0],
|
|
91
|
-
o[1],
|
|
92
|
-
o[2]
|
|
93
|
-
);
|
|
94
|
-
const r = [121.46790813287619, 31.239514870157972, 1e3], a = this.toRenderCoordinates(r);
|
|
95
|
-
this.sun.target.position.set(
|
|
96
87
|
a[0],
|
|
97
88
|
a[1],
|
|
98
89
|
a[2]
|
|
90
|
+
);
|
|
91
|
+
const r = [121.46790813287619, 31.239514870157972, 1e3], o = this.toRenderCoordinates(r);
|
|
92
|
+
this.sun.target.position.set(
|
|
93
|
+
o[0],
|
|
94
|
+
o[1],
|
|
95
|
+
o[2]
|
|
99
96
|
), this.scene.add(this.sun), i.resetWebGLState();
|
|
100
97
|
}
|
|
101
98
|
async render(i) {
|
|
@@ -104,14 +101,14 @@ class k {
|
|
|
104
101
|
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(
|
|
105
102
|
new h.Vector3(e.center[0], e.center[1], e.center[2])
|
|
106
103
|
), this.camera.projectionMatrix.fromArray(e.projectionMatrix), !this.isPaused && this.needInterpolate)
|
|
107
|
-
for (const
|
|
108
|
-
const r = (s = this.vehicleObjectMap.get(
|
|
104
|
+
for (const a of this.vehicleObjectMap.keys()) {
|
|
105
|
+
const r = (s = this.vehicleObjectMap.get(a)) == null ? void 0 : s.model;
|
|
109
106
|
if (!r)
|
|
110
107
|
continue;
|
|
111
|
-
const
|
|
112
|
-
if (
|
|
113
|
-
const n = this.toRenderCoordinates(
|
|
114
|
-
r.position.set(n[0], n[1], n[2]), r.rotation.y = h.MathUtils.degToRad(-
|
|
108
|
+
const o = this.computeVehiclePosition(a);
|
|
109
|
+
if (o) {
|
|
110
|
+
const n = this.toRenderCoordinates(o);
|
|
111
|
+
r.position.set(n[0], n[1], n[2]), r.rotation.y = h.MathUtils.degToRad(-o[3]);
|
|
115
112
|
}
|
|
116
113
|
}
|
|
117
114
|
const t = i.sunLight;
|
|
@@ -131,9 +128,9 @@ class k {
|
|
|
131
128
|
async addVehicles(i) {
|
|
132
129
|
if (!(this.isPaused || !this.carModelReady || !this.vanModelReady || !this.truckModelReady || !this.busModelReady || !this.bicycleModelReady))
|
|
133
130
|
for (const e of i) {
|
|
134
|
-
const { vehicleId: t, localTimestamp: s } = e,
|
|
131
|
+
const { vehicleId: t, localTimestamp: s } = e, a = Number(e.x), r = Number(e.y), o = Number(e.heading);
|
|
135
132
|
this.historyPositionMap.set(t, [
|
|
136
|
-
{ pos: [
|
|
133
|
+
{ pos: [a, r, 0], heading: o, time: s }
|
|
137
134
|
]);
|
|
138
135
|
const n = this.getVehicleModel(e);
|
|
139
136
|
n.name = t, n.visible = !this.needInterpolate;
|
|
@@ -159,7 +156,7 @@ class k {
|
|
|
159
156
|
return;
|
|
160
157
|
const e = [];
|
|
161
158
|
for (const t of i) {
|
|
162
|
-
const { vehicleId: s, localTimestamp:
|
|
159
|
+
const { vehicleId: s, localTimestamp: a } = t, r = Number(t.x), o = Number(t.y);
|
|
163
160
|
let n = Number(t.heading);
|
|
164
161
|
const l = this.vehicleObjectMap.get(s), m = this.historyPositionMap.get(
|
|
165
162
|
s
|
|
@@ -181,15 +178,15 @@ class k {
|
|
|
181
178
|
if (l.data = t, this.needInterpolate) {
|
|
182
179
|
const c = m[m.length - 1];
|
|
183
180
|
Math.abs(n - c.heading) >= 180 && (n > c.heading ? c.heading += 360 : n += 360), m.push({
|
|
184
|
-
pos: [r,
|
|
181
|
+
pos: [r, o, 0],
|
|
185
182
|
heading: n,
|
|
186
|
-
time:
|
|
183
|
+
time: a
|
|
187
184
|
});
|
|
188
185
|
} else {
|
|
189
186
|
this.historyPositionMap.set(s, [
|
|
190
|
-
{ pos: [r,
|
|
187
|
+
{ pos: [r, o, 0], heading: n, time: a }
|
|
191
188
|
]);
|
|
192
|
-
const c = this.toRenderCoordinates([r,
|
|
189
|
+
const c = this.toRenderCoordinates([r, o, 0]);
|
|
193
190
|
l.model.position.set(c[0], c[1], c[2]), l.model.rotation.y = h.MathUtils.degToRad(-n);
|
|
194
191
|
}
|
|
195
192
|
}
|
|
@@ -254,8 +251,8 @@ class k {
|
|
|
254
251
|
if (t) {
|
|
255
252
|
const s = t.model.getObjectByName("VehiclePlate");
|
|
256
253
|
if (s && (t.model.remove(s), this.disposeModel(s)), i !== d.None) {
|
|
257
|
-
const
|
|
258
|
-
|
|
254
|
+
const a = await this.createPlateSprite(t.data);
|
|
255
|
+
a && (t.model.add(a), a.position.set(0, 5, -4));
|
|
259
256
|
}
|
|
260
257
|
}
|
|
261
258
|
}
|
|
@@ -284,8 +281,8 @@ class k {
|
|
|
284
281
|
return;
|
|
285
282
|
const s = Date.now();
|
|
286
283
|
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);
|
|
287
|
-
const
|
|
288
|
-
|
|
284
|
+
const a = s - t.segmentStartTime, r = Math.min(
|
|
285
|
+
a / t.segmentTotalTime,
|
|
289
286
|
1
|
|
290
287
|
);
|
|
291
288
|
if (r === 1)
|
|
@@ -295,15 +292,15 @@ class k {
|
|
|
295
292
|
} else
|
|
296
293
|
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);
|
|
297
294
|
else {
|
|
298
|
-
const
|
|
299
|
-
return [
|
|
295
|
+
const o = e[0].pos[0] + (e[1].pos[0] - e[0].pos[0]) * r, n = e[0].pos[1] + (e[1].pos[1] - e[0].pos[1]) * r, l = e[0].heading + (e[1].heading - e[0].heading) * r;
|
|
296
|
+
return [o, n, 0, l];
|
|
300
297
|
}
|
|
301
298
|
}
|
|
302
299
|
/**
|
|
303
300
|
* 根据车辆类型、车身颜色获取模型
|
|
304
301
|
* */
|
|
305
302
|
getVehicleModel(i) {
|
|
306
|
-
if (this.view.camera.position.z >= this.
|
|
303
|
+
if (this.view.camera.position.z >= this.cameraHeightThreshold) {
|
|
307
304
|
const e = new h.SphereGeometry(5, 32, 32), t = new h.MeshPhysicalMaterial({
|
|
308
305
|
color: 325253,
|
|
309
306
|
emissive: 0,
|
|
@@ -335,8 +332,8 @@ class k {
|
|
|
335
332
|
}
|
|
336
333
|
const t = this.materialMap.get(i.vehicleColor) || this.defaultMaterial;
|
|
337
334
|
let s = !1;
|
|
338
|
-
e.traverse((
|
|
339
|
-
!s &&
|
|
335
|
+
e.traverse((a) => {
|
|
336
|
+
!s && a instanceof h.Mesh && (a.material = t, s = !0);
|
|
340
337
|
});
|
|
341
338
|
}
|
|
342
339
|
return e;
|
|
@@ -346,14 +343,14 @@ class k {
|
|
|
346
343
|
* 创建号牌canvas
|
|
347
344
|
* */
|
|
348
345
|
createCanvas(i, e, t) {
|
|
349
|
-
const s = document.createElement("canvas"),
|
|
350
|
-
s.width =
|
|
351
|
-
const
|
|
352
|
-
if (!
|
|
346
|
+
const s = document.createElement("canvas"), a = i.width, r = i.height;
|
|
347
|
+
s.width = a, s.height = r;
|
|
348
|
+
const o = s.getContext("2d");
|
|
349
|
+
if (!o) {
|
|
353
350
|
console.log("canvas创建失败");
|
|
354
351
|
return;
|
|
355
352
|
}
|
|
356
|
-
return
|
|
353
|
+
return o.fillStyle = "rgba(0,0,0,0.0)", o.fillRect(0, 0, a, r), o.drawImage(i, 0, 0, a, r), o.beginPath(), o.translate(a / 2, r / 2), o.fillStyle = t, o.font = "bold 32px 宋体", o.textBaseline = "middle", o.textAlign = "center", o.fillText(e, 0, 0), s;
|
|
357
354
|
}
|
|
358
355
|
createPlateSprite(i) {
|
|
359
356
|
return new Promise((e, t) => {
|
|
@@ -363,13 +360,13 @@ class k {
|
|
|
363
360
|
e(void 0);
|
|
364
361
|
return;
|
|
365
362
|
}
|
|
366
|
-
const
|
|
367
|
-
let r = "",
|
|
363
|
+
const a = new Image();
|
|
364
|
+
let r = "", o = "", n = "";
|
|
368
365
|
if (this.currentSpriteContent === d.PlateNumber || this.currentSpriteContent === d.Mix)
|
|
369
366
|
if (s)
|
|
370
|
-
r = "grey",
|
|
367
|
+
r = "grey", o = i.ptcId, n = "#ffffff";
|
|
371
368
|
else
|
|
372
|
-
switch (
|
|
369
|
+
switch (o = ((l = i.showName) == null ? void 0 : l.substring(0, 2)) + "•" + ((m = i.showName) == null ? void 0 : m.substring(2)), i.plateColor) {
|
|
373
370
|
case 1:
|
|
374
371
|
r = "blue", n = "#ffffff";
|
|
375
372
|
break;
|
|
@@ -389,24 +386,24 @@ class k {
|
|
|
389
386
|
r = "neo_green", n = "#000000";
|
|
390
387
|
break;
|
|
391
388
|
default:
|
|
392
|
-
r = "grey",
|
|
389
|
+
r = "grey", o = i.plateNo, n = "#ffffff";
|
|
393
390
|
break;
|
|
394
391
|
}
|
|
395
392
|
else
|
|
396
|
-
this.currentSpriteContent === d.Id && (r = "grey",
|
|
397
|
-
|
|
398
|
-
const c = this.createCanvas(
|
|
393
|
+
this.currentSpriteContent === d.Id && (r = "grey", o = i.ptcId, n = "#ffffff");
|
|
394
|
+
a.src = `${this.assetsRoot}/Images/PlateBG/${r}.png`, a.onload = () => {
|
|
395
|
+
const c = this.createCanvas(a, o, n);
|
|
399
396
|
if (!c)
|
|
400
397
|
t("canvas创建失败");
|
|
401
398
|
else {
|
|
402
399
|
const p = new h.CanvasTexture(c), M = new h.SpriteMaterial({
|
|
403
400
|
map: p,
|
|
404
401
|
transparent: !1
|
|
405
|
-
}),
|
|
406
|
-
|
|
402
|
+
}), f = new h.Sprite(M), u = 0.05, b = c.width * u, v = c.height * u;
|
|
403
|
+
f.scale.set(b, v, 1), f.name = "VehiclePlate", e(f);
|
|
407
404
|
}
|
|
408
|
-
|
|
409
|
-
console.log(`号牌背景加载失败: ${
|
|
405
|
+
a.onerror = (p) => {
|
|
406
|
+
console.log(`号牌背景加载失败: ${a.src}`, p), t(p);
|
|
410
407
|
};
|
|
411
408
|
};
|
|
412
409
|
});
|
|
@@ -6,7 +6,7 @@ export default class TraceRendererExternal implements ITraceRendererInterface {
|
|
|
6
6
|
private ambient;
|
|
7
7
|
private sun;
|
|
8
8
|
/** 车辆模型变化的阈值 */
|
|
9
|
-
private readonly
|
|
9
|
+
private readonly cameraHeightThreshold;
|
|
10
10
|
/** 车辆材质参数 */
|
|
11
11
|
private readonly roughness;
|
|
12
12
|
private readonly metalness;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const P=require("@arcgis/core/core/reactiveUtils.js"),R=require("@arcgis/core/geometry/SpatialReference"),S=require("@arcgis/core/views/3d/externalRenderers"),C=require("three"),T=require("three/examples/jsm/loaders/GLTFLoader.js"),d=require("../../../types/index.js"),V=require("../../stores/index.js");function g(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 N=g(P),b=g(S),h=g(C);class k{constructor(i){this.zoomThreshold=1e3,this.roughness=.2,this.metalness=.8,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.isPaused=!1,this.currentSpriteContent=d.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),N.watch(()=>this.view.camera.position.z,(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=n=>{e(n),n==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.51925377934634,31.893973071723785,1e4],a=this.toRenderCoordinates(s);this.sun.position.set(a[0],a[1],a[2]);const r=[121.46790813287619,31.239514870157972,1e3],o=this.toRenderCoordinates(r);this.sun.target.position.set(o[0],o[1],o[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.isPaused&&this.needInterpolate)for(const a of this.vehicleObjectMap.keys()){const r=(s=this.vehicleObjectMap.get(a))==null?void 0:s.model;if(!r)continue;const o=this.computeVehiclePosition(a);if(o){const n=this.toRenderCoordinates(o);r.position.set(n[0],n[1],n[2]),r.rotation.y=h.MathUtils.degToRad(-o[3])}}const t=i.sunLight;this.sun.position.set(t.direction[0],t.direction[1],t.direction[2]),this.sun.intensity=t.diffuse.intensity,this.sun.color=new 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.isPaused||!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),r=Number(e.y),o=Number(e.heading);this.historyPositionMap.set(t,[{pos:[a,r,0],heading:o,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))}catch(l){console.log("createPlateSprite error:",l)}this.scene.add(n),this.vehicleObjectMap.set(t,{model:n,data:e,waitForDelete:!1,isMoving:!1})}}async updateVehicles(i){if(this.isPaused||!this.carModelReady||!this.vanModelReady||!this.truckModelReady||!this.busModelReady||!this.bicycleModelReady)return;const e=[];for(const t of i){const{vehicleId:s,localTimestamp:a}=t,r=Number(t.x),o=Number(t.y);let n=Number(t.heading);const l=this.vehicleObjectMap.get(s),p=this.historyPositionMap.get(s);if(!l||!p)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 u=await this.createPlateSprite(t);u&&(l.model.add(u),u.position.set(0,5,-4))}if(l.data=t,this.needInterpolate){const c=p[p.length-1];Math.abs(n-c.heading)>=180&&(n>c.heading?c.heading+=360:n+=360),p.push({pos:[r,o,0],heading:n,time:a})}else{this.historyPositionMap.set(s,[{pos:[r,o,0],heading:n,time:a}]);const c=this.toRenderCoordinates([r,o,0]);l.model.position.set(c[0],c[1],c[2]),l.model.rotation.y=h.MathUtils.degToRad(-n)}}}await this.addVehicles(e),this.updateModel=!1,this.needInterpolate||this.render(this.context)}toRenderCoordinates(i){const e=[0,0,0];return b.toRenderCoordinates(this.view,i,0,R.WGS84,e,0,1),e}deleteVehicles(i){this.isPaused||i.forEach(e=>{const t=this.vehicleObjectMap.get(e);t&&(this.needInterpolate?t.isMoving?t.waitForDelete=!0:this.deleteVehicle(t):this.deleteVehicle(t))})}deleteVehicle(i){this.scene.remove(i.model),this.disposeModel(i.model);const e=i.data.vehicleId;this.vehicleObjectMap.delete(e),this.historyPositionMap.delete(e)}async toggleTrafficInfo(i){i.name==="vehiclePlate"&&(i.visible===!0&&this.currentSpriteContent===d.EVehiclePlateState.None?await this.updatePanelContent(d.EVehiclePlateState.PlateNumber):await this.updatePanelContent(i.visible?this.currentSpriteContent:d.EVehiclePlateState.None))}togglePause(i){this.isPaused=i}clearVehicles(){for(const i of this.vehicleObjectMap.keys()){const e=this.vehicleObjectMap.get(i);e&&(this.disposeModel(e.model),this.scene.remove(e.model))}this.vehicleObjectMap.clear(),this.historyPositionMap.clear()}async updatePanelContent(i){if(i!==this.currentSpriteContent){this.currentSpriteContent=i;for(const e of this.vehicleObjectMap.keys()){const t=this.vehicleObjectMap.get(e);if(t){const s=t.model.getObjectByName("VehiclePlate");if(s&&(t.model.remove(s),this.disposeModel(s)),i!==d.EVehiclePlateState.None){const a=await this.createPlateSprite(t.data);a&&(t.model.add(a),a.position.set(0,5,-4))}}}}}toggleGroundVehicle(i){console.log("toggleGroundVehicle",i),this.showGroundVehicle=i}toggleElevatedVehicle(i){this.showElevatedVehicle=i}disposeModel(i){i.traverse(e=>{e instanceof 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,r=Math.min(a/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("hide vehicle",i));return}else return t.segmentStartTime=Date.now(),t.segmentTotalTime=e[1].time-e[0].time,(e[1].heading>=270&&e[0].heading<=90||e[1].heading<=90&&e[0].heading>=270)&&(e[1].heading>e[0].heading?e[0].heading+=360:e[1].heading+=360),e[0].pos.concat(e[0].heading);else{const o=e[0].pos[0]+(e[1].pos[0]-e[0].pos[0])*r,n=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[o,n,0,l]}}getVehicleModel(i){if(this.view.camera.position.z>=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,r=i.height;s.width=a,s.height=r;const o=s.getContext("2d");if(!o){console.log("canvas创建失败");return}return o.fillStyle="rgba(0,0,0,0.0)",o.fillRect(0,0,a,r),o.drawImage(i,0,0,a,r),o.beginPath(),o.translate(a/2,r/2),o.fillStyle=t,o.font="bold 32px 宋体",o.textBaseline="middle",o.textAlign="center",o.fillText(e,0,0),s}createPlateSprite(i){return new Promise((e,t)=>{var l,p;const s=!i.plateNo||i.plateNo==="0"||i.plateNo==="000000";if(this.currentSpriteContent===d.EVehiclePlateState.None||this.currentSpriteContent===d.EVehiclePlateState.PlateNumber&&s){e(void 0);return}const a=new Image;let r="",o="",n="";if(this.currentSpriteContent===d.EVehiclePlateState.PlateNumber||this.currentSpriteContent===d.EVehiclePlateState.Mix)if(s)r="grey",o=i.ptcId,n="#ffffff";else switch(o=((l=i.showName)==null?void 0:l.substring(0,2))+"•"+((p=i.showName)==null?void 0:p.substring(2)),i.plateColor){case 1:r="blue",n="#ffffff";break;case 2:r="yellow",n="#000000";break;case 3:r="white",n="#000000";break;case 4:r="black";break;case 5:r="neo_yellow",n="#000000";break;case 6:r="neo_green",n="#000000";break;default:r="grey",o=i.plateNo,n="#ffffff";break}else this.currentSpriteContent===d.EVehiclePlateState.Id&&(r="grey",o=i.ptcId,n="#ffffff");a.src=`${this.assetsRoot}/Images/PlateBG/${r}.png`,a.onload=()=>{const c=this.createCanvas(a,o,n);if(!c)t("canvas创建失败");else{const u=new h.CanvasTexture(c),v=new h.SpriteMaterial({map:u,transparent:!1}),m=new h.Sprite(v),M=.05,y=c.width*M,w=c.height*M;m.scale.set(y,w,1),m.name="VehiclePlate",e(m)}a.onerror=u=>{console.log(`号牌背景加载失败: ${a.src}`,u),t(u)}}})}}exports.default=k;
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const P=require("@arcgis/core/core/reactiveUtils.js"),R=require("@arcgis/core/geometry/SpatialReference"),S=require("@arcgis/core/views/3d/externalRenderers"),C=require("three"),T=require("three/examples/jsm/loaders/GLTFLoader.js"),d=require("../../../types/index.js"),V=require("../../stores/index.js");function g(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 N=g(P),b=g(S),h=g(C);class k{constructor(i){this.cameraHeightThreshold=1e3,this.roughness=.2,this.metalness=.8,this.defaultMaterial=new h.MeshPhongMaterial({color:16777215}),this.materialMap=new Map([[1,this.createCarMaterial(16777215)],[2,this.createCarMaterial(7833753)],[3,this.createCarMaterial(16766720)],[4,this.createCarMaterial(16758465)],[5,this.createCarMaterial(14423100)],[6,this.createCarMaterial(3329330)],[7,this.createCarMaterial(2003183)],[8,this.createCarMaterial(16032864)],[9,this.createCarMaterial(2105376)],[10,this.createCarMaterial(9662683)],[99,this.createCarMaterial(6908265)]]),this.carModelReady=!1,this.vanModelReady=!1,this.truckModelReady=!1,this.busModelReady=!1,this.bicycleModelReady=!1,this.showGroundVehicle=!0,this.showElevatedVehicle=!0,this.isPaused=!1,this.currentSpriteContent=d.EVehiclePlateState.None,this.historyPositionMap=new Map,this.vehicleObjectMap=new Map,this.needInterpolate=!0,this.updateModel=!1;const e=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),N.watch(()=>this.view.camera.position.z,(s,a)=>{(a<=this.cameraHeightThreshold&&s>this.cameraHeightThreshold||a>this.cameraHeightThreshold&&s<=this.cameraHeightThreshold)&&(this.updateModel=!0)})}createCarMaterial(i){return new h.MeshPhongMaterial({color:i})}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=n=>{e(n),n==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.51925377934634,31.893973071723785,1e4],a=this.toRenderCoordinates(s);this.sun.position.set(a[0],a[1],a[2]);const r=[121.46790813287619,31.239514870157972,1e3],o=this.toRenderCoordinates(r);this.sun.target.position.set(o[0],o[1],o[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.isPaused&&this.needInterpolate)for(const a of this.vehicleObjectMap.keys()){const r=(s=this.vehicleObjectMap.get(a))==null?void 0:s.model;if(!r)continue;const o=this.computeVehiclePosition(a);if(o){const n=this.toRenderCoordinates(o);r.position.set(n[0],n[1],n[2]),r.rotation.y=h.MathUtils.degToRad(-o[3])}}const t=i.sunLight;this.sun.position.set(t.direction[0],t.direction[1],t.direction[2]),this.sun.intensity=t.diffuse.intensity,this.sun.color=new 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.isPaused||!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),r=Number(e.y),o=Number(e.heading);this.historyPositionMap.set(t,[{pos:[a,r,0],heading:o,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))}catch(l){console.log("createPlateSprite error:",l)}this.scene.add(n),this.vehicleObjectMap.set(t,{model:n,data:e,waitForDelete:!1,isMoving:!1})}}async updateVehicles(i){if(this.isPaused||!this.carModelReady||!this.vanModelReady||!this.truckModelReady||!this.busModelReady||!this.bicycleModelReady)return;const e=[];for(const t of i){const{vehicleId:s,localTimestamp:a}=t,r=Number(t.x),o=Number(t.y);let n=Number(t.heading);const l=this.vehicleObjectMap.get(s),p=this.historyPositionMap.get(s);if(!l||!p)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 u=await this.createPlateSprite(t);u&&(l.model.add(u),u.position.set(0,5,-4))}if(l.data=t,this.needInterpolate){const c=p[p.length-1];Math.abs(n-c.heading)>=180&&(n>c.heading?c.heading+=360:n+=360),p.push({pos:[r,o,0],heading:n,time:a})}else{this.historyPositionMap.set(s,[{pos:[r,o,0],heading:n,time:a}]);const c=this.toRenderCoordinates([r,o,0]);l.model.position.set(c[0],c[1],c[2]),l.model.rotation.y=h.MathUtils.degToRad(-n)}}}await this.addVehicles(e),this.updateModel=!1,this.needInterpolate||this.render(this.context)}toRenderCoordinates(i){const e=[0,0,0];return b.toRenderCoordinates(this.view,i,0,R.WGS84,e,0,1),e}deleteVehicles(i){this.isPaused||i.forEach(e=>{const t=this.vehicleObjectMap.get(e);t&&(this.needInterpolate?t.isMoving?t.waitForDelete=!0:this.deleteVehicle(t):this.deleteVehicle(t))})}deleteVehicle(i){this.scene.remove(i.model),this.disposeModel(i.model);const e=i.data.vehicleId;this.vehicleObjectMap.delete(e),this.historyPositionMap.delete(e)}async toggleTrafficInfo(i){i.name==="vehiclePlate"&&(i.visible===!0&&this.currentSpriteContent===d.EVehiclePlateState.None?await this.updatePanelContent(d.EVehiclePlateState.PlateNumber):await this.updatePanelContent(i.visible?this.currentSpriteContent:d.EVehiclePlateState.None))}togglePause(i){this.isPaused=i}clearVehicles(){for(const i of this.vehicleObjectMap.keys()){const e=this.vehicleObjectMap.get(i);e&&(this.disposeModel(e.model),this.scene.remove(e.model))}this.vehicleObjectMap.clear(),this.historyPositionMap.clear()}async updatePanelContent(i){if(i!==this.currentSpriteContent){this.currentSpriteContent=i;for(const e of this.vehicleObjectMap.keys()){const t=this.vehicleObjectMap.get(e);if(t){const s=t.model.getObjectByName("VehiclePlate");if(s&&(t.model.remove(s),this.disposeModel(s)),i!==d.EVehiclePlateState.None){const a=await this.createPlateSprite(t.data);a&&(t.model.add(a),a.position.set(0,5,-4))}}}}}toggleGroundVehicle(i){console.log("toggleGroundVehicle",i),this.showGroundVehicle=i}toggleElevatedVehicle(i){this.showElevatedVehicle=i}disposeModel(i){i.traverse(e=>{e instanceof 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,r=Math.min(a/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("hide vehicle",i));return}else return t.segmentStartTime=Date.now(),t.segmentTotalTime=e[1].time-e[0].time,(e[1].heading>=270&&e[0].heading<=90||e[1].heading<=90&&e[0].heading>=270)&&(e[1].heading>e[0].heading?e[0].heading+=360:e[1].heading+=360),e[0].pos.concat(e[0].heading);else{const o=e[0].pos[0]+(e[1].pos[0]-e[0].pos[0])*r,n=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[o,n,0,l]}}getVehicleModel(i){if(this.view.camera.position.z>=this.cameraHeightThreshold){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,r=i.height;s.width=a,s.height=r;const o=s.getContext("2d");if(!o){console.log("canvas创建失败");return}return o.fillStyle="rgba(0,0,0,0.0)",o.fillRect(0,0,a,r),o.drawImage(i,0,0,a,r),o.beginPath(),o.translate(a/2,r/2),o.fillStyle=t,o.font="bold 32px 宋体",o.textBaseline="middle",o.textAlign="center",o.fillText(e,0,0),s}createPlateSprite(i){return new Promise((e,t)=>{var l,p;const s=!i.plateNo||i.plateNo==="0"||i.plateNo==="000000";if(this.currentSpriteContent===d.EVehiclePlateState.None||this.currentSpriteContent===d.EVehiclePlateState.PlateNumber&&s){e(void 0);return}const a=new Image;let r="",o="",n="";if(this.currentSpriteContent===d.EVehiclePlateState.PlateNumber||this.currentSpriteContent===d.EVehiclePlateState.Mix)if(s)r="grey",o=i.ptcId,n="#ffffff";else switch(o=((l=i.showName)==null?void 0:l.substring(0,2))+"•"+((p=i.showName)==null?void 0:p.substring(2)),i.plateColor){case 1:r="blue",n="#ffffff";break;case 2:r="yellow",n="#000000";break;case 3:r="white",n="#000000";break;case 4:r="black";break;case 5:r="neo_yellow",n="#000000";break;case 6:r="neo_green",n="#000000";break;default:r="grey",o=i.plateNo,n="#ffffff";break}else this.currentSpriteContent===d.EVehiclePlateState.Id&&(r="grey",o=i.ptcId,n="#ffffff");a.src=`${this.assetsRoot}/Images/PlateBG/${r}.png`,a.onload=()=>{const c=this.createCanvas(a,o,n);if(!c)t("canvas创建失败");else{const u=new h.CanvasTexture(c),v=new h.SpriteMaterial({map:u,transparent:!1}),m=new h.Sprite(v),M=.05,y=c.width*M,w=c.height*M;m.scale.set(y,w,1),m.name="VehiclePlate",e(m)}a.onerror=u=>{console.log(`号牌背景加载失败: ${a.src}`,u),t(u)}}})}}exports.default=k;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const T=require("@arcgis/core/Basemap"),z=require("@arcgis/core/Map"),y=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 k=v(q),p=v(O),C=v(I);function b(r,e){return r.startsWith("http://")||r.startsWith("https://")?r:e+r}class G{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:o,markerClickCallback:n,mapClickCallback:f}=e;y.assetsPath=`${t.assetsRoot}/ArcgisAssets`,y.fontsUrl=`${t.assetsRoot}/fonts`,y.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:o,...t.mapOptions}):this.view=new R({map:l,container:o,environment:{lighting:{type:"sun",date:new Date("January 1, 2022
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const T=require("@arcgis/core/Basemap"),z=require("@arcgis/core/Map"),y=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 k=v(q),p=v(O),C=v(I);function b(r,e){return r.startsWith("http://")||r.startsWith("https://")?r:e+r}class G{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:o,markerClickCallback:n,mapClickCallback:f}=e;y.assetsPath=`${t.assetsRoot}/ArcgisAssets`,y.fontsUrl=`${t.assetsRoot}/fonts`,y.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:o,...t.mapOptions}):this.view=new R({map:l,container:o,environment:{lighting:{type:"sun",date:new Date("January 1, 2022 07:00:00 UTC")}},...t==null?void 0:t.mapOptions}),this.view.on("click",async s=>{var M,P;if(f){let a=s.mapPoint;a.spatialReference.isWebMercator&&(a=p.webMercatorToGeographic(a)),f([a.x,a.y],[s.screenPoint.x,s.screenPoint.y],s)}if(this.view.type==="3d"){const a=this.view.camera;if(this.view.spatialReference.isWebMercator){const u=p.webMercatorToGeographic(a.position),d={heading:a.heading,tilt:a.tilt,position:u.toJSON()};console.log(d),(M=navigator.clipboard)==null||M.writeText(JSON.stringify(d))}else console.log(a.toJSON());console.log(this.view.zoom,this.view.scale)}else{let a=this.view.center;this.view.spatialReference.isWebMercator&&(a=p.webMercatorToGeographic(a)),console.log({center:a.toJSON(),zoom:this.view.zoom})}const h=(P=(await this.view.hitTest(s)).results)==null?void 0:P.filter(a=>a.type==="graphic");h.length>0&&h.forEach(a=>{var d;const u=a.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=b(s.url,t.assetsRoot),h=new x({urlTemplate:c,...s.options});l.add(h);break}case"tile":{const c=b(s.url,t.assetsRoot),h=new W({url:c,...s.options});l.add(h);break}case"arcgis":{const c=new T(s.options);l.basemap=c;break}}}):l.basemap=new T({style:{id:"arcgis/dark-gray",language:"zh-CN"}}),t!=null&&t.hdLayers){const s=t.hdLayers.map(c=>new S({url:b(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,o=this.view.map.findLayerById(i);return o?(o.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 o=Math.tan(i*Math.PI/180)*e.height,n=H(C.point(e.center),o,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:o}=this.mapConfig;if(!o)return{status:-1,message:"未配置camera"};const n=o[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=k.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]}),o=this.view.toScreen(t);return[o.x,o.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=k.watch(()=>this.view.zoom,o=>{i&&o<=i&&(this.view.zoom=i),t&&o>=t&&(this.view.zoom=t)}))}}exports.default=G;
|