gisviewer-vue3-arcgis 1.0.119 → 1.0.121
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.
- package/es/src/gis-map/utils/common-utils.d.ts +4 -3
- package/es/src/gis-map/utils/common-utils.mjs +21 -8
- package/es/src/gis-map/utils/map-initializer.mjs +100 -99
- package/es/src/gis-map/utils/open-drive-renderer/index.d.ts +23 -3
- package/es/src/gis-map/utils/open-drive-renderer/index.mjs +294 -136
- package/es/src/gis-map/utils/open-drive-renderer/junction.d.ts +2 -1
- package/es/src/gis-map/utils/open-drive-renderer/road.d.ts +2 -0
- package/es/src/gis-map/utils/open-drive-renderer/road.mjs +16 -8
- package/es/src/gis-map/utils/open-drive-renderer/wasm-loader.d.ts +20 -0
- package/es/src/gis-map/utils/open-drive-renderer/wasm-loader.mjs +154 -104
- package/es/src/types/index.d.ts +11 -0
- package/lib/src/gis-map/utils/common-utils.d.ts +4 -3
- package/lib/src/gis-map/utils/common-utils.js +1 -1
- package/lib/src/gis-map/utils/map-initializer.js +1 -1
- package/lib/src/gis-map/utils/open-drive-renderer/index.d.ts +23 -3
- package/lib/src/gis-map/utils/open-drive-renderer/index.js +2 -1
- package/lib/src/gis-map/utils/open-drive-renderer/junction.d.ts +2 -1
- package/lib/src/gis-map/utils/open-drive-renderer/road.d.ts +2 -0
- package/lib/src/gis-map/utils/open-drive-renderer/road.js +1 -1
- package/lib/src/gis-map/utils/open-drive-renderer/wasm-loader.d.ts +20 -0
- package/lib/src/gis-map/utils/open-drive-renderer/wasm-loader.js +1 -1
- package/lib/src/types/index.d.ts +11 -0
- package/package.json +1 -1
|
@@ -1 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const 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,4 +1,4 @@
|
|
|
1
|
-
import { ILaneInfo } from '../../../types';
|
|
1
|
+
import { IJunctionTableData, ILaneInfo } from '../../../types';
|
|
2
2
|
interface ILink {
|
|
3
3
|
incoming: ILaneInfo;
|
|
4
4
|
connecting: ILaneInfo;
|
|
@@ -9,6 +9,7 @@ export default class Junction {
|
|
|
9
9
|
name: string;
|
|
10
10
|
/** 路口内的行车通道,包含进口道->转接道->出口道三个车道 */
|
|
11
11
|
laneLinks: Array<ILink>;
|
|
12
|
+
tableData: IJunctionTableData | undefined;
|
|
12
13
|
/** 进口车道按roadId归类, */
|
|
13
14
|
private incomingLanes;
|
|
14
15
|
private outline;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const a=require("../common-utils.js"),h=require("./lane-section.js");class l{constructor(e){this.id=e.id,this.name=e.name,this.length=e.length,this.junction=e.junction,this.sToLaneSection=new Map;const t=a.default.getStdVecEntries(e.ref_line,!0);this.refLine=a.default.transformLineProjection(t);for(const i of[!0,!1]){const o=i?e.predecessor:e.successor,r={elementId:o.id,elementType:o.type,contactPoint:o.contact_point};i?this.predecessor=r:this.successor=r}a.default.getStdVecEntries(e.odr_lanesections,!0).forEach(i=>{const o=new h.default(i,this);this.sToLaneSection.set(o.s0,o)}),this.borders=this.getBorderLine();const n=[];n.push(...this.borders.right),n.push(...this.borders.top),n.push(...[...this.borders.left].reverse()),n.push(...[...this.borders.bottom].reverse()),n.push(n[0]),this.polygon=n}getLaneSection(e){return this.sToLaneSection.get(e)}getFirstLaneSection(){const e=[...this.sToLaneSection.keys()];return e.sort((t,s)=>t-s),this.sToLaneSection.get(e[0])}getLastLaneSection(){const e=[...this.sToLaneSection.keys()];return e.sort((t,s)=>t-s),this.sToLaneSection.get(e[e.length-1])}isLastLaneSection(e){const t=[...this.sToLaneSection.keys()];return t.sort((s,n)=>s-n),e===t[t.length-1]}getNextLaneSection(e){const t=[...this.sToLaneSection.keys()],s=t.indexOf(e);if(s>=0&&s<t.length-1)return this.sToLaneSection.get(t[s+1])}getPrevLaneSection(e){const t=[...this.sToLaneSection.keys()],s=t.indexOf(e);if(s>0)return this.sToLaneSection.get(t[s-1])}get allLaneSections(){return[...this.sToLaneSection.values()]}get laneSectionNumber(){return this.sToLaneSection.size}get sampledRoad(){return{id:this.id,name:this.name,junction:this.junction,refLine:this.refLine,laneSections:this.allLaneSections.map(e=>e.sampledLaneSection)}}getBorderLine(){const e=[],t=[];let s=[],n=[];const i=[...this.sToLaneSection.keys()];return i.forEach((o,r)=>{const c=this.getLaneSection(o);r===0?n=c.borders.bottom:r===i.length-1&&(s=c.borders.top),e.push(...c.borders.left),t.push(...c.borders.right)}),{left:e,right:t,top:s,bottom:n}}}exports.default=l;
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const a=require("../common-utils.js"),h=require("./lane-section.js");class l{constructor(e){this.id=e.id,this.name=e.name,this.length=e.length,this.junction=e.junction,this.sToLaneSection=new Map;const t=a.default.getStdVecEntries(e.ref_line,!0);this.refLine=a.default.transformLineProjection(t);for(const i of[!0,!1]){const o=i?e.predecessor:e.successor,r={elementId:o.id,elementType:o.type,contactPoint:o.contact_point};i?this.predecessor=r:this.successor=r}a.default.getStdVecEntries(e.odr_lanesections,!0).forEach(i=>{const o=new h.default(i,this);this.sToLaneSection.set(o.s0,o)}),this.borders=this.getBorderLine();const n=[];n.push(...this.borders.right),n.push(...this.borders.top),n.push(...[...this.borders.left].reverse()),n.push(...[...this.borders.bottom].reverse()),n.push(n[0]),this.polygon=n}getLaneSection(e){return this.sToLaneSection.get(e)}getFirstLaneSection(){const e=[...this.sToLaneSection.keys()];return e.sort((t,s)=>t-s),this.sToLaneSection.get(e[0])}getLastLaneSection(){const e=[...this.sToLaneSection.keys()];return e.sort((t,s)=>t-s),this.sToLaneSection.get(e[e.length-1])}getLaneSectionIndex(e){return[...this.sToLaneSection.keys()].indexOf(e)}getLaneSectionLength(e){const t=[...this.sToLaneSection.keys()],s=t.indexOf(e);let n=0;return s===0?t.length===1?n=this.length:n=t[1]:s===t.length-1?n=this.length-t[t.length-1]:n=t[s+1]-e,n}isLastLaneSection(e){const t=[...this.sToLaneSection.keys()];return t.sort((s,n)=>s-n),e===t[t.length-1]}getNextLaneSection(e){const t=[...this.sToLaneSection.keys()],s=t.indexOf(e);if(s>=0&&s<t.length-1)return this.sToLaneSection.get(t[s+1])}getPrevLaneSection(e){const t=[...this.sToLaneSection.keys()],s=t.indexOf(e);if(s>0)return this.sToLaneSection.get(t[s-1])}get allLaneSections(){return[...this.sToLaneSection.values()]}get laneSectionNumber(){return this.sToLaneSection.size}get sampledRoad(){return{id:this.id,name:this.name,junction:this.junction,refLine:this.refLine,laneSections:this.allLaneSections.map(e=>e.sampledLaneSection)}}getBorderLine(){const e=[],t=[];let s=[],n=[];const i=[...this.sToLaneSection.keys()];return i.forEach((o,r)=>{const c=this.getLaneSection(o);r===0?n=c.borders.bottom:r===i.length-1&&(s=c.borders.top),e.push(...c.borders.left),t.push(...c.borders.right)}),{left:e,right:t,top:s,bottom:n}}}exports.default=l;
|
|
@@ -7,6 +7,7 @@ export default class WasmLoader {
|
|
|
7
7
|
static getInstance(): WasmLoader;
|
|
8
8
|
roadList: Map<string, Road>;
|
|
9
9
|
junctionList: Map<string, Junction>;
|
|
10
|
+
private junctionTableData;
|
|
10
11
|
private isWasmLoaded;
|
|
11
12
|
private ModuleOpenDrive;
|
|
12
13
|
private ModuleOpenDriveMap;
|
|
@@ -18,6 +19,11 @@ export default class WasmLoader {
|
|
|
18
19
|
*/
|
|
19
20
|
load(file: string): Promise<IResult>;
|
|
20
21
|
clear(): void;
|
|
22
|
+
/**
|
|
23
|
+
* 读取xodr中wasm接口不提供的数据
|
|
24
|
+
* @param fileText
|
|
25
|
+
*/
|
|
26
|
+
private readXodrString;
|
|
21
27
|
/**
|
|
22
28
|
* 解析路网
|
|
23
29
|
*/
|
|
@@ -85,4 +91,18 @@ export default class WasmLoader {
|
|
|
85
91
|
getRoadStopLine(junctionId: string): IResult;
|
|
86
92
|
getLaneStopLine(laneInfo: ILaneInfo): IResult;
|
|
87
93
|
getLaneCenterLine(laneInfo: ILaneInfo): IResult;
|
|
94
|
+
getSumoEdgeInfo(sectionCode: string): {
|
|
95
|
+
obj_id: string;
|
|
96
|
+
obj_type: number;
|
|
97
|
+
obj_desc: string;
|
|
98
|
+
obj_info: {
|
|
99
|
+
obj_id: string;
|
|
100
|
+
length: number;
|
|
101
|
+
from: string;
|
|
102
|
+
to: string;
|
|
103
|
+
numLanes: number;
|
|
104
|
+
type: string;
|
|
105
|
+
laneList: any[];
|
|
106
|
+
};
|
|
107
|
+
} | undefined;
|
|
88
108
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const m=require("fast-xml-parser"),L=require("../../stores/index.js"),g=require("../common-utils.js"),p=require("./junction.js"),S=require("./road.js");class c{constructor(){this.roadList=new Map,this.junctionList=new Map,this.junctionTableData=new Map,this.isWasmLoaded=!1,this.appDataStore=L.default.useAppDataStore,this.FsFile="data.xodr"}static getInstance(){return c.instance||(c.instance=new c),c.instance}async load(o){if(!this.isWasmLoaded){const r=window.libOpenDrive;this.ModuleOpenDrive=await r(),this.isWasmLoaded=!0}console.time("加载用时");const t=await(await fetch(o)).text();this.readXodrString(t);const n=new TextEncoder().encode(t);try{this.ModuleOpenDrive.FS_unlink(`./${this.FsFile}`)}catch{}this.ModuleOpenDrive.FS_createDataFile(".",this.FsFile,n,!0,!0);const i={with_lateralProfile:!0,with_laneHeight:!0,with_road_objects:!1,center_map:!1,abs_z_for_for_local_road_obj_outline:!0};return this.ModuleOpenDriveMap=new this.ModuleOpenDrive.OpenDriveMap(`./${this.FsFile}`,i),console.timeEnd("加载用时"),this.getRoadNetwork()}clear(){this.roadList.clear(),this.junctionList.clear();try{this.ModuleOpenDrive.FS_unlink(`./${this.FsFile}`)}catch{}}readXodrString(o){const t=new m.XMLParser({ignoreAttributes:!1,allowBooleanAttributes:!0}).parse(o),s=t.OpenDRIVE.header.geoReference,n=t.OpenDRIVE.header.offset;if(n){const r=Number(n["@_x"])||0,a=Number(n["@_y"])||0;g.default.setGeoData(s,r,a)}const i=t.OpenDRIVE.junction;for(const r of i){const a=JSON.parse(r.userData.tableData);this.junctionTableData.set(a.id,a)}}getRoadNetwork(){this.roadList.clear(),this.junctionList.clear();let o;try{console.time("采样用时"),o=this.ModuleOpenDrive.get_odr_road_network(this.ModuleOpenDriveMap,.5)}catch(s){return{status:-1,message:`解析路网失败, ${s}`}}finally{console.timeEnd("采样用时")}console.time("投影转换用时");try{g.default.getStdVecEntries(o.roads,!0).forEach(n=>{const i=new S.default(n);this.roadList.set(i.id,i)})}catch(s){return{status:-1,message:`解析道路失败, ${s}`}}try{g.default.getStdVecEntries(o.junctions,!0).forEach(n=>{const i=new p.default(n);i.tableData=this.junctionTableData.get(i.id),this.junctionList.set(n.id,i)})}catch(s){return{status:-1,message:`解析路口失败, ${s}`}}console.timeEnd("投影转换用时");const e=[];this.roadList.forEach(s=>{const n=s.allLaneSections.map(i=>{const r=i.allLanes.map(a=>({id:a.id,type:a.type,innerPath:a.innerBorder,outerPath:a.outerBorder,centerLine:a.centerLine}));return{id:i.s0,lanePaths:r}});e.push({id:s.id,name:s.name,laneSections:n,junction:s.junction,refLine:s.refLine})});const t=[];return this.junctionList.forEach(s=>{s.tableData&&t.push(s.tableData)}),{status:0,message:"ok",result:{roads:e,junctions:t}}}get allSampledRoads(){return[...this.roadList.values()].map(o=>o.sampledRoad)}get roadNetwork(){return[...this.roadList.values()].map(e=>{const t=e.allLaneSections.map(s=>{const n=s.allLaneIds.filter(i=>i!==0);return{sectionId:s.s0,laneIds:n}});return{roadName:e.name,roadId:e.id,roadLength:e.length,sections:t}})}getLane(o){const e=this.roadList.get(o.roadId),t=e==null?void 0:e.getLaneSection(o.sectionId);return t==null?void 0:t.getLane(o.laneId)}getFunctionFromIncomingToOutgoing(o,e){const t=this.getLane(o),s=this.getLane(e);if(!t||!s||!t.drivingAngle||!s.drivingAngle)return{status:-1,message:"车道信息错误"};let n=s.drivingAngle-t.drivingAngle;n>180?n-=360:n<-180&&(n+=360);let i="";return-45<n&&n<45?i="s":45<=n&&n<=135?i="r":-135<=n&&n<=-45?i="l":i="t",{status:0,result:i,message:"ok"}}getJunctionOutline(o){const e=[];if(o!==""){const t=this.junctionList.get(o);if(t){const s=t.getJunctionOutline();e.push({junctionId:o,name:t.name,outline:s})}}else for(const t of this.junctionList){const s=t[0],n=t[1],i=n.getJunctionOutline();i.length<=4?console.log(i,s):e.push({junctionId:s,name:n.name,outline:i})}return{status:0,result:e,message:"ok"}}getLaneLink(o){const e=this.getLane(o);return e?{status:0,result:e.getLink(),message:"ok"}:{status:-1,message:"车道信息错误"}}getRoadLink(o){const e=[];if(o!==""){const t=this.roadList.get(o);t&&e.push({roadId:o,successor:t.successor,predecessor:t.predecessor})}else[...this.roadList.values()].forEach(s=>{e.push({roadId:o,successor:s.successor,predecessor:s.predecessor})});return{status:0,result:e,message:"ok"}}getConnectionLink(o){const e=[];for(const t of this.junctionList){const s=t[0],n=t[1];if((o===""||s===o)&&(e.push({id:s,name:n.name,links:n.laneLinks}),o!==""))break}return{status:0,result:e,message:"ok"}}getLaneAngle(o){const e=this.getLane(o);if(e){const t=e.drivingAngle;if(t)return{status:0,result:t,message:"ok"}}return{status:-1,message:"车道信息错误"}}getTurnArrow(o){const e=this.getLane(o.incoming);if(!e)return{status:-1,message:"进口道信息错误"};const t=e.drivingAngle;if(!t)return{status:-1,message:"进口道信息错误"};const s=this.getLane(o.outgoing);if(!s)return{status:-1,message:"出口道信息错误"};const n=s.drivingAngle;if(!n)return{status:-1,message:"出口道信息错误"};let i=n-t;i>180?i-=360:i<-180&&(i+=360);let r="";return-45<i&&i<45?r="s":45<=i&&i<=135?r="r":-135<=i&&i<=-45?r="l":r="t",{status:0,message:"ok",result:{incomingAngle:t,outgoingAngle:n,direction:r}}}getPolygon(o,e,t){const s=this.roadList.get(o);if(!s)return{status:-1,message:"道路id错误"};if(e!==void 0&&t!==void 0&&!isNaN(e)&&!isNaN(t)){const n=this.getLane({roadId:o,sectionId:e,laneId:t});return n?{status:0,message:"ok",result:n.ring}:{status:-1,message:"车道信息错误"}}else if(e!==void 0&&!isNaN(e)){const n=s.getLaneSection(e);return n?{status:0,message:"ok",result:n.polygon}:{status:-1,message:"路段信息错误"}}else return{status:0,message:"ok",result:s.polygon}}getLaneLength(o){const e=this.getLane(o);if(e){let t=0;return e.road.isLastLaneSection(e.laneSection.s0)?t=e.road.length-e.laneSection.s0:t=e.road.getNextLaneSection(e.laneSection.s0).s0-e.laneSection.s0,{status:0,message:"ok",result:Number(t.toFixed(2))}}else return{status:-1,message:"车道信息错误"}}getRoadStopLine(o){const e=[];for(const t of this.junctionList){const s=t[0],n=t[1];if(s===o){const i=n.getRoadStopLine();e.push({junctionId:s,stopLines:i});break}else if(o===""){const i=n.getRoadStopLine();e.push({junctionId:s,stopLines:i})}}return{status:0,message:"ok",result:e}}getLaneStopLine(o){const e=this.getLane(o);return e?{status:0,message:"ok",result:e.getStopLine()}:{status:-1,message:"车道信息错误"}}getLaneCenterLine(o){const e=this.getLane(o);return e?{status:0,message:"ok",result:e.getLaneEndPoints("middle")}:{status:-1,message:"车道信息错误"}}getSumoEdgeInfo(o){const e=o.split("+"),t=e[0],s=Number(e[1]),n=this.roadList.get(t);if(!n)return;let i="";if(n.laneSectionNumber===1)i=`-${t}`;else{const u=n.getLaneSectionIndex(s);if(u===-1)return;i=`-${t}#${u}`}const r=n.predecessor.elementId,a=n.successor.elementId,l=n.getLaneSection(s);if(!l)return;const d=[],f=l.laneNumber-1;for(const u of l.allLanes){if(u.id===0)continue;const h=f-Math.abs(u.id);d.push({obj_id:`${i}_${h}`})}return{obj_id:i,obj_type:1,obj_desc:"edge",obj_info:{obj_id:i,length:n.getLaneSectionLength(s),from:r,to:a,numLanes:f,type:"driving",laneList:d}}}}exports.default=c;
|
package/lib/src/types/index.d.ts
CHANGED
|
@@ -208,11 +208,13 @@ export interface IRoadStopLinesResult {
|
|
|
208
208
|
}[];
|
|
209
209
|
}
|
|
210
210
|
export interface IShowOpenDriveFromFileParams {
|
|
211
|
+
server: string;
|
|
211
212
|
file: string;
|
|
212
213
|
options?: {
|
|
213
214
|
showJunctionPolygon: boolean;
|
|
214
215
|
showJunctionLane: boolean;
|
|
215
216
|
showRoadName: boolean;
|
|
217
|
+
centerMap?: boolean;
|
|
216
218
|
};
|
|
217
219
|
}
|
|
218
220
|
export interface IFindSumoParams {
|
|
@@ -224,3 +226,12 @@ export interface ISplitOpenDriveLaneParams {
|
|
|
224
226
|
start: number;
|
|
225
227
|
end: number;
|
|
226
228
|
}
|
|
229
|
+
export interface IJunctionTableData {
|
|
230
|
+
id: string;
|
|
231
|
+
name: string;
|
|
232
|
+
type: string;
|
|
233
|
+
coordinates: number[];
|
|
234
|
+
district: string;
|
|
235
|
+
crossId?: string;
|
|
236
|
+
factoryCode?: string;
|
|
237
|
+
}
|