qa-regulatory-gwj-vue/static/map/cesium91/CesiumUnminified/Workers/VarintReader.js

2 lines
4.1 KiB
JavaScript
Raw Normal View History

2023-11-07 10:04:37 +08:00
define(["./snappyJs","./CodeTool","./LayerContentModel","./GisTools"],(function(e,t,r,a){"use strict";return class{constructor(e,t,r){this.headerLength=t,this.proSizeObj=r,this.intLength=4,this.vectorName="vector",this.gTypeKey="gType",this.encoding="utf8",this.featureSpace="#@",this.vectorVarintBuffer=e,this.layerMap=new Object,this.vectorHeaderProMap=new Object,this.layerHeaderProMap=new Object,this.layerHeaderProBuffer=new Object,this.geometyTypeMap=new Object,this.featureMap=new Object,this.featureArrayMap=new Object,this.offsetBufferMap=new Object,this.offsetArrayMap=new Object,this.varintMap=new Object,this._parseVector(e)}getVectorHeaderProMap(){return this.vectorHeaderProMap}getLayerHeaderProMap(){return this.layerHeaderProMap}getLayerBuffer(e){return this.layerMap[e]}getLayerProByFilter(e,t){let a,s,i,h=[],n=this.offsetArrayMap[e],o=this._lazyParseFeature(e),l=[];this.proSizeObj[e];for(let r=0;r<t.length;r++)a=t[r],l.push(...o[a]),s=n[2*a],i=n[2*a+1],h.push(this.varintMap[e].slice(s,s+i));let f=new r;return f.setLayerHeaderProBuffer(this.layerHeaderProBuffer[e]),f.setFeatureArray(l),f.setCoordinateBufferArray(h),f}getAllLayerNames(){let e=[];for(let t in this.layerMap)e.push(t);return e}getGeometryType(e){return this.geometyTypeMap[e]}getLayerProByIndex(e,t){return this._lazyParseFeature(e)[t]}getLayerPro(e){return this._lazyParseFeature(e)}getOffsetArray(e){return this.offsetArrayMap[e]}getOffsetByIndex(e,t){let r=this.offsetArrayMap[e],a=[];return a.push(r[2*t]),a.push(r[2*t+1]),a}getLayerCoordinate(e){return this.varintMap[e]}getLayerFeature(e){return[this.featureMap[e],this.offsetArrayMap[e],this.varintMap[e]]}getAllCoordinates(e,t){let r,a,s,i=this.offsetArrayMap[e],h=this.varintMap[e],n=[];for(let e=0;e<i.length/2;e++)r=i[2*e],a=i[2*e+1],s=h.slice(r,r+a),n.push(this._bufferToDoubleArray(s,t)[0]);return n}getCoordinatesByIndex(e,t,r){let a=this.getOffsetByIndex(e,t),s=this.varintMap[e],i=a[0],h=a[1],n=s.slice(i,i+h);return this._bufferToDoubleArray(n,r)[0]}_parseVector(e){let t=this.headerLength,r=e.readInt32BE(t);t+=this.intLength;let a=e.slice(t,t+r).toString("utf-8");if(t+=r,a!==this.vectorName)return void console.error("不是瓦片数据!");let s=this._parseHeaderPro(e,t);t=s[0],this.vectorHeaderProMap=s[1];let i=e.readInt32BE(t);t+=this.intLength;let h=e.slice(t,t+i);t+=i;let n,o,l,f=e.slice(t,this.vectorVarintBuffer.length),p=0,u=0,y=0,g=0;for(let e=0;e<h.length;)y=e,p=h.readInt32BE(y),y+=this.intLength,g=y+p,n=h.toString(this.encoding,y,g),y=g,o=h.readInt32BE(y),y+=this.intLength,l=f.slice(u,u+o),u+=o,this.layerMap[n]=l,this._parseLayer(n,l),e=y}_parseLayer(t,r){if(0===r.length)return;let a=this.headerLength,s=this._parseHeaderPro(r,a);a=s[0],this.layerHeaderProMap[t]=s[1],this.layerHeaderProBuffer[t]=s[2];let i=this.layerHeaderProMap[t][this.gTypeKey];this.geometyTypeMap[t]=i;let h=r.readInt32BE(a);a+=this.intLength;let n=r.slice(a,a+h);n=e(n),a+=h,this.featureMap[t]=n;let o=this._parseIndex(r,a);a=o.offset,this.offsetBufferMap[t]=o.buffer,this.offsetArrayMap[t]=o.array;let l=r.slice(a);this.varintMap[t]=l}_parseHeaderPro(t,r){let s=new Object,i=t.readInt32BE(r);r+=this.intLength;let h=t.slice(r,r+i);if(r+=i,0==i)return[r,s];let n=a.Utf8ArrayToStr(e(h)).split(":");for(let e=0;e<n.length/2;e++)s[n[2*e]]=n[2*e+1];return[r,s,h]}_parseIndex(e,r){let a=e.readInt32BE(r);r+=this.intLength;let s=e.slice(r,r+a);return{offset:r+=a,buffer:s,array:t.varintToIntArray(s)}}_lazyParseFeature(e){let t=this.featureArrayMap[e],r=this.proSizeObj[e];if(null==t){let s=[];if(!(this.featureMap[e].length>0))return this.featureArrayMap[e]=[],[];s=a.Utf8ArrayToStr(this.featureMap[e]).split(this.featureSpace);let i=[],h=(s.length-1)/r;t=[];let n=0,o=n;for(let e=0;e<h;e++)o=n+r,i=s.slice(n,o),t.push(i),n=o;this.featureArrayMap[e]=t}return t}_bufferToDoubleArray(e,r){let a,s,i,h=[],n=[],o=0,l=[],f=0,p=0,u=!0;for(let y=0;y<=e.length;y++)a=0|e[y]>>7&1,0===a&&o>0&&(o>0&&o<=5?(u?(s=t.varintToInt(h)+f,n.push(s/r),u=!1,f=s):(i=t.varintToInt(h)+p,n.push(i/r),u=!0,p=i),o=0,h=[]):o>5&&(f=0,p=0,o=0,h=[],l.push(n),n=[])),y!==e.length?(