gisviewer-vue3-arcgis
Version:
在应用中引入私服的包, 项目根目录下 新建文件 .npmrc 在 .npmrc 中对包源进行配置:
2 lines (1 loc) • 6.79 kB
JavaScript
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const E=require("ol/Feature"),F=require("ol/geom/Point"),Y=require("ol/layer/Vector"),K=require("ol/Observable"),U=require("ol/source/Vector"),q=require("ol/style/Circle"),f=require("ol/style/Fill"),V=require("ol/style/Icon"),C=require("ol/style/Stroke"),g=require("ol/style/Style"),Z=require("ol/style/Text"),X=require("../cluster/pixel-cluster-calculator.js");class G{constructor(e){this.showName="detail",this.showStyle="scatter",this.viewChangeKey=null,this.mapMoveKey=null,this.resolutionChangeTimeout=null,this.locations=[],this.allLocations=[],this.changeStyle=!0,this.map=e,this.view=e.getView(),this.clusterCalculator=new X.PixelClusterCalculator(e),this.source=new U,this.crossLayer=new Y({source:this.source}),this.crossLayer.set("id","signal-control-cross-layer"),this.map.addLayer(this.crossLayer),this.configureVectorLayerStyle()}showSignalCross(e){if(this.changeStyle=e.changeStyle??!0,this.crossLayer.setVisible(!0),this.source.clear(),this.showName=e.showName||"detail",this.showStyle=e.style||"scatter",this.viewChangeKey||(this.viewChangeKey=this.view.on("change:resolution",()=>{this.showStyle==="cluster"&&(this.resolutionChangeTimeout&&clearTimeout(this.resolutionChangeTimeout),this.resolutionChangeTimeout=setTimeout(()=>{this.calculateCluster(),this.resolutionChangeTimeout=null},150))})),this.mapMoveKey||(this.mapMoveKey=this.map.on("moveend",()=>{this.showStyle==="cluster"&&this.calculateCluster()})),this.showStyle==="scatter"){const t=[],o=[];e.points.forEach(a=>{const r=this.createCrossFeature(a);a.isMalfunction===!0||a.isOnline===!1?o.push(r):t.push(r)}),this.source.addFeatures(t),this.source.addFeatures(o),this.crossLayer.changed()}else this.locations=e.points.map(t=>({id:t.crossId,x:t.x,y:t.y,visited:!1,clusterId:void 0,properties:t})),this.allLocations=[...this.locations],this.calculateCluster();return{status:0,message:"success"}}calculateCluster(){const e=this.clusterCalculator.calculate(this.locations),t=this.clusterCalculator.calculateSymbolSizes(e);this.showClusterResult(t)}clearSignalCross(){this.source.clear(),this.viewChangeKey&&(K.unByKey(this.viewChangeKey),this.viewChangeKey=null),this.mapMoveKey&&(K.unByKey(this.mapMoveKey),this.mapMoveKey=null),this.resolutionChangeTimeout&&(clearTimeout(this.resolutionChangeTimeout),this.resolutionChangeTimeout=null)}changeShowName(e){this.showName=e,this.showStyle==="scatter"&&this.updateScatterSymbol()}setVisible(e){this.crossLayer.setVisible(e)}updateScatterSymbol(){this.crossLayer.changed()}configureVectorLayerStyle(){const s=this.map.getView(),h=s.getResolutionForZoom(14),u=s.getResolutionForZoom(17),d=s.getResolutionForZoom(17),z=(n,i,l)=>n===void 0&&i===void 0&&l===void 0?"/GisViewerAssets/Images/cross/gis_xhj_blue.png":`/GisViewerAssets/Images/cross/ic_${(n??"gc").toLowerCase()==="scats"?"scats":"gc"}_${i===!1?"offline":"online"}_${l?"malfunction":"normal"}.png`,M=new Map,O=new Map,x=new WeakMap,b={online:"#22c55e",offline:"#9ca3af"},p=new C({color:"#ffffff",width:1.5}),I=new Map,k=n=>{const i=n===!1?"offline":"online",l=I.get(i);if(l)return l;const c=[new g({image:new q({radius:3,fill:new f({color:b[i]}),stroke:p}),zIndex:1})];return I.set(i,c),c},L=new Map,m=n=>{const i=n===!1?"offline":"online",l=L.get(i);if(l)return l;const c=[new g({image:new q({radius:5,fill:new f({color:b[i]}),stroke:p}),zIndex:1})];return L.set(i,c),c},A=new f({color:"#1f2937"}),B=new C({color:"#ffffff",width:3}),_=n=>{const i=M.get(n);if(i)return i;const l=new g({image:new V({src:n,scale:.5,anchor:[.5,1],anchorXUnits:"fraction",anchorYUnits:"fraction"}),zIndex:1});return M.set(n,l),l},R=n=>{const i=O.get(n);if(i)return i;const l=[_(n)];return O.set(n,l),l};this.crossLayer.setStyle((n,i)=>{if((n.get("type")??"")==="signal-cluster")return this.getClusterStyle(n.getProperties());const c=this.showName==="crossName"?n.get("name"):this.showName==="signalId"?n.get("signalId"):`${n.get("name")}(${n.get("signalId")})`,T=n.get("brand"),y=n.get("isOnline"),v=n.get("isMalfunction"),w=z(T,y,v);if(i>h)return k(y);if(i>u)return m(y);if(i>d)return this.changeStyle?R(w):m(y);const S=x.get(n);if(S&&S.label===c&&S.iconKey===w)return S.styles;const P=this.changeStyle?_(w):m(y)[0],D=new g({text:new Z({text:c,font:'12px "Microsoft YaHei"',textAlign:"center",textBaseline:"bottom",offsetY:this.changeStyle?-28:-8,fill:A,stroke:B}),zIndex:2}),N=[P,D];return x.set(n,{label:c,iconKey:w,styles:N}),N})}createCrossFeature(e){var o;return e.brand=(o=e.brand)==null?void 0:o.toLowerCase(),new E({geometry:new F([e.x,e.y]),type:"signal-cross",id:e.crossId,brandLabel:this.getBrandLabel(e.brand),isOnlineLabel:this.getOnlineLabel(e.isOnline),isMalfunctionLabel:this.getMalfunctionLabel(e.isMalfunction),...e})}getClusterStyle(e){const t=e.clusterSymbolSize,o=new V({src:"/GisViewerAssets/Images/cross/gis_xhj_blue.png",scale:t/32}),a=-(t+10),r=new Z({text:String(e.count??0),font:"16px Arial Unicode MS",fill:new f({color:[255,255,255,255]}),backgroundFill:new f({color:[2,72,200,1]}),backgroundStroke:new C({color:[2,72,200,.5],width:2}),padding:[1,2,1,2],offsetY:a,textAlign:"center",justify:"center",textBaseline:"middle"});return[new g({image:o}),new g({text:r})]}getBrandLabel(e){const t=(e??"").toLowerCase();return t==="scats"?"SCATS":t==="gc"?"国产":e??""}getOnlineLabel(e){return e?"在线":"离线"}getMalfunctionLabel(e){return e?"故障":"正常"}showClusterResult(e){this.source.clear(),e.forEach(t=>{if(t.id!==-1&&t.center&&t.symbolSize){const o=new E({geometry:new F([t.center.x,t.center.y]),type:"signal-cluster",count:t.count,clusterSymbolSize:t.symbolSize});this.source.addFeature(o)}else t.items.forEach(o=>{const a=this.createCrossFeature({...o.properties,x:o.x,y:o.y});this.source.addFeature(a)})}),this.crossLayer.changed()}highlight(e,t){var a;if(this.showStyle==="cluster"){const r=this.allLocations.filter(s=>s.properties[e]===t);if(r.length>0){this.locations=r,this.calculateCluster();const s=[1/0,1/0,-1/0,-1/0];return r.forEach(h=>{s[0]=Math.min(s[0],h.x),s[1]=Math.min(s[1],h.y),s[2]=Math.max(s[2],h.x),s[3]=Math.max(s[3],h.y)}),s}return null}const o=[];if(this.source.getFeatures().forEach(r=>{r.get(e)===t?(r.setStyle(void 0),o.push(r)):r.setStyle(new g({}))}),o.length>0){const r=(a=o[0].getGeometry())==null?void 0:a.getExtent();if(r){const s=[...r];return o.slice(1).forEach(h=>{var d;const u=(d=h.getGeometry())==null?void 0:d.getExtent();u&&(s[0]=Math.min(s[0],u[0]),s[1]=Math.min(s[1],u[1]),s[2]=Math.max(s[2],u[2]),s[3]=Math.max(s[3],u[3]))}),s}}return null}clearHighlight(){if(this.showStyle==="cluster"){this.locations=[...this.allLocations],this.calculateCluster();return}this.source.getFeatures().forEach(e=>{e.setStyle(void 0)})}}exports.default=G;