gisviewer-vue3-arcgis 1.0.107 → 1.0.108
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.
|
@@ -53,7 +53,7 @@ class k {
|
|
|
53
53
|
createCarMaterial(i) {
|
|
54
54
|
return new h.MeshPhongMaterial({
|
|
55
55
|
color: i
|
|
56
|
-
// emissive: 0xc3c3c3,
|
|
56
|
+
// // emissive: 0xc3c3c3,
|
|
57
57
|
// roughness: this.roughness,
|
|
58
58
|
// metalness: this.metalness
|
|
59
59
|
});
|
|
@@ -72,8 +72,8 @@ class k {
|
|
|
72
72
|
const e = this.renderer.setRenderTarget.bind(
|
|
73
73
|
this.renderer
|
|
74
74
|
);
|
|
75
|
-
this.renderer.setRenderTarget = (
|
|
76
|
-
e(
|
|
75
|
+
this.renderer.setRenderTarget = (s) => {
|
|
76
|
+
e(s), s == null && i.bindRenderTarget();
|
|
77
77
|
}, this.scene = new h.Scene();
|
|
78
78
|
const { camera: t } = i;
|
|
79
79
|
this.camera = new h.PerspectiveCamera(
|
|
@@ -81,19 +81,7 @@ class k {
|
|
|
81
81
|
t.aspect,
|
|
82
82
|
0.1,
|
|
83
83
|
1e5
|
|
84
|
-
), this.ambient = new h.AmbientLight(16777215,
|
|
85
|
-
const s = [121.51925377934634, 31.893973071723785, 1e4], a = this.toRenderCoordinates(s);
|
|
86
|
-
this.sun.position.set(
|
|
87
|
-
a[0],
|
|
88
|
-
a[1],
|
|
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]
|
|
96
|
-
), this.scene.add(this.sun), i.resetWebGLState();
|
|
84
|
+
), this.ambient = new h.AmbientLight(16777215, 2), this.scene.add(this.ambient), this.sun = new h.DirectionalLight(16777215, 2), this.scene.add(this.sun), i.resetWebGLState();
|
|
97
85
|
}
|
|
98
86
|
async render(i) {
|
|
99
87
|
var s;
|
|
@@ -102,13 +90,13 @@ class k {
|
|
|
102
90
|
new h.Vector3(e.center[0], e.center[1], e.center[2])
|
|
103
91
|
), this.camera.projectionMatrix.fromArray(e.projectionMatrix), !this.isPaused && this.needInterpolate)
|
|
104
92
|
for (const a of this.vehicleObjectMap.keys()) {
|
|
105
|
-
const
|
|
106
|
-
if (!
|
|
93
|
+
const o = (s = this.vehicleObjectMap.get(a)) == null ? void 0 : s.model;
|
|
94
|
+
if (!o)
|
|
107
95
|
continue;
|
|
108
|
-
const
|
|
109
|
-
if (
|
|
110
|
-
const
|
|
111
|
-
|
|
96
|
+
const r = this.computeVehiclePosition(a);
|
|
97
|
+
if (r) {
|
|
98
|
+
const l = this.toRenderCoordinates(r);
|
|
99
|
+
o.position.set(l[0], l[1], l[2]), o.rotation.y = h.MathUtils.degToRad(-r[3]);
|
|
112
100
|
}
|
|
113
101
|
}
|
|
114
102
|
const t = i.sunLight;
|
|
@@ -128,20 +116,20 @@ class k {
|
|
|
128
116
|
async addVehicles(i) {
|
|
129
117
|
if (!(this.isPaused || !this.carModelReady || !this.vanModelReady || !this.truckModelReady || !this.busModelReady || !this.bicycleModelReady))
|
|
130
118
|
for (const e of i) {
|
|
131
|
-
const { vehicleId: t, localTimestamp: s } = e, a = Number(e.x),
|
|
119
|
+
const { vehicleId: t, localTimestamp: s } = e, a = Number(e.x), o = Number(e.y), r = Number(e.heading);
|
|
132
120
|
this.historyPositionMap.set(t, [
|
|
133
|
-
{ pos: [a,
|
|
121
|
+
{ pos: [a, o, 0], heading: r, time: s }
|
|
134
122
|
]);
|
|
135
|
-
const
|
|
136
|
-
|
|
123
|
+
const l = this.getVehicleModel(e);
|
|
124
|
+
l.name = t, l.visible = !this.needInterpolate;
|
|
137
125
|
try {
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
} catch (
|
|
141
|
-
console.log("createPlateSprite error:",
|
|
126
|
+
const n = await this.createPlateSprite(e);
|
|
127
|
+
n && (l.add(n), n.position.set(0, 5, -4));
|
|
128
|
+
} catch (n) {
|
|
129
|
+
console.log("createPlateSprite error:", n);
|
|
142
130
|
}
|
|
143
|
-
this.scene.add(
|
|
144
|
-
model:
|
|
131
|
+
this.scene.add(l), this.vehicleObjectMap.set(t, {
|
|
132
|
+
model: l,
|
|
145
133
|
data: e,
|
|
146
134
|
waitForDelete: !1,
|
|
147
135
|
isMoving: !1
|
|
@@ -156,38 +144,38 @@ class k {
|
|
|
156
144
|
return;
|
|
157
145
|
const e = [];
|
|
158
146
|
for (const t of i) {
|
|
159
|
-
const { vehicleId: s, localTimestamp: a } = t,
|
|
160
|
-
let
|
|
161
|
-
const
|
|
147
|
+
const { vehicleId: s, localTimestamp: a } = t, o = Number(t.x), r = Number(t.y);
|
|
148
|
+
let l = Number(t.heading);
|
|
149
|
+
const n = this.vehicleObjectMap.get(s), m = this.historyPositionMap.get(
|
|
162
150
|
s
|
|
163
151
|
);
|
|
164
|
-
if (!
|
|
152
|
+
if (!n || !m)
|
|
165
153
|
e.push(t);
|
|
166
154
|
else {
|
|
167
|
-
if (this.updateModel ||
|
|
168
|
-
this.scene.remove(
|
|
155
|
+
if (this.updateModel || n.data.vehicleColor !== t.vehicleColor || n.data.vehicleType !== t.vehicleType) {
|
|
156
|
+
this.scene.remove(n.model), this.disposeModel(n.model), n.model = this.getVehicleModel(t);
|
|
169
157
|
const c = await this.createPlateSprite(t);
|
|
170
|
-
c && (
|
|
158
|
+
c && (n.model.add(c), c.position.set(0, 5, -4)), this.scene.add(n.model);
|
|
171
159
|
}
|
|
172
|
-
if (
|
|
173
|
-
const c =
|
|
174
|
-
c && (
|
|
160
|
+
if (n.data.showName !== t.showName || n.data.plateColor !== t.plateColor) {
|
|
161
|
+
const c = n.model.getObjectByName("VehiclePlate");
|
|
162
|
+
c && (n.model.remove(c), this.disposeModel(c));
|
|
175
163
|
const p = await this.createPlateSprite(t);
|
|
176
|
-
p && (
|
|
164
|
+
p && (n.model.add(p), p.position.set(0, 5, -4));
|
|
177
165
|
}
|
|
178
|
-
if (
|
|
166
|
+
if (n.data = t, this.needInterpolate) {
|
|
179
167
|
const c = m[m.length - 1];
|
|
180
|
-
Math.abs(
|
|
181
|
-
pos: [
|
|
182
|
-
heading:
|
|
168
|
+
Math.abs(l - c.heading) >= 180 && (l > c.heading ? c.heading += 360 : l += 360), m.push({
|
|
169
|
+
pos: [o, r, 0],
|
|
170
|
+
heading: l,
|
|
183
171
|
time: a
|
|
184
172
|
});
|
|
185
173
|
} else {
|
|
186
174
|
this.historyPositionMap.set(s, [
|
|
187
|
-
{ pos: [
|
|
175
|
+
{ pos: [o, r, 0], heading: l, time: a }
|
|
188
176
|
]);
|
|
189
|
-
const c = this.toRenderCoordinates([
|
|
190
|
-
|
|
177
|
+
const c = this.toRenderCoordinates([o, r, 0]);
|
|
178
|
+
n.model.position.set(c[0], c[1], c[2]), n.model.rotation.y = h.MathUtils.degToRad(-l);
|
|
191
179
|
}
|
|
192
180
|
}
|
|
193
181
|
}
|
|
@@ -281,19 +269,19 @@ class k {
|
|
|
281
269
|
return;
|
|
282
270
|
const s = Date.now();
|
|
283
271
|
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);
|
|
284
|
-
const a = s - t.segmentStartTime,
|
|
272
|
+
const a = s - t.segmentStartTime, o = Math.min(
|
|
285
273
|
a / t.segmentTotalTime,
|
|
286
274
|
1
|
|
287
275
|
);
|
|
288
|
-
if (
|
|
276
|
+
if (o === 1)
|
|
289
277
|
if (e.shift(), e.length === 1) {
|
|
290
278
|
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));
|
|
291
279
|
return;
|
|
292
280
|
} else
|
|
293
281
|
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);
|
|
294
282
|
else {
|
|
295
|
-
const
|
|
296
|
-
return [
|
|
283
|
+
const r = e[0].pos[0] + (e[1].pos[0] - e[0].pos[0]) * o, l = e[0].pos[1] + (e[1].pos[1] - e[0].pos[1]) * o, n = e[0].heading + (e[1].heading - e[0].heading) * o;
|
|
284
|
+
return [r, l, 0, n];
|
|
297
285
|
}
|
|
298
286
|
}
|
|
299
287
|
/**
|
|
@@ -343,56 +331,56 @@ class k {
|
|
|
343
331
|
* 创建号牌canvas
|
|
344
332
|
* */
|
|
345
333
|
createCanvas(i, e, t) {
|
|
346
|
-
const s = document.createElement("canvas"), a = i.width,
|
|
347
|
-
s.width = a, s.height =
|
|
348
|
-
const
|
|
349
|
-
if (!
|
|
334
|
+
const s = document.createElement("canvas"), a = i.width, o = i.height;
|
|
335
|
+
s.width = a, s.height = o;
|
|
336
|
+
const r = s.getContext("2d");
|
|
337
|
+
if (!r) {
|
|
350
338
|
console.log("canvas创建失败");
|
|
351
339
|
return;
|
|
352
340
|
}
|
|
353
|
-
return
|
|
341
|
+
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;
|
|
354
342
|
}
|
|
355
343
|
createPlateSprite(i) {
|
|
356
344
|
return new Promise((e, t) => {
|
|
357
|
-
var
|
|
345
|
+
var n, m;
|
|
358
346
|
const s = !i.plateNo || i.plateNo === "0" || i.plateNo === "000000";
|
|
359
347
|
if (this.currentSpriteContent === d.None || this.currentSpriteContent === d.PlateNumber && s) {
|
|
360
348
|
e(void 0);
|
|
361
349
|
return;
|
|
362
350
|
}
|
|
363
351
|
const a = new Image();
|
|
364
|
-
let
|
|
352
|
+
let o = "", r = "", l = "";
|
|
365
353
|
if (this.currentSpriteContent === d.PlateNumber || this.currentSpriteContent === d.Mix)
|
|
366
354
|
if (s)
|
|
367
|
-
|
|
355
|
+
o = "grey", r = i.ptcId, l = "#ffffff";
|
|
368
356
|
else
|
|
369
|
-
switch (
|
|
357
|
+
switch (r = ((n = i.showName) == null ? void 0 : n.substring(0, 2)) + "•" + ((m = i.showName) == null ? void 0 : m.substring(2)), i.plateColor) {
|
|
370
358
|
case 1:
|
|
371
|
-
|
|
359
|
+
o = "blue", l = "#ffffff";
|
|
372
360
|
break;
|
|
373
361
|
case 2:
|
|
374
|
-
|
|
362
|
+
o = "yellow", l = "#000000";
|
|
375
363
|
break;
|
|
376
364
|
case 3:
|
|
377
|
-
|
|
365
|
+
o = "white", l = "#000000";
|
|
378
366
|
break;
|
|
379
367
|
case 4:
|
|
380
|
-
|
|
368
|
+
o = "black";
|
|
381
369
|
break;
|
|
382
370
|
case 5:
|
|
383
|
-
|
|
371
|
+
o = "neo_yellow", l = "#000000";
|
|
384
372
|
break;
|
|
385
373
|
case 6:
|
|
386
|
-
|
|
374
|
+
o = "neo_green", l = "#000000";
|
|
387
375
|
break;
|
|
388
376
|
default:
|
|
389
|
-
|
|
377
|
+
o = "grey", r = i.plateNo, l = "#ffffff";
|
|
390
378
|
break;
|
|
391
379
|
}
|
|
392
380
|
else
|
|
393
|
-
this.currentSpriteContent === d.Id && (
|
|
394
|
-
a.src = `${this.assetsRoot}/Images/PlateBG/${
|
|
395
|
-
const c = this.createCanvas(a,
|
|
381
|
+
this.currentSpriteContent === d.Id && (o = "grey", r = i.ptcId, l = "#ffffff");
|
|
382
|
+
a.src = `${this.assetsRoot}/Images/PlateBG/${o}.png`, a.onload = () => {
|
|
383
|
+
const c = this.createCanvas(a, r, l);
|
|
396
384
|
if (!c)
|
|
397
385
|
t("canvas创建失败");
|
|
398
386
|
else {
|
|
@@ -11,7 +11,7 @@ import S from "@arcgis/core/views/MapView";
|
|
|
11
11
|
import H from "@arcgis/core/views/SceneView";
|
|
12
12
|
import I from "@turf/destination";
|
|
13
13
|
import * as O from "@turf/helpers";
|
|
14
|
-
import
|
|
14
|
+
import G from "../stores/index.mjs";
|
|
15
15
|
function y(m, t) {
|
|
16
16
|
return m.startsWith("http://") || m.startsWith("https://") ? m : t + m;
|
|
17
17
|
}
|
|
@@ -25,7 +25,7 @@ class Q {
|
|
|
25
25
|
* @returns view
|
|
26
26
|
*/
|
|
27
27
|
async initialize(t) {
|
|
28
|
-
const i =
|
|
28
|
+
const i = G.useAppDataStore, e = JSON.parse(JSON.stringify(i.mapConfig));
|
|
29
29
|
this.mapConfig = e;
|
|
30
30
|
const { container: a, markerClickCallback: r, mapClickCallback: d } = t;
|
|
31
31
|
g.assetsPath = `${e.assetsRoot}/ArcgisAssets`, g.fontsUrl = `${e.assetsRoot}/fonts`, g.apiKey = "AAPKf5a3e1044d7a4faeb3b1ec7060f5c68equIrP2KbRyL-t_b40Kk4GTWUQ1BFCyttvyQPQnWpFmBd7kp9gkrVihjfmcKBwxjW";
|
|
@@ -38,9 +38,9 @@ class Q {
|
|
|
38
38
|
map: c,
|
|
39
39
|
container: a,
|
|
40
40
|
environment: {
|
|
41
|
+
atmosphereEnabled: !0,
|
|
41
42
|
lighting: {
|
|
42
|
-
type: "
|
|
43
|
-
date: new Date("January 1, 2022 07:00:00 UTC")
|
|
43
|
+
type: "virtual"
|
|
44
44
|
}
|
|
45
45
|
},
|
|
46
46
|
...e == null ? void 0 : e.mapOptions
|
|
@@ -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.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
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const P=require("@arcgis/core/core/reactiveUtils.js"),S=require("@arcgis/core/geometry/SpatialReference"),R=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(R),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=s=>{e(s),s==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,2),this.scene.add(this.ambient),this.sun=new h.DirectionalLight(16777215,2),this.scene.add(this.sun),i.resetWebGLState()}async render(i){var s;const e=i.camera;if(this.camera.position.set(e.eye[0],e.eye[1],e.eye[2]),this.camera.up.set(e.up[0],e.up[1],e.up[2]),this.camera.lookAt(new 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 o=(s=this.vehicleObjectMap.get(a))==null?void 0:s.model;if(!o)continue;const r=this.computeVehiclePosition(a);if(r){const l=this.toRenderCoordinates(r);o.position.set(l[0],l[1],l[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.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),o=Number(e.y),r=Number(e.heading);this.historyPositionMap.set(t,[{pos:[a,o,0],heading:r,time:s}]);const l=this.getVehicleModel(e);l.name=t,l.visible=!this.needInterpolate;try{const n=await this.createPlateSprite(e);n&&(l.add(n),n.position.set(0,5,-4))}catch(n){console.log("createPlateSprite error:",n)}this.scene.add(l),this.vehicleObjectMap.set(t,{model:l,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,o=Number(t.x),r=Number(t.y);let l=Number(t.heading);const n=this.vehicleObjectMap.get(s),u=this.historyPositionMap.get(s);if(!n||!u)e.push(t);else{if(this.updateModel||n.data.vehicleColor!==t.vehicleColor||n.data.vehicleType!==t.vehicleType){this.scene.remove(n.model),this.disposeModel(n.model),n.model=this.getVehicleModel(t);const c=await this.createPlateSprite(t);c&&(n.model.add(c),c.position.set(0,5,-4)),this.scene.add(n.model)}if(n.data.showName!==t.showName||n.data.plateColor!==t.plateColor){const c=n.model.getObjectByName("VehiclePlate");c&&(n.model.remove(c),this.disposeModel(c));const p=await this.createPlateSprite(t);p&&(n.model.add(p),p.position.set(0,5,-4))}if(n.data=t,this.needInterpolate){const c=u[u.length-1];Math.abs(l-c.heading)>=180&&(l>c.heading?c.heading+=360:l+=360),u.push({pos:[o,r,0],heading:l,time:a})}else{this.historyPositionMap.set(s,[{pos:[o,r,0],heading:l,time:a}]);const c=this.toRenderCoordinates([o,r,0]);n.model.position.set(c[0],c[1],c[2]),n.model.rotation.y=h.MathUtils.degToRad(-l)}}}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,S.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,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("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 r=e[0].pos[0]+(e[1].pos[0]-e[0].pos[0])*o,l=e[0].pos[1]+(e[1].pos[1]-e[0].pos[1])*o,n=e[0].heading+(e[1].heading-e[0].heading)*o;return[r,l,0,n]}}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,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 n,u;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 o="",r="",l="";if(this.currentSpriteContent===d.EVehiclePlateState.PlateNumber||this.currentSpriteContent===d.EVehiclePlateState.Mix)if(s)o="grey",r=i.ptcId,l="#ffffff";else switch(r=((n=i.showName)==null?void 0:n.substring(0,2))+"•"+((u=i.showName)==null?void 0:u.substring(2)),i.plateColor){case 1:o="blue",l="#ffffff";break;case 2:o="yellow",l="#000000";break;case 3:o="white",l="#000000";break;case 4:o="black";break;case 5:o="neo_yellow",l="#000000";break;case 6:o="neo_green",l="#000000";break;default:o="grey",r=i.plateNo,l="#ffffff";break}else this.currentSpriteContent===d.EVehiclePlateState.Id&&(o="grey",r=i.ptcId,l="#ffffff");a.src=`${this.assetsRoot}/Images/PlateBG/${o}.png`,a.onload=()=>{const c=this.createCanvas(a,r,l);if(!c)t("canvas创建失败");else{const p=new h.CanvasTexture(c),v=new h.SpriteMaterial({map:p,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=p=>{console.log(`号牌背景加载失败: ${a.src}`,p),t(p)}}})}}exports.default=k;
|
|
@@ -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 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:o,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:o,...t.mapOptions}):this.view=new R({map:l,container:o,environment:{atmosphereEnabled:!0,lighting:{type:"virtual"}},...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=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,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(G.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=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]}),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=T.watch(()=>this.view.zoom,o=>{i&&o<=i&&(this.view.zoom=i),t&&o>=t&&(this.view.zoom=t)}))}}exports.default=N;
|