gisviewer-vue3-arcgis 1.0.121 → 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,25 +268,27 @@ 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;
283
+ async showOpenDriveFromFile(t) {
284
+ var h, d;
285
+ this.openDriveClickCallback = t.selectedCallback, this.projectName = Date.now().toString(), this.openDriveServer = t.server;
284
286
  const o = `http://${this.openDriveServer}/api/openDrive/uploadXodr`, i = await f.post(
285
287
  o,
286
288
  {},
287
289
  {
288
290
  params: {
289
- url: e.file,
291
+ url: t.file,
290
292
  projectName: this.projectName
291
293
  }
292
294
  }
@@ -295,23 +297,23 @@ class N {
295
297
  throw new Error(`OpenDriveRenderer: ${i.statusText}`);
296
298
  console.time("渲染用时");
297
299
  const s = i.data.result.geoSetting;
298
- S.setGeoData(
300
+ j.setGeoData(
299
301
  s.geoReference,
300
302
  s.offsetX,
301
303
  s.offsetY
302
304
  );
303
- let t = i.data.result.json;
304
- t.startsWith(window.location.protocol) || (t = `${window.location.protocol}//${e.server}${t}`);
305
- 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);
306
308
  await this.showAllLanes(
307
- r,
308
- ((u = e.options) == null ? void 0 : u.showJunctionLane) || !1,
309
- ((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
310
312
  );
311
- const n = i.data.result.junctions;
312
- if (this.showJunction(n), e.options && e.options.centerMap !== !1) {
313
- const m = S.transformPointProjection([0, 0]);
314
- 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);
315
317
  }
316
318
  return this.mouseMoveHandler || this.monitorMouseMove(), this.mouseClickHandler || this.monitorMouseClick(), console.timeEnd("渲染用时"), { status: 0, message: "ok" };
317
319
  }
@@ -320,8 +322,8 @@ class N {
320
322
  * @param server
321
323
  * @param projectName
322
324
  */
323
- async showOpenDriveFromServer(e, o) {
324
- 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, {
325
327
  headers: {
326
328
  projectName: o
327
329
  },
@@ -332,102 +334,107 @@ class N {
332
334
  });
333
335
  if (s.status !== 200)
334
336
  throw new Error(`OpenDriveRenderer: ${s.statusText}`);
335
- let t = s.data.result.json;
336
- t.startsWith(window.location.protocol) || (t = `${window.location.protocol}//${e}${t}`);
337
- const l = await (await fetch(t)).arrayBuffer(), a = j.inflate(l, { to: "string" }), r = JSON.parse(a);
338
- 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" };
339
341
  }
340
- async showAllLanes(e, o, i) {
342
+ async showAllLanes(t, o, i) {
341
343
  const s = await this.laneLayer.queryFeatures();
342
344
  return s.features.length > 0 && this.laneLayer.applyEdits({
343
345
  deleteFeatures: s.features
344
- }), this.roadNameLayer.visible = i, new Promise((t) => {
345
- let h = 0;
346
+ }), this.roadNameLayer.visible = i, new Promise((e) => {
347
+ let c = 0;
346
348
  this.allLaneGraphics = [], this.allRefLineGraphics = [];
347
- const l = [];
348
- for (const r of e) {
349
- if (!o && r.junction !== "-1")
349
+ const r = [];
350
+ for (const a of t) {
351
+ if (!o && a.junction !== "-1")
350
352
  continue;
351
- const { id: n, refLine: u } = r;
352
- let c = r.name;
353
- c.includes("(") && (c = c.slice(0, c.indexOf("("))), c = c.replace(/(.)/g, "$1 ");
354
- 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({
355
357
  geometry: {
356
358
  type: "polyline",
357
- paths: [u]
359
+ paths: [h]
358
360
  },
359
361
  attributes: {
360
- ObjectID: h++,
361
- roadId: n,
362
- roadName: c
362
+ ObjectID: c++,
363
+ roadId: l,
364
+ roadName: d
363
365
  }
364
366
  });
365
- this.allRefLineGraphics.push(m);
366
- for (const w of r.laneSections) {
367
- const b = Number(w.id);
368
- for (const p of w.lanePaths) {
369
- 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);
370
372
  if (y === 0)
371
373
  continue;
372
- const k = p.type, g = p.innerPath.concat(
373
- p.outerPath.reverse()
374
+ const O = u.type, w = u.innerPath.concat(
375
+ u.outerPath.reverse()
374
376
  );
375
- if (g.length <= 3) {
377
+ if (w.length <= 3) {
376
378
  console.warn(`lane ${y} has less than 3 points`);
377
379
  continue;
378
380
  }
379
- g.push(p.innerPath[0]);
380
- const v = new C({
381
- rings: [g]
381
+ w.push(u.innerPath[0]);
382
+ const L = new N({
383
+ rings: [w]
382
384
  });
383
- if (v) {
384
- const I = new d({
385
- geometry: v,
385
+ if (L) {
386
+ const I = new p({
387
+ geometry: L,
386
388
  attributes: {
387
- ObjectID: h++,
388
- id: `${n}+${b}+${y}`,
389
- roadId: n,
390
- roadName: r.name,
389
+ ObjectID: c++,
390
+ id: `${l}+${b}+${y}`,
391
+ roadId: l,
392
+ roadName: a.name,
391
393
  sectionId: b,
392
394
  laneId: y,
393
- type: k,
395
+ type: O,
394
396
  sumoId: ""
395
397
  }
396
398
  });
397
- this.allLaneGraphics.push(I), l.push(I);
399
+ this.allLaneGraphics.push(I), r.push(I);
398
400
  }
399
401
  }
400
402
  }
401
403
  }
402
- const a = setInterval(() => {
403
- if (l.length > 0 || this.allRefLineGraphics.length > 0) {
404
- if (l.length > 0) {
405
- 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);
406
408
  this.laneLayer.applyEdits({
407
- addFeatures: r
409
+ addFeatures: a
408
410
  });
409
411
  }
410
412
  if (this.allRefLineGraphics.length > 0) {
411
- const r = this.allRefLineGraphics.splice(0, 10);
413
+ const a = this.allRefLineGraphics.splice(0, 10);
412
414
  this.roadNameLayer.applyEdits({
413
- addFeatures: r
415
+ addFeatures: a
414
416
  });
415
417
  }
416
418
  } else
417
- clearInterval(a), t();
419
+ clearInterval(n), e();
418
420
  }, 10);
419
421
  });
420
422
  }
421
- showJunction(e) {
423
+ showJunction(t) {
422
424
  const o = [];
423
- for (const i of e) {
424
- const s = new d({
425
+ for (const i of t) {
426
+ i.nodeType = i.type;
427
+ const s = new p({
425
428
  geometry: {
426
429
  type: "point",
427
430
  x: i.coordinates[0],
428
431
  y: i.coordinates[1]
429
432
  },
430
- attributes: { ...i, selected: !1 },
433
+ attributes: {
434
+ ...i,
435
+ selected: !1,
436
+ type: "OpenDriveJunction"
437
+ },
431
438
  symbol: {
432
439
  type: "picture-marker",
433
440
  url: i.crossId ? "/GisViewerAssets/Images/point_green.png" : "/GisViewerAssets/Images/normal-cross.png",
@@ -443,30 +450,32 @@ class N {
443
450
  * 监听鼠标移动事件,高亮显示鼠标所在路段和路口
444
451
  */
445
452
  monitorMouseMove() {
446
- const e = O.debounce(async (o) => {
447
- var h;
448
- 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, {
449
456
  include: [this.laneLayer, this.junctionLayer]
450
- })).results) == null ? void 0 : h.filter(
451
- (l) => l.type === "graphic"
457
+ })).results) == null ? void 0 : c.filter(
458
+ (r) => r.type === "graphic"
452
459
  );
453
460
  if (s.length === 0) {
454
461
  this.currentSectionCode !== "" && (this.currentSectionCode = "", this.highlightGraphic = void 0, this.highlightLayer.removeAll()), this.currentJunctionId !== "" && (this.currentJunctionId = "", this.highlightGraphic = void 0, this.highlightLayer.removeAll());
455
462
  return;
456
463
  }
457
- const t = s[0];
458
- if (this.hitGraphic = t.graphic, t.layer.id === "OpenDriveLane") {
459
- const l = `${this.hitGraphic.attributes.roadId}+${this.hitGraphic.attributes.sectionId}`;
460
- 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)
461
470
  return;
462
- this.currentSectionCode = l;
471
+ this.currentSectionCode = r;
463
472
  const a = this.allLaneGraphics.filter(
464
- (n) => `${n.attributes.roadId}+${n.attributes.sectionId}` === l
465
- ), r = await L.union(
466
- 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)
467
476
  );
468
- this.highlightGraphic = new d({
469
- geometry: r,
477
+ this.highlightGraphic = new p({
478
+ geometry: l,
470
479
  symbol: {
471
480
  type: "simple-fill",
472
481
  color: [255, 0, 0, 0.5],
@@ -478,31 +487,16 @@ class N {
478
487
  },
479
488
  attributes: {
480
489
  type: "OpenDriveSection",
481
- id: l,
482
- detail: ""
490
+ id: r,
491
+ selected: !1
483
492
  }
484
493
  }), this.highlightLayer.removeAll(), this.highlightLayer.add(this.highlightGraphic);
485
- } else if (t.layer.id === "OpenDriveJunction") {
486
- const l = this.hitGraphic.attributes.id;
487
- if (l === this.currentJunctionId)
494
+ } else if (e.layer.id === "OpenDriveJunction") {
495
+ const r = this.hitGraphic.attributes.id;
496
+ if (r === this.currentJunctionId)
488
497
  return;
489
- this.currentJunctionId = l, this.highlightGraphic = new d({
490
- geometry: this.hitGraphic.geometry,
491
- symbol: {
492
- type: "simple-marker",
493
- style: "circle",
494
- size: 40,
495
- color: [0, 0, 0, 0],
496
- outline: {
497
- color: [0, 0, 0, 0]
498
- }
499
- },
500
- attributes: {
501
- type: "OpenDriveJunction",
502
- id: l
503
- }
504
- });
505
- const a = new d({
498
+ this.currentJunctionId = r;
499
+ const n = new p({
506
500
  geometry: this.hitGraphic.geometry,
507
501
  symbol: {
508
502
  type: "text",
@@ -516,11 +510,11 @@ ${this.hitGraphic.attributes.id}`,
516
510
  yoffset: 40
517
511
  }
518
512
  });
519
- this.highlightLayer.removeAll(), this.highlightLayer.addMany([this.highlightGraphic, a]);
513
+ this.highlightLayer.removeAll(), this.highlightLayer.add(n);
520
514
  }
521
515
  });
522
516
  this.mouseMoveHandler = this.view.on("pointer-move", async (o) => {
523
- e(o).catch(() => {
517
+ t(o).catch(() => {
524
518
  });
525
519
  });
526
520
  }
@@ -528,42 +522,81 @@ ${this.hitGraphic.attributes.id}`,
528
522
  * 监听鼠标点击事件,获取高亮要素的拓扑信息
529
523
  */
530
524
  monitorMouseClick() {
531
- this.mouseClickHandler = this.view.on("immediate-click", async () => {
532
- var e, o;
533
- if (this.hitGraphic && !this.currentSectionCode) {
534
- if (this.currentJunctionId)
535
- if (this.hitGraphic.getAttribute("selected") === !1) {
536
- const i = `http://${this.openDriveServer}/api/sumo/getSumoJunction`, s = await f.get(i, {
537
- params: {
538
- id: this.currentJunctionId,
539
- projectName: this.projectName
540
- }
541
- });
542
- 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));
543
- } else
544
- (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);
545
- }
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
+ });
546
579
  });
547
580
  }
548
- increasePictureMarkerSize(e, o) {
581
+ increasePictureMarkerSize(t, o) {
549
582
  const i = setInterval(() => {
550
- const s = e.symbol, t = s.width;
551
- t < o ? e.symbol = {
583
+ const s = t.symbol, e = s.width;
584
+ e < o ? t.symbol = {
552
585
  type: "picture-marker",
553
586
  url: s.url,
554
- width: t + 1,
555
- height: t + 1
587
+ width: e + 1,
588
+ height: e + 1
556
589
  } : clearInterval(i);
557
590
  }, 20);
558
591
  }
559
- decreasePictureMarkerSize(e, o) {
592
+ decreasePictureMarkerSize(t, o) {
560
593
  const i = setInterval(() => {
561
- const s = e.symbol, t = s.width;
562
- t > o ? e.symbol = {
594
+ const s = t.symbol, e = s.width;
595
+ e > o ? t.symbol = {
563
596
  type: "picture-marker",
564
597
  url: s.url,
565
- width: t - 1,
566
- height: t - 1
598
+ width: e - 1,
599
+ height: e - 1
567
600
  } : clearInterval(i);
568
601
  }, 20);
569
602
  }
@@ -572,11 +605,11 @@ ${this.hitGraphic.attributes.id}`,
572
605
  */
573
606
  async clearOpenDrive() {
574
607
  var o, i;
575
- let e = await this.laneLayer.queryFeatures();
576
- e.features.length > 0 && await this.laneLayer.applyEdits({
577
- deleteFeatures: e.features
578
- }), e = await this.roadNameLayer.queryFeatures(), e.features.length > 0 && await this.roadNameLayer.applyEdits({
579
- 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
580
613
  }), this.highlightLayer.removeAll(), this.junctionLayer.removeAll(), this.wasmLoader.clear(), (o = this.mouseMoveHandler) == null || o.remove(), (i = this.mouseClickHandler) == null || i.remove();
581
614
  }
582
615
  /**
@@ -584,82 +617,112 @@ ${this.hitGraphic.attributes.id}`,
584
617
  * @param params
585
618
  * @returns
586
619
  */
587
- async findSumo(e) {
588
- const { id: o } = e, i = e.flash === void 0 ? !0 : e.flash, s = o.split("+");
589
- if (s.length > 2)
590
- return { status: -1, message: "id格式错误" };
591
- const t = s.length === 2 ? Number(s[1]) : void 0, h = s[0].split("#");
592
- if (h.length > 2)
593
- return { status: -1, message: "id格式错误" };
594
- let l = h[0];
595
- l.startsWith("-") && (l = l.slice(1));
596
- const a = h.length === 2 ? Number(h[1]) : void 0;
597
- 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" };
598
659
  }
599
660
  /**
600
661
  * 用sumo的id定位车道、基本段、路段
601
662
  * @param params
602
663
  * @returns
603
664
  */
604
- async findLane(e) {
605
- let { segmentId: o, laneId: i } = e;
606
- const { roadsectId: s } = e;
607
- let t = this.allLaneGraphics.filter(
608
- (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
609
670
  );
610
- if (t.length === 0)
671
+ if (e.length === 0)
611
672
  return { status: -1, message: "未找到。请检查路段编号" };
612
- if (o !== void 0) {
613
- const a = [];
614
- if (t.forEach((r) => {
615
- const n = Number(r.attributes.sectionId);
616
- a.indexOf(n) === -1 && a.push(n);
617
- }), 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)
618
679
  return { status: -1, message: "未找到。请检查基本段编号" };
619
- o = a[o], t = t.filter(
620
- (r) => Number(r.attributes.sectionId) === o
680
+ i = n[i], e = e.filter(
681
+ (a) => Number(a.attributes.sectionId) === i
621
682
  );
622
683
  }
623
- if (i !== void 0) {
624
- const a = [];
625
- if (t.forEach((r) => {
626
- const n = Number(r.attributes.laneId);
627
- a.indexOf(n) === -1 && a.push(n);
628
- }), 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)
629
690
  return { status: -1, message: "未找到。请检查车道编号" };
630
- i = a[i], t = t.filter(
631
- (r) => Number(r.attributes.laneId) === i
691
+ s = n[s], e = e.filter(
692
+ (a) => Number(a.attributes.laneId) === s
632
693
  );
633
694
  }
634
- const h = t.map(
635
- (a) => a.geometry
636
- ), l = await L.union(h);
637
- if (e.flash) {
638
- this.highlightLayer.removeAll();
639
- const a = new d({
640
- 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,
641
701
  symbol: {
642
702
  type: "simple-fill",
643
703
  color: [255, 0, 0, 0.5],
644
704
  style: "solid",
645
705
  outline: {
646
706
  color: "red",
647
- width: 2
707
+ width: 0
648
708
  }
649
709
  }
650
710
  });
651
- this.highlightLayer.add(a);
652
- let r = 0, n = !0;
653
- const u = setInterval(() => {
654
- 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));
655
- }, 20);
711
+ this.flashGraphic(n);
656
712
  }
657
- 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);
658
721
  }
659
- async splitLane(e) {
660
- return { status: 0, message: "ok", result: e };
722
+ async splitLane(t) {
723
+ return { status: 0, message: "ok", result: t };
661
724
  }
662
725
  }
663
726
  export {
664
- N as default
727
+ S as default
665
728
  };
@@ -216,8 +216,10 @@ export interface IShowOpenDriveFromFileParams {
216
216
  showRoadName: boolean;
217
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,{},{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;
@@ -216,8 +216,10 @@ export interface IShowOpenDriveFromFileParams {
216
216
  showRoadName: boolean;
217
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.121",
3
+ "version": "1.0.122",
4
4
  "main": "lib/index.js",
5
5
  "module": "es/index.mjs",
6
6
  "files": [