gisviewer-vue3-arcgis 1.0.149 → 1.0.150

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.
@@ -346,20 +346,20 @@ class F {
346
346
  );
347
347
  let c = o.data.result.json;
348
348
  c.startsWith(window.location.protocol) || (c = `${window.location.protocol}//${e.server}${c}`);
349
- const l = await (await fetch(c)).arrayBuffer(), r = O.inflate(l, { to: "string" }), n = JSON.parse(r);
349
+ const a = await (await fetch(c)).arrayBuffer(), r = O.inflate(a, { to: "string" }), n = JSON.parse(r);
350
350
  await this.showAllLanes(
351
351
  n,
352
352
  ((g = e.options) == null ? void 0 : g.showJunctionLane) || !1,
353
353
  ((p = e.options) == null ? void 0 : p.showRoadName) || !0
354
354
  );
355
- const h = o.data.result.junctions;
356
- this.showJunction(h), e.options && e.options.centerMap !== !1 && await this.view.goTo(this.allLaneGraphics), this.mouseMoveHandler || this.monitorMouseMove(), this.mouseClickHandler || this.monitorMouseClick();
357
- const d = J.useAppDataStore;
355
+ const d = o.data.result.junctions;
356
+ this.showJunction(d), e.options && e.options.centerMap !== !1 && await this.view.goTo(this.allLaneGraphics), this.mouseMoveHandler || this.monitorMouseMove(), this.mouseClickHandler || this.monitorMouseClick();
357
+ const h = J.useAppDataStore;
358
358
  return x(
359
- () => d.isSketching,
359
+ () => h.isSketching,
360
360
  () => {
361
361
  var m, u;
362
- d.isSketching ? ((m = this.mouseMoveHandler) == null || m.remove(), this.mouseMoveHandler = void 0, (u = this.mouseClickHandler) == null || u.remove(), this.mouseClickHandler = void 0) : (this.monitorMouseMove(), this.monitorMouseClick());
362
+ h.isSketching ? ((m = this.mouseMoveHandler) == null || m.remove(), this.mouseMoveHandler = void 0, (u = this.mouseClickHandler) == null || u.remove(), this.mouseClickHandler = void 0) : (this.monitorMouseMove(), this.monitorMouseClick());
363
363
  }
364
364
  ), console.timeEnd("渲染用时"), { status: 0, message: "ok" };
365
365
  }
@@ -382,7 +382,7 @@ class F {
382
382
  throw new Error(`OpenDriveRenderer: ${o.statusText}`);
383
383
  let s = o.data.result.json;
384
384
  s.startsWith(window.location.protocol) || (s = `${window.location.protocol}//${e}${s}`);
385
- const a = await (await fetch(s)).arrayBuffer(), l = O.inflate(a, { to: "string" }), r = JSON.parse(l);
385
+ const l = await (await fetch(s)).arrayBuffer(), a = O.inflate(l, { to: "string" }), r = JSON.parse(a);
386
386
  return await this.showAllLanes(r, !1, !1), { status: 0, message: "ok" };
387
387
  }
388
388
  /**
@@ -399,23 +399,23 @@ class F {
399
399
  }), this.roadNameLayer.visible = i, new Promise((s) => {
400
400
  let c = 0;
401
401
  this.allLaneGraphics = [], this.allRefLineGraphics = [];
402
- const a = [];
402
+ const l = [];
403
403
  console.log(e.length);
404
404
  for (const r of e) {
405
405
  if (!t && r.junction !== "-1")
406
406
  continue;
407
- const { id: n, refLine: h } = r;
408
- let d = r.name;
409
- d.includes("(") && (d = d.slice(0, d.indexOf("("))), d = d.replace(/(.)/g, "$1 ");
407
+ const { id: n, refLine: d } = r;
408
+ let h = r.name;
409
+ h.includes("(") && (h = h.slice(0, h.indexOf("("))), h = h.replace(/(.)/g, "$1 ");
410
410
  const g = new y({
411
411
  geometry: {
412
412
  type: "polyline",
413
- paths: [h]
413
+ paths: [d]
414
414
  },
415
415
  attributes: {
416
416
  ObjectID: c++,
417
417
  roadId: n,
418
- roadName: d
418
+ roadName: h
419
419
  }
420
420
  });
421
421
  this.allRefLineGraphics.push(g), r.laneSections.sort((p, m) => Number(p.id) - Number(m.id));
@@ -456,15 +456,15 @@ class F {
456
456
  rightLine: f.outerPath
457
457
  }
458
458
  });
459
- this.allLaneGraphics.push(D), a.push(D);
459
+ this.allLaneGraphics.push(D), l.push(D);
460
460
  }
461
461
  }
462
462
  }
463
463
  }
464
- const l = setInterval(() => {
465
- if (a.length > 0 || this.allRefLineGraphics.length > 0) {
466
- if (a.length > 0) {
467
- const r = a.splice(0, 100);
464
+ const a = setInterval(() => {
465
+ if (l.length > 0 || this.allRefLineGraphics.length > 0) {
466
+ if (l.length > 0) {
467
+ const r = l.splice(0, 100);
468
468
  this.laneLayer.applyEdits({
469
469
  addFeatures: r
470
470
  });
@@ -476,7 +476,7 @@ class F {
476
476
  });
477
477
  }
478
478
  } else
479
- clearInterval(l), s();
479
+ clearInterval(a), s();
480
480
  }, 10);
481
481
  });
482
482
  }
@@ -540,7 +540,7 @@ class F {
540
540
  const o = (c = (await this.view.hitTest(t, {
541
541
  include: [this.laneLayer, this.junctionLayer]
542
542
  })).results) == null ? void 0 : c.filter(
543
- (a) => a.type === "graphic"
543
+ (l) => l.type === "graphic"
544
544
  );
545
545
  if (o.length === 0) {
546
546
  this.currentSectionCode !== "" && (this.currentSectionCode = "", this.highlightGraphic = void 0, this.highlightLayer.removeAll()), this.currentJunctionId !== "" && (this.currentJunctionId = "", this.view.closePopup());
@@ -548,19 +548,19 @@ class F {
548
548
  }
549
549
  const s = o[0];
550
550
  if (this.hitGraphic = s.graphic, s.layer.id === "OpenDriveLane") {
551
- const a = `${this.hitGraphic.getAttribute(
551
+ const l = `${this.hitGraphic.getAttribute(
552
552
  "roadId"
553
553
  )}+${this.hitGraphic.getAttribute("sectionId")}`;
554
- if (a === this.currentSectionCode || this.sectionLayer.graphics.findIndex(
555
- (u) => u.getAttribute("id") === a
554
+ if (l === this.currentSectionCode || this.sectionLayer.graphics.findIndex(
555
+ (u) => u.getAttribute("id") === l
556
556
  ) >= 0)
557
557
  return;
558
- this.currentSectionCode = a;
558
+ this.currentSectionCode = l;
559
559
  const r = this.allLaneGraphics.filter(
560
- (u) => `${u.attributes.roadId}+${u.attributes.sectionId}` === a
560
+ (u) => `${u.attributes.roadId}+${u.attributes.sectionId}` === l
561
561
  ), n = L.union(
562
562
  r.map((u) => u.geometry)
563
- ), h = this.hitGraphic.getAttribute("fromNode"), d = this.hitGraphic.getAttribute("toNode"), g = this.junctionNames.get(h) || h, p = this.junctionNames.get(d) || d;
563
+ ), d = this.hitGraphic.getAttribute("fromNode"), h = this.hitGraphic.getAttribute("toNode"), g = this.junctionNames.get(d) || d, p = this.junctionNames.get(h) || h;
564
564
  this.highlightGraphic = new y({
565
565
  geometry: n,
566
566
  symbol: {
@@ -574,7 +574,7 @@ class F {
574
574
  },
575
575
  attributes: {
576
576
  type: "OpenDriveSection",
577
- id: a,
577
+ id: l,
578
578
  selected: !1,
579
579
  fromNodeName: g,
580
580
  toNodeName: p,
@@ -609,10 +609,10 @@ class F {
609
609
  location: m
610
610
  });
611
611
  } else if (s.layer.id === "OpenDriveJunction") {
612
- const a = this.hitGraphic.getAttribute("id");
613
- if (a === this.currentJunctionId)
612
+ const l = this.hitGraphic.getAttribute("id");
613
+ if (l === this.currentJunctionId)
614
614
  return;
615
- this.currentJunctionId = a, this.view.openPopup({
615
+ this.currentJunctionId = l, this.view.openPopup({
616
616
  features: [this.hitGraphic],
617
617
  location: this.hitGraphic.geometry
618
618
  });
@@ -628,32 +628,32 @@ class F {
628
628
  */
629
629
  monitorMouseClick() {
630
630
  const e = j.debounce(async (t) => {
631
- var l;
632
- const o = (l = (await this.view.hitTest(t, {
631
+ var a;
632
+ const o = (a = (await this.view.hitTest(t, {
633
633
  include: [this.highlightLayer, this.junctionLayer, this.sectionLayer]
634
- })).results) == null ? void 0 : l.filter(
634
+ })).results) == null ? void 0 : a.filter(
635
635
  (r) => r.type === "graphic"
636
636
  );
637
637
  if (o.length === 0)
638
638
  return;
639
- const s = o[0].graphic, c = s.getAttribute("type"), a = s.getAttribute("id");
639
+ const s = o[0].graphic, c = s.getAttribute("type"), l = s.getAttribute("id");
640
640
  if (c === "OpenDriveJunction")
641
641
  if (s.getAttribute("selected") === !1) {
642
642
  const r = `http://${this.openDriveServer}/api/sumo/getSumoJunction`, n = await b.get(r, {
643
643
  params: {
644
- id: a,
644
+ id: l,
645
645
  projectName: this.projectName
646
646
  }
647
647
  });
648
648
  n.status === 200 && n.data.status === 0 && (this.openDriveClickCallback && this.openDriveClickCallback({
649
649
  type: "OpenDriveJunction",
650
- id: a,
650
+ id: l,
651
651
  details: n.data.result
652
652
  }), s.setAttribute("selected", !0), s.symbol.url = "/GisViewerAssets/Images/point_red.png", this.increasePictureMarkerSize(s, 50));
653
653
  } else {
654
654
  this.openDriveClickCallback && this.openDriveClickCallback({
655
655
  type: "OpenDriveJunction",
656
- id: a,
656
+ id: l,
657
657
  details: void 0
658
658
  }), s.setAttribute("selected", !1);
659
659
  const r = s.getAttribute("crossId");
@@ -663,22 +663,25 @@ class F {
663
663
  if (s.getAttribute("selected"))
664
664
  this.sectionLayer.remove(s), this.openDriveClickCallback && this.openDriveClickCallback({
665
665
  type: "OpenDriveSection",
666
- id: a,
666
+ id: s.getAttribute("edgeId"),
667
667
  details: void 0
668
668
  });
669
669
  else {
670
670
  this.highlightLayer.remove(s), this.sectionLayer.add(s), s.setAttribute("selected", !0);
671
671
  const r = `http://${this.openDriveServer}/api/sumo/getSumoEdge`, n = await b.get(r, {
672
672
  params: {
673
- id: a,
673
+ id: l,
674
674
  projectName: this.projectName
675
675
  }
676
676
  });
677
- n.status === 200 && n.data.status === 0 && this.openDriveClickCallback && (s.setAttribute("edgeId", n.data.result.obj_id), this.openDriveClickCallback({
678
- type: "OpenDriveSection",
679
- id: a,
680
- details: n.data.result
681
- }));
677
+ if (n.status === 200 && n.data.status === 0 && this.openDriveClickCallback) {
678
+ const d = n.data.result.obj_id;
679
+ s.setAttribute("edgeId", d), this.openDriveClickCallback({
680
+ type: "OpenDriveSection",
681
+ id: d,
682
+ details: n.data.result
683
+ });
684
+ }
682
685
  }
683
686
  });
684
687
  this.mouseClickHandler = this.view.on("immediate-click", async (t) => {
@@ -741,13 +744,13 @@ class F {
741
744
  if (s) {
742
745
  const c = `${i}+${s.getAttribute(
743
746
  "sectionId"
744
- )}`, a = `http://${this.openDriveServer}/api/sumo/getSumoEdge`, l = await b.get(a, {
747
+ )}`, l = `http://${this.openDriveServer}/api/sumo/getSumoEdge`, a = await b.get(l, {
745
748
  params: {
746
749
  id: c,
747
750
  projectName: this.projectName
748
751
  }
749
752
  });
750
- return l.status === 200 ? l.data : { status: -1, message: `路段信息查询失败: ${c}` };
753
+ return a.status === 200 ? a.data : { status: -1, message: `路段信息查询失败: ${c}` };
751
754
  } else
752
755
  return { status: -1, message: "未知类型" };
753
756
  }
@@ -780,11 +783,11 @@ class F {
780
783
  const s = i.split("_");
781
784
  if (s.length > 2)
782
785
  return { status: -1, message: "id格式错误" };
783
- const c = s.length === 2 ? Number(s[1]) : void 0, a = s[0].split("#");
784
- if (a.length > 2)
786
+ const c = s.length === 2 ? Number(s[1]) : void 0, l = s[0].split("#");
787
+ if (l.length > 2)
785
788
  return { status: -1, message: "id格式错误" };
786
- const l = a[0], r = a.length === 2 ? Number(a[1]) : void 0;
787
- return await this.findLane({ roadsectId: l, segmentId: r, laneId: c, flash: o });
789
+ const a = l[0], r = l.length === 2 ? Number(l[1]) : void 0;
790
+ return await this.findLane({ roadsectId: a, segmentId: r, laneId: c, flash: o });
788
791
  } else
789
792
  return { status: -1, message: "未知类型" };
790
793
  }
@@ -821,38 +824,38 @@ class F {
821
824
  let { roadsectId: t, segmentId: i, laneId: o } = e;
822
825
  t.startsWith("-") && (t = t.slice(1));
823
826
  let s = this.allLaneGraphics.filter(
824
- (l) => l.attributes.roadId === t
827
+ (a) => a.attributes.roadId === t
825
828
  );
826
829
  if (s.length === 0)
827
830
  return { status: -1, message: "未找到。请检查路段编号" };
828
831
  if (i !== void 0) {
829
- const l = [];
832
+ const a = [];
830
833
  if (s.forEach((r) => {
831
834
  const n = Number(r.attributes.sectionId);
832
- l.indexOf(n) === -1 && l.push(n);
833
- }), l.sort((r, n) => r - n), i > l.length - 1)
835
+ a.indexOf(n) === -1 && a.push(n);
836
+ }), a.sort((r, n) => r - n), i > a.length - 1)
834
837
  return { status: -1, message: "未找到。请检查基本段编号" };
835
- i = l[i], s = s.filter(
838
+ i = a[i], s = s.filter(
836
839
  (r) => Number(r.attributes.sectionId) === i
837
840
  );
838
841
  }
839
842
  if (o !== void 0) {
840
- const l = [];
843
+ const a = [];
841
844
  if (s.forEach((r) => {
842
845
  const n = Number(r.attributes.laneId);
843
- l.indexOf(n) === -1 && l.push(n);
844
- }), l.sort((r, n) => r - n), o > l.length - 1)
846
+ a.indexOf(n) === -1 && a.push(n);
847
+ }), a.sort((r, n) => r - n), o > a.length - 1)
845
848
  return { status: -1, message: "未找到。请检查车道编号" };
846
- o = l[o], s = s.filter(
849
+ o = a[o], s = s.filter(
847
850
  (r) => Number(r.attributes.laneId) === o
848
851
  );
849
852
  }
850
853
  const c = s.map(
851
- (l) => l.geometry
852
- ), a = L.union(c);
854
+ (a) => a.geometry
855
+ ), l = L.union(c);
853
856
  if (e.flash) {
854
- const l = new y({
855
- geometry: a,
857
+ const a = new y({
858
+ geometry: l,
856
859
  symbol: {
857
860
  type: "simple-fill",
858
861
  color: [255, 0, 0, 0.5],
@@ -863,9 +866,9 @@ class F {
863
866
  }
864
867
  }
865
868
  });
866
- this.flashGraphic(l);
869
+ this.flashGraphic(a);
867
870
  }
868
- return await this.view.goTo(a, { duration: 1e3 }), { status: 0, message: "ok" };
871
+ return await this.view.goTo(l, { duration: 1e3 }), { status: 0, message: "ok" };
869
872
  }
870
873
  /**
871
874
  * graphic渐隐渐显闪烁
@@ -926,8 +929,8 @@ class F {
926
929
  (c) => c.getAttribute("roadId") === i && c.getAttribute("sectionId") === o
927
930
  )), s.length > 0) {
928
931
  const c = L.union(
929
- s.map((l) => l.geometry)
930
- ), a = new y({
932
+ s.map((a) => a.geometry)
933
+ ), l = new y({
931
934
  geometry: c,
932
935
  symbol: {
933
936
  type: "simple-fill",
@@ -944,7 +947,7 @@ class F {
944
947
  selected: !0
945
948
  }
946
949
  });
947
- return this.sectionLayer.add(a), { status: 0, message: "ok" };
950
+ return this.sectionLayer.add(l), { status: 0, message: "ok" };
948
951
  } else
949
952
  return { status: -1, message: "未找到路段" };
950
953
  }
@@ -959,14 +962,14 @@ class F {
959
962
  geometry: t,
960
963
  outFields: ["*"]
961
964
  }), o = [], s = [];
962
- for (const l of i.features) {
963
- const r = l.getAttribute("roadId"), n = l.getAttribute("sectionId"), h = `${r}#${n}`;
964
- if (o.indexOf(h) === -1) {
965
- o.push(h), this.selectSumo({
965
+ for (const a of i.features) {
966
+ const r = a.getAttribute("roadId"), n = a.getAttribute("sectionId"), d = `${r}#${n}`;
967
+ if (o.indexOf(d) === -1) {
968
+ o.push(d), this.selectSumo({
966
969
  type: "edge",
967
- id: h
970
+ id: d
968
971
  });
969
- const d = `http://${this.openDriveServer}/api/sumo/getSumoEdge`, g = await b.get(d, {
972
+ const h = `http://${this.openDriveServer}/api/sumo/getSumoEdge`, g = await b.get(h, {
970
973
  params: {
971
974
  id: `${r}+${n}`,
972
975
  projectName: this.projectName
@@ -975,29 +978,29 @@ class F {
975
978
  g.status === 200 && g.data.status === 0 && s.push(g.data.result);
976
979
  }
977
980
  }
978
- const c = this.junctionLayer.graphics.filter((l) => {
979
- const r = l.geometry;
981
+ const c = this.junctionLayer.graphics.filter((a) => {
982
+ const r = a.geometry;
980
983
  return L.contains(t, r);
981
- }), a = [];
982
- for (const l of c) {
983
- const r = l.getAttribute("id");
984
+ }), l = [];
985
+ for (const a of c) {
986
+ const r = a.getAttribute("id");
984
987
  this.selectSumo({
985
988
  type: "junction",
986
989
  id: r
987
990
  });
988
- const n = `http://${this.openDriveServer}/api/sumo/getSumoJunction`, h = await b.get(n, {
991
+ const n = `http://${this.openDriveServer}/api/sumo/getSumoJunction`, d = await b.get(n, {
989
992
  params: {
990
993
  id: r,
991
994
  projectName: this.projectName
992
995
  }
993
996
  });
994
- h.status === 200 && h.data.status === 0 && a.push(h.data.result);
997
+ d.status === 200 && d.data.status === 0 && l.push(d.data.result);
995
998
  }
996
999
  return {
997
1000
  status: 0,
998
1001
  message: "ok",
999
1002
  result: {
1000
- junctions: a,
1003
+ junctions: l,
1001
1004
  edges: s
1002
1005
  }
1003
1006
  };
@@ -1007,19 +1010,19 @@ class F {
1007
1010
  if (i.length !== 2)
1008
1011
  return { status: -1, message: "车道编号格式错误" };
1009
1012
  const o = Number(i[1]), s = i[0].split("#"), c = s.length === 2 ? Number(s[1]) : 0;
1010
- let a = s[0];
1011
- a.startsWith("-") && (a = a.slice(1));
1012
- const l = this.allLaneGraphics.filter((v) => v.getAttribute("roadId") === a && v.getAttribute("sectionIndex") === c);
1013
- if (l.length === 0)
1013
+ let l = s[0];
1014
+ l.startsWith("-") && (l = l.slice(1));
1015
+ const a = this.allLaneGraphics.filter((v) => v.getAttribute("roadId") === l && v.getAttribute("sectionIndex") === c);
1016
+ if (a.length === 0)
1014
1017
  return { status: -1, message: "未找到路段" };
1015
- const r = l.length - o, n = l.find(
1018
+ const r = a.length - o, n = a.find(
1016
1019
  (v) => Math.abs(v.getAttribute("laneId")) === r
1017
1020
  );
1018
1021
  if (!n)
1019
1022
  return { status: -1, message: "未找到车道" };
1020
- const h = e.start || 0, d = e.end || 100, g = G.lineString(n.getAttribute("leftLine")), p = C(g, h, d, {
1023
+ const d = e.start || 0, h = e.end || 100, g = G.lineString(n.getAttribute("leftLine")), p = C(g, d, h, {
1021
1024
  units: "meters"
1022
- }), m = G.lineString(n.getAttribute("rightLine")), u = C(m, h, d, {
1025
+ }), m = G.lineString(n.getAttribute("rightLine")), u = C(m, d, h, {
1023
1026
  units: "meters"
1024
1027
  }), f = p.geometry.coordinates.concat(
1025
1028
  u.geometry.coordinates.reverse()
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const y=require("@arcgis/core/Graphic"),x=require("@arcgis/core/core/promiseUtils"),A=require("@arcgis/core/geometry"),J=require("@arcgis/core/geometry/geometryEngine"),C=require("@arcgis/core/layers/FeatureLayer"),I=require("@arcgis/core/layers/GraphicsLayer"),q=require("@turf/helpers"),O=require("@turf/line-slice-along"),b=require("axios"),T=require("md5"),F=require("pako"),E=require("vue"),R=require("../../stores/index.js"),_=require("../common-utils.js");function j(L){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(L){for(const t in L)if(t!=="default"){const i=Object.getOwnPropertyDescriptor(L,t);Object.defineProperty(e,t,i.get?i:{enumerable:!0,get:()=>L[t]})}}return e.default=L,Object.freeze(e)}const M=j(x),S=j(J),$=j(q);class D{constructor(e){this.junctionNames=new Map,this.projectName="",this.openDriveServer="",this.currentSectionCode="",this.currentJunctionId="",this.view=e,this.view.popup.visibleElements={collapseButton:!1,actionBar:!1},this.laneLayer=new C({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"},{name:"fromNode",alias:"起点路口",type:"string"},{name:"toNode",alias:"终点路口",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 C({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 I({id:"OpenDriveJunction"}),this.sectionLayer=new I({id:"OpenDriveSection"}),this.highlightLayer=new I({id:"OpenDriveHighlight"}),this.flashLayer=new I({id:"OpenDriveFlash"}),this.drawLayer=new I({id:"Draw"}),this.splitLaneLayer=new I({id:"SplitLane"}),this.view.map.addMany([this.laneLayer,this.junctionLayer,this.sectionLayer,this.roadNameLayer,this.highlightLayer,this.flashLayer,this.drawLayer,this.splitLaneLayer])}static getInstance(e){return this.instance||(this.instance=new D(e)),this.instance}async makeMd5FromFile(e){try{const i=await(await fetch(e)).text();return{status:0,message:"ok",result:T(i)}}catch(t){return{status:-1,message:t.message}}}async showOpenDriveFromFile(e){var g,p;this.openDriveClickCallback=e.selectedCallback,console.time("md5用时");const t=await this.makeMd5FromFile(e.file);if(t.status!==0)return t;this.projectName=t.result,console.timeEnd("md5用时"),this.openDriveServer=e.server,await this.makeMd5FromFile(e.file);const i=`http://${this.openDriveServer}/api/openDrive/uploadXodr`;let o;try{o=await b.post(i,{},{params:{url:e.file,projectName:this.projectName}})}catch(m){return{status:-1,message:m.message}}if(o.status!==200)return{status:-1,message:o.statusText};console.time("渲染用时");const s=o.data.result.geoSetting;_.default.setGeoData(s.geoReference,s.offsetX,s.offsetY);let c=o.data.result.json;c.startsWith(window.location.protocol)||(c=`${window.location.protocol}//${e.server}${c}`);const l=await(await fetch(c)).arrayBuffer(),n=F.inflate(l,{to:"string"}),r=JSON.parse(n);await this.showAllLanes(r,((g=e.options)==null?void 0:g.showJunctionLane)||!1,((p=e.options)==null?void 0:p.showRoadName)||!0);const d=o.data.result.junctions;this.showJunction(d),e.options&&e.options.centerMap!==!1&&await this.view.goTo(this.allLaneGraphics),this.mouseMoveHandler||this.monitorMouseMove(),this.mouseClickHandler||this.monitorMouseClick();const u=R.default.useAppDataStore;return E.watch(()=>u.isSketching,()=>{var m,h;u.isSketching?((m=this.mouseMoveHandler)==null||m.remove(),this.mouseMoveHandler=void 0,(h=this.mouseClickHandler)==null||h.remove(),this.mouseClickHandler=void 0):(this.monitorMouseMove(),this.monitorMouseClick())}),console.timeEnd("渲染用时"),{status:0,message:"ok"}}async showOpenDriveFromServer(e,t){const i=`http://${e}/api/openDrive/analyzeXodr`,o=await b.get(i,{headers:{projectName:t},params:{analyze:!1,compressed:!0}});if(o.status!==200)throw new Error(`OpenDriveRenderer: ${o.statusText}`);let s=o.data.result.json;s.startsWith(window.location.protocol)||(s=`${window.location.protocol}//${e}${s}`);const a=await(await fetch(s)).arrayBuffer(),l=F.inflate(a,{to:"string"}),n=JSON.parse(l);return await this.showAllLanes(n,!1,!1),{status:0,message:"ok"}}async showAllLanes(e,t,i){const o=await this.laneLayer.queryFeatures();return o.features.length>0&&this.laneLayer.applyEdits({deleteFeatures:o.features}),this.roadNameLayer.visible=i,new Promise(s=>{let c=0;this.allLaneGraphics=[],this.allRefLineGraphics=[];const a=[];console.log(e.length);for(const n of e){if(!t&&n.junction!=="-1")continue;const{id:r,refLine:d}=n;let u=n.name;u.includes("(")&&(u=u.slice(0,u.indexOf("("))),u=u.replace(/(.)/g,"$1 ");const g=new y({geometry:{type:"polyline",paths:[d]},attributes:{ObjectID:c++,roadId:r,roadName:u}});this.allRefLineGraphics.push(g),n.laneSections.sort((p,m)=>Number(p.id)-Number(m.id));for(let p=0;p<n.laneSections.length;p++){const m=n.laneSections[p],h=Number(m.id);for(const f of m.lanePaths){const w=Number(f.id);if(w===0)continue;const v=f.type,P=[...f.outerPath],N=f.innerPath.concat(P.reverse());if(N.length<=3){console.warn(`lane ${w} has less than 3 points`);continue}N.push(f.innerPath[0]);const k=new A.Polygon({rings:[N]});if(k){const G=new y({geometry:k,attributes:{ObjectID:c++,id:`${r}+${h}+${w}`,fromNode:n.fromNode,toNode:n.toNode,roadId:String(r),roadName:n.name,sectionId:String(h),sectionIndex:p,laneId:w,type:v,sumoId:"",leftLine:f.innerPath,rightLine:f.outerPath}});this.allLaneGraphics.push(G),a.push(G)}}}}const l=setInterval(()=>{if(a.length>0||this.allRefLineGraphics.length>0){if(a.length>0){const n=a.splice(0,100);this.laneLayer.applyEdits({addFeatures:n})}if(this.allRefLineGraphics.length>0){const n=this.allRefLineGraphics.splice(0,10);this.roadNameLayer.applyEdits({addFeatures:n})}}else clearInterval(l),s()},10)})}showJunction(e){const t=[];for(const i of e){if(!i)continue;this.junctionNames.set(i.id,i.name),i.nodeType=i.type;const o=new y({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/point_yellow.png",width:30,height:30},popupTemplate:{title:i.name,content:[{type:"fields",fieldInfos:[{fieldName:"id",label:"路口编号"},{fieldName:"crossId",label:"信号机编号"}]}]}});t.push(o)}this.junctionLayer.addMany(t)}monitorMouseMove(){const e=M.debounce(async t=>{var c;const o=(c=(await this.view.hitTest(t,{include:[this.laneLayer,this.junctionLayer]})).results)==null?void 0:c.filter(a=>a.type==="graphic");if(o.length===0){this.currentSectionCode!==""&&(this.currentSectionCode="",this.highlightGraphic=void 0,this.highlightLayer.removeAll()),this.currentJunctionId!==""&&(this.currentJunctionId="",this.view.closePopup());return}const s=o[0];if(this.hitGraphic=s.graphic,s.layer.id==="OpenDriveLane"){const a=`${this.hitGraphic.getAttribute("roadId")}+${this.hitGraphic.getAttribute("sectionId")}`;if(a===this.currentSectionCode||this.sectionLayer.graphics.findIndex(h=>h.getAttribute("id")===a)>=0)return;this.currentSectionCode=a;const n=this.allLaneGraphics.filter(h=>`${h.attributes.roadId}+${h.attributes.sectionId}`===a),r=S.union(n.map(h=>h.geometry)),d=this.hitGraphic.getAttribute("fromNode"),u=this.hitGraphic.getAttribute("toNode"),g=this.junctionNames.get(d)||d,p=this.junctionNames.get(u)||u;this.highlightGraphic=new y({geometry:r,symbol:{type:"simple-fill",color:[0,255,255,.5],style:"solid",outline:{color:[0,255,255],width:1}},attributes:{type:"OpenDriveSection",id:a,selected:!1,fromNodeName:g,toNodeName:p,laneCount:n.length},popupTemplate:{title:this.hitGraphic.getAttribute("roadName"),content:[{type:"fields",fieldInfos:[{fieldName:"fromNodeName",label:"起点路口"},{fieldName:"toNodeName",label:"终点路口"},{fieldName:"laneCount",label:"车道数量"}]}]}}),this.highlightLayer.removeAll(),this.highlightLayer.add(this.highlightGraphic);const m=this.view.toMap(t);this.view.openPopup({features:[this.highlightGraphic],location:m})}else if(s.layer.id==="OpenDriveJunction"){const a=this.hitGraphic.getAttribute("id");if(a===this.currentJunctionId)return;this.currentJunctionId=a,this.view.openPopup({features:[this.hitGraphic],location:this.hitGraphic.geometry})}});this.mouseMoveHandler=this.view.on("pointer-move",async t=>{e(t).catch(()=>{})})}monitorMouseClick(){const e=M.debounce(async t=>{var l;const o=(l=(await this.view.hitTest(t,{include:[this.highlightLayer,this.junctionLayer,this.sectionLayer]})).results)==null?void 0:l.filter(n=>n.type==="graphic");if(o.length===0)return;const s=o[0].graphic,c=s.getAttribute("type"),a=s.getAttribute("id");if(c==="OpenDriveJunction")if(s.getAttribute("selected")===!1){const n=`http://${this.openDriveServer}/api/sumo/getSumoJunction`,r=await b.get(n,{params:{id:a,projectName:this.projectName}});r.status===200&&r.data.status===0&&(this.openDriveClickCallback&&this.openDriveClickCallback({type:"OpenDriveJunction",id:a,details:r.data.result}),s.setAttribute("selected",!0),s.symbol.url="/GisViewerAssets/Images/point_red.png",this.increasePictureMarkerSize(s,50))}else{this.openDriveClickCallback&&this.openDriveClickCallback({type:"OpenDriveJunction",id:a,details:void 0}),s.setAttribute("selected",!1);const n=s.getAttribute("crossId");s.symbol.url=n?"/GisViewerAssets/Images/point_green.png":"/GisViewerAssets/Images/point_yellow.png",this.decreasePictureMarkerSize(s,30)}else if(c==="OpenDriveSection")if(s.getAttribute("selected"))this.sectionLayer.remove(s),this.openDriveClickCallback&&this.openDriveClickCallback({type:"OpenDriveSection",id:a,details:void 0});else{this.highlightLayer.remove(s),this.sectionLayer.add(s),s.setAttribute("selected",!0);const n=`http://${this.openDriveServer}/api/sumo/getSumoEdge`,r=await b.get(n,{params:{id:a,projectName:this.projectName}});r.status===200&&r.data.status===0&&this.openDriveClickCallback&&(s.setAttribute("edgeId",r.data.result.obj_id),this.openDriveClickCallback({type:"OpenDriveSection",id:a,details:r.data.result}))}});this.mouseClickHandler=this.view.on("immediate-click",async t=>{e(t).catch(()=>{})})}increasePictureMarkerSize(e,t){const i=setInterval(()=>{const o=e.symbol,s=o.width;s<t?e.symbol={type:"picture-marker",url:o.url,width:s+1,height:s+1}:clearInterval(i)},20)}decreasePictureMarkerSize(e,t){const i=setInterval(()=>{const o=e.symbol,s=o.width;s>t?e.symbol={type:"picture-marker",url:o.url,width:s-1,height:s-1}:clearInterval(i)},20)}async getSumoInfo(e){switch(e.type){case"junction":{const t=`http://${this.openDriveServer}/api/sumo/getSumoJunction`,i=await b.get(t,{params:{id:e.id,projectName:this.projectName}});return i.status===200?i.data:{status:-1,message:`路口信息查询失败: ${e.id}`}}case"edge":{const t=e.id.split("#");let i=t[0];i.startsWith("-")&&(i=i.slice(1));let o=0;t.length===2&&(o=Number(t[1]));const s=this.allLaneGraphics.find(c=>c.getAttribute("roadId")===i&&c.getAttribute("sectionIndex")===o);if(s){const c=`${i}+${s.getAttribute("sectionId")}`,a=`http://${this.openDriveServer}/api/sumo/getSumoEdge`,l=await b.get(a,{params:{id:c,projectName:this.projectName}});return l.status===200?l.data:{status:-1,message:`路段信息查询失败: ${c}`}}else return{status:-1,message:"未知类型"}}default:return{status:-1,message:"未知类型"}}}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.sectionLayer.removeAll(),this.flashLayer.removeAll(),(t=this.mouseMoveHandler)==null||t.remove(),this.mouseMoveHandler=void 0,(i=this.mouseClickHandler)==null||i.remove(),this.mouseClickHandler=void 0}async findSumo(e){const{type:t,id:i}=e,o=e.flash===void 0?!0:e.flash;if(t==="junction")return await this.findJunction(i,o);if(t==="edge"){const s=i.split("_");if(s.length>2)return{status:-1,message:"id格式错误"};const c=s.length===2?Number(s[1]):void 0,a=s[0].split("#");if(a.length>2)return{status:-1,message:"id格式错误"};const l=a[0],n=a.length===2?Number(a[1]):void 0;return await this.findLane({roadsectId:l,segmentId:n,laneId:c,flash:o})}else return{status:-1,message:"未知类型"}}async findJunction(e,t){const i=this.junctionLayer.graphics.find(o=>o.attributes.id===e);if(!i)return{status:-1,message:"未找到。请检查路口编号"};if(t){const o=new y({geometry:i.geometry,symbol:{type:"simple-marker",style:"circle",size:30,color:[255,0,0,.6],outline:{color:"red",width:1}}});this.flashGraphic(o)}return await this.view.goTo(i.geometry,{duration:1e3}),{status:0,message:"ok"}}async findLane(e){let{roadsectId:t,segmentId:i,laneId:o}=e;t.startsWith("-")&&(t=t.slice(1));let s=this.allLaneGraphics.filter(l=>l.attributes.roadId===t);if(s.length===0)return{status:-1,message:"未找到。请检查路段编号"};if(i!==void 0){const l=[];if(s.forEach(n=>{const r=Number(n.attributes.sectionId);l.indexOf(r)===-1&&l.push(r)}),l.sort((n,r)=>n-r),i>l.length-1)return{status:-1,message:"未找到。请检查基本段编号"};i=l[i],s=s.filter(n=>Number(n.attributes.sectionId)===i)}if(o!==void 0){const l=[];if(s.forEach(n=>{const r=Number(n.attributes.laneId);l.indexOf(r)===-1&&l.push(r)}),l.sort((n,r)=>n-r),o>l.length-1)return{status:-1,message:"未找到。请检查车道编号"};o=l[o],s=s.filter(n=>Number(n.attributes.laneId)===o)}const c=s.map(l=>l.geometry),a=S.union(c);if(e.flash){const l=new y({geometry:a,symbol:{type:"simple-fill",color:[255,0,0,.5],style:"solid",outline:{color:"red",width:0}}});this.flashGraphic(l)}return await this.view.goTo(a,{duration:1e3}),{status:0,message:"ok"}}flashGraphic(e){this.flashLayer.removeAll(),this.flashLayer.add(e);let t=0,i=!0;const o=setInterval(()=>{i?(this.flashLayer.opacity-=.02,this.flashLayer.opacity<=.1&&(i=!1,t++)):(this.flashLayer.opacity+=.02,this.flashLayer.opacity>=1&&(i=!0)),t>=5&&(this.flashLayer.removeAll(),this.flashLayer.opacity=1,clearInterval(o))},10)}unselectSumo(e){if((!e||e.type==="junction")&&this.junctionLayer.graphics.forEach(t=>{if((!e||!e.id||e.id===""||e.id===t.getAttribute("id"))&&t.getAttribute("selected")){t.setAttribute("selected",!1);const i=t.getAttribute("crossId");t.symbol.url=i?"/GisViewerAssets/Images/point_green.png":"/GisViewerAssets/Images/point_yellow.png",this.decreasePictureMarkerSize(t,30)}}),!e||e.type==="edge")if(!e||!e.id||e.id==="")this.sectionLayer.removeAll();else{const t=this.sectionLayer.graphics.find(i=>i.getAttribute("edgeId")===e.id);t&&this.sectionLayer.remove(t)}return{status:0,message:"ok"}}selectSumo(e){switch(e.type){case"junction":return this.junctionLayer.graphics.forEach(t=>{if(e.id===t.getAttribute("id"))return t.setAttribute("selected",!0),t.symbol.url="/GisViewerAssets/Images/point_red.png",this.increasePictureMarkerSize(t,50),{status:0,message:"ok"}}),{status:-1,message:"未找到路口"};case"edge":{const t=e.id.split("#");let i=String(t[0]);i.startsWith("-")&&(i=i.slice(1));let o="0";t.length===2&&(o=String(t[1]));let s=[];if(t.length===1?s=this.allLaneGraphics.filter(c=>c.getAttribute("roadId")===i):t.length===2&&(s=this.allLaneGraphics.filter(c=>c.getAttribute("roadId")===i&&c.getAttribute("sectionId")===o)),s.length>0){const c=S.union(s.map(l=>l.geometry)),a=new y({geometry:c,symbol:{type:"simple-fill",color:[0,255,255,.5],style:"solid",outline:{color:[0,255,255],width:1}},attributes:{type:"OpenDriveSection",edgeId:e.id,selected:!0}});return this.sectionLayer.add(a),{status:0,message:"ok"}}else return{status:-1,message:"未找到路段"}}default:return{status:-1,message:"未知类型"}}}async geometrySearch(e){const t=new A.Polygon({rings:[e]}),i=await this.laneLayer.queryFeatures({geometry:t,outFields:["*"]}),o=[],s=[];for(const l of i.features){const n=l.getAttribute("roadId"),r=l.getAttribute("sectionId"),d=`${n}#${r}`;if(o.indexOf(d)===-1){o.push(d),this.selectSumo({type:"edge",id:d});const u=`http://${this.openDriveServer}/api/sumo/getSumoEdge`,g=await b.get(u,{params:{id:`${n}+${r}`,projectName:this.projectName}});g.status===200&&g.data.status===0&&s.push(g.data.result)}}const c=this.junctionLayer.graphics.filter(l=>{const n=l.geometry;return S.contains(t,n)}),a=[];for(const l of c){const n=l.getAttribute("id");this.selectSumo({type:"junction",id:n});const r=`http://${this.openDriveServer}/api/sumo/getSumoJunction`,d=await b.get(r,{params:{id:n,projectName:this.projectName}});d.status===200&&d.data.status===0&&a.push(d.data.result)}return{status:0,message:"ok",result:{junctions:a,edges:s}}}async splitLane(e){const i=e.id.split("_");if(i.length!==2)return{status:-1,message:"车道编号格式错误"};const o=Number(i[1]),s=i[0].split("#"),c=s.length===2?Number(s[1]):0;let a=s[0];a.startsWith("-")&&(a=a.slice(1));const l=this.allLaneGraphics.filter(v=>v.getAttribute("roadId")===a&&v.getAttribute("sectionIndex")===c);if(l.length===0)return{status:-1,message:"未找到路段"};const n=l.length-o,r=l.find(v=>Math.abs(v.getAttribute("laneId"))===n);if(!r)return{status:-1,message:"未找到车道"};const d=e.start||0,u=e.end||100,g=$.lineString(r.getAttribute("leftLine")),p=O.lineSliceAlong(g,d,u,{units:"meters"}),m=$.lineString(r.getAttribute("rightLine")),h=O.lineSliceAlong(m,d,u,{units:"meters"}),f=p.geometry.coordinates.concat(h.geometry.coordinates.reverse());f.push(f[f.length-1]);const w=new y({geometry:new A.Polygon({rings:[f]}),attributes:{ObjectID:r.getAttribute("ObjectID"),id:r.getAttribute("id"),fromNode:r.getAttribute("fromNode"),toNode:r.getAttribute("toNode"),roadId:r.getAttribute("roadId"),roadName:r.getAttribute("roadName"),sectionId:r.getAttribute("sectionId"),sectionIndex:r.getAttribute("sectionIndex"),laneId:r.getAttribute("laneId"),type:r.getAttribute("type"),sumoId:r.getAttribute("sumoId"),leftLine:p.geometry.coordinates,rightLine:h.geometry.coordinates},symbol:{type:"simple-fill",color:[255,0,0,.8],outline:{color:"red"}}});return this.splitLaneLayer.add(w),this.view.goTo(w),{status:0,message:"ok",result:e}}clearSplitLane(){this.splitLaneLayer.removeAll()}}exports.default=D;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const y=require("@arcgis/core/Graphic"),x=require("@arcgis/core/core/promiseUtils"),A=require("@arcgis/core/geometry"),J=require("@arcgis/core/geometry/geometryEngine"),C=require("@arcgis/core/layers/FeatureLayer"),I=require("@arcgis/core/layers/GraphicsLayer"),q=require("@turf/helpers"),O=require("@turf/line-slice-along"),b=require("axios"),T=require("md5"),F=require("pako"),E=require("vue"),R=require("../../stores/index.js"),_=require("../common-utils.js");function j(L){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(L){for(const t in L)if(t!=="default"){const i=Object.getOwnPropertyDescriptor(L,t);Object.defineProperty(e,t,i.get?i:{enumerable:!0,get:()=>L[t]})}}return e.default=L,Object.freeze(e)}const M=j(x),S=j(J),$=j(q);class D{constructor(e){this.junctionNames=new Map,this.projectName="",this.openDriveServer="",this.currentSectionCode="",this.currentJunctionId="",this.view=e,this.view.popup.visibleElements={collapseButton:!1,actionBar:!1},this.laneLayer=new C({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"},{name:"fromNode",alias:"起点路口",type:"string"},{name:"toNode",alias:"终点路口",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 C({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 I({id:"OpenDriveJunction"}),this.sectionLayer=new I({id:"OpenDriveSection"}),this.highlightLayer=new I({id:"OpenDriveHighlight"}),this.flashLayer=new I({id:"OpenDriveFlash"}),this.drawLayer=new I({id:"Draw"}),this.splitLaneLayer=new I({id:"SplitLane"}),this.view.map.addMany([this.laneLayer,this.junctionLayer,this.sectionLayer,this.roadNameLayer,this.highlightLayer,this.flashLayer,this.drawLayer,this.splitLaneLayer])}static getInstance(e){return this.instance||(this.instance=new D(e)),this.instance}async makeMd5FromFile(e){try{const i=await(await fetch(e)).text();return{status:0,message:"ok",result:T(i)}}catch(t){return{status:-1,message:t.message}}}async showOpenDriveFromFile(e){var m,p;this.openDriveClickCallback=e.selectedCallback,console.time("md5用时");const t=await this.makeMd5FromFile(e.file);if(t.status!==0)return t;this.projectName=t.result,console.timeEnd("md5用时"),this.openDriveServer=e.server,await this.makeMd5FromFile(e.file);const i=`http://${this.openDriveServer}/api/openDrive/uploadXodr`;let o;try{o=await b.post(i,{},{params:{url:e.file,projectName:this.projectName}})}catch(g){return{status:-1,message:g.message}}if(o.status!==200)return{status:-1,message:o.statusText};console.time("渲染用时");const s=o.data.result.geoSetting;_.default.setGeoData(s.geoReference,s.offsetX,s.offsetY);let c=o.data.result.json;c.startsWith(window.location.protocol)||(c=`${window.location.protocol}//${e.server}${c}`);const a=await(await fetch(c)).arrayBuffer(),n=F.inflate(a,{to:"string"}),r=JSON.parse(n);await this.showAllLanes(r,((m=e.options)==null?void 0:m.showJunctionLane)||!1,((p=e.options)==null?void 0:p.showRoadName)||!0);const u=o.data.result.junctions;this.showJunction(u),e.options&&e.options.centerMap!==!1&&await this.view.goTo(this.allLaneGraphics),this.mouseMoveHandler||this.monitorMouseMove(),this.mouseClickHandler||this.monitorMouseClick();const d=R.default.useAppDataStore;return E.watch(()=>d.isSketching,()=>{var g,h;d.isSketching?((g=this.mouseMoveHandler)==null||g.remove(),this.mouseMoveHandler=void 0,(h=this.mouseClickHandler)==null||h.remove(),this.mouseClickHandler=void 0):(this.monitorMouseMove(),this.monitorMouseClick())}),console.timeEnd("渲染用时"),{status:0,message:"ok"}}async showOpenDriveFromServer(e,t){const i=`http://${e}/api/openDrive/analyzeXodr`,o=await b.get(i,{headers:{projectName:t},params:{analyze:!1,compressed:!0}});if(o.status!==200)throw new Error(`OpenDriveRenderer: ${o.statusText}`);let s=o.data.result.json;s.startsWith(window.location.protocol)||(s=`${window.location.protocol}//${e}${s}`);const l=await(await fetch(s)).arrayBuffer(),a=F.inflate(l,{to:"string"}),n=JSON.parse(a);return await this.showAllLanes(n,!1,!1),{status:0,message:"ok"}}async showAllLanes(e,t,i){const o=await this.laneLayer.queryFeatures();return o.features.length>0&&this.laneLayer.applyEdits({deleteFeatures:o.features}),this.roadNameLayer.visible=i,new Promise(s=>{let c=0;this.allLaneGraphics=[],this.allRefLineGraphics=[];const l=[];console.log(e.length);for(const n of e){if(!t&&n.junction!=="-1")continue;const{id:r,refLine:u}=n;let d=n.name;d.includes("(")&&(d=d.slice(0,d.indexOf("("))),d=d.replace(/(.)/g,"$1 ");const m=new y({geometry:{type:"polyline",paths:[u]},attributes:{ObjectID:c++,roadId:r,roadName:d}});this.allRefLineGraphics.push(m),n.laneSections.sort((p,g)=>Number(p.id)-Number(g.id));for(let p=0;p<n.laneSections.length;p++){const g=n.laneSections[p],h=Number(g.id);for(const f of g.lanePaths){const w=Number(f.id);if(w===0)continue;const v=f.type,P=[...f.outerPath],N=f.innerPath.concat(P.reverse());if(N.length<=3){console.warn(`lane ${w} has less than 3 points`);continue}N.push(f.innerPath[0]);const k=new A.Polygon({rings:[N]});if(k){const G=new y({geometry:k,attributes:{ObjectID:c++,id:`${r}+${h}+${w}`,fromNode:n.fromNode,toNode:n.toNode,roadId:String(r),roadName:n.name,sectionId:String(h),sectionIndex:p,laneId:w,type:v,sumoId:"",leftLine:f.innerPath,rightLine:f.outerPath}});this.allLaneGraphics.push(G),l.push(G)}}}}const a=setInterval(()=>{if(l.length>0||this.allRefLineGraphics.length>0){if(l.length>0){const n=l.splice(0,100);this.laneLayer.applyEdits({addFeatures:n})}if(this.allRefLineGraphics.length>0){const n=this.allRefLineGraphics.splice(0,10);this.roadNameLayer.applyEdits({addFeatures:n})}}else clearInterval(a),s()},10)})}showJunction(e){const t=[];for(const i of e){if(!i)continue;this.junctionNames.set(i.id,i.name),i.nodeType=i.type;const o=new y({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/point_yellow.png",width:30,height:30},popupTemplate:{title:i.name,content:[{type:"fields",fieldInfos:[{fieldName:"id",label:"路口编号"},{fieldName:"crossId",label:"信号机编号"}]}]}});t.push(o)}this.junctionLayer.addMany(t)}monitorMouseMove(){const e=M.debounce(async t=>{var c;const o=(c=(await this.view.hitTest(t,{include:[this.laneLayer,this.junctionLayer]})).results)==null?void 0:c.filter(l=>l.type==="graphic");if(o.length===0){this.currentSectionCode!==""&&(this.currentSectionCode="",this.highlightGraphic=void 0,this.highlightLayer.removeAll()),this.currentJunctionId!==""&&(this.currentJunctionId="",this.view.closePopup());return}const s=o[0];if(this.hitGraphic=s.graphic,s.layer.id==="OpenDriveLane"){const l=`${this.hitGraphic.getAttribute("roadId")}+${this.hitGraphic.getAttribute("sectionId")}`;if(l===this.currentSectionCode||this.sectionLayer.graphics.findIndex(h=>h.getAttribute("id")===l)>=0)return;this.currentSectionCode=l;const n=this.allLaneGraphics.filter(h=>`${h.attributes.roadId}+${h.attributes.sectionId}`===l),r=S.union(n.map(h=>h.geometry)),u=this.hitGraphic.getAttribute("fromNode"),d=this.hitGraphic.getAttribute("toNode"),m=this.junctionNames.get(u)||u,p=this.junctionNames.get(d)||d;this.highlightGraphic=new y({geometry:r,symbol:{type:"simple-fill",color:[0,255,255,.5],style:"solid",outline:{color:[0,255,255],width:1}},attributes:{type:"OpenDriveSection",id:l,selected:!1,fromNodeName:m,toNodeName:p,laneCount:n.length},popupTemplate:{title:this.hitGraphic.getAttribute("roadName"),content:[{type:"fields",fieldInfos:[{fieldName:"fromNodeName",label:"起点路口"},{fieldName:"toNodeName",label:"终点路口"},{fieldName:"laneCount",label:"车道数量"}]}]}}),this.highlightLayer.removeAll(),this.highlightLayer.add(this.highlightGraphic);const g=this.view.toMap(t);this.view.openPopup({features:[this.highlightGraphic],location:g})}else if(s.layer.id==="OpenDriveJunction"){const l=this.hitGraphic.getAttribute("id");if(l===this.currentJunctionId)return;this.currentJunctionId=l,this.view.openPopup({features:[this.hitGraphic],location:this.hitGraphic.geometry})}});this.mouseMoveHandler=this.view.on("pointer-move",async t=>{e(t).catch(()=>{})})}monitorMouseClick(){const e=M.debounce(async t=>{var a;const o=(a=(await this.view.hitTest(t,{include:[this.highlightLayer,this.junctionLayer,this.sectionLayer]})).results)==null?void 0:a.filter(n=>n.type==="graphic");if(o.length===0)return;const s=o[0].graphic,c=s.getAttribute("type"),l=s.getAttribute("id");if(c==="OpenDriveJunction")if(s.getAttribute("selected")===!1){const n=`http://${this.openDriveServer}/api/sumo/getSumoJunction`,r=await b.get(n,{params:{id:l,projectName:this.projectName}});r.status===200&&r.data.status===0&&(this.openDriveClickCallback&&this.openDriveClickCallback({type:"OpenDriveJunction",id:l,details:r.data.result}),s.setAttribute("selected",!0),s.symbol.url="/GisViewerAssets/Images/point_red.png",this.increasePictureMarkerSize(s,50))}else{this.openDriveClickCallback&&this.openDriveClickCallback({type:"OpenDriveJunction",id:l,details:void 0}),s.setAttribute("selected",!1);const n=s.getAttribute("crossId");s.symbol.url=n?"/GisViewerAssets/Images/point_green.png":"/GisViewerAssets/Images/point_yellow.png",this.decreasePictureMarkerSize(s,30)}else if(c==="OpenDriveSection")if(s.getAttribute("selected"))this.sectionLayer.remove(s),this.openDriveClickCallback&&this.openDriveClickCallback({type:"OpenDriveSection",id:s.getAttribute("edgeId"),details:void 0});else{this.highlightLayer.remove(s),this.sectionLayer.add(s),s.setAttribute("selected",!0);const n=`http://${this.openDriveServer}/api/sumo/getSumoEdge`,r=await b.get(n,{params:{id:l,projectName:this.projectName}});if(r.status===200&&r.data.status===0&&this.openDriveClickCallback){const u=r.data.result.obj_id;s.setAttribute("edgeId",u),this.openDriveClickCallback({type:"OpenDriveSection",id:u,details:r.data.result})}}});this.mouseClickHandler=this.view.on("immediate-click",async t=>{e(t).catch(()=>{})})}increasePictureMarkerSize(e,t){const i=setInterval(()=>{const o=e.symbol,s=o.width;s<t?e.symbol={type:"picture-marker",url:o.url,width:s+1,height:s+1}:clearInterval(i)},20)}decreasePictureMarkerSize(e,t){const i=setInterval(()=>{const o=e.symbol,s=o.width;s>t?e.symbol={type:"picture-marker",url:o.url,width:s-1,height:s-1}:clearInterval(i)},20)}async getSumoInfo(e){switch(e.type){case"junction":{const t=`http://${this.openDriveServer}/api/sumo/getSumoJunction`,i=await b.get(t,{params:{id:e.id,projectName:this.projectName}});return i.status===200?i.data:{status:-1,message:`路口信息查询失败: ${e.id}`}}case"edge":{const t=e.id.split("#");let i=t[0];i.startsWith("-")&&(i=i.slice(1));let o=0;t.length===2&&(o=Number(t[1]));const s=this.allLaneGraphics.find(c=>c.getAttribute("roadId")===i&&c.getAttribute("sectionIndex")===o);if(s){const c=`${i}+${s.getAttribute("sectionId")}`,l=`http://${this.openDriveServer}/api/sumo/getSumoEdge`,a=await b.get(l,{params:{id:c,projectName:this.projectName}});return a.status===200?a.data:{status:-1,message:`路段信息查询失败: ${c}`}}else return{status:-1,message:"未知类型"}}default:return{status:-1,message:"未知类型"}}}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.sectionLayer.removeAll(),this.flashLayer.removeAll(),(t=this.mouseMoveHandler)==null||t.remove(),this.mouseMoveHandler=void 0,(i=this.mouseClickHandler)==null||i.remove(),this.mouseClickHandler=void 0}async findSumo(e){const{type:t,id:i}=e,o=e.flash===void 0?!0:e.flash;if(t==="junction")return await this.findJunction(i,o);if(t==="edge"){const s=i.split("_");if(s.length>2)return{status:-1,message:"id格式错误"};const c=s.length===2?Number(s[1]):void 0,l=s[0].split("#");if(l.length>2)return{status:-1,message:"id格式错误"};const a=l[0],n=l.length===2?Number(l[1]):void 0;return await this.findLane({roadsectId:a,segmentId:n,laneId:c,flash:o})}else return{status:-1,message:"未知类型"}}async findJunction(e,t){const i=this.junctionLayer.graphics.find(o=>o.attributes.id===e);if(!i)return{status:-1,message:"未找到。请检查路口编号"};if(t){const o=new y({geometry:i.geometry,symbol:{type:"simple-marker",style:"circle",size:30,color:[255,0,0,.6],outline:{color:"red",width:1}}});this.flashGraphic(o)}return await this.view.goTo(i.geometry,{duration:1e3}),{status:0,message:"ok"}}async findLane(e){let{roadsectId:t,segmentId:i,laneId:o}=e;t.startsWith("-")&&(t=t.slice(1));let s=this.allLaneGraphics.filter(a=>a.attributes.roadId===t);if(s.length===0)return{status:-1,message:"未找到。请检查路段编号"};if(i!==void 0){const a=[];if(s.forEach(n=>{const r=Number(n.attributes.sectionId);a.indexOf(r)===-1&&a.push(r)}),a.sort((n,r)=>n-r),i>a.length-1)return{status:-1,message:"未找到。请检查基本段编号"};i=a[i],s=s.filter(n=>Number(n.attributes.sectionId)===i)}if(o!==void 0){const a=[];if(s.forEach(n=>{const r=Number(n.attributes.laneId);a.indexOf(r)===-1&&a.push(r)}),a.sort((n,r)=>n-r),o>a.length-1)return{status:-1,message:"未找到。请检查车道编号"};o=a[o],s=s.filter(n=>Number(n.attributes.laneId)===o)}const c=s.map(a=>a.geometry),l=S.union(c);if(e.flash){const a=new y({geometry:l,symbol:{type:"simple-fill",color:[255,0,0,.5],style:"solid",outline:{color:"red",width:0}}});this.flashGraphic(a)}return await this.view.goTo(l,{duration:1e3}),{status:0,message:"ok"}}flashGraphic(e){this.flashLayer.removeAll(),this.flashLayer.add(e);let t=0,i=!0;const o=setInterval(()=>{i?(this.flashLayer.opacity-=.02,this.flashLayer.opacity<=.1&&(i=!1,t++)):(this.flashLayer.opacity+=.02,this.flashLayer.opacity>=1&&(i=!0)),t>=5&&(this.flashLayer.removeAll(),this.flashLayer.opacity=1,clearInterval(o))},10)}unselectSumo(e){if((!e||e.type==="junction")&&this.junctionLayer.graphics.forEach(t=>{if((!e||!e.id||e.id===""||e.id===t.getAttribute("id"))&&t.getAttribute("selected")){t.setAttribute("selected",!1);const i=t.getAttribute("crossId");t.symbol.url=i?"/GisViewerAssets/Images/point_green.png":"/GisViewerAssets/Images/point_yellow.png",this.decreasePictureMarkerSize(t,30)}}),!e||e.type==="edge")if(!e||!e.id||e.id==="")this.sectionLayer.removeAll();else{const t=this.sectionLayer.graphics.find(i=>i.getAttribute("edgeId")===e.id);t&&this.sectionLayer.remove(t)}return{status:0,message:"ok"}}selectSumo(e){switch(e.type){case"junction":return this.junctionLayer.graphics.forEach(t=>{if(e.id===t.getAttribute("id"))return t.setAttribute("selected",!0),t.symbol.url="/GisViewerAssets/Images/point_red.png",this.increasePictureMarkerSize(t,50),{status:0,message:"ok"}}),{status:-1,message:"未找到路口"};case"edge":{const t=e.id.split("#");let i=String(t[0]);i.startsWith("-")&&(i=i.slice(1));let o="0";t.length===2&&(o=String(t[1]));let s=[];if(t.length===1?s=this.allLaneGraphics.filter(c=>c.getAttribute("roadId")===i):t.length===2&&(s=this.allLaneGraphics.filter(c=>c.getAttribute("roadId")===i&&c.getAttribute("sectionId")===o)),s.length>0){const c=S.union(s.map(a=>a.geometry)),l=new y({geometry:c,symbol:{type:"simple-fill",color:[0,255,255,.5],style:"solid",outline:{color:[0,255,255],width:1}},attributes:{type:"OpenDriveSection",edgeId:e.id,selected:!0}});return this.sectionLayer.add(l),{status:0,message:"ok"}}else return{status:-1,message:"未找到路段"}}default:return{status:-1,message:"未知类型"}}}async geometrySearch(e){const t=new A.Polygon({rings:[e]}),i=await this.laneLayer.queryFeatures({geometry:t,outFields:["*"]}),o=[],s=[];for(const a of i.features){const n=a.getAttribute("roadId"),r=a.getAttribute("sectionId"),u=`${n}#${r}`;if(o.indexOf(u)===-1){o.push(u),this.selectSumo({type:"edge",id:u});const d=`http://${this.openDriveServer}/api/sumo/getSumoEdge`,m=await b.get(d,{params:{id:`${n}+${r}`,projectName:this.projectName}});m.status===200&&m.data.status===0&&s.push(m.data.result)}}const c=this.junctionLayer.graphics.filter(a=>{const n=a.geometry;return S.contains(t,n)}),l=[];for(const a of c){const n=a.getAttribute("id");this.selectSumo({type:"junction",id:n});const r=`http://${this.openDriveServer}/api/sumo/getSumoJunction`,u=await b.get(r,{params:{id:n,projectName:this.projectName}});u.status===200&&u.data.status===0&&l.push(u.data.result)}return{status:0,message:"ok",result:{junctions:l,edges:s}}}async splitLane(e){const i=e.id.split("_");if(i.length!==2)return{status:-1,message:"车道编号格式错误"};const o=Number(i[1]),s=i[0].split("#"),c=s.length===2?Number(s[1]):0;let l=s[0];l.startsWith("-")&&(l=l.slice(1));const a=this.allLaneGraphics.filter(v=>v.getAttribute("roadId")===l&&v.getAttribute("sectionIndex")===c);if(a.length===0)return{status:-1,message:"未找到路段"};const n=a.length-o,r=a.find(v=>Math.abs(v.getAttribute("laneId"))===n);if(!r)return{status:-1,message:"未找到车道"};const u=e.start||0,d=e.end||100,m=$.lineString(r.getAttribute("leftLine")),p=O.lineSliceAlong(m,u,d,{units:"meters"}),g=$.lineString(r.getAttribute("rightLine")),h=O.lineSliceAlong(g,u,d,{units:"meters"}),f=p.geometry.coordinates.concat(h.geometry.coordinates.reverse());f.push(f[f.length-1]);const w=new y({geometry:new A.Polygon({rings:[f]}),attributes:{ObjectID:r.getAttribute("ObjectID"),id:r.getAttribute("id"),fromNode:r.getAttribute("fromNode"),toNode:r.getAttribute("toNode"),roadId:r.getAttribute("roadId"),roadName:r.getAttribute("roadName"),sectionId:r.getAttribute("sectionId"),sectionIndex:r.getAttribute("sectionIndex"),laneId:r.getAttribute("laneId"),type:r.getAttribute("type"),sumoId:r.getAttribute("sumoId"),leftLine:p.geometry.coordinates,rightLine:h.geometry.coordinates},symbol:{type:"simple-fill",color:[255,0,0,.8],outline:{color:"red"}}});return this.splitLaneLayer.add(w),this.view.goTo(w),{status:0,message:"ok",result:e}}clearSplitLane(){this.splitLaneLayer.removeAll()}}exports.default=D;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gisviewer-vue3-arcgis",
3
- "version": "1.0.149",
3
+ "version": "1.0.150",
4
4
  "main": "lib/index.js",
5
5
  "module": "es/index.mjs",
6
6
  "files": [