UNPKG

gisviewer-vue3-arcgis

Version:

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

44 lines (35 loc) 8.78 kB
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const E=require("@arcgis/core/layers/GraphicsLayer"),R=require("@arcgis/core/views/2d/layers/BaseLayerViewGL2D"),o=require("gl-matrix"),T=require("@arcgis/core/core/reactiveUtils");function U(t){const a=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const s in t)if(s!=="default"){const l=Object.getOwnPropertyDescriptor(t,s);Object.defineProperty(a,s,l.get?l:{enumerable:!0,get:()=>t[s]})}}return a.default=t,Object.freeze(a)}const B=U(T),V=R.createSubclass({aPosition:0,aOffset:1,aDistance:2,aSide:3,aColor:4,constructor:function(){this.transform=o.mat3.create(),this.extrude=o.mat3.create(),this.translationToCenter=o.vec2.create(),this.screenTranslation=o.vec2.create(),this.display=o.mat3.fromValues(NaN,0,0,0,NaN,0,-1,1,1),this.screenScaling=o.vec3.fromValues(NaN,NaN,1),this.needsUpdate=!1},attach:function(){const t=this.context,a=()=>{this.needsUpdate=!0,this.requestRender()};this.watcher=B.on(()=>this.layer.graphics,"change",a);const s=` precision highp float; uniform mat3 u_transform; uniform mat3 u_extrude; uniform mat3 u_display; attribute vec2 a_position; attribute vec2 a_offset; attribute float a_distance; attribute float a_side; attribute vec4 a_color; varying float v_distance; varying float v_side; varying vec4 v_color; void main(void) { gl_Position.xy = (u_display * (u_transform * vec3(a_position, 1.0) + u_extrude * vec3(a_offset, 0.0))).xy; gl_Position.zw = vec2(0.0, 1.0); v_distance = a_distance; v_side = a_side; v_color = a_color; }`,l=` precision highp float; uniform float u_current_time; varying float v_distance; varying float v_side; varying vec4 v_color; const float TRAIL_SPEED = 90.0; const float TRAIL_LENGTH = 300.0; const float TRAIL_CYCLE = 500.0; void main(void) { float d = mod(v_distance - u_current_time * TRAIL_SPEED, TRAIL_CYCLE); float a1 = d < TRAIL_LENGTH ? mix(0.0, 1.0, d / TRAIL_LENGTH) : 0.0; float a2 = exp(-abs(v_side) * 3.0); float a = a1 * a2; gl_FragColor = v_color * a; }`,u=t.createShader(t.VERTEX_SHADER);t.shaderSource(u,s),t.compileShader(u);const m=t.createShader(t.FRAGMENT_SHADER);if(t.shaderSource(m,l),t.compileShader(m),this.program=t.createProgram(),t.attachShader(this.program,u),t.attachShader(this.program,m),t.bindAttribLocation(this.program,this.aPosition,"a_position"),t.bindAttribLocation(this.program,this.aOffset,"a_offset"),t.bindAttribLocation(this.program,this.aDistance,"a_distance"),t.bindAttribLocation(this.program,this.aSide,"a_side"),t.bindAttribLocation(this.program,this.aColor,"a_color"),t.linkProgram(this.program),t.deleteShader(u),t.deleteShader(m),this.uTransform=t.getUniformLocation(this.program,"u_transform"),this.uExtrude=t.getUniformLocation(this.program,"u_extrude"),this.uDisplay=t.getUniformLocation(this.program,"u_display"),this.uCurrentTime=t.getUniformLocation(this.program,"u_current_time"),this.vertexBuffer=t.createBuffer(),this.indexBuffer=t.createBuffer(),this.indexBufferSize=0,t.getParameter(t.VERSION).startsWith("WebGL 2.0"))this.vao=t.createVertexArray(),this.bindVertexArray=d=>t.bindVertexArray(d),this.deleteVertexArray=d=>t.deleteVertexArray(d);else{const d=t.getExtension("OES_vertex_array_object");this.vao=d.createVertexArrayOES(),this.bindVertexArray=A=>d.bindVertexArrayOES(A),this.deleteVertexArray=A=>d.deleteVertexArrayOES(A)}this.bindVertexArray(this.vao),t.bindBuffer(t.ARRAY_BUFFER,this.vertexBuffer),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,this.indexBuffer),t.enableVertexAttribArray(this.aPosition),t.enableVertexAttribArray(this.aOffset),t.enableVertexAttribArray(this.aDistance),t.enableVertexAttribArray(this.aSide),t.enableVertexAttribArray(this.aColor),t.vertexAttribPointer(this.aPosition,2,t.FLOAT,!1,28,0),t.vertexAttribPointer(this.aOffset,2,t.FLOAT,!1,28,8),t.vertexAttribPointer(this.aDistance,1,t.FLOAT,!1,28,16),t.vertexAttribPointer(this.aSide,1,t.FLOAT,!1,28,20),t.vertexAttribPointer(this.aColor,4,t.UNSIGNED_BYTE,!0,28,24),this.bindVertexArray(null),this.centerAtLastUpdate=o.vec2.fromValues(this.view.state.center[0],this.view.state.center[1])},detach:function(){this.watcher.remove();const t=this.context;t.deleteBuffer(this.vertexBuffer),t.deleteBuffer(this.indexBuffer),this.deleteVertexArray(this.vao),t.deleteProgram(this.program)},render:function(t){const a=t.context,s=t.state;if(this.updatePositions(t),this.indexBufferSize===0)return;o.mat3.identity(this.transform),this.screenTranslation[0]=s.pixelRatio*s.size[0]/2,this.screenTranslation[1]=s.pixelRatio*s.size[1]/2,o.mat3.translate(this.transform,this.transform,this.screenTranslation),o.mat3.rotate(this.transform,this.transform,Math.PI*s.rotation/180),this.screenScaling[0]=s.pixelRatio/s.resolution,this.screenScaling[1]=-s.pixelRatio/s.resolution,o.mat3.scale(this.transform,this.transform,this.screenScaling),o.mat3.translate(this.transform,this.transform,this.translationToCenter),o.mat3.identity(this.extrude),o.mat3.rotate(this.extrude,this.extrude,Math.PI*s.rotation/180);const l=8;o.mat3.scale(this.extrude,this.extrude,[l,-l,1]),this.display[0]=2/(s.pixelRatio*s.size[0]),this.display[4]=-2/(s.pixelRatio*s.size[1]),a.useProgram(this.program),a.uniformMatrix3fv(this.uTransform,!1,this.transform),a.uniformMatrix3fv(this.uExtrude,!1,this.extrude),a.uniformMatrix3fv(this.uDisplay,!1,this.display),a.uniform1f(this.uCurrentTime,performance.now()/1e3),this.bindVertexArray(this.vao),a.enable(a.BLEND),a.blendFunc(a.ONE,a.ONE_MINUS_SRC_ALPHA),a.drawElements(a.TRIANGLES,this.indexBufferSize,a.UNSIGNED_SHORT,0),this.requestRender()},updatePositions:function(t){const a=t.context,s=t.stationary,l=t.state;if(!s){o.vec2.sub(this.translationToCenter,this.centerAtLastUpdate,l.center),this.requestRender();return}if(!this.needsUpdate&&this.translationToCenter[0]===0&&this.translationToCenter[1]===0)return;this.centerAtLastUpdate.set(l.center),this.translationToCenter[0]=0,this.translationToCenter[1]=0,this.needsUpdate=!1;const u=this.layer.graphics;let m=0,d=0;for(let p=0;p<u.items.length;++p){const _=u.items[p].geometry.paths[0];m+=_.length*2,d+=(_.length-1)*6}const A=new ArrayBuffer(7*m*4),i=new Float32Array(A),n=new Uint8Array(A),c=new Uint16Array(d);let r=0,f=0;for(let p=0;p<u.items.length;++p){const v=u.items[p],_=v.geometry.paths[0],h=v.attributes.color,e={};for(let g=0;g<_.length;++g){const b=_[g];if(e.current){e.delta=[b[0]-e.current[0],b[1]-e.current[1]];const y=Math.sqrt(e.delta[0]*e.delta[0]+e.delta[1]*e.delta[1]);e.direction=[e.delta[0]/y,e.delta[1]/y];const x=[-e.direction[1],e.direction[0]];if(e.normal){e.offset=[e.normal[0]+x[0],e.normal[1]+x[1]];const L=Math.sqrt(e.offset[0]*e.offset[0]+e.offset[1]*e.offset[1]);e.offset[0]/=L,e.offset[1]/=L;const S=e.normal[0]*e.offset[0]+e.normal[1]*e.offset[1];e.offset[0]/=S,e.offset[1]/=S}else e.offset=[x[0],x[1]];i[r*7+0]=e.current[0]-this.centerAtLastUpdate[0],i[r*7+1]=e.current[1]-this.centerAtLastUpdate[1],i[r*7+2]=e.offset[0],i[r*7+3]=e.offset[1],i[r*7+4]=e.distance,i[r*7+5]=1,n[4*(r*7+6)+0]=h[0],n[4*(r*7+6)+1]=h[1],n[4*(r*7+6)+2]=h[2],n[4*(r*7+6)+3]=255,i[r*7+7]=e.current[0]-this.centerAtLastUpdate[0],i[r*7+8]=e.current[1]-this.centerAtLastUpdate[1],i[r*7+9]=-e.offset[0],i[r*7+10]=-e.offset[1],i[r*7+11]=e.distance,i[r*7+12]=-1,n[4*(r*7+13)+0]=h[0],n[4*(r*7+13)+1]=h[1],n[4*(r*7+13)+2]=h[2],n[4*(r*7+13)+3]=255,r+=2,g>=2&&(c[f+0]=r-4,c[f+1]=r-3,c[f+2]=r-2,c[f+3]=r-3,c[f+4]=r-1,c[f+5]=r-2,f+=6),e.normal=x,e.distance+=y}else e.distance=0;e.current=b}e.offset=[e.normal[0],e.normal[1]],i[r*7+0]=e.current[0]-this.centerAtLastUpdate[0],i[r*7+1]=e.current[1]-this.centerAtLastUpdate[1],i[r*7+2]=e.offset[0],i[r*7+3]=e.offset[1],i[r*7+4]=e.distance,i[r*7+5]=1,n[4*(r*7+6)+0]=h[0],n[4*(r*7+6)+1]=h[1],n[4*(r*7+6)+2]=h[2],n[4*(r*7+6)+3]=255,i[r*7+7]=e.current[0]-this.centerAtLastUpdate[0],i[r*7+8]=e.current[1]-this.centerAtLastUpdate[1],i[r*7+9]=-e.offset[0],i[r*7+10]=-e.offset[1],i[r*7+11]=e.distance,i[r*7+12]=-1,n[4*(r*7+13)+0]=h[0],n[4*(r*7+13)+1]=h[1],n[4*(r*7+13)+2]=h[2],n[4*(r*7+13)+3]=255,r+=2,c[f+0]=r-4,c[f+1]=r-3,c[f+2]=r-2,c[f+3]=r-3,c[f+4]=r-1,c[f+5]=r-2,f+=6,e.current=null}a.bindBuffer(a.ARRAY_BUFFER,this.vertexBuffer),a.bufferData(a.ARRAY_BUFFER,A,a.STATIC_DRAW),a.bindBuffer(a.ELEMENT_ARRAY_BUFFER,this.indexBuffer),a.bufferData(a.ELEMENT_ARRAY_BUFFER,c,a.STATIC_DRAW),this.indexBufferSize=c.length}}),C=E.createSubclass({createLayerView:function(t){if(t.type==="2d")return new V({view:t,layer:this})}});exports.default=C;