UNPKG

gisviewer-vue3-arcgis

Version:

在应用中引入私服的包, 项目根目录下 新建文件 .npmrc 在 .npmrc 中对包源进行配置:

2 lines (1 loc) 7.33 kB
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const O=require("@turf/turf"),j=require("axios"),L=require("ol/Feature"),B=require("ol/format/GeoJSON"),M=require("ol/geom/LineString"),x=require("ol/geom/Polygon"),F=require("ol/layer/Vector"),q=require("ol/source/Vector"),P=require("ol/style/Fill"),D=require("ol/style/Stroke"),N=require("ol/style/Style"),V=require("ol/style/Text"),E=require("pako"),k=require("../../../gis-map/utils/common-utils.js");function G(p){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(p){for(const o in p)if(o!=="default"){const a=Object.getOwnPropertyDescriptor(p,o);Object.defineProperty(e,o,a.get?a:{enumerable:!0,get:()=>p[o]})}}return e.default=p,Object.freeze(e)}const $=G(O);class T{constructor(e){this.hiddenRoadNameStyle=new N({}),this.handleMapMoveEnd=()=>{this.updateRoadNameVisibility()},this.map=e,this.openDriveSource=new q,this.openDriveLayer=new F({source:this.openDriveSource,declutter:!0}),this.openDriveLayer.set("id","open-drive-layer"),this.map.addLayer(this.openDriveLayer),this.mergedLaneSource=new q,this.mergedLaneLayer=new F({source:this.mergedLaneSource}),this.mergedLaneLayer.set("id","open-drive-merged-lane-layer"),this.map.addLayer(this.mergedLaneLayer),this.map.on("moveend",this.handleMapMoveEnd)}async showOpenDriveFromFile(e){let o=e.file.split("/").pop()||"";o=o.split(".").slice(0,-1).join("."),this.openDriveServer=e.server;const a=`http://${this.openDriveServer}/api/openDrive/uploadXodr`;let c;try{c=await j.post(a,{},{params:{url:e.file,projectName:o}})}catch(i){return{status:-1,message:i.message}}if(c.status!==200)return{status:-1,message:c.statusText};const n=c.data.result.geoSetting;k.default.setGeoData(n.geoReference,n.offsetX,n.offsetY);let r=c.data.result.json;r.startsWith(window.location.protocol)||(r=`${window.location.protocol}//${e.server}${r}`);const t=await fetch(r);let l;if(r.endsWith("bin")){const i=await t.arrayBuffer(),d=E.inflate(i,{to:"string"});l=JSON.parse(d)}else l=await t.json();return this.showAllRoadsects(l),{status:0,message:"ok"}}clearOpenDrive(){var e,o;(e=this.openDriveLayer.getSource())==null||e.clear(),(o=this.mergedLaneLayer.getSource())==null||o.clear()}selectComputable(e){let o=[];if(e.type==="roadsectBase")o=this.openDriveSource.getFeatures().filter(t=>{var l;return(l=t.get("roadsectBaseIds"))==null?void 0:l.split(",").includes(e.id)});else if(e.type==="roadsect")o=this.openDriveSource.getFeatures().filter(t=>t.get("roadId")===e.id);else if(e.type==="lane"){const[t,l]=e.id.split("_");console.log("roadsectId, laneIndex",t,l),o=this.openDriveSource.getFeatures().filter(i=>{var d;return(d=i.get("roadsectBaseIds"))==null?void 0:d.split(",").includes(t)}),o.sort((i,d)=>{const h=i.get("laneId");return d.get("laneId")-h}),o=[o[Number(l)]]}if(o.length===0){this.mergedLaneSource.clear();return}const a=new B,c=o.map(t=>t.getGeometry()).filter(t=>{const l=t==null?void 0:t.getType();return l==="Polygon"||l==="MultiPolygon"}).map(t=>a.writeGeometryObject(t));if(c.length===0){this.mergedLaneSource.clear();return}let n=c[0];for(let t=1;t<c.length;t++){const l=$.union(n,c[t]);l&&(n=l.geometry)}const r=new L({geometry:a.readGeometry(n),roadsectBaseIds:o[0].get("roadsectBaseIds")});r.setStyle(new N({fill:new P({color:"rgba(0, 255, 255, 0.35)"}),stroke:new D({color:"rgba(0, 255, 255, 0.9)",width:2})})),this.mergedLaneSource.clear(),this.mergedLaneSource.addFeature(r),this.map.getView().fit(r.getGeometry().getExtent(),{padding:[50,50,50,50],maxZoom:18})}unSelectComputable(e){this.mergedLaneSource.clear()}destroy(){this.map.un("moveend",this.handleMapMoveEnd),this.clearOpenDrive(),this.map.removeLayer(this.openDriveLayer),this.openDriveLayer.dispose(),this.map.removeLayer(this.mergedLaneLayer),this.mergedLaneLayer.dispose()}showAllRoadsects(e){const o=[];for(const a of e){const c=this.buildRoadsectPolygon(a);c&&o.push(c)}o.length!==0&&(this.openDriveSource.addFeatures(o),this.map.getView().fit(this.openDriveSource.getExtent(),{padding:[50,50,50,50],maxZoom:18}))}showAllLanes(e,o){var n;const a=[],c=new N({fill:new P({color:"rgba(47, 79, 79, 0.8)"}),stroke:new D({color:"rgba(255, 255, 255, 0.8)",width:1})});for(const r of e){const t=r.id,l=r.junction;let i=r.name;if(o.showRoadName){const d=r.refLine;if(l==="-1"&&!i.includes("匝道")&&!i.includes("辅路")){i.includes("(")&&(i=i.slice(0,i.indexOf("("))),i=i.replace(/(.)/g,"$1 ");const h=new M(d),s=new L({geometry:h,roadId:t,roadName:i,isRoadNameLabel:!0}),u=new N({text:new V({text:i,placement:"line",font:"12px sans-serif",fill:new P({color:"#333"}),stroke:new D({color:"#fff",width:3}),overflow:!0,repeat:500})});s.set("roadNameStyle",u),s.setStyle(u),a.push(s)}}r.laneSections.sort((d,h)=>Number(d.id)-Number(h.id));for(let d=0;d<r.laneSections.length;d++){const h=r.laneSections[d],s=Number(h.id);for(const u of h.lanePaths){const S=Number(u.id);if(S===0)continue;const v=u.type,y=[...u.outerPath],f=u.innerPath.concat(y.reverse());f.push(u.innerPath[0]);const b=new L({geometry:new x([f]),id:`${t}+${s}+${S}`,fromNode:r.fromNode,toNode:r.toNode,roadId:String(t),roadName:r.name,sectionId:String(s),sectionIndex:d,laneId:S,type:v,roadsectBaseIds:(n=h.roadsectBaseIds)==null?void 0:n.toString()});b.setStyle(c),a.push(b)}}}this.openDriveSource.addFeatures(a),this.map.getView().fit(this.openDriveSource.getExtent(),{padding:[50,50,50,50],maxZoom:18}),this.updateRoadNameVisibility()}buildRoadsectPolygon(e){var d,h;const o=new N({fill:new P({color:"rgba(255, 165, 0, 0.25)"}),stroke:new D({color:"rgba(255, 140, 0, 0.9)",width:2})});e.laneSections.sort((s,u)=>Number(s.id)-Number(u.id));const a=[],c=[];for(let s=0;s<e.laneSections.length;s++){const S=(e.laneSections[s].lanePaths||[]).filter(g=>Number(g.id)!==0);if(S.length===0)continue;const v=[...S].sort((g,m)=>{const w=Math.abs(Number(g.id)),R=Math.abs(Number(m.id));return w!==R?w-R:Number(g.id)-Number(m.id)}),y=v[0],f=v[v.length-1];if(!((d=y==null?void 0:y.innerPath)!=null&&d.length)||!((h=f==null?void 0:f.outerPath)!=null&&h.length))continue;const b=[...y.innerPath],I=[...f.outerPath];for(const g of b){const m=a[a.length-1];(!m||m[0]!==g[0]||m[1]!==g[1])&&a.push(g)}for(let g=I.length-1;g>=0;g--){const m=I[g],w=c[c.length-1];(!w||w[0]!==m[0]||w[1]!==m[1])&&c.push(m)}}const n=a.concat(c);if(n.length<3)return;const r=n[0],t=n[n.length-1];r&&t&&(r[0]!==t[0]||r[1]!==t[1])&&n.push([...r]);const l=e.laneSections.map(s=>s.roadsectBaseIds).filter(s=>s!=null).flatMap(s=>s.toString().split(",")).filter(s=>s!=="").join(","),i=new L({geometry:new x([n]),roadId:String(e.id),roadName:e.name,roadsectBaseIds:l});return i.setStyle(o),i}updateRoadNameVisibility(){const e=this.map.getSize();if(!e)return;const o=this.map.getView().calculateExtent(e),a=this.map.getView().getCenter();if(!a)return;const c=new Map;for(const n of this.openDriveSource.getFeatures()){if(!n.get("isRoadNameLabel"))continue;const r=n.getGeometry(),t=n.get("roadName"),l=n.get("roadNameStyle");if(!r||!t||!r.intersectsExtent(o)){n.setStyle(this.hiddenRoadNameStyle);continue}const i=r.getClosestPoint(a),d=i[0]-a[0],h=i[1]-a[1],s=d*d+h*h,u=c.get(t);!u||s<u.distanceSq?(u&&u.feature.setStyle(this.hiddenRoadNameStyle),c.set(t,{feature:n,distanceSq:s}),n.setStyle(l)):n.setStyle(this.hiddenRoadNameStyle)}}}exports.default=T;