UNPKG

gisviewer-vue3-arcgis

Version:

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

2 lines (1 loc) 2.67 kB
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const m=require("@turf/turf"),g=require("ol/Feature"),p=require("ol/geom"),y=require("ol/layer/Vector"),S=require("ol/Observable"),w=require("ol/source/Vector"),L=require("ol/style/Stroke"),b=require("ol/style/Style");function F(o){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(o){for(const e in o)if(e!=="default"){const t=Object.getOwnPropertyDescriptor(o,e);Object.defineProperty(r,e,t.get?t:{enumerable:!0,get:()=>o[e]})}}return r.default=o,Object.freeze(r)}const u=F(m),P=(o,r)=>{try{const e=u.lineString(o);return u.lineOffset(e,r,{units:"meters"}).geometry.coordinates}catch{return o}},_=o=>o<5?"#f50b00":o<10?"#f7a030":o<20?"#f2df1a":"#46a914";class q{constructor(r){this.lastParams=null,this.resolutionListenerKey=null,this.hasGpu=!0;const e=localStorage.getItem("gpu");this.hasGpu=e!=="Unknown",this.map=r,this.roadSource=new w,this.roadLayer=new y({source:this.roadSource}),this.map.addLayer(this.roadLayer)}_normalizeParams(r){const e=r.roadSegmentList.reduce((t,n)=>{let s=n.shape;if(!s)return t;if(typeof s=="string")try{s=JSON.parse(s)}catch{return t}if(!Array.isArray(s)||s.length<2)return t;const l=s.filter(a=>Array.isArray(a)&&a.length>=2&&Number.isFinite(a[0])&&Number.isFinite(a[1]));return l.length<2||t.push({...n,shape:l}),t},[]);return{...r,roadSegmentList:e}}showRoadFlow(r){var t;const e=this._normalizeParams(r);if(this.lastParams=e,this.resolutionListenerKey||(this.resolutionListenerKey=this.map.getView().on("change:resolution",()=>{this.lastParams&&(this.roadSource.clear(),this._renderSegments(this.lastParams))})),this.roadSource.clear(),this._renderSegments(e),(t=e.options)!=null&&t.needZoom){const n=e.roadSegmentList.flatMap(s=>s.shape);if(n.length>=2){const s=u.bbox(u.lineString(n));this.map.getView().fit(s,{padding:[10,10,10,10],duration:this.hasGpu?500:0})}}}_renderSegments(r){const e=r.roadSegmentList;if(!e.length)return;const t=e.map(i=>i.flow),n=Math.min(...t),l=Math.max(...t)-n||1,a=this.map.getView().getResolution()??1;for(const i of e){const c=2+(i.flow-n)/l*8,d=c*a*3,f=P(i.shape,d),h=new g({geometry:new p.LineString(f),roadId:i.roadId,flow:i.flow,avgSpeed:i.avgSpeed,type:"roadFlowSegment"});h.setStyle(new b({stroke:new L({color:_(i.avgSpeed),width:c,lineCap:"square"})})),this.roadSource.addFeature(h)}}clearRoadFlow(){this.lastParams=null,this.resolutionListenerKey&&(S.unByKey(this.resolutionListenerKey),this.resolutionListenerKey=null),this.roadSource.clear()}destroy(){this.clearRoadFlow(),this.map.removeLayer(this.roadLayer),this.roadLayer.dispose()}}exports.default=q;