gisviewer-vue3-arcgis 1.0.120 → 1.0.122

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,9 @@ export default class OpenDriveRenderer {
6
6
  private laneLayer;
7
7
  private roadNameLayer;
8
8
  private junctionLayer;
9
+ private sectionLayer;
9
10
  private highlightLayer;
11
+ private flashLayer;
10
12
  private allLaneGraphics;
11
13
  private allRefLineGraphics;
12
14
  private mouseMoveHandler;
@@ -15,6 +17,7 @@ export default class OpenDriveRenderer {
15
17
  constructor(view: __esri.MapView | __esri.SceneView);
16
18
  private projectName;
17
19
  private openDriveServer;
20
+ private openDriveClickCallback;
18
21
  showOpenDriveFromFile(params: IShowOpenDriveFromFileParams): Promise<IResult>;
19
22
  /**
20
23
  * 从服务器载入OpenDrive文件解析结果并显示
@@ -48,11 +51,13 @@ export default class OpenDriveRenderer {
48
51
  * @returns
49
52
  */
50
53
  findSumo(params: IFindSumoParams): Promise<IResult>;
54
+ private findJunction;
51
55
  /**
52
56
  * 用sumo的id定位车道、基本段、路段
53
57
  * @param params
54
58
  * @returns
55
59
  */
56
60
  private findLane;
61
+ private flashGraphic;
57
62
  splitLane(params: ISplitOpenDriveLaneParams): Promise<IResult>;
58
63
  }
@@ -1,16 +1,16 @@
1
- import d from "@arcgis/core/Graphic";
2
- import * as O from "@arcgis/core/core/promiseUtils";
3
- import { Polygon as C } from "@arcgis/core/geometry";
4
- import * as L from "@arcgis/core/geometry/geometryEngineAsync";
5
- import G from "@arcgis/core/layers/FeatureLayer";
6
- import D from "@arcgis/core/layers/GraphicsLayer";
1
+ import p from "@arcgis/core/Graphic";
2
+ import * as D from "@arcgis/core/core/promiseUtils";
3
+ import { Polygon as N } from "@arcgis/core/geometry";
4
+ import * as k from "@arcgis/core/geometry/geometryEngineAsync";
5
+ import C from "@arcgis/core/layers/FeatureLayer";
6
+ import m from "@arcgis/core/layers/GraphicsLayer";
7
7
  import f from "axios";
8
- import j from "pako";
9
- import S from "../common-utils.mjs";
8
+ import G from "pako";
9
+ import j from "../common-utils.mjs";
10
10
  import F from "./wasm-loader.mjs";
11
- class N {
12
- constructor(e) {
13
- this.wasmLoader = F.getInstance(), this.projectName = "", this.openDriveServer = "", this.currentSectionCode = "", this.currentJunctionId = "", this.view = e, this.laneLayer = new G({
11
+ class S {
12
+ constructor(t) {
13
+ this.wasmLoader = F.getInstance(), this.projectName = "", this.openDriveServer = "", this.currentSectionCode = "", this.currentJunctionId = "", this.view = t, this.laneLayer = new C({
14
14
  id: "OpenDriveLane",
15
15
  fields: [
16
16
  {
@@ -218,7 +218,7 @@ class N {
218
218
  }
219
219
  ]
220
220
  }
221
- }), this.roadNameLayer = new G({
221
+ }), this.roadNameLayer = new C({
222
222
  id: "OpenDriveRoadName",
223
223
  fields: [
224
224
  {
@@ -268,46 +268,52 @@ class N {
268
268
  }
269
269
  }
270
270
  ]
271
- }), this.junctionLayer = new D({ id: "OpenDriveJunction" }), this.highlightLayer = new D({ id: "OpenDriveHighlight" }), this.view.map.addMany([
271
+ }), this.junctionLayer = new m({ id: "OpenDriveJunction" }), this.sectionLayer = new m({ id: "OpenDriveSection" }), this.highlightLayer = new m({ id: "OpenDriveHighlight" }), this.flashLayer = new m({ id: "OpenDriveFlash" }), this.view.map.addMany([
272
272
  this.laneLayer,
273
273
  this.junctionLayer,
274
+ this.sectionLayer,
274
275
  this.roadNameLayer,
275
- this.highlightLayer
276
+ this.highlightLayer,
277
+ this.flashLayer
276
278
  ]);
277
279
  }
278
- static getInstance(e) {
279
- return this.instance || (this.instance = new N(e)), this.instance;
280
+ static getInstance(t) {
281
+ return this.instance || (this.instance = new S(t)), this.instance;
280
282
  }
281
- async showOpenDriveFromFile(e) {
282
- var u, c;
283
- this.projectName = Date.now().toString(), this.openDriveServer = e.server;
284
- const o = `http://${this.openDriveServer}/api/openDrive/uploadXodr`, i = await f.post(o, null, {
285
- params: {
286
- url: e.file,
287
- projectName: this.projectName
283
+ async showOpenDriveFromFile(t) {
284
+ var h, d;
285
+ this.openDriveClickCallback = t.selectedCallback, this.projectName = Date.now().toString(), this.openDriveServer = t.server;
286
+ const o = `http://${this.openDriveServer}/api/openDrive/uploadXodr`, i = await f.post(
287
+ o,
288
+ {},
289
+ {
290
+ params: {
291
+ url: t.file,
292
+ projectName: this.projectName
293
+ }
288
294
  }
289
- });
295
+ );
290
296
  if (i.status !== 200)
291
297
  throw new Error(`OpenDriveRenderer: ${i.statusText}`);
292
298
  console.time("渲染用时");
293
299
  const s = i.data.result.geoSetting;
294
- S.setGeoData(
300
+ j.setGeoData(
295
301
  s.geoReference,
296
302
  s.offsetX,
297
303
  s.offsetY
298
304
  );
299
- let t = i.data.result.json;
300
- t.startsWith(window.location.protocol) || (t = `${window.location.protocol}//${e.server}${t}`);
301
- const l = await (await fetch(t)).arrayBuffer(), a = j.inflate(l, { to: "string" }), r = JSON.parse(a);
305
+ let e = i.data.result.json;
306
+ e.startsWith(window.location.protocol) || (e = `${window.location.protocol}//${t.server}${e}`);
307
+ const r = await (await fetch(e)).arrayBuffer(), n = G.inflate(r, { to: "string" }), a = JSON.parse(n);
302
308
  await this.showAllLanes(
303
- r,
304
- ((u = e.options) == null ? void 0 : u.showJunctionLane) || !1,
305
- ((c = e.options) == null ? void 0 : c.showRoadName) || !0
309
+ a,
310
+ ((h = t.options) == null ? void 0 : h.showJunctionLane) || !1,
311
+ ((d = t.options) == null ? void 0 : d.showRoadName) || !0
306
312
  );
307
- const n = i.data.result.junctions;
308
- if (this.showJunction(n), e.options && e.options.centerMap !== !1) {
309
- const m = S.transformPointProjection([0, 0]);
310
- await this.view.goTo(m);
313
+ const l = i.data.result.junctions;
314
+ if (this.showJunction(l), t.options && t.options.centerMap !== !1) {
315
+ const g = j.transformPointProjection([0, 0]);
316
+ await this.view.goTo(g);
311
317
  }
312
318
  return this.mouseMoveHandler || this.monitorMouseMove(), this.mouseClickHandler || this.monitorMouseClick(), console.timeEnd("渲染用时"), { status: 0, message: "ok" };
313
319
  }
@@ -316,8 +322,8 @@ class N {
316
322
  * @param server
317
323
  * @param projectName
318
324
  */
319
- async showOpenDriveFromServer(e, o) {
320
- const i = `http://${e}/api/openDrive/analyzeXodr`, s = await f.get(i, {
325
+ async showOpenDriveFromServer(t, o) {
326
+ const i = `http://${t}/api/openDrive/analyzeXodr`, s = await f.get(i, {
321
327
  headers: {
322
328
  projectName: o
323
329
  },
@@ -328,102 +334,107 @@ class N {
328
334
  });
329
335
  if (s.status !== 200)
330
336
  throw new Error(`OpenDriveRenderer: ${s.statusText}`);
331
- let t = s.data.result.json;
332
- t.startsWith(window.location.protocol) || (t = `${window.location.protocol}//${e}${t}`);
333
- const l = await (await fetch(t)).arrayBuffer(), a = j.inflate(l, { to: "string" }), r = JSON.parse(a);
334
- return await this.showAllLanes(r, !1, !1), { status: 0, message: "ok" };
337
+ let e = s.data.result.json;
338
+ e.startsWith(window.location.protocol) || (e = `${window.location.protocol}//${t}${e}`);
339
+ const r = await (await fetch(e)).arrayBuffer(), n = G.inflate(r, { to: "string" }), a = JSON.parse(n);
340
+ return await this.showAllLanes(a, !1, !1), { status: 0, message: "ok" };
335
341
  }
336
- async showAllLanes(e, o, i) {
342
+ async showAllLanes(t, o, i) {
337
343
  const s = await this.laneLayer.queryFeatures();
338
344
  return s.features.length > 0 && this.laneLayer.applyEdits({
339
345
  deleteFeatures: s.features
340
- }), this.roadNameLayer.visible = i, new Promise((t) => {
341
- let h = 0;
346
+ }), this.roadNameLayer.visible = i, new Promise((e) => {
347
+ let c = 0;
342
348
  this.allLaneGraphics = [], this.allRefLineGraphics = [];
343
- const l = [];
344
- for (const r of e) {
345
- if (!o && r.junction !== "-1")
349
+ const r = [];
350
+ for (const a of t) {
351
+ if (!o && a.junction !== "-1")
346
352
  continue;
347
- const { id: n, refLine: u } = r;
348
- let c = r.name;
349
- c.includes("(") && (c = c.slice(0, c.indexOf("("))), c = c.replace(/(.)/g, "$1 ");
350
- const m = new d({
353
+ const { id: l, refLine: h } = a;
354
+ let d = a.name;
355
+ d.includes("(") && (d = d.slice(0, d.indexOf("("))), d = d.replace(/(.)/g, "$1 ");
356
+ const g = new p({
351
357
  geometry: {
352
358
  type: "polyline",
353
- paths: [u]
359
+ paths: [h]
354
360
  },
355
361
  attributes: {
356
- ObjectID: h++,
357
- roadId: n,
358
- roadName: c
362
+ ObjectID: c++,
363
+ roadId: l,
364
+ roadName: d
359
365
  }
360
366
  });
361
- this.allRefLineGraphics.push(m);
362
- for (const w of r.laneSections) {
363
- const b = Number(w.id);
364
- for (const p of w.lanePaths) {
365
- const y = Number(p.id);
367
+ this.allRefLineGraphics.push(g);
368
+ for (const v of a.laneSections) {
369
+ const b = Number(v.id);
370
+ for (const u of v.lanePaths) {
371
+ const y = Number(u.id);
366
372
  if (y === 0)
367
373
  continue;
368
- const k = p.type, g = p.innerPath.concat(
369
- p.outerPath.reverse()
374
+ const O = u.type, w = u.innerPath.concat(
375
+ u.outerPath.reverse()
370
376
  );
371
- if (g.length <= 3) {
377
+ if (w.length <= 3) {
372
378
  console.warn(`lane ${y} has less than 3 points`);
373
379
  continue;
374
380
  }
375
- g.push(p.innerPath[0]);
376
- const v = new C({
377
- rings: [g]
381
+ w.push(u.innerPath[0]);
382
+ const L = new N({
383
+ rings: [w]
378
384
  });
379
- if (v) {
380
- const I = new d({
381
- geometry: v,
385
+ if (L) {
386
+ const I = new p({
387
+ geometry: L,
382
388
  attributes: {
383
- ObjectID: h++,
384
- id: `${n}+${b}+${y}`,
385
- roadId: n,
386
- roadName: r.name,
389
+ ObjectID: c++,
390
+ id: `${l}+${b}+${y}`,
391
+ roadId: l,
392
+ roadName: a.name,
387
393
  sectionId: b,
388
394
  laneId: y,
389
- type: k,
395
+ type: O,
390
396
  sumoId: ""
391
397
  }
392
398
  });
393
- this.allLaneGraphics.push(I), l.push(I);
399
+ this.allLaneGraphics.push(I), r.push(I);
394
400
  }
395
401
  }
396
402
  }
397
403
  }
398
- const a = setInterval(() => {
399
- if (l.length > 0 || this.allRefLineGraphics.length > 0) {
400
- if (l.length > 0) {
401
- const r = l.splice(0, 100);
404
+ const n = setInterval(() => {
405
+ if (r.length > 0 || this.allRefLineGraphics.length > 0) {
406
+ if (r.length > 0) {
407
+ const a = r.splice(0, 100);
402
408
  this.laneLayer.applyEdits({
403
- addFeatures: r
409
+ addFeatures: a
404
410
  });
405
411
  }
406
412
  if (this.allRefLineGraphics.length > 0) {
407
- const r = this.allRefLineGraphics.splice(0, 10);
413
+ const a = this.allRefLineGraphics.splice(0, 10);
408
414
  this.roadNameLayer.applyEdits({
409
- addFeatures: r
415
+ addFeatures: a
410
416
  });
411
417
  }
412
418
  } else
413
- clearInterval(a), t();
419
+ clearInterval(n), e();
414
420
  }, 10);
415
421
  });
416
422
  }
417
- showJunction(e) {
423
+ showJunction(t) {
418
424
  const o = [];
419
- for (const i of e) {
420
- const s = new d({
425
+ for (const i of t) {
426
+ i.nodeType = i.type;
427
+ const s = new p({
421
428
  geometry: {
422
429
  type: "point",
423
430
  x: i.coordinates[0],
424
431
  y: i.coordinates[1]
425
432
  },
426
- attributes: { ...i, selected: !1 },
433
+ attributes: {
434
+ ...i,
435
+ selected: !1,
436
+ type: "OpenDriveJunction"
437
+ },
427
438
  symbol: {
428
439
  type: "picture-marker",
429
440
  url: i.crossId ? "/GisViewerAssets/Images/point_green.png" : "/GisViewerAssets/Images/normal-cross.png",
@@ -439,30 +450,32 @@ class N {
439
450
  * 监听鼠标移动事件,高亮显示鼠标所在路段和路口
440
451
  */
441
452
  monitorMouseMove() {
442
- const e = O.debounce(async (o) => {
443
- var h;
444
- const s = (h = (await this.view.hitTest(o, {
453
+ const t = D.debounce(async (o) => {
454
+ var c;
455
+ const s = (c = (await this.view.hitTest(o, {
445
456
  include: [this.laneLayer, this.junctionLayer]
446
- })).results) == null ? void 0 : h.filter(
447
- (l) => l.type === "graphic"
457
+ })).results) == null ? void 0 : c.filter(
458
+ (r) => r.type === "graphic"
448
459
  );
449
460
  if (s.length === 0) {
450
461
  this.currentSectionCode !== "" && (this.currentSectionCode = "", this.highlightGraphic = void 0, this.highlightLayer.removeAll()), this.currentJunctionId !== "" && (this.currentJunctionId = "", this.highlightGraphic = void 0, this.highlightLayer.removeAll());
451
462
  return;
452
463
  }
453
- const t = s[0];
454
- if (this.hitGraphic = t.graphic, t.layer.id === "OpenDriveLane") {
455
- const l = `${this.hitGraphic.attributes.roadId}+${this.hitGraphic.attributes.sectionId}`;
456
- if (l === this.currentSectionCode)
464
+ const e = s[0];
465
+ if (this.hitGraphic = e.graphic, e.layer.id === "OpenDriveLane") {
466
+ const r = `${this.hitGraphic.attributes.roadId}+${this.hitGraphic.attributes.sectionId}`;
467
+ if (r === this.currentSectionCode || this.sectionLayer.graphics.findIndex(
468
+ (h) => h.getAttribute("id") === r
469
+ ) >= 0)
457
470
  return;
458
- this.currentSectionCode = l;
471
+ this.currentSectionCode = r;
459
472
  const a = this.allLaneGraphics.filter(
460
- (n) => `${n.attributes.roadId}+${n.attributes.sectionId}` === l
461
- ), r = await L.union(
462
- a.map((n) => n.geometry)
473
+ (h) => `${h.attributes.roadId}+${h.attributes.sectionId}` === r
474
+ ), l = await k.union(
475
+ a.map((h) => h.geometry)
463
476
  );
464
- this.highlightGraphic = new d({
465
- geometry: r,
477
+ this.highlightGraphic = new p({
478
+ geometry: l,
466
479
  symbol: {
467
480
  type: "simple-fill",
468
481
  color: [255, 0, 0, 0.5],
@@ -474,31 +487,16 @@ class N {
474
487
  },
475
488
  attributes: {
476
489
  type: "OpenDriveSection",
477
- id: l,
478
- detail: ""
490
+ id: r,
491
+ selected: !1
479
492
  }
480
493
  }), this.highlightLayer.removeAll(), this.highlightLayer.add(this.highlightGraphic);
481
- } else if (t.layer.id === "OpenDriveJunction") {
482
- const l = this.hitGraphic.attributes.id;
483
- if (l === this.currentJunctionId)
494
+ } else if (e.layer.id === "OpenDriveJunction") {
495
+ const r = this.hitGraphic.attributes.id;
496
+ if (r === this.currentJunctionId)
484
497
  return;
485
- this.currentJunctionId = l, this.highlightGraphic = new d({
486
- geometry: this.hitGraphic.geometry,
487
- symbol: {
488
- type: "simple-marker",
489
- style: "circle",
490
- size: 40,
491
- color: [0, 0, 0, 0],
492
- outline: {
493
- color: [0, 0, 0, 0]
494
- }
495
- },
496
- attributes: {
497
- type: "OpenDriveJunction",
498
- id: l
499
- }
500
- });
501
- const a = new d({
498
+ this.currentJunctionId = r;
499
+ const n = new p({
502
500
  geometry: this.hitGraphic.geometry,
503
501
  symbol: {
504
502
  type: "text",
@@ -512,11 +510,11 @@ ${this.hitGraphic.attributes.id}`,
512
510
  yoffset: 40
513
511
  }
514
512
  });
515
- this.highlightLayer.removeAll(), this.highlightLayer.addMany([this.highlightGraphic, a]);
513
+ this.highlightLayer.removeAll(), this.highlightLayer.add(n);
516
514
  }
517
515
  });
518
516
  this.mouseMoveHandler = this.view.on("pointer-move", async (o) => {
519
- e(o).catch(() => {
517
+ t(o).catch(() => {
520
518
  });
521
519
  });
522
520
  }
@@ -524,42 +522,81 @@ ${this.hitGraphic.attributes.id}`,
524
522
  * 监听鼠标点击事件,获取高亮要素的拓扑信息
525
523
  */
526
524
  monitorMouseClick() {
527
- this.mouseClickHandler = this.view.on("immediate-click", async () => {
528
- var e, o;
529
- if (this.hitGraphic && !this.currentSectionCode) {
530
- if (this.currentJunctionId)
531
- if (this.hitGraphic.getAttribute("selected") === !1) {
532
- const i = `http://${this.openDriveServer}/api/sumo/getSumoJunction`, s = await f.get(i, {
533
- params: {
534
- id: this.currentJunctionId,
535
- projectName: this.projectName
536
- }
537
- });
538
- s.status === 200 && s.data.status === 0 && ((e = this.highlightGraphic) == null || e.setAttribute("detail", s.data.result), this.hitGraphic.setAttribute("selected", !0), this.hitGraphic.symbol.url = "/GisViewerAssets/Images/point_red.png", this.increasePictureMarkerSize(this.hitGraphic, 50));
539
- } else
540
- (o = this.highlightGraphic) == null || o.setAttribute("detail", void 0), this.hitGraphic.setAttribute("selected", !1), this.hitGraphic.symbol.url = "/GisViewerAssets/Images/point_green.png", this.decreasePictureMarkerSize(this.hitGraphic, 30);
541
- }
525
+ const t = D.debounce(async (o) => {
526
+ var n;
527
+ const s = (n = (await this.view.hitTest(o, {
528
+ include: [this.highlightLayer, this.junctionLayer, this.sectionLayer]
529
+ })).results) == null ? void 0 : n.filter(
530
+ (a) => a.type === "graphic"
531
+ );
532
+ if (s.length === 0)
533
+ return;
534
+ const e = s[0].graphic, c = e.getAttribute("type"), r = e.getAttribute("id");
535
+ if (c === "OpenDriveJunction")
536
+ if (e.getAttribute("selected") === !1) {
537
+ const a = `http://${this.openDriveServer}/api/sumo/getSumoJunction`, l = await f.get(a, {
538
+ params: {
539
+ id: r,
540
+ projectName: this.projectName
541
+ }
542
+ });
543
+ l.status === 200 && l.data.status === 0 && (this.openDriveClickCallback && this.openDriveClickCallback({
544
+ type: "OpenDriveJunction",
545
+ id: r,
546
+ details: l.data.result
547
+ }), e.setAttribute("selected", !0), e.symbol.url = "/GisViewerAssets/Images/point_red.png", this.increasePictureMarkerSize(e, 50));
548
+ } else
549
+ this.openDriveClickCallback && this.openDriveClickCallback({
550
+ type: "OpenDriveJunction",
551
+ id: r,
552
+ details: void 0
553
+ }), e.setAttribute("selected", !1), e.symbol.url = "/GisViewerAssets/Images/point_green.png", this.decreasePictureMarkerSize(e, 30);
554
+ else if (c === "OpenDriveSection")
555
+ if (e.getAttribute("selected"))
556
+ this.sectionLayer.remove(e), this.openDriveClickCallback && this.openDriveClickCallback({
557
+ type: "OpenDriveSection",
558
+ id: r,
559
+ details: void 0
560
+ });
561
+ else {
562
+ this.highlightLayer.remove(e), this.sectionLayer.add(e), e.setAttribute("selected", !0);
563
+ const a = `http://${this.openDriveServer}/api/sumo/getSumoEdge`, l = await f.get(a, {
564
+ params: {
565
+ id: r,
566
+ projectName: this.projectName
567
+ }
568
+ });
569
+ l.status === 200 && l.data.status === 0 && this.openDriveClickCallback && this.openDriveClickCallback({
570
+ type: "OpenDriveSection",
571
+ id: r,
572
+ details: l.data.result
573
+ });
574
+ }
575
+ });
576
+ this.mouseClickHandler = this.view.on("immediate-click", async (o) => {
577
+ t(o).catch(() => {
578
+ });
542
579
  });
543
580
  }
544
- increasePictureMarkerSize(e, o) {
581
+ increasePictureMarkerSize(t, o) {
545
582
  const i = setInterval(() => {
546
- const s = e.symbol, t = s.width;
547
- t < o ? e.symbol = {
583
+ const s = t.symbol, e = s.width;
584
+ e < o ? t.symbol = {
548
585
  type: "picture-marker",
549
586
  url: s.url,
550
- width: t + 1,
551
- height: t + 1
587
+ width: e + 1,
588
+ height: e + 1
552
589
  } : clearInterval(i);
553
590
  }, 20);
554
591
  }
555
- decreasePictureMarkerSize(e, o) {
592
+ decreasePictureMarkerSize(t, o) {
556
593
  const i = setInterval(() => {
557
- const s = e.symbol, t = s.width;
558
- t > o ? e.symbol = {
594
+ const s = t.symbol, e = s.width;
595
+ e > o ? t.symbol = {
559
596
  type: "picture-marker",
560
597
  url: s.url,
561
- width: t - 1,
562
- height: t - 1
598
+ width: e - 1,
599
+ height: e - 1
563
600
  } : clearInterval(i);
564
601
  }, 20);
565
602
  }
@@ -568,11 +605,11 @@ ${this.hitGraphic.attributes.id}`,
568
605
  */
569
606
  async clearOpenDrive() {
570
607
  var o, i;
571
- let e = await this.laneLayer.queryFeatures();
572
- e.features.length > 0 && await this.laneLayer.applyEdits({
573
- deleteFeatures: e.features
574
- }), e = await this.roadNameLayer.queryFeatures(), e.features.length > 0 && await this.roadNameLayer.applyEdits({
575
- deleteFeatures: e.features
608
+ let t = await this.laneLayer.queryFeatures();
609
+ t.features.length > 0 && await this.laneLayer.applyEdits({
610
+ deleteFeatures: t.features
611
+ }), t = await this.roadNameLayer.queryFeatures(), t.features.length > 0 && await this.roadNameLayer.applyEdits({
612
+ deleteFeatures: t.features
576
613
  }), this.highlightLayer.removeAll(), this.junctionLayer.removeAll(), this.wasmLoader.clear(), (o = this.mouseMoveHandler) == null || o.remove(), (i = this.mouseClickHandler) == null || i.remove();
577
614
  }
578
615
  /**
@@ -580,82 +617,112 @@ ${this.hitGraphic.attributes.id}`,
580
617
  * @param params
581
618
  * @returns
582
619
  */
583
- async findSumo(e) {
584
- const { id: o } = e, i = e.flash === void 0 ? !0 : e.flash, s = o.split("+");
585
- if (s.length > 2)
586
- return { status: -1, message: "id格式错误" };
587
- const t = s.length === 2 ? Number(s[1]) : void 0, h = s[0].split("#");
588
- if (h.length > 2)
589
- return { status: -1, message: "id格式错误" };
590
- let l = h[0];
591
- l.startsWith("-") && (l = l.slice(1));
592
- const a = h.length === 2 ? Number(h[1]) : void 0;
593
- return await this.findLane({ roadsectId: l, segmentId: a, laneId: t, flash: i });
620
+ async findSumo(t) {
621
+ const { type: o, id: i } = t, s = t.flash === void 0 ? !0 : t.flash;
622
+ if (o === "junction")
623
+ return await this.findJunction(i, s);
624
+ if (o === "edge") {
625
+ const e = i.split("+");
626
+ if (e.length > 2)
627
+ return { status: -1, message: "id格式错误" };
628
+ const c = e.length === 2 ? Number(e[1]) : void 0, r = e[0].split("#");
629
+ if (r.length > 2)
630
+ return { status: -1, message: "id格式错误" };
631
+ const n = r[0], a = r.length === 2 ? Number(r[1]) : void 0;
632
+ return await this.findLane({ roadsectId: n, segmentId: a, laneId: c, flash: s });
633
+ } else
634
+ return { status: -1, message: "未知类型" };
635
+ }
636
+ async findJunction(t, o) {
637
+ const i = this.junctionLayer.graphics.find(
638
+ (s) => s.attributes.id === t
639
+ );
640
+ if (!i)
641
+ return { status: -1, message: "未找到。请检查路口编号" };
642
+ if (o) {
643
+ const s = new p({
644
+ geometry: i.geometry,
645
+ symbol: {
646
+ type: "simple-marker",
647
+ style: "circle",
648
+ size: 30,
649
+ color: [255, 0, 0, 0.6],
650
+ outline: {
651
+ color: "red",
652
+ width: 1
653
+ }
654
+ }
655
+ });
656
+ this.flashGraphic(s);
657
+ }
658
+ return await this.view.goTo(i.geometry, { duration: 1e3 }), { status: 0, message: "ok" };
594
659
  }
595
660
  /**
596
661
  * 用sumo的id定位车道、基本段、路段
597
662
  * @param params
598
663
  * @returns
599
664
  */
600
- async findLane(e) {
601
- let { segmentId: o, laneId: i } = e;
602
- const { roadsectId: s } = e;
603
- let t = this.allLaneGraphics.filter(
604
- (a) => a.attributes.roadId === s
665
+ async findLane(t) {
666
+ let { roadsectId: o, segmentId: i, laneId: s } = t;
667
+ o.startsWith("-") && (o = o.slice(1));
668
+ let e = this.allLaneGraphics.filter(
669
+ (n) => n.attributes.roadId === o
605
670
  );
606
- if (t.length === 0)
671
+ if (e.length === 0)
607
672
  return { status: -1, message: "未找到。请检查路段编号" };
608
- if (o !== void 0) {
609
- const a = [];
610
- if (t.forEach((r) => {
611
- const n = Number(r.attributes.sectionId);
612
- a.indexOf(n) === -1 && a.push(n);
613
- }), a.sort((r, n) => r - n), o > a.length - 1)
673
+ if (i !== void 0) {
674
+ const n = [];
675
+ if (e.forEach((a) => {
676
+ const l = Number(a.attributes.sectionId);
677
+ n.indexOf(l) === -1 && n.push(l);
678
+ }), n.sort((a, l) => a - l), i > n.length - 1)
614
679
  return { status: -1, message: "未找到。请检查基本段编号" };
615
- o = a[o], t = t.filter(
616
- (r) => Number(r.attributes.sectionId) === o
680
+ i = n[i], e = e.filter(
681
+ (a) => Number(a.attributes.sectionId) === i
617
682
  );
618
683
  }
619
- if (i !== void 0) {
620
- const a = [];
621
- if (t.forEach((r) => {
622
- const n = Number(r.attributes.laneId);
623
- a.indexOf(n) === -1 && a.push(n);
624
- }), a.sort((r, n) => r - n), i > a.length - 1)
684
+ if (s !== void 0) {
685
+ const n = [];
686
+ if (e.forEach((a) => {
687
+ const l = Number(a.attributes.laneId);
688
+ n.indexOf(l) === -1 && n.push(l);
689
+ }), n.sort((a, l) => a - l), s > n.length - 1)
625
690
  return { status: -1, message: "未找到。请检查车道编号" };
626
- i = a[i], t = t.filter(
627
- (r) => Number(r.attributes.laneId) === i
691
+ s = n[s], e = e.filter(
692
+ (a) => Number(a.attributes.laneId) === s
628
693
  );
629
694
  }
630
- const h = t.map(
631
- (a) => a.geometry
632
- ), l = await L.union(h);
633
- if (e.flash) {
634
- this.highlightLayer.removeAll();
635
- const a = new d({
636
- geometry: l,
695
+ const c = e.map(
696
+ (n) => n.geometry
697
+ ), r = await k.union(c);
698
+ if (t.flash) {
699
+ const n = new p({
700
+ geometry: r,
637
701
  symbol: {
638
702
  type: "simple-fill",
639
703
  color: [255, 0, 0, 0.5],
640
704
  style: "solid",
641
705
  outline: {
642
706
  color: "red",
643
- width: 2
707
+ width: 0
644
708
  }
645
709
  }
646
710
  });
647
- this.highlightLayer.add(a);
648
- let r = 0, n = !0;
649
- const u = setInterval(() => {
650
- n ? (this.highlightLayer.opacity -= 0.02, this.highlightLayer.opacity <= 0.1 && (n = !1, r++)) : (this.highlightLayer.opacity += 0.02, this.highlightLayer.opacity >= 1 && (n = !0)), r > 5 && (this.highlightLayer.removeAll(), this.highlightLayer.opacity = 1, clearInterval(u));
651
- }, 20);
711
+ this.flashGraphic(n);
652
712
  }
653
- return await this.view.goTo(l, { duration: 1e3 }), { status: 0, message: "ok" };
713
+ return await this.view.goTo(r, { duration: 1e3 }), { status: 0, message: "ok" };
714
+ }
715
+ flashGraphic(t) {
716
+ this.flashLayer.removeAll(), this.flashLayer.add(t);
717
+ let o = 0, i = !0;
718
+ const s = setInterval(() => {
719
+ i ? (this.flashLayer.opacity -= 0.02, this.flashLayer.opacity <= 0.1 && (i = !1, o++)) : (this.flashLayer.opacity += 0.02, this.flashLayer.opacity >= 1 && (i = !0)), o >= 5 && (this.flashLayer.removeAll(), this.flashLayer.opacity = 1, clearInterval(s));
720
+ }, 10);
654
721
  }
655
- async splitLane(e) {
656
- return { status: 0, message: "ok", result: e };
722
+ async splitLane(t) {
723
+ return { status: 0, message: "ok", result: t };
657
724
  }
658
725
  }
659
726
  export {
660
- N as default
727
+ S as default
661
728
  };
@@ -214,10 +214,12 @@ export interface IShowOpenDriveFromFileParams {
214
214
  showJunctionPolygon: boolean;
215
215
  showJunctionLane: boolean;
216
216
  showRoadName: boolean;
217
- centerMap: boolean;
217
+ centerMap?: boolean;
218
218
  };
219
+ selectedCallback?: (info: any) => void;
219
220
  }
220
221
  export interface IFindSumoParams {
222
+ type: string;
221
223
  id: string;
222
224
  flash?: boolean;
223
225
  }
@@ -229,6 +231,7 @@ export interface ISplitOpenDriveLaneParams {
229
231
  export interface IJunctionTableData {
230
232
  id: string;
231
233
  name: string;
234
+ nodeType: string;
232
235
  type: string;
233
236
  coordinates: number[];
234
237
  district: string;
@@ -6,7 +6,9 @@ export default class OpenDriveRenderer {
6
6
  private laneLayer;
7
7
  private roadNameLayer;
8
8
  private junctionLayer;
9
+ private sectionLayer;
9
10
  private highlightLayer;
11
+ private flashLayer;
10
12
  private allLaneGraphics;
11
13
  private allRefLineGraphics;
12
14
  private mouseMoveHandler;
@@ -15,6 +17,7 @@ export default class OpenDriveRenderer {
15
17
  constructor(view: __esri.MapView | __esri.SceneView);
16
18
  private projectName;
17
19
  private openDriveServer;
20
+ private openDriveClickCallback;
18
21
  showOpenDriveFromFile(params: IShowOpenDriveFromFileParams): Promise<IResult>;
19
22
  /**
20
23
  * 从服务器载入OpenDrive文件解析结果并显示
@@ -48,11 +51,13 @@ export default class OpenDriveRenderer {
48
51
  * @returns
49
52
  */
50
53
  findSumo(params: IFindSumoParams): Promise<IResult>;
54
+ private findJunction;
51
55
  /**
52
56
  * 用sumo的id定位车道、基本段、路段
53
57
  * @param params
54
58
  * @returns
55
59
  */
56
60
  private findLane;
61
+ private flashGraphic;
57
62
  splitLane(params: ISplitOpenDriveLaneParams): Promise<IResult>;
58
63
  }
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const u=require("@arcgis/core/Graphic"),C=require("@arcgis/core/core/promiseUtils"),$=require("@arcgis/core/geometry"),A=require("@arcgis/core/geometry/geometryEngineAsync"),D=require("@arcgis/core/layers/FeatureLayer"),j=require("@arcgis/core/layers/GraphicsLayer"),w=require("axios"),S=require("pako"),O=require("../common-utils.js"),M=require("./wasm-loader.js");function k(p){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(p){for(const t in p)if(t!=="default"){const i=Object.getOwnPropertyDescriptor(p,t);Object.defineProperty(e,t,i.get?i:{enumerable:!0,get:()=>p[t]})}}return e.default=p,Object.freeze(e)}const P=k(C),N=k(A);class b{constructor(e){this.wasmLoader=M.default.getInstance(),this.projectName="",this.openDriveServer="",this.currentSectionCode="",this.currentJunctionId="",this.view=e,this.laneLayer=new D({id:"OpenDriveLane",fields:[{name:"ObjectID",alias:"ObjectID",type:"oid"},{name:"id",alias:"编号",type:"string"},{name:"roadId",alias:"道路号",type:"string"},{name:"roadName",alias:"道路名称",type:"string"},{name:"sectionId",alias:"路段号",type:"string"},{name:"laneId",alias:"车道号",type:"string"},{name:"type",alias:"类型",type:"string"},{name:"sumoId",alias:"sumo编号",type:"string"}],objectIdField:"ObjectID",geometryType:"polygon",spatialReference:{wkid:4326},source:[],outFields:["*"],renderer:{type:"unique-value",field:"type",defaultSymbol:{type:"simple-fill",color:[100,100,100],style:"solid",outline:{color:"white",width:1}},uniqueValueInfos:[{value:"shoulder",label:"路肩",symbol:{type:"simple-fill",color:"#008000",style:"solid",outline:{color:"white",width:1}}},{value:"border",label:"路沿",symbol:{type:"simple-fill",color:"#DCDCDC",style:"solid",outline:{color:"white",width:1}}},{value:"driving",label:"机动车道",symbol:{type:"simple-fill",color:[47,79,79,.8],style:"solid",outline:{color:"white",width:1}}},{value:"none",label:"无",symbol:{type:"simple-fill",color:[111,120,135],style:"none",outline:{color:"white",width:1}}},{value:"restricted",label:"禁行区",symbol:{type:"simple-fill",color:"yellow",style:"solid",outline:{color:"yellow",width:2}}},{value:"parking",label:"停车区",symbol:{type:"simple-fill",color:[115,115,115],style:"solid",outline:{color:"white",width:1}}},{value:"median",label:"中央隔离带",symbol:{type:"simple-fill",color:"#008000",style:"solid",outline:{color:"white",width:1}}},{value:"biking",label:"非机动车道",symbol:{type:"simple-fill",color:"#D3D3D3",style:"solid",outline:{color:"white",width:1}}},{value:"sidewalk",label:"人行道",symbol:{type:"simple-fill",color:"#C0C0C0",style:"solid",outline:{color:"white",width:1}}},{value:"junction",label:"路口区域",symbol:{type:"simple-fill",color:"#2F4F4F",style:"solid",outline:{color:"white",width:1}}},{value:"selected",label:"选中车道",symbol:{type:"simple-fill",color:[141,168,211],style:"solid",outline:{color:"white",width:1}}}]}}),this.roadNameLayer=new D({id:"OpenDriveRoadName",fields:[{name:"ObjectID",alias:"ObjectID",type:"oid"},{name:"roadId",alias:"道路号",type:"string"},{name:"roadName",alias:"道路名称",type:"string"}],objectIdField:"ObjectID",geometryType:"polyline",spatialReference:{wkid:4326},source:[],renderer:{type:"simple",symbol:{type:"simple-line",style:"solid",color:[0,0,0,0],width:1}},labelingInfo:[{symbol:{type:"text",color:"black",haloColor:"white",haloSize:1,font:{size:12,family:"sans-serif"}},labelPlacement:this.view.type==="2d"?"center-along":void 0,labelExpressionInfo:{expression:"$feature.roadName"}}]}),this.junctionLayer=new j({id:"OpenDriveJunction"}),this.highlightLayer=new j({id:"OpenDriveHighlight"}),this.view.map.addMany([this.laneLayer,this.junctionLayer,this.roadNameLayer,this.highlightLayer])}static getInstance(e){return this.instance||(this.instance=new b(e)),this.instance}async showOpenDriveFromFile(e){var d,c;this.projectName=Date.now().toString(),this.openDriveServer=e.server;const t=`http://${this.openDriveServer}/api/openDrive/uploadXodr`,i=await w.post(t,null,{params:{url:e.file,projectName:this.projectName}});if(i.status!==200)throw new Error(`OpenDriveRenderer: ${i.statusText}`);console.time("渲染用时");const r=i.data.result.geoSetting;O.default.setGeoData(r.geoReference,r.offsetX,r.offsetY);let s=i.data.result.json;s.startsWith(window.location.protocol)||(s=`${window.location.protocol}//${e.server}${s}`);const n=await(await fetch(s)).arrayBuffer(),a=S.inflate(n,{to:"string"}),o=JSON.parse(a);await this.showAllLanes(o,((d=e.options)==null?void 0:d.showJunctionLane)||!1,((c=e.options)==null?void 0:c.showRoadName)||!0);const l=i.data.result.junctions;if(this.showJunction(l),e.options&&e.options.centerMap!==!1){const g=O.default.transformPointProjection([0,0]);await this.view.goTo(g)}return this.mouseMoveHandler||this.monitorMouseMove(),this.mouseClickHandler||this.monitorMouseClick(),console.timeEnd("渲染用时"),{status:0,message:"ok"}}async showOpenDriveFromServer(e,t){const i=`http://${e}/api/openDrive/analyzeXodr`,r=await w.get(i,{headers:{projectName:t},params:{analyze:!1,compressed:!0}});if(r.status!==200)throw new Error(`OpenDriveRenderer: ${r.statusText}`);let s=r.data.result.json;s.startsWith(window.location.protocol)||(s=`${window.location.protocol}//${e}${s}`);const n=await(await fetch(s)).arrayBuffer(),a=S.inflate(n,{to:"string"}),o=JSON.parse(a);return await this.showAllLanes(o,!1,!1),{status:0,message:"ok"}}async showAllLanes(e,t,i){const r=await this.laneLayer.queryFeatures();return r.features.length>0&&this.laneLayer.applyEdits({deleteFeatures:r.features}),this.roadNameLayer.visible=i,new Promise(s=>{let h=0;this.allLaneGraphics=[],this.allRefLineGraphics=[];const n=[];for(const o of e){if(!t&&o.junction!=="-1")continue;const{id:l,refLine:d}=o;let c=o.name;c.includes("(")&&(c=c.slice(0,c.indexOf("("))),c=c.replace(/(.)/g,"$1 ");const g=new u({geometry:{type:"polyline",paths:[d]},attributes:{ObjectID:h++,roadId:l,roadName:c}});this.allRefLineGraphics.push(g);for(const v of o.laneSections){const I=Number(v.id);for(const y of v.lanePaths){const m=Number(y.id);if(m===0)continue;const F=y.type,f=y.innerPath.concat(y.outerPath.reverse());if(f.length<=3){console.warn(`lane ${m} has less than 3 points`);continue}f.push(y.innerPath[0]);const L=new $.Polygon({rings:[f]});if(L){const G=new u({geometry:L,attributes:{ObjectID:h++,id:`${l}+${I}+${m}`,roadId:l,roadName:o.name,sectionId:I,laneId:m,type:F,sumoId:""}});this.allLaneGraphics.push(G),n.push(G)}}}}const a=setInterval(()=>{if(n.length>0||this.allRefLineGraphics.length>0){if(n.length>0){const o=n.splice(0,100);this.laneLayer.applyEdits({addFeatures:o})}if(this.allRefLineGraphics.length>0){const o=this.allRefLineGraphics.splice(0,10);this.roadNameLayer.applyEdits({addFeatures:o})}}else clearInterval(a),s()},10)})}showJunction(e){const t=[];for(const i of e){const r=new u({geometry:{type:"point",x:i.coordinates[0],y:i.coordinates[1]},attributes:{...i,selected:!1},symbol:{type:"picture-marker",url:i.crossId?"/GisViewerAssets/Images/point_green.png":"/GisViewerAssets/Images/normal-cross.png",width:30,height:30}});t.push(r)}this.junctionLayer.addMany(t)}monitorMouseMove(){const e=P.debounce(async t=>{var h;const r=(h=(await this.view.hitTest(t,{include:[this.laneLayer,this.junctionLayer]})).results)==null?void 0:h.filter(n=>n.type==="graphic");if(r.length===0){this.currentSectionCode!==""&&(this.currentSectionCode="",this.highlightGraphic=void 0,this.highlightLayer.removeAll()),this.currentJunctionId!==""&&(this.currentJunctionId="",this.highlightGraphic=void 0,this.highlightLayer.removeAll());return}const s=r[0];if(this.hitGraphic=s.graphic,s.layer.id==="OpenDriveLane"){const n=`${this.hitGraphic.attributes.roadId}+${this.hitGraphic.attributes.sectionId}`;if(n===this.currentSectionCode)return;this.currentSectionCode=n;const a=this.allLaneGraphics.filter(l=>`${l.attributes.roadId}+${l.attributes.sectionId}`===n),o=await N.union(a.map(l=>l.geometry));this.highlightGraphic=new u({geometry:o,symbol:{type:"simple-fill",color:[255,0,0,.5],style:"solid",outline:{color:"red",width:2}},attributes:{type:"OpenDriveSection",id:n,detail:""}}),this.highlightLayer.removeAll(),this.highlightLayer.add(this.highlightGraphic)}else if(s.layer.id==="OpenDriveJunction"){const n=this.hitGraphic.attributes.id;if(n===this.currentJunctionId)return;this.currentJunctionId=n,this.highlightGraphic=new u({geometry:this.hitGraphic.geometry,symbol:{type:"simple-marker",style:"circle",size:40,color:[0,0,0,0],outline:{color:[0,0,0,0]}},attributes:{type:"OpenDriveJunction",id:n}});const a=new u({geometry:this.hitGraphic.geometry,symbol:{type:"text",color:"black",backgroundColor:"gray",text:`${this.hitGraphic.attributes.name}
2
- ${this.hitGraphic.attributes.id}`,font:{size:10},yoffset:40}});this.highlightLayer.removeAll(),this.highlightLayer.addMany([this.highlightGraphic,a])}});this.mouseMoveHandler=this.view.on("pointer-move",async t=>{e(t).catch(()=>{})})}monitorMouseClick(){this.mouseClickHandler=this.view.on("immediate-click",async()=>{var e,t;if(this.hitGraphic&&!this.currentSectionCode){if(this.currentJunctionId)if(this.hitGraphic.getAttribute("selected")===!1){const i=`http://${this.openDriveServer}/api/sumo/getSumoJunction`,r=await w.get(i,{params:{id:this.currentJunctionId,projectName:this.projectName}});r.status===200&&r.data.status===0&&((e=this.highlightGraphic)==null||e.setAttribute("detail",r.data.result),this.hitGraphic.setAttribute("selected",!0),this.hitGraphic.symbol.url="/GisViewerAssets/Images/point_red.png",this.increasePictureMarkerSize(this.hitGraphic,50))}else(t=this.highlightGraphic)==null||t.setAttribute("detail",void 0),this.hitGraphic.setAttribute("selected",!1),this.hitGraphic.symbol.url="/GisViewerAssets/Images/point_green.png",this.decreasePictureMarkerSize(this.hitGraphic,30)}})}increasePictureMarkerSize(e,t){const i=setInterval(()=>{const r=e.symbol,s=r.width;s<t?e.symbol={type:"picture-marker",url:r.url,width:s+1,height:s+1}:clearInterval(i)},20)}decreasePictureMarkerSize(e,t){const i=setInterval(()=>{const r=e.symbol,s=r.width;s>t?e.symbol={type:"picture-marker",url:r.url,width:s-1,height:s-1}:clearInterval(i)},20)}async clearOpenDrive(){var t,i;let e=await this.laneLayer.queryFeatures();e.features.length>0&&await this.laneLayer.applyEdits({deleteFeatures:e.features}),e=await this.roadNameLayer.queryFeatures(),e.features.length>0&&await this.roadNameLayer.applyEdits({deleteFeatures:e.features}),this.highlightLayer.removeAll(),this.junctionLayer.removeAll(),this.wasmLoader.clear(),(t=this.mouseMoveHandler)==null||t.remove(),(i=this.mouseClickHandler)==null||i.remove()}async findSumo(e){const{id:t}=e,i=e.flash===void 0?!0:e.flash,r=t.split("+");if(r.length>2)return{status:-1,message:"id格式错误"};const s=r.length===2?Number(r[1]):void 0,h=r[0].split("#");if(h.length>2)return{status:-1,message:"id格式错误"};let n=h[0];n.startsWith("-")&&(n=n.slice(1));const a=h.length===2?Number(h[1]):void 0;return await this.findLane({roadsectId:n,segmentId:a,laneId:s,flash:i})}async findLane(e){let{segmentId:t,laneId:i}=e;const{roadsectId:r}=e;let s=this.allLaneGraphics.filter(a=>a.attributes.roadId===r);if(s.length===0)return{status:-1,message:"未找到。请检查路段编号"};if(t!==void 0){const a=[];if(s.forEach(o=>{const l=Number(o.attributes.sectionId);a.indexOf(l)===-1&&a.push(l)}),a.sort((o,l)=>o-l),t>a.length-1)return{status:-1,message:"未找到。请检查基本段编号"};t=a[t],s=s.filter(o=>Number(o.attributes.sectionId)===t)}if(i!==void 0){const a=[];if(s.forEach(o=>{const l=Number(o.attributes.laneId);a.indexOf(l)===-1&&a.push(l)}),a.sort((o,l)=>o-l),i>a.length-1)return{status:-1,message:"未找到。请检查车道编号"};i=a[i],s=s.filter(o=>Number(o.attributes.laneId)===i)}const h=s.map(a=>a.geometry),n=await N.union(h);if(e.flash){this.highlightLayer.removeAll();const a=new u({geometry:n,symbol:{type:"simple-fill",color:[255,0,0,.5],style:"solid",outline:{color:"red",width:2}}});this.highlightLayer.add(a);let o=0,l=!0;const d=setInterval(()=>{l?(this.highlightLayer.opacity-=.02,this.highlightLayer.opacity<=.1&&(l=!1,o++)):(this.highlightLayer.opacity+=.02,this.highlightLayer.opacity>=1&&(l=!0)),o>5&&(this.highlightLayer.removeAll(),this.highlightLayer.opacity=1,clearInterval(d))},20)}return await this.view.goTo(n,{duration:1e3}),{status:0,message:"ok"}}async splitLane(e){return{status:0,message:"ok",result:e}}}exports.default=b;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const d=require("@arcgis/core/Graphic"),F=require("@arcgis/core/core/promiseUtils"),$=require("@arcgis/core/geometry"),J=require("@arcgis/core/geometry/geometryEngineAsync"),j=require("@arcgis/core/layers/FeatureLayer"),m=require("@arcgis/core/layers/GraphicsLayer"),g=require("axios"),G=require("pako"),C=require("../common-utils.js"),M=require("./wasm-loader.js");function N(p){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(p){for(const s in p)if(s!=="default"){const i=Object.getOwnPropertyDescriptor(p,s);Object.defineProperty(e,s,i.get?i:{enumerable:!0,get:()=>p[s]})}}return e.default=p,Object.freeze(e)}const O=N(F),S=N(J);class v{constructor(e){this.wasmLoader=M.default.getInstance(),this.projectName="",this.openDriveServer="",this.currentSectionCode="",this.currentJunctionId="",this.view=e,this.laneLayer=new j({id:"OpenDriveLane",fields:[{name:"ObjectID",alias:"ObjectID",type:"oid"},{name:"id",alias:"编号",type:"string"},{name:"roadId",alias:"道路号",type:"string"},{name:"roadName",alias:"道路名称",type:"string"},{name:"sectionId",alias:"路段号",type:"string"},{name:"laneId",alias:"车道号",type:"string"},{name:"type",alias:"类型",type:"string"},{name:"sumoId",alias:"sumo编号",type:"string"}],objectIdField:"ObjectID",geometryType:"polygon",spatialReference:{wkid:4326},source:[],outFields:["*"],renderer:{type:"unique-value",field:"type",defaultSymbol:{type:"simple-fill",color:[100,100,100],style:"solid",outline:{color:"white",width:1}},uniqueValueInfos:[{value:"shoulder",label:"路肩",symbol:{type:"simple-fill",color:"#008000",style:"solid",outline:{color:"white",width:1}}},{value:"border",label:"路沿",symbol:{type:"simple-fill",color:"#DCDCDC",style:"solid",outline:{color:"white",width:1}}},{value:"driving",label:"机动车道",symbol:{type:"simple-fill",color:[47,79,79,.8],style:"solid",outline:{color:"white",width:1}}},{value:"none",label:"无",symbol:{type:"simple-fill",color:[111,120,135],style:"none",outline:{color:"white",width:1}}},{value:"restricted",label:"禁行区",symbol:{type:"simple-fill",color:"yellow",style:"solid",outline:{color:"yellow",width:2}}},{value:"parking",label:"停车区",symbol:{type:"simple-fill",color:[115,115,115],style:"solid",outline:{color:"white",width:1}}},{value:"median",label:"中央隔离带",symbol:{type:"simple-fill",color:"#008000",style:"solid",outline:{color:"white",width:1}}},{value:"biking",label:"非机动车道",symbol:{type:"simple-fill",color:"#D3D3D3",style:"solid",outline:{color:"white",width:1}}},{value:"sidewalk",label:"人行道",symbol:{type:"simple-fill",color:"#C0C0C0",style:"solid",outline:{color:"white",width:1}}},{value:"junction",label:"路口区域",symbol:{type:"simple-fill",color:"#2F4F4F",style:"solid",outline:{color:"white",width:1}}},{value:"selected",label:"选中车道",symbol:{type:"simple-fill",color:[141,168,211],style:"solid",outline:{color:"white",width:1}}}]}}),this.roadNameLayer=new j({id:"OpenDriveRoadName",fields:[{name:"ObjectID",alias:"ObjectID",type:"oid"},{name:"roadId",alias:"道路号",type:"string"},{name:"roadName",alias:"道路名称",type:"string"}],objectIdField:"ObjectID",geometryType:"polyline",spatialReference:{wkid:4326},source:[],renderer:{type:"simple",symbol:{type:"simple-line",style:"solid",color:[0,0,0,0],width:1}},labelingInfo:[{symbol:{type:"text",color:"black",haloColor:"white",haloSize:1,font:{size:12,family:"sans-serif"}},labelPlacement:this.view.type==="2d"?"center-along":void 0,labelExpressionInfo:{expression:"$feature.roadName"}}]}),this.junctionLayer=new m({id:"OpenDriveJunction"}),this.sectionLayer=new m({id:"OpenDriveSection"}),this.highlightLayer=new m({id:"OpenDriveHighlight"}),this.flashLayer=new m({id:"OpenDriveFlash"}),this.view.map.addMany([this.laneLayer,this.junctionLayer,this.sectionLayer,this.roadNameLayer,this.highlightLayer,this.flashLayer])}static getInstance(e){return this.instance||(this.instance=new v(e)),this.instance}async showOpenDriveFromFile(e){var h,u;this.openDriveClickCallback=e.selectedCallback,this.projectName=Date.now().toString(),this.openDriveServer=e.server;const s=`http://${this.openDriveServer}/api/openDrive/uploadXodr`,i=await g.post(s,{},{params:{url:e.file,projectName:this.projectName}});if(i.status!==200)throw new Error(`OpenDriveRenderer: ${i.statusText}`);console.time("渲染用时");const r=i.data.result.geoSetting;C.default.setGeoData(r.geoReference,r.offsetX,r.offsetY);let t=i.data.result.json;t.startsWith(window.location.protocol)||(t=`${window.location.protocol}//${e.server}${t}`);const o=await(await fetch(t)).arrayBuffer(),n=G.inflate(o,{to:"string"}),a=JSON.parse(n);await this.showAllLanes(a,((h=e.options)==null?void 0:h.showJunctionLane)||!1,((u=e.options)==null?void 0:u.showRoadName)||!0);const l=i.data.result.junctions;if(this.showJunction(l),e.options&&e.options.centerMap!==!1){const w=C.default.transformPointProjection([0,0]);await this.view.goTo(w)}return this.mouseMoveHandler||this.monitorMouseMove(),this.mouseClickHandler||this.monitorMouseClick(),console.timeEnd("渲染用时"),{status:0,message:"ok"}}async showOpenDriveFromServer(e,s){const i=`http://${e}/api/openDrive/analyzeXodr`,r=await g.get(i,{headers:{projectName:s},params:{analyze:!1,compressed:!0}});if(r.status!==200)throw new Error(`OpenDriveRenderer: ${r.statusText}`);let t=r.data.result.json;t.startsWith(window.location.protocol)||(t=`${window.location.protocol}//${e}${t}`);const o=await(await fetch(t)).arrayBuffer(),n=G.inflate(o,{to:"string"}),a=JSON.parse(n);return await this.showAllLanes(a,!1,!1),{status:0,message:"ok"}}async showAllLanes(e,s,i){const r=await this.laneLayer.queryFeatures();return r.features.length>0&&this.laneLayer.applyEdits({deleteFeatures:r.features}),this.roadNameLayer.visible=i,new Promise(t=>{let c=0;this.allLaneGraphics=[],this.allRefLineGraphics=[];const o=[];for(const a of e){if(!s&&a.junction!=="-1")continue;const{id:l,refLine:h}=a;let u=a.name;u.includes("(")&&(u=u.slice(0,u.indexOf("("))),u=u.replace(/(.)/g,"$1 ");const w=new d({geometry:{type:"polyline",paths:[h]},attributes:{ObjectID:c++,roadId:l,roadName:u}});this.allRefLineGraphics.push(w);for(const L of a.laneSections){const I=Number(L.id);for(const y of L.lanePaths){const f=Number(y.id);if(f===0)continue;const A=y.type,b=y.innerPath.concat(y.outerPath.reverse());if(b.length<=3){console.warn(`lane ${f} has less than 3 points`);continue}b.push(y.innerPath[0]);const D=new $.Polygon({rings:[b]});if(D){const k=new d({geometry:D,attributes:{ObjectID:c++,id:`${l}+${I}+${f}`,roadId:l,roadName:a.name,sectionId:I,laneId:f,type:A,sumoId:""}});this.allLaneGraphics.push(k),o.push(k)}}}}const n=setInterval(()=>{if(o.length>0||this.allRefLineGraphics.length>0){if(o.length>0){const a=o.splice(0,100);this.laneLayer.applyEdits({addFeatures:a})}if(this.allRefLineGraphics.length>0){const a=this.allRefLineGraphics.splice(0,10);this.roadNameLayer.applyEdits({addFeatures:a})}}else clearInterval(n),t()},10)})}showJunction(e){const s=[];for(const i of e){i.nodeType=i.type;const r=new d({geometry:{type:"point",x:i.coordinates[0],y:i.coordinates[1]},attributes:{...i,selected:!1,type:"OpenDriveJunction"},symbol:{type:"picture-marker",url:i.crossId?"/GisViewerAssets/Images/point_green.png":"/GisViewerAssets/Images/normal-cross.png",width:30,height:30}});s.push(r)}this.junctionLayer.addMany(s)}monitorMouseMove(){const e=O.debounce(async s=>{var c;const r=(c=(await this.view.hitTest(s,{include:[this.laneLayer,this.junctionLayer]})).results)==null?void 0:c.filter(o=>o.type==="graphic");if(r.length===0){this.currentSectionCode!==""&&(this.currentSectionCode="",this.highlightGraphic=void 0,this.highlightLayer.removeAll()),this.currentJunctionId!==""&&(this.currentJunctionId="",this.highlightGraphic=void 0,this.highlightLayer.removeAll());return}const t=r[0];if(this.hitGraphic=t.graphic,t.layer.id==="OpenDriveLane"){const o=`${this.hitGraphic.attributes.roadId}+${this.hitGraphic.attributes.sectionId}`;if(o===this.currentSectionCode||this.sectionLayer.graphics.findIndex(h=>h.getAttribute("id")===o)>=0)return;this.currentSectionCode=o;const a=this.allLaneGraphics.filter(h=>`${h.attributes.roadId}+${h.attributes.sectionId}`===o),l=await S.union(a.map(h=>h.geometry));this.highlightGraphic=new d({geometry:l,symbol:{type:"simple-fill",color:[255,0,0,.5],style:"solid",outline:{color:"red",width:2}},attributes:{type:"OpenDriveSection",id:o,selected:!1}}),this.highlightLayer.removeAll(),this.highlightLayer.add(this.highlightGraphic)}else if(t.layer.id==="OpenDriveJunction"){const o=this.hitGraphic.attributes.id;if(o===this.currentJunctionId)return;this.currentJunctionId=o;const n=new d({geometry:this.hitGraphic.geometry,symbol:{type:"text",color:"black",backgroundColor:"gray",text:`${this.hitGraphic.attributes.name}
2
+ ${this.hitGraphic.attributes.id}`,font:{size:10},yoffset:40}});this.highlightLayer.removeAll(),this.highlightLayer.add(n)}});this.mouseMoveHandler=this.view.on("pointer-move",async s=>{e(s).catch(()=>{})})}monitorMouseClick(){const e=O.debounce(async s=>{var n;const r=(n=(await this.view.hitTest(s,{include:[this.highlightLayer,this.junctionLayer,this.sectionLayer]})).results)==null?void 0:n.filter(a=>a.type==="graphic");if(r.length===0)return;const t=r[0].graphic,c=t.getAttribute("type"),o=t.getAttribute("id");if(c==="OpenDriveJunction")if(t.getAttribute("selected")===!1){const a=`http://${this.openDriveServer}/api/sumo/getSumoJunction`,l=await g.get(a,{params:{id:o,projectName:this.projectName}});l.status===200&&l.data.status===0&&(this.openDriveClickCallback&&this.openDriveClickCallback({type:"OpenDriveJunction",id:o,details:l.data.result}),t.setAttribute("selected",!0),t.symbol.url="/GisViewerAssets/Images/point_red.png",this.increasePictureMarkerSize(t,50))}else this.openDriveClickCallback&&this.openDriveClickCallback({type:"OpenDriveJunction",id:o,details:void 0}),t.setAttribute("selected",!1),t.symbol.url="/GisViewerAssets/Images/point_green.png",this.decreasePictureMarkerSize(t,30);else if(c==="OpenDriveSection")if(t.getAttribute("selected"))this.sectionLayer.remove(t),this.openDriveClickCallback&&this.openDriveClickCallback({type:"OpenDriveSection",id:o,details:void 0});else{this.highlightLayer.remove(t),this.sectionLayer.add(t),t.setAttribute("selected",!0);const a=`http://${this.openDriveServer}/api/sumo/getSumoEdge`,l=await g.get(a,{params:{id:o,projectName:this.projectName}});l.status===200&&l.data.status===0&&this.openDriveClickCallback&&this.openDriveClickCallback({type:"OpenDriveSection",id:o,details:l.data.result})}});this.mouseClickHandler=this.view.on("immediate-click",async s=>{e(s).catch(()=>{})})}increasePictureMarkerSize(e,s){const i=setInterval(()=>{const r=e.symbol,t=r.width;t<s?e.symbol={type:"picture-marker",url:r.url,width:t+1,height:t+1}:clearInterval(i)},20)}decreasePictureMarkerSize(e,s){const i=setInterval(()=>{const r=e.symbol,t=r.width;t>s?e.symbol={type:"picture-marker",url:r.url,width:t-1,height:t-1}:clearInterval(i)},20)}async clearOpenDrive(){var s,i;let e=await this.laneLayer.queryFeatures();e.features.length>0&&await this.laneLayer.applyEdits({deleteFeatures:e.features}),e=await this.roadNameLayer.queryFeatures(),e.features.length>0&&await this.roadNameLayer.applyEdits({deleteFeatures:e.features}),this.highlightLayer.removeAll(),this.junctionLayer.removeAll(),this.wasmLoader.clear(),(s=this.mouseMoveHandler)==null||s.remove(),(i=this.mouseClickHandler)==null||i.remove()}async findSumo(e){const{type:s,id:i}=e,r=e.flash===void 0?!0:e.flash;if(s==="junction")return await this.findJunction(i,r);if(s==="edge"){const t=i.split("+");if(t.length>2)return{status:-1,message:"id格式错误"};const c=t.length===2?Number(t[1]):void 0,o=t[0].split("#");if(o.length>2)return{status:-1,message:"id格式错误"};const n=o[0],a=o.length===2?Number(o[1]):void 0;return await this.findLane({roadsectId:n,segmentId:a,laneId:c,flash:r})}else return{status:-1,message:"未知类型"}}async findJunction(e,s){const i=this.junctionLayer.graphics.find(r=>r.attributes.id===e);if(!i)return{status:-1,message:"未找到。请检查路口编号"};if(s){const r=new d({geometry:i.geometry,symbol:{type:"simple-marker",style:"circle",size:30,color:[255,0,0,.6],outline:{color:"red",width:1}}});this.flashGraphic(r)}return await this.view.goTo(i.geometry,{duration:1e3}),{status:0,message:"ok"}}async findLane(e){let{roadsectId:s,segmentId:i,laneId:r}=e;s.startsWith("-")&&(s=s.slice(1));let t=this.allLaneGraphics.filter(n=>n.attributes.roadId===s);if(t.length===0)return{status:-1,message:"未找到。请检查路段编号"};if(i!==void 0){const n=[];if(t.forEach(a=>{const l=Number(a.attributes.sectionId);n.indexOf(l)===-1&&n.push(l)}),n.sort((a,l)=>a-l),i>n.length-1)return{status:-1,message:"未找到。请检查基本段编号"};i=n[i],t=t.filter(a=>Number(a.attributes.sectionId)===i)}if(r!==void 0){const n=[];if(t.forEach(a=>{const l=Number(a.attributes.laneId);n.indexOf(l)===-1&&n.push(l)}),n.sort((a,l)=>a-l),r>n.length-1)return{status:-1,message:"未找到。请检查车道编号"};r=n[r],t=t.filter(a=>Number(a.attributes.laneId)===r)}const c=t.map(n=>n.geometry),o=await S.union(c);if(e.flash){const n=new d({geometry:o,symbol:{type:"simple-fill",color:[255,0,0,.5],style:"solid",outline:{color:"red",width:0}}});this.flashGraphic(n)}return await this.view.goTo(o,{duration:1e3}),{status:0,message:"ok"}}flashGraphic(e){this.flashLayer.removeAll(),this.flashLayer.add(e);let s=0,i=!0;const r=setInterval(()=>{i?(this.flashLayer.opacity-=.02,this.flashLayer.opacity<=.1&&(i=!1,s++)):(this.flashLayer.opacity+=.02,this.flashLayer.opacity>=1&&(i=!0)),s>=5&&(this.flashLayer.removeAll(),this.flashLayer.opacity=1,clearInterval(r))},10)}async splitLane(e){return{status:0,message:"ok",result:e}}}exports.default=v;
@@ -214,10 +214,12 @@ export interface IShowOpenDriveFromFileParams {
214
214
  showJunctionPolygon: boolean;
215
215
  showJunctionLane: boolean;
216
216
  showRoadName: boolean;
217
- centerMap: boolean;
217
+ centerMap?: boolean;
218
218
  };
219
+ selectedCallback?: (info: any) => void;
219
220
  }
220
221
  export interface IFindSumoParams {
222
+ type: string;
221
223
  id: string;
222
224
  flash?: boolean;
223
225
  }
@@ -229,6 +231,7 @@ export interface ISplitOpenDriveLaneParams {
229
231
  export interface IJunctionTableData {
230
232
  id: string;
231
233
  name: string;
234
+ nodeType: string;
232
235
  type: string;
233
236
  coordinates: number[];
234
237
  district: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gisviewer-vue3-arcgis",
3
- "version": "1.0.120",
3
+ "version": "1.0.122",
4
4
  "main": "lib/index.js",
5
5
  "module": "es/index.mjs",
6
6
  "files": [