1
0

decodeGoogleEarthEnterprisePacket.js 24 KB

1
  1. define(["./RuntimeError-346a3079","./when-4bbc8319","./createTaskProcessorWorker"],function(k,i,e){"use strict";function u(e,t){if(u.passThroughDataForTesting)return t;var i=e.byteLength;if(0===i||i%4!=0)throw new k.RuntimeError("The length of key must be greater than 0 and a multiple of 4.");var r=new DataView(t),n=r.getUint32(0,!0);if(1953029805===n||2917034100===n)return t;for(var a,o=new DataView(e),s=0,f=t.byteLength,l=f-f%8,d=i,h=8;s<l;)for(a=h=(h+8)%24;s<l&&a<d;)r.setUint32(s,r.getUint32(s,!0)^o.getUint32(a,!0),!0),r.setUint32(s+4,r.getUint32(s+4,!0)^o.getUint32(a+4,!0),!0),s+=8,a+=24;if(s<f)for(d<=a&&(a=h=(h+8)%24);s<f;)r.setUint8(s,r.getUint8(s)^o.getUint8(a)),s++,a++}function t(e,t){return 0!=(e&t)}u.passThroughDataForTesting=!1;var r=[1,2,4,8];function p(e,t,i,r,n,a){this._bits=e,this.cnodeVersion=t,this.imageryVersion=i,this.terrainVersion=r,this.imageryProvider=n,this.terrainProvider=a,this.ancestorHasTerrain=!1,this.terrainState=void 0}p.clone=function(e,t){return i.defined(t)?(t._bits=e._bits,t.cnodeVersion=e.cnodeVersion,t.imageryVersion=e.imageryVersion,t.terrainVersion=e.terrainVersion,t.imageryProvider=e.imageryProvider,t.terrainProvider=e.terrainProvider):t=new p(e._bits,e.cnodeVersion,e.imageryVersion,e.terrainVersion,e.imageryProvider,e.terrainProvider),t.ancestorHasTerrain=e.ancestorHasTerrain,t.terrainState=e.terrainState,t},p.prototype.setParent=function(e){this.ancestorHasTerrain=e.ancestorHasTerrain||this.hasTerrain()},p.prototype.hasSubtree=function(){return t(this._bits,16)},p.prototype.hasImagery=function(){return t(this._bits,64)},p.prototype.hasTerrain=function(){return t(this._bits,128)},p.prototype.hasChildren=function(){return t(this._bits,15)},p.prototype.hasChild=function(e){return t(this._bits,r[e])},p.prototype.getChildBitmask=function(){return 15&this._bits};var D=i.createCommonjsModule(function(e,t){var i="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Int32Array;t.assign=function(e){for(var t,i,r=Array.prototype.slice.call(arguments,1);r.length;){var n=r.shift();if(n){if("object"!=typeof n)throw new TypeError(n+"must be non-object");for(var a in n)t=n,i=a,Object.prototype.hasOwnProperty.call(t,i)&&(e[a]=n[a])}}return e},t.shrinkBuf=function(e,t){return e.length===t?e:e.subarray?e.subarray(0,t):(e.length=t,e)};var r={arraySet:function(e,t,i,r,n){if(t.subarray&&e.subarray)e.set(t.subarray(i,i+r),n);else for(var a=0;a<r;a++)e[n+a]=t[i+a]},flattenChunks:function(e){for(var t,i,r,n=0,a=0,o=e.length;a<o;a++)n+=e[a].length;for(r=new Uint8Array(n),a=t=0,o=e.length;a<o;a++)i=e[a],r.set(i,t),t+=i.length;return r}},n={arraySet:function(e,t,i,r,n){for(var a=0;a<r;a++)e[n+a]=t[i+a]},flattenChunks:function(e){return[].concat.apply([],e)}};t.setTyped=function(e){e?(t.Buf8=Uint8Array,t.Buf16=Uint16Array,t.Buf32=Int32Array,t.assign(t,r)):(t.Buf8=Array,t.Buf16=Array,t.Buf32=Array,t.assign(t,n))},t.setTyped(i)});var S=function(e,t,i,r){for(var n=65535&e|0,a=e>>>16&65535|0,o=0;0!==i;){for(i-=o=2e3<i?2e3:i;a=a+(n=n+t[r++]|0)|0,--o;);n%=65521,a%=65521}return n|a<<16|0};var s=function(){for(var e=[],t=0;t<256;t++){for(var i=t,r=0;r<8;r++)i=1&i?3988292384^i>>>1:i>>>1;e[t]=i}return e}();var R=function(e,t,i,r){var n=s,a=r+i;e^=-1;for(var o=r;o<a;o++)e=e>>>8^n[255&(e^t[o])];return-1^e},C=30,I=12,V=15,P=852,O=592,M=0,j=1,H=2,N=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0],L=[16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78],Y=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0],F=[16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64],z=function(e,t,i,r,n,a,o,s){for(var f,l,d,h,u,c,w,b,m,g=s.bits,v=0,k=0,p=0,y=0,_=0,x=0,B=0,E=0,A=0,T=0,U=null,S=0,R=new D.Buf16(V+1),C=new D.Buf16(V+1),I=null,z=0,v=0;v<=V;v++)R[v]=0;for(k=0;k<r;k++)R[t[i+k]]++;for(_=g,y=V;1<=y&&0===R[y];y--);if(y<_&&(_=y),0===y)return n[a++]=20971520,n[a++]=20971520,s.bits=1,0;for(p=1;p<y&&0===R[p];p++);for(_<p&&(_=p),v=E=1;v<=V;v++)if(E<<=1,(E-=R[v])<0)return-1;if(0<E&&(e===M||1!==y))return-1;for(C[1]=0,v=1;v<V;v++)C[v+1]=C[v]+R[v];for(k=0;k<r;k++)0!==t[i+k]&&(o[C[t[i+k]]++]=k);if(c=e===M?(U=I=o,19):e===j?(U=N,S-=257,I=L,z-=257,256):(U=Y,I=F,-1),v=p,u=a,B=k=T=0,d=-1,h=(A=1<<(x=_))-1,e===j&&P<A||e===H&&O<A)return 1;for(;;){for(m=o[k]<c?(b=0,o[k]):o[k]>c?(b=I[z+o[k]],U[S+o[k]]):(b=96,0),f=1<<(w=v-B),p=l=1<<x;n[u+(T>>B)+(l-=f)]=w<<24|b<<16|m|0,0!==l;);for(f=1<<v-1;T&f;)f>>=1;if(0!==f?(T&=f-1,T+=f):T=0,k++,0==--R[v]){if(v===y)break;v=t[i+o[k]]}if(_<v&&(T&h)!==d){for(u+=p,E=1<<(x=v-(B=0===B?_:B));x+B<y&&!((E-=R[x+B])<=0);)x++,E<<=1;if(A+=1<<x,e===j&&P<A||e===H&&O<A)return 1;n[d=T&h]=_<<24|x<<16|u-a|0}}return 0!==T&&(n[u+T]=v-B<<24|64<<16|0),s.bits=_,0},G=1,K=2,Q=0,q=-2,W=1,n=852,a=592;function J(e){return(e>>>24&255)+(e>>>8&65280)+((65280&e)<<8)+((255&e)<<24)}function o(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new D.Buf16(320),this.work=new D.Buf16(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function f(e){var t;return e&&e.state?(t=e.state,e.total_in=e.total_out=t.total=0,e.msg="",t.wrap&&(e.adler=1&t.wrap),t.mode=W,t.last=0,t.havedict=0,t.dmax=32768,t.head=null,t.hold=0,t.bits=0,t.lencode=t.lendyn=new D.Buf32(n),t.distcode=t.distdyn=new D.Buf32(a),t.sane=1,t.back=-1,Q):q}function l(e){var t;return e&&e.state?((t=e.state).wsize=0,t.whave=0,t.wnext=0,f(e)):q}function d(e,t){var i,r;return e&&e.state?(r=e.state,t<0?(i=0,t=-t):(i=1+(t>>4),t<48&&(t&=15)),t&&(t<8||15<t)?q:(null!==r.window&&r.wbits!==t&&(r.window=null),r.wrap=i,r.wbits=t,l(e))):q}function h(e,t){var i;return e?(i=new o,(e.state=i).window=null,(t=d(e,t))!==Q&&(e.state=null),t):q}var X,Z,$=!0;function ee(e,t,i,r){var n=e.state;return null===n.window&&(n.wsize=1<<n.wbits,n.wnext=0,n.whave=0,n.window=new D.Buf8(n.wsize)),r>=n.wsize?(D.arraySet(n.window,t,i-n.wsize,n.wsize,0),n.wnext=0,n.whave=n.wsize):(r<(e=n.wsize-n.wnext)&&(e=r),D.arraySet(n.window,t,i-r,e,n.wnext),(r-=e)?(D.arraySet(n.window,t,i-r,r,0),n.wnext=r,n.whave=n.wsize):(n.wnext+=e,n.wnext===n.wsize&&(n.wnext=0),n.whave<n.wsize&&(n.whave+=e))),0}var c={inflateReset:l,inflateReset2:d,inflateResetKeep:f,inflateInit:function(e){return h(e,15)},inflateInit2:h,inflate:function(e,t){var i,r,n,a,o,s,f,l,d,h,u,c,w,b,m,g,v,k,p,y,_,x,B,E,A=0,T=new D.Buf8(4),U=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];if(!e||!e.state||!e.output||!e.input&&0!==e.avail_in)return q;12===(i=e.state).mode&&(i.mode=13),o=e.next_out,n=e.output,f=e.avail_out,a=e.next_in,r=e.input,s=e.avail_in,l=i.hold,d=i.bits,h=s,u=f,x=Q;e:for(;;)switch(i.mode){case W:if(0===i.wrap){i.mode=13;break}for(;d<16;){if(0===s)break e;s--,l+=r[a++]<<d,d+=8}if(2&i.wrap&&35615===l){T[i.check=0]=255&l,T[1]=l>>>8&255,i.check=R(i.check,T,2,0),d=l=0,i.mode=2;break}if(i.flags=0,i.head&&(i.head.done=!1),!(1&i.wrap)||(((255&l)<<8)+(l>>8))%31){e.msg="incorrect header check",i.mode=30;break}if(8!=(15&l)){e.msg="unknown compression method",i.mode=30;break}if(d-=4,_=8+(15&(l>>>=4)),0===i.wbits)i.wbits=_;else if(_>i.wbits){e.msg="invalid window size",i.mode=30;break}i.dmax=1<<_,e.adler=i.check=1,i.mode=512&l?10:12,d=l=0;break;case 2:for(;d<16;){if(0===s)break e;s--,l+=r[a++]<<d,d+=8}if(i.flags=l,8!=(255&i.flags)){e.msg="unknown compression method",i.mode=30;break}if(57344&i.flags){e.msg="unknown header flags set",i.mode=30;break}i.head&&(i.head.text=l>>8&1),512&i.flags&&(T[0]=255&l,T[1]=l>>>8&255,i.check=R(i.check,T,2,0)),d=l=0,i.mode=3;case 3:for(;d<32;){if(0===s)break e;s--,l+=r[a++]<<d,d+=8}i.head&&(i.head.time=l),512&i.flags&&(T[0]=255&l,T[1]=l>>>8&255,T[2]=l>>>16&255,T[3]=l>>>24&255,i.check=R(i.check,T,4,0)),d=l=0,i.mode=4;case 4:for(;d<16;){if(0===s)break e;s--,l+=r[a++]<<d,d+=8}i.head&&(i.head.xflags=255&l,i.head.os=l>>8),512&i.flags&&(T[0]=255&l,T[1]=l>>>8&255,i.check=R(i.check,T,2,0)),d=l=0,i.mode=5;case 5:if(1024&i.flags){for(;d<16;){if(0===s)break e;s--,l+=r[a++]<<d,d+=8}i.length=l,i.head&&(i.head.extra_len=l),512&i.flags&&(T[0]=255&l,T[1]=l>>>8&255,i.check=R(i.check,T,2,0)),d=l=0}else i.head&&(i.head.extra=null);i.mode=6;case 6:if(1024&i.flags&&((c=s<(c=i.length)?s:c)&&(i.head&&(_=i.head.extra_len-i.length,i.head.extra||(i.head.extra=new Array(i.head.extra_len)),D.arraySet(i.head.extra,r,a,c,_)),512&i.flags&&(i.check=R(i.check,r,c,a)),s-=c,a+=c,i.length-=c),i.length))break e;i.length=0,i.mode=7;case 7:if(2048&i.flags){if(0===s)break e;for(c=0;_=r[a+c++],i.head&&_&&i.length<65536&&(i.head.name+=String.fromCharCode(_)),_&&c<s;);if(512&i.flags&&(i.check=R(i.check,r,c,a)),s-=c,a+=c,_)break e}else i.head&&(i.head.name=null);i.length=0,i.mode=8;case 8:if(4096&i.flags){if(0===s)break e;for(c=0;_=r[a+c++],i.head&&_&&i.length<65536&&(i.head.comment+=String.fromCharCode(_)),_&&c<s;);if(512&i.flags&&(i.check=R(i.check,r,c,a)),s-=c,a+=c,_)break e}else i.head&&(i.head.comment=null);i.mode=9;case 9:if(512&i.flags){for(;d<16;){if(0===s)break e;s--,l+=r[a++]<<d,d+=8}if(l!==(65535&i.check)){e.msg="header crc mismatch",i.mode=30;break}d=l=0}i.head&&(i.head.hcrc=i.flags>>9&1,i.head.done=!0),e.adler=i.check=0,i.mode=12;break;case 10:for(;d<32;){if(0===s)break e;s--,l+=r[a++]<<d,d+=8}e.adler=i.check=J(l),d=l=0,i.mode=11;case 11:if(0===i.havedict)return e.next_out=o,e.avail_out=f,e.next_in=a,e.avail_in=s,i.hold=l,i.bits=d,2;e.adler=i.check=1,i.mode=12;case 12:if(5===t||6===t)break e;case 13:if(i.last){l>>>=7&d,d-=7&d,i.mode=27;break}for(;d<3;){if(0===s)break e;s--,l+=r[a++]<<d,d+=8}switch(i.last=1&l,--d,3&(l>>>=1)){case 0:i.mode=14;break;case 1:if(!function(e){if($){var t;for(X=new D.Buf32(512),Z=new D.Buf32(32),t=0;t<144;)e.lens[t++]=8;for(;t<256;)e.lens[t++]=9;for(;t<280;)e.lens[t++]=7;for(;t<288;)e.lens[t++]=8;for(z(G,e.lens,0,288,X,0,e.work,{bits:9}),t=0;t<32;)e.lens[t++]=5;z(K,e.lens,0,32,Z,0,e.work,{bits:5}),$=!1}e.lencode=X,e.lenbits=9,e.distcode=Z,e.distbits=5}(i),i.mode=20,6!==t)break;l>>>=2,d-=2;break e;case 2:i.mode=17;break;case 3:e.msg="invalid block type",i.mode=30}l>>>=2,d-=2;break;case 14:for(l>>>=7&d,d-=7&d;d<32;){if(0===s)break e;s--,l+=r[a++]<<d,d+=8}if((65535&l)!=(l>>>16^65535)){e.msg="invalid stored block lengths",i.mode=30;break}if(i.length=65535&l,d=l=0,i.mode=15,6===t)break e;case 15:i.mode=16;case 16:if(c=i.length){if(0===(c=f<(c=s<c?s:c)?f:c))break e;D.arraySet(n,r,a,c,o),s-=c,a+=c,f-=c,o+=c,i.length-=c;break}i.mode=12;break;case 17:for(;d<14;){if(0===s)break e;s--,l+=r[a++]<<d,d+=8}if(i.nlen=257+(31&l),l>>>=5,d-=5,i.ndist=1+(31&l),l>>>=5,d-=5,i.ncode=4+(15&l),l>>>=4,d-=4,286<i.nlen||30<i.ndist){e.msg="too many length or distance symbols",i.mode=30;break}i.have=0,i.mode=18;case 18:for(;i.have<i.ncode;){for(;d<3;){if(0===s)break e;s--,l+=r[a++]<<d,d+=8}i.lens[U[i.have++]]=7&l,l>>>=3,d-=3}for(;i.have<19;)i.lens[U[i.have++]]=0;if(i.lencode=i.lendyn,i.lenbits=7,B={bits:i.lenbits},x=z(0,i.lens,0,19,i.lencode,0,i.work,B),i.lenbits=B.bits,x){e.msg="invalid code lengths set",i.mode=30;break}i.have=0,i.mode=19;case 19:for(;i.have<i.nlen+i.ndist;){for(;g=(A=i.lencode[l&(1<<i.lenbits)-1])>>>16&255,v=65535&A,!((m=A>>>24)<=d);){if(0===s)break e;s--,l+=r[a++]<<d,d+=8}if(v<16)l>>>=m,d-=m,i.lens[i.have++]=v;else{if(16===v){for(E=m+2;d<E;){if(0===s)break e;s--,l+=r[a++]<<d,d+=8}if(l>>>=m,d-=m,0===i.have){e.msg="invalid bit length repeat",i.mode=30;break}_=i.lens[i.have-1],c=3+(3&l),l>>>=2,d-=2}else if(17===v){for(E=m+3;d<E;){if(0===s)break e;s--,l+=r[a++]<<d,d+=8}d-=m,_=0,c=3+(7&(l>>>=m)),l>>>=3,d-=3}else{for(E=m+7;d<E;){if(0===s)break e;s--,l+=r[a++]<<d,d+=8}d-=m,_=0,c=11+(127&(l>>>=m)),l>>>=7,d-=7}if(i.have+c>i.nlen+i.ndist){e.msg="invalid bit length repeat",i.mode=30;break}for(;c--;)i.lens[i.have++]=_}}if(30===i.mode)break;if(0===i.lens[256]){e.msg="invalid code -- missing end-of-block",i.mode=30;break}if(i.lenbits=9,B={bits:i.lenbits},x=z(G,i.lens,0,i.nlen,i.lencode,0,i.work,B),i.lenbits=B.bits,x){e.msg="invalid literal/lengths set",i.mode=30;break}if(i.distbits=6,i.distcode=i.distdyn,B={bits:i.distbits},x=z(K,i.lens,i.nlen,i.ndist,i.distcode,0,i.work,B),i.distbits=B.bits,x){e.msg="invalid distances set",i.mode=30;break}if(i.mode=20,6===t)break e;case 20:i.mode=21;case 21:if(6<=s&&258<=f){e.next_out=o,e.avail_out=f,e.next_in=a,e.avail_in=s,i.hold=l,i.bits=d,function(e,t){var i,r,n,a,o,s,f=e.state,l=e.next_in,d=e.input,h=l+(e.avail_in-5),u=e.next_out,c=e.output,w=u-(t-e.avail_out),b=u+(e.avail_out-257),m=f.dmax,g=f.wsize,v=f.whave,k=f.wnext,p=f.window,y=f.hold,_=f.bits,x=f.lencode,B=f.distcode,E=(1<<f.lenbits)-1,A=(1<<f.distbits)-1;t:do{_<15&&(y+=d[l++]<<_,_+=8,y+=d[l++]<<_,_+=8),i=x[y&E];i:for(;;){if(y>>>=r=i>>>24,_-=r,0===(r=i>>>16&255))c[u++]=65535&i;else{if(!(16&r)){if(0==(64&r)){i=x[(65535&i)+(y&(1<<r)-1)];continue i}if(32&r){f.mode=I;break t}e.msg="invalid literal/length code",f.mode=C;break t}n=65535&i,(r&=15)&&(_<r&&(y+=d[l++]<<_,_+=8),n+=y&(1<<r)-1,y>>>=r,_-=r),_<15&&(y+=d[l++]<<_,_+=8,y+=d[l++]<<_,_+=8),i=B[y&A];r:for(;;){if(y>>>=r=i>>>24,_-=r,!(16&(r=i>>>16&255))){if(0==(64&r)){i=B[(65535&i)+(y&(1<<r)-1)];continue r}e.msg="invalid distance code",f.mode=C;break t}if(a=65535&i,_<(r&=15)&&(y+=d[l++]<<_,(_+=8)<r&&(y+=d[l++]<<_,_+=8)),m<(a+=y&(1<<r)-1)){e.msg="invalid distance too far back",f.mode=C;break t}if(y>>>=r,_-=r,(r=u-w)<a){if(v<(r=a-r)&&f.sane){e.msg="invalid distance too far back",f.mode=C;break t}if(s=p,(o=0)===k){if(o+=g-r,r<n){for(n-=r;c[u++]=p[o++],--r;);o=u-a,s=c}}else if(k<r){if(o+=g+k-r,(r-=k)<n){for(n-=r;c[u++]=p[o++],--r;);if(o=0,k<n){for(n-=r=k;c[u++]=p[o++],--r;);o=u-a,s=c}}}else if(o+=k-r,r<n){for(n-=r;c[u++]=p[o++],--r;);o=u-a,s=c}for(;2<n;)c[u++]=s[o++],c[u++]=s[o++],c[u++]=s[o++],n-=3;n&&(c[u++]=s[o++],1<n&&(c[u++]=s[o++]))}else{for(o=u-a;c[u++]=c[o++],c[u++]=c[o++],c[u++]=c[o++],2<(n-=3););n&&(c[u++]=c[o++],1<n&&(c[u++]=c[o++]))}break}}break}}while(l<h&&u<b);y&=(1<<(_-=(n=_>>3)<<3))-1,e.next_in=l-=n,e.next_out=u,e.avail_in=l<h?h-l+5:5-(l-h),e.avail_out=u<b?b-u+257:257-(u-b),f.hold=y,f.bits=_}(e,u),o=e.next_out,n=e.output,f=e.avail_out,a=e.next_in,r=e.input,s=e.avail_in,l=i.hold,d=i.bits,12===i.mode&&(i.back=-1);break}for(i.back=0;g=(A=i.lencode[l&(1<<i.lenbits)-1])>>>16&255,v=65535&A,!((m=A>>>24)<=d);){if(0===s)break e;s--,l+=r[a++]<<d,d+=8}if(g&&0==(240&g)){for(k=m,p=g,y=v;g=(A=i.lencode[y+((l&(1<<k+p)-1)>>k)])>>>16&255,v=65535&A,!(k+(m=A>>>24)<=d);){if(0===s)break e;s--,l+=r[a++]<<d,d+=8}l>>>=k,d-=k,i.back+=k}if(l>>>=m,d-=m,i.back+=m,i.length=v,0===g){i.mode=26;break}if(32&g){i.back=-1,i.mode=12;break}if(64&g){e.msg="invalid literal/length code",i.mode=30;break}i.extra=15&g,i.mode=22;case 22:if(i.extra){for(E=i.extra;d<E;){if(0===s)break e;s--,l+=r[a++]<<d,d+=8}i.length+=l&(1<<i.extra)-1,l>>>=i.extra,d-=i.extra,i.back+=i.extra}i.was=i.length,i.mode=23;case 23:for(;g=(A=i.distcode[l&(1<<i.distbits)-1])>>>16&255,v=65535&A,!((m=A>>>24)<=d);){if(0===s)break e;s--,l+=r[a++]<<d,d+=8}if(0==(240&g)){for(k=m,p=g,y=v;g=(A=i.distcode[y+((l&(1<<k+p)-1)>>k)])>>>16&255,v=65535&A,!(k+(m=A>>>24)<=d);){if(0===s)break e;s--,l+=r[a++]<<d,d+=8}l>>>=k,d-=k,i.back+=k}if(l>>>=m,d-=m,i.back+=m,64&g){e.msg="invalid distance code",i.mode=30;break}i.offset=v,i.extra=15&g,i.mode=24;case 24:if(i.extra){for(E=i.extra;d<E;){if(0===s)break e;s--,l+=r[a++]<<d,d+=8}i.offset+=l&(1<<i.extra)-1,l>>>=i.extra,d-=i.extra,i.back+=i.extra}if(i.offset>i.dmax){e.msg="invalid distance too far back",i.mode=30;break}i.mode=25;case 25:if(0===f)break e;if(i.offset>(c=u-f)){if((c=i.offset-c)>i.whave&&i.sane){e.msg="invalid distance too far back",i.mode=30;break}w=c>i.wnext?(c-=i.wnext,i.wsize-c):i.wnext-c,c>i.length&&(c=i.length),b=i.window}else b=n,w=o-i.offset,c=i.length;for(f-=c=f<c?f:c,i.length-=c;n[o++]=b[w++],--c;);0===i.length&&(i.mode=21);break;case 26:if(0===f)break e;n[o++]=i.length,f--,i.mode=21;break;case 27:if(i.wrap){for(;d<32;){if(0===s)break e;s--,l|=r[a++]<<d,d+=8}if(u-=f,e.total_out+=u,i.total+=u,u&&(e.adler=i.check=(i.flags?R:S)(i.check,n,u,o-u)),u=f,(i.flags?l:J(l))!==i.check){e.msg="incorrect data check",i.mode=30;break}d=l=0}i.mode=28;case 28:if(i.wrap&&i.flags){for(;d<32;){if(0===s)break e;s--,l+=r[a++]<<d,d+=8}if(l!==(4294967295&i.total)){e.msg="incorrect length check",i.mode=30;break}d=l=0}i.mode=29;case 29:x=1;break e;case 30:x=-3;break e;case 31:return-4;default:return q}return e.next_out=o,e.avail_out=f,e.next_in=a,e.avail_in=s,i.hold=l,i.bits=d,(i.wsize||u!==e.avail_out&&i.mode<30&&(i.mode<27||4!==t))&&ee(e,e.output,e.next_out,u-e.avail_out),h-=e.avail_in,u-=e.avail_out,e.total_in+=h,e.total_out+=u,i.total+=u,i.wrap&&u&&(e.adler=i.check=(i.flags?R:S)(i.check,n,u,e.next_out-u)),e.data_type=i.bits+(i.last?64:0)+(12===i.mode?128:0)+(20===i.mode||15===i.mode?256:0),x=(0==h&&0===u||4===t)&&x===Q?-5:x},inflateEnd:function(e){if(!e||!e.state)return q;var t=e.state;return t.window&&(t.window=null),e.state=null,Q},inflateGetHeader:function(e,t){return!e||!e.state||0==(2&(e=e.state).wrap)?q:((e.head=t).done=!1,Q)},inflateSetDictionary:function(e,t){var i,r=t.length;return!e||!e.state||0!==(i=e.state).wrap&&11!==i.mode?q:11===i.mode&&S(1,t,r,0)!==i.check?-3:ee(e,t,r,r)?(i.mode=31,-4):(i.havedict=1,Q)},inflateInfo:"pako inflate (from Nodeca project)"},w=!0,b=!0;try{String.fromCharCode.apply(null,[0])}catch(e){w=!1}try{String.fromCharCode.apply(null,new Uint8Array(1))}catch(e){b=!1}for(var m=new D.Buf8(256),g=0;g<256;g++)m[g]=252<=g?6:248<=g?5:240<=g?4:224<=g?3:192<=g?2:1;m[254]=m[254]=1;function v(e,t){if(t<65534&&(e.subarray&&b||!e.subarray&&w))return String.fromCharCode.apply(null,D.shrinkBuf(e,t));for(var i="",r=0;r<t;r++)i+=String.fromCharCode(e[r]);return i}var y=function(e){for(var t,i,r,n,a=e.length,o=0,s=0;s<a;s++)55296==(64512&(i=e.charCodeAt(s)))&&s+1<a&&56320==(64512&(r=e.charCodeAt(s+1)))&&(i=65536+(i-55296<<10)+(r-56320),s++),o+=i<128?1:i<2048?2:i<65536?3:4;for(t=new D.Buf8(o),s=n=0;n<o;s++)55296==(64512&(i=e.charCodeAt(s)))&&s+1<a&&56320==(64512&(r=e.charCodeAt(s+1)))&&(i=65536+(i-55296<<10)+(r-56320),s++),i<128?t[n++]=i:(i<2048?t[n++]=192|i>>>6:(i<65536?t[n++]=224|i>>>12:(t[n++]=240|i>>>18,t[n++]=128|i>>>12&63),t[n++]=128|i>>>6&63),t[n++]=128|63&i);return t},_=function(e){for(var t=new D.Buf8(e.length),i=0,r=t.length;i<r;i++)t[i]=e.charCodeAt(i);return t},x=function(e,t){for(var i,r,n=t||e.length,a=new Array(2*n),o=0,s=0;s<n;)if((i=e[s++])<128)a[o++]=i;else if(4<(r=m[i]))a[o++]=65533,s+=r-1;else{for(i&=2===r?31:3===r?15:7;1<r&&s<n;)i=i<<6|63&e[s++],r--;1<r?a[o++]=65533:i<65536?a[o++]=i:(i-=65536,a[o++]=55296|i>>10&1023,a[o++]=56320|1023&i)}return v(a,o)},B=function(e,t){for(var i=(t=(t=t||e.length)>e.length?e.length:t)-1;0<=i&&128==(192&e[i]);)i--;return!(i<0)&&0!==i&&i+m[e[i]]>t?i:t},E=0,A=2,T=4,U=0,te=1,ie=2,re=-5,ne={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"};var ae=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0};var oe=function(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1},se=Object.prototype.toString;function fe(e){if(!(this instanceof fe))return new fe(e);this.options=D.assign({chunkSize:16384,windowBits:0,to:""},e||{});var t=this.options;t.raw&&0<=t.windowBits&&t.windowBits<16&&(t.windowBits=-t.windowBits,0===t.windowBits&&(t.windowBits=-15)),!(0<=t.windowBits&&t.windowBits<16)||e&&e.windowBits||(t.windowBits+=32),15<t.windowBits&&t.windowBits<48&&0==(15&t.windowBits)&&(t.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new ae,this.strm.avail_out=0;e=c.inflateInit2(this.strm,t.windowBits);if(e!==U)throw new Error(ne[e]);if(this.header=new oe,c.inflateGetHeader(this.strm,this.header),t.dictionary&&("string"==typeof t.dictionary?t.dictionary=y(t.dictionary):"[object ArrayBuffer]"===se.call(t.dictionary)&&(t.dictionary=new Uint8Array(t.dictionary)),t.raw&&(e=c.inflateSetDictionary(this.strm,t.dictionary))!==U))throw new Error(ne[e])}function le(e,t){t=new fe(t);if(t.push(e,!0),t.err)throw t.msg||ne[t.err];return t.result}fe.prototype.push=function(e,t){var i,r,n,a,o,s=this.strm,f=this.options.chunkSize,l=this.options.dictionary,d=!1;if(this.ended)return!1;r=t===~~t?t:!0===t?T:E,"string"==typeof e?s.input=_(e):"[object ArrayBuffer]"===se.call(e)?s.input=new Uint8Array(e):s.input=e,s.next_in=0,s.avail_in=s.input.length;do{if(0===s.avail_out&&(s.output=new D.Buf8(f),s.next_out=0,s.avail_out=f),(i=(i=c.inflate(s,E))===ie&&l?c.inflateSetDictionary(this.strm,l):i)===re&&!0===d&&(i=U,d=!1),i!==te&&i!==U)return this.onEnd(i),!(this.ended=!0)}while(s.next_out&&(0!==s.avail_out&&i!==te&&(0!==s.avail_in||r!==T&&r!==A)||("string"===this.options.to?(n=B(s.output,s.next_out),a=s.next_out-n,o=x(s.output,n),s.next_out=a,s.avail_out=f-a,a&&D.arraySet(s.output,s.output,n,a,0),this.onData(o)):this.onData(D.shrinkBuf(s.output,s.next_out)))),0===s.avail_in&&0===s.avail_out&&(d=!0),(0<s.avail_in||0===s.avail_out)&&i!==te);return(r=i===te?T:r)===T?(i=c.inflateEnd(this.strm),this.onEnd(i),this.ended=!0,i===U):r!==A||(this.onEnd(U),!(s.avail_out=0))},fe.prototype.onData=function(e){this.chunks.push(e)},fe.prototype.onEnd=function(e){e===U&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=D.flattenChunks(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};var de={Inflate:fe,inflate:le,inflateRaw:function(e,t){return(t=t||{}).raw=!0,le(e,t)},ungzip:le},he=Uint16Array.BYTES_PER_ELEMENT,ue=Int32Array.BYTES_PER_ELEMENT,ce=Uint32Array.BYTES_PER_ELEMENT,we={METADATA:0,TERRAIN:1,DBROOT:2};we.fromString=function(e){return"Metadata"===e?we.METADATA:"Terrain"===e?we.TERRAIN:"DbRoot"===e?we.DBROOT:void 0};var be=32301;var me=5,ge=4;var ve=1953029805,ke=2917034100;return e(function(e,t){var i=we.fromString(e.type),r=e.buffer;u(e.key,r);var n=function(e){var t=new DataView(e),i=0,r=t.getUint32(0,!0);if(i+=ce,r!==ve&&r!==ke)throw new k.RuntimeError("Invalid magic");r=t.getUint32(i,r===ve);i+=ce;i=new Uint8Array(e,i),i=de.inflate(i);if(i.length===r)return i;throw new k.RuntimeError("Size of packet doesn't match header")}(r),r=n.buffer,a=n.length;switch(i){case we.METADATA:return function(e,t,i){var r=new DataView(e),n=0,a=r.getUint32(n,!0);if(n+=ce,a!==be)throw new k.RuntimeError("Invalid magic");var o=r.getUint32(n,!0);if(n+=ce,1!==o)throw new k.RuntimeError("Invalid data type. Must be 1 for QuadTreePacket");var s=r.getUint32(n,!0);if(n+=ce,2!==s)throw new k.RuntimeError("Invalid QuadTreePacket version. Only version 2 is supported.");var f=r.getInt32(n,!0);n+=ue;e=r.getInt32(n,!0);if(n+=ue,32!==e)throw new k.RuntimeError("Invalid instance size.");a=r.getInt32(n,!0);n+=ue;o=r.getInt32(n,!0);n+=ue;s=r.getInt32(n,!0);if(a!==f*e+(n+=ue))throw new k.RuntimeError("Invalid dataBufferOffset");if(a+o+s!==t)throw new k.RuntimeError("Invalid packet offsets");for(var l=[],d=0;d<f;++d){var h=r.getUint8(n);++n,++n;var u=r.getUint16(n,!0);n+=he;var c=r.getUint16(n,!0);n+=he;var w=r.getUint16(n,!0);n+=he,n+=he,n+=he,n+=ue,n+=ue,n+=8;var b=r.getUint8(n++),m=r.getUint8(n++);n+=he,l.push(new p(h,u,c,w,b,m))}var g=[],v=0;s=0,t=l[v++];""===i?++s:g[i]=t;return function e(t,i,r){var n=!1;if(4===r){if(i.hasSubtree())return;n=!0}for(var a=0;a<4;++a){var o=t+a.toString();if(n)g[o]=null;else if(r<4)if(i.hasChild(a)){if(v===f)return void console.log("Incorrect number of instances");var s=l[v++];e(o,g[o]=s,r+1)}else g[o]=null}}(i,t,s),g}(r,a,e.quadKey);case we.TERRAIN:return function(e,r,t){var n=new DataView(e),i=0,a=[];for(;a.length<me;){var o=i;i=function(e){for(var t=0;t<ge;++t){var i=n.getUint32(e,!0);if(e+=ce,r<(e+=i))throw new k.RuntimeError("Malformed terrain packet found.")}return e}(i);o=e.slice(o,i);t.push(o),a.push(o)}return a}(r,a,t);case we.DBROOT:return t.push(r),{buffer:r}}})});