gisviewer-vue3-arcgis
Version:
在应用中引入私服的包, 项目根目录下 新建文件 .npmrc 在 .npmrc 中对包源进行配置:
2 lines (1 loc) • 6.15 kB
JavaScript
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const P=require("axios"),m=require("ol/Feature"),M=require("ol/geom/LineString"),C=require("ol/geom/Point"),F=require("ol/geom/Polygon"),y=require("ol/layer/Vector"),w=require("ol/source/Vector"),q=require("ol/style/Circle"),L=require("ol/style/Fill"),x=require("ol/style/Icon"),S=require("ol/style/Stroke"),u=require("ol/style/Style"),d=require("./sumo-utils.js");class v{constructor(t){this.arrowCanvasCache=new Map,this.nodeStyleCache=new Map,this.trafficLightStyleCache=new Map,this.stopLineStyleCache=new Map,this.map=t,this.trafficLightImage=d.default.createTrafficLightImage(),this.setupLayers()}setupLayers(){this.nodePolygonSource=new w,this.nodePolygonLayer=new y({source:this.nodePolygonSource}),this.nodePolygonLayer.set("id","sumo-node-polygon-layer"),this.nodePolygonLayer.setStyle(new u({fill:new L({color:"#8B0000"})})),this.map.addLayer(this.nodePolygonLayer),this.polygonLaneSource=new w;const t=new y({source:this.polygonLaneSource});t.set("id","sumo-polygon-lane-layer");const o=new u({fill:new L({color:"#1a1a1a"})}),r=new u({fill:new L({color:"#1a1a1a"}),stroke:new S({color:"#ffffff",width:1,lineDash:[5,3]})});t.setStyle(()=>(this.map.getView().getZoom()??0)<=16?o:r),this.map.addLayer(t),this.connectorLaneSource=new w;const e=new y({source:this.connectorLaneSource,style:[new u({stroke:new S({color:[255,255,255,.6],width:4,lineCap:"round",lineJoin:"round"})}),new u({stroke:new S({color:"#666666",width:2,lineCap:"round",lineJoin:"round"})})]});e.set("id","sumo-connector-lane-layer"),this.map.addLayer(e),this.stopLineSource=new w;const c=new y({source:this.stopLineSource});c.setStyle(s=>{const l=s.get("color")||"#52C41A";let n=this.stopLineStyleCache.get(l);return n||(n=new u({stroke:new S({color:l,width:4,lineCap:"butt",lineJoin:"round"})}),this.stopLineStyleCache.set(l,n)),n}),c.set("id","sumo-stop-line-layer"),this.map.addLayer(c),this.laneArrowSource=new w;const a=new y({source:this.laneArrowSource});a.set("id","sumo-lane-arrow-layer"),a.setStyle(s=>{if((this.map.getView().getZoom()??0)<=17)return;const l=s.get("arrowType"),n=s.get("angle");return new u({image:new x({img:this.getArrowCanvas(l),scale:this.getArrowScale(),rotation:n*Math.PI/180,anchor:[.5,.5]})})}),this.map.addLayer(a),this.nodePointSource=new w,this.nodePointLayer=new y({source:this.nodePointSource}),this.nodePointLayer.set("id","sumo-node-point-layer"),this.nodePointLayer.setStyle(s=>this.getNodeStyle(s)),this.map.addLayer(this.nodePointLayer)}getNodeStyle(t){const o=this.getNodeScale(),r=t.get("type");if((this.map.getView().getZoom()??0)<=15&&r==="traffic_light")return;const e=Math.round(o*100)/100,c=r==="traffic_light"?this.trafficLightStyleCache:this.nodeStyleCache;let a=c.get(e);return a||(a=r==="traffic_light"?new u({image:new x({img:this.trafficLightImage,scale:e})}):new u({image:new q({radius:6,scale:e,fill:new L({color:"#FF6B6B"}),stroke:new S({color:"#ffffff",width:1.5})})}),c.set(e,a)),a}async showSumoFromFile(t){var h,f,p;let o;try{const i=await P.get(t.file,{responseType:"blob"}),g=new URL(t.file).pathname.split("/").pop()||"sumo";o=new File([i.data],g,{type:i.data.type})}catch(i){return console.error("下载 SUMO 文件失败:",t.file,i),{status:-1,message:`下载 SUMO 文件失败:${(i==null?void 0:i.message)||"未知错误"}`}}const r=new FormData;r.append("file",o);let e;try{e=await P.post(t.server,r)}catch(i){return console.error("解析 SUMO 文件失败:",t.server,i),{status:-1,message:`解析 SUMO 文件失败:${(i==null?void 0:i.message)||"未知错误"}`}}if(e.status!==200)return{status:-1,message:e.statusText||"error"};this.nodePolygonLayer.setVisible(((h=t.options)==null?void 0:h.showJunctionPolygon)!==!1),this.nodePointLayer.setVisible(((f=t.options)==null?void 0:f.showJunctionPoint)!==!1);const{nodes:c,edges:a,connections:s,trafficLights:l}=e.data;console.log(l),this.showNodes(c);const n=this.showEdges(a,s);if(((p=t.options)==null?void 0:p.needZoom)!==!1){const i=d.default.getFeaturesExtent(n);i&&this.map.getView().fit(i,{padding:[10,10,10,10]})}return{status:0,message:"success"}}showNodes(t){this.nodePointSource.clear(),this.nodePolygonSource.clear();const o=[],r=[];for(const e of t)o.push(new m({geometry:new C([e.x,e.y]),...e})),!(e.type==="internal"||!e.shape||e.shape.length<3)&&r.push(new m({geometry:new F([[...e.shape,e.shape[0]]]),...e}));this.nodePointSource.addFeatures(o),this.nodePolygonSource.addFeatures(r)}showEdges(t,o){const r=[],e=[],c=[],a=new Map;for(const s of o){if(s.fromLane===void 0)continue;const l=`${s.from}_${s.fromLane}`,n=a.get(l)??[];if(s.dir){const h=s.dir.toUpperCase();n.includes(h)||n.push(h)}a.set(l,n)}for(const s of t){if(!s.lanes||s.lanes.length===0)continue;const l=s.isInternal??!1;for(const n of s.lanes)if(!(!n.shape||n.shape.length<2))if(l){const h=`${s.id}_${n.index}`,i=!(a.get(h)??[]).some(g=>g!=="S")?n.shape:d.default.smoothShape(n.shape);r.push(new m({geometry:new M(i),id:s.id,laneIndex:n.index}))}else{const h=d.default.laneToPolygon(n.shape,n.width);h.length>0&&e.push(new m({geometry:new F([h]),id:s.id,laneIndex:n.index}));const{point:f,angle:p}=d.default.getLaneArrowPosition(n.shape),i=`${s.id}_${n.index}`,g=a.get(i)??[];if(g.length>0){const A=d.default.determineArrowType(g);c.push(new m({geometry:new C(f),id:i,angle:p,arrowType:A}))}}}return this.connectorLaneSource.addFeatures(r),this.polygonLaneSource.addFeatures(e),this.laneArrowSource.addFeatures(c),[...r,...e]}showStopLines(t,o){}getArrowScale(){const t=this.map.getView().getZoom()??14,o=18,r=21,e=.035,c=.6;if(t<=o)return e;if(t>=r)return c;const a=(t-o)/(r-o);return e+a*(c-e)}getNodeScale(){const t=this.map.getView().getZoom()??14,o=18,r=21,e=.6,c=1.2;if(t<=o)return e;if(t>=r)return c;const a=(t-o)/(r-o);return e+a*(c-e)}getArrowCanvas(t){let o=this.arrowCanvasCache.get(t);return o||(o=d.default.createArrowIcon(t,64),this.arrowCanvasCache.set(t,o)),o}clearSumo(){this.nodePointSource.clear(),this.nodePolygonSource.clear(),this.connectorLaneSource.clear(),this.polygonLaneSource.clear(),this.laneArrowSource.clear()}}exports.default=v;