gisviewer-vue3-arcgis 1.0.106 → 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.
@@ -6,7 +6,7 @@ export default class TraceRendererExternal implements ITraceRendererInterface {
6
6
  private ambient;
7
7
  private sun;
8
8
  /** 车辆模型变化的阈值 */
9
- private readonly zoomThreshold;
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.zoomThreshold = 1e3, this.roughness = 0.2, this.metalness = 0.8, this.defaultMaterial = new h.MeshPhysicalMaterial({
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, o) => {
52
- (o <= this.zoomThreshold && s > this.zoomThreshold || o > this.zoomThreshold && s <= this.zoomThreshold) && (this.updateModel = !0);
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.MeshPhysicalMaterial({
58
- color: i,
59
- emissive: 0,
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) {
@@ -75,8 +72,8 @@ class k {
75
72
  const e = this.renderer.setRenderTarget.bind(
76
73
  this.renderer
77
74
  );
78
- this.renderer.setRenderTarget = (n) => {
79
- e(n), n == null && i.bindRenderTarget();
75
+ this.renderer.setRenderTarget = (s) => {
76
+ e(s), s == null && i.bindRenderTarget();
80
77
  }, this.scene = new h.Scene();
81
78
  const { camera: t } = i;
82
79
  this.camera = new h.PerspectiveCamera(
@@ -84,19 +81,7 @@ class k {
84
81
  t.aspect,
85
82
  0.1,
86
83
  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.51925377934634, 31.893973071723785, 1e4], o = this.toRenderCoordinates(s);
89
- 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
- a[0],
97
- a[1],
98
- a[2]
99
- ), 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();
100
85
  }
101
86
  async render(i) {
102
87
  var s;
@@ -104,14 +89,14 @@ class k {
104
89
  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
90
  new h.Vector3(e.center[0], e.center[1], e.center[2])
106
91
  ), this.camera.projectionMatrix.fromArray(e.projectionMatrix), !this.isPaused && this.needInterpolate)
107
- for (const o of this.vehicleObjectMap.keys()) {
108
- const r = (s = this.vehicleObjectMap.get(o)) == null ? void 0 : s.model;
109
- if (!r)
92
+ for (const a of this.vehicleObjectMap.keys()) {
93
+ const o = (s = this.vehicleObjectMap.get(a)) == null ? void 0 : s.model;
94
+ if (!o)
110
95
  continue;
111
- const a = this.computeVehiclePosition(o);
112
- if (a) {
113
- const n = this.toRenderCoordinates(a);
114
- r.position.set(n[0], n[1], n[2]), r.rotation.y = h.MathUtils.degToRad(-a[3]);
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]);
115
100
  }
116
101
  }
117
102
  const t = i.sunLight;
@@ -131,20 +116,20 @@ class k {
131
116
  async addVehicles(i) {
132
117
  if (!(this.isPaused || !this.carModelReady || !this.vanModelReady || !this.truckModelReady || !this.busModelReady || !this.bicycleModelReady))
133
118
  for (const e of i) {
134
- const { vehicleId: t, localTimestamp: s } = e, o = Number(e.x), r = Number(e.y), a = Number(e.heading);
119
+ const { vehicleId: t, localTimestamp: s } = e, a = Number(e.x), o = Number(e.y), r = Number(e.heading);
135
120
  this.historyPositionMap.set(t, [
136
- { pos: [o, r, 0], heading: a, time: s }
121
+ { pos: [a, o, 0], heading: r, time: s }
137
122
  ]);
138
- const n = this.getVehicleModel(e);
139
- n.name = t, n.visible = !this.needInterpolate;
123
+ const l = this.getVehicleModel(e);
124
+ l.name = t, l.visible = !this.needInterpolate;
140
125
  try {
141
- const l = await this.createPlateSprite(e);
142
- l && (n.add(l), l.position.set(0, 5, -4));
143
- } catch (l) {
144
- console.log("createPlateSprite error:", l);
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);
145
130
  }
146
- this.scene.add(n), this.vehicleObjectMap.set(t, {
147
- model: n,
131
+ this.scene.add(l), this.vehicleObjectMap.set(t, {
132
+ model: l,
148
133
  data: e,
149
134
  waitForDelete: !1,
150
135
  isMoving: !1
@@ -159,38 +144,38 @@ class k {
159
144
  return;
160
145
  const e = [];
161
146
  for (const t of i) {
162
- const { vehicleId: s, localTimestamp: o } = t, r = Number(t.x), a = Number(t.y);
163
- let n = Number(t.heading);
164
- const l = this.vehicleObjectMap.get(s), m = this.historyPositionMap.get(
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(
165
150
  s
166
151
  );
167
- if (!l || !m)
152
+ if (!n || !m)
168
153
  e.push(t);
169
154
  else {
170
- if (this.updateModel || l.data.vehicleColor !== t.vehicleColor || l.data.vehicleType !== t.vehicleType) {
171
- this.scene.remove(l.model), this.disposeModel(l.model), l.model = this.getVehicleModel(t);
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);
172
157
  const c = await this.createPlateSprite(t);
173
- c && (l.model.add(c), c.position.set(0, 5, -4)), this.scene.add(l.model);
158
+ c && (n.model.add(c), c.position.set(0, 5, -4)), this.scene.add(n.model);
174
159
  }
175
- if (l.data.showName !== t.showName || l.data.plateColor !== t.plateColor) {
176
- const c = l.model.getObjectByName("VehiclePlate");
177
- c && (l.model.remove(c), this.disposeModel(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));
178
163
  const p = await this.createPlateSprite(t);
179
- p && (l.model.add(p), p.position.set(0, 5, -4));
164
+ p && (n.model.add(p), p.position.set(0, 5, -4));
180
165
  }
181
- if (l.data = t, this.needInterpolate) {
166
+ if (n.data = t, this.needInterpolate) {
182
167
  const c = m[m.length - 1];
183
- Math.abs(n - c.heading) >= 180 && (n > c.heading ? c.heading += 360 : n += 360), m.push({
184
- pos: [r, a, 0],
185
- heading: n,
186
- time: o
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,
171
+ time: a
187
172
  });
188
173
  } else {
189
174
  this.historyPositionMap.set(s, [
190
- { pos: [r, a, 0], heading: n, time: o }
175
+ { pos: [o, r, 0], heading: l, time: a }
191
176
  ]);
192
- const c = this.toRenderCoordinates([r, a, 0]);
193
- l.model.position.set(c[0], c[1], c[2]), l.model.rotation.y = h.MathUtils.degToRad(-n);
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);
194
179
  }
195
180
  }
196
181
  }
@@ -254,8 +239,8 @@ class k {
254
239
  if (t) {
255
240
  const s = t.model.getObjectByName("VehiclePlate");
256
241
  if (s && (t.model.remove(s), this.disposeModel(s)), i !== d.None) {
257
- const o = await this.createPlateSprite(t.data);
258
- o && (t.model.add(o), o.position.set(0, 5, -4));
242
+ const a = await this.createPlateSprite(t.data);
243
+ a && (t.model.add(a), a.position.set(0, 5, -4));
259
244
  }
260
245
  }
261
246
  }
@@ -284,26 +269,26 @@ class k {
284
269
  return;
285
270
  const s = Date.now();
286
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);
287
- const o = s - t.segmentStartTime, r = Math.min(
288
- o / t.segmentTotalTime,
272
+ const a = s - t.segmentStartTime, o = Math.min(
273
+ a / t.segmentTotalTime,
289
274
  1
290
275
  );
291
- if (r === 1)
276
+ if (o === 1)
292
277
  if (e.shift(), e.length === 1) {
293
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));
294
279
  return;
295
280
  } else
296
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);
297
282
  else {
298
- const a = 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;
299
- return [a, n, 0, l];
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];
300
285
  }
301
286
  }
302
287
  /**
303
288
  * 根据车辆类型、车身颜色获取模型
304
289
  * */
305
290
  getVehicleModel(i) {
306
- if (this.view.camera.position.z >= this.zoomThreshold) {
291
+ if (this.view.camera.position.z >= this.cameraHeightThreshold) {
307
292
  const e = new h.SphereGeometry(5, 32, 32), t = new h.MeshPhysicalMaterial({
308
293
  color: 325253,
309
294
  emissive: 0,
@@ -335,8 +320,8 @@ class k {
335
320
  }
336
321
  const t = this.materialMap.get(i.vehicleColor) || this.defaultMaterial;
337
322
  let s = !1;
338
- e.traverse((o) => {
339
- !s && o instanceof h.Mesh && (o.material = t, s = !0);
323
+ e.traverse((a) => {
324
+ !s && a instanceof h.Mesh && (a.material = t, s = !0);
340
325
  });
341
326
  }
342
327
  return e;
@@ -346,67 +331,67 @@ class k {
346
331
  * 创建号牌canvas
347
332
  * */
348
333
  createCanvas(i, e, t) {
349
- const s = document.createElement("canvas"), o = i.width, r = i.height;
350
- s.width = o, s.height = r;
351
- const a = s.getContext("2d");
352
- if (!a) {
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) {
353
338
  console.log("canvas创建失败");
354
339
  return;
355
340
  }
356
- return a.fillStyle = "rgba(0,0,0,0.0)", a.fillRect(0, 0, o, r), a.drawImage(i, 0, 0, o, r), a.beginPath(), a.translate(o / 2, r / 2), a.fillStyle = t, a.font = "bold 32px 宋体", a.textBaseline = "middle", a.textAlign = "center", a.fillText(e, 0, 0), s;
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;
357
342
  }
358
343
  createPlateSprite(i) {
359
344
  return new Promise((e, t) => {
360
- var l, m;
345
+ var n, m;
361
346
  const s = !i.plateNo || i.plateNo === "0" || i.plateNo === "000000";
362
347
  if (this.currentSpriteContent === d.None || this.currentSpriteContent === d.PlateNumber && s) {
363
348
  e(void 0);
364
349
  return;
365
350
  }
366
- const o = new Image();
367
- let r = "", a = "", n = "";
351
+ const a = new Image();
352
+ let o = "", r = "", l = "";
368
353
  if (this.currentSpriteContent === d.PlateNumber || this.currentSpriteContent === d.Mix)
369
354
  if (s)
370
- r = "grey", a = i.ptcId, n = "#ffffff";
355
+ o = "grey", r = i.ptcId, l = "#ffffff";
371
356
  else
372
- switch (a = ((l = i.showName) == null ? void 0 : l.substring(0, 2)) + "•" + ((m = i.showName) == null ? void 0 : m.substring(2)), i.plateColor) {
357
+ switch (r = ((n = i.showName) == null ? void 0 : n.substring(0, 2)) + "•" + ((m = i.showName) == null ? void 0 : m.substring(2)), i.plateColor) {
373
358
  case 1:
374
- r = "blue", n = "#ffffff";
359
+ o = "blue", l = "#ffffff";
375
360
  break;
376
361
  case 2:
377
- r = "yellow", n = "#000000";
362
+ o = "yellow", l = "#000000";
378
363
  break;
379
364
  case 3:
380
- r = "white", n = "#000000";
365
+ o = "white", l = "#000000";
381
366
  break;
382
367
  case 4:
383
- r = "black";
368
+ o = "black";
384
369
  break;
385
370
  case 5:
386
- r = "neo_yellow", n = "#000000";
371
+ o = "neo_yellow", l = "#000000";
387
372
  break;
388
373
  case 6:
389
- r = "neo_green", n = "#000000";
374
+ o = "neo_green", l = "#000000";
390
375
  break;
391
376
  default:
392
- r = "grey", a = i.plateNo, n = "#ffffff";
377
+ o = "grey", r = i.plateNo, l = "#ffffff";
393
378
  break;
394
379
  }
395
380
  else
396
- this.currentSpriteContent === d.Id && (r = "grey", a = i.ptcId, n = "#ffffff");
397
- o.src = `${this.assetsRoot}/Images/PlateBG/${r}.png`, o.onload = () => {
398
- const c = this.createCanvas(o, a, n);
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);
399
384
  if (!c)
400
385
  t("canvas创建失败");
401
386
  else {
402
387
  const p = new h.CanvasTexture(c), M = new h.SpriteMaterial({
403
388
  map: p,
404
389
  transparent: !1
405
- }), u = new h.Sprite(M), f = 0.05, b = c.width * f, v = c.height * f;
406
- u.scale.set(b, v, 1), u.name = "VehiclePlate", e(u);
390
+ }), f = new h.Sprite(M), u = 0.05, b = c.width * u, v = c.height * u;
391
+ f.scale.set(b, v, 1), f.name = "VehiclePlate", e(f);
407
392
  }
408
- o.onerror = (p) => {
409
- console.log(`号牌背景加载失败: ${o.src}`, p), t(p);
393
+ a.onerror = (p) => {
394
+ console.log(`号牌背景加载失败: ${a.src}`, p), t(p);
410
395
  };
411
396
  };
412
397
  });
@@ -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 C from "../stores/index.mjs";
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 = C.useAppDataStore, e = JSON.parse(JSON.stringify(i.mapConfig));
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: "sun",
43
- date: new Date("January 1, 2022 02:00:00 UTC")
43
+ type: "virtual"
44
44
  }
45
45
  },
46
46
  ...e == null ? void 0 : e.mapOptions
@@ -6,7 +6,7 @@ export default class TraceRendererExternal implements ITraceRendererInterface {
6
6
  private ambient;
7
7
  private sun;
8
8
  /** 车辆模型变化的阈值 */
9
- private readonly zoomThreshold;
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"),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 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 02: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;
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gisviewer-vue3-arcgis",
3
- "version": "1.0.106",
3
+ "version": "1.0.108",
4
4
  "main": "lib/index.js",
5
5
  "module": "es/index.mjs",
6
6
  "files": [