rlayers
Version:
React Components for OpenLayers
1 lines • 56 kB
JavaScript
(self.webpackChunkrlayers=self.webpackChunkrlayers||[]).push([[9633],{563:(e,t,i)=>{const r=i(8556);function s(e,t,i){const s=[],n=i&&i.debug||!1,o=!i||"boolean"!=typeof i.nested||i.nested;let a,l=i&&i.startIndex||0;for(;a=r(e,t,{debug:n,startIndex:l});)l=o?a.start+1+t.length:a.end,s.push(a);return n&&console.log("findTagsByName found",s.length,"tags"),s}e.exports=s,e.exports.default=s},3614:e=>{function t(e,t,i){const r=new RegExp(t).exec(e.slice(i));return r?i+r.index:-1}e.exports=t,e.exports.default=t},6675:e=>{function t(e,t){const i=new RegExp(t,"g"),r=e.match(i);return r?r.length:0}e.exports=t,e.exports.default=t},7379:e=>{function t(e,t,i){const r=i&&i.debug||!1;r&&console.log("[xml-utils] getting "+t+" in "+e);const s="object"==typeof e?e.outer:e,n=s.slice(0,s.indexOf(">")+1),o=['"',"'"];for(let e=0;e<o.length;e++){const i=o[e],s=t+"\\="+i+"([^"+i+"]*)"+i;r&&console.log("[xml-utils] pattern:",s);const a=new RegExp(s).exec(n);if(r&&console.log("[xml-utils] match:",a),a)return a[1]}}e.exports=t,e.exports.default=t},8556:(e,t,i)=>{const r=i(3614),s=i(8694),n=i(6675);function o(e,t,i){const o=i&&i.debug||!1,a=!(i&&!1===typeof i.nested),l=i&&i.startIndex||0;o&&console.log("[xml-utils] starting findTagByName with",t," and ",i);const h=r(e,`<${t}[ \n>/]`,l);if(o&&console.log("[xml-utils] start:",h),-1===h)return;const c=e.slice(h+t.length);let f=s(c,"^[^<]*[ /]>",0);const u=-1!==f&&"/"===c[f-1];if(o&&console.log("[xml-utils] selfClosing:",u),!1===u)if(a){let e=0,i=1,r=0;for(;-1!==(f=s(c,"[ /]"+t+">",e));){const s=c.substring(e,f+1);if(i+=n(s,"<"+t+"[ \n\t>]"),r+=n(s,"</"+t+">"),r>=i)break;e=f}}else f=s(c,"[ /]"+t+">",0);const g=h+t.length+f+1;if(o&&console.log("[xml-utils] end:",g),-1===g)return;const d=e.slice(h,g);let p;return p=u?null:d.slice(d.indexOf(">")+1,d.lastIndexOf("<")),{inner:p,outer:d,start:h,end:g}}e.exports=o,e.exports.default=o},8622:(e,t,i)=>{"use strict";i.d(t,{$:()=>r,AC:()=>h,Hm:()=>u,NZ:()=>n,S3:()=>f,TZ:()=>c,s$:()=>a,ub:()=>l});const r={315:"Artist",258:"BitsPerSample",265:"CellLength",264:"CellWidth",320:"ColorMap",259:"Compression",33432:"Copyright",306:"DateTime",338:"ExtraSamples",266:"FillOrder",289:"FreeByteCounts",288:"FreeOffsets",291:"GrayResponseCurve",290:"GrayResponseUnit",316:"HostComputer",270:"ImageDescription",257:"ImageLength",256:"ImageWidth",271:"Make",281:"MaxSampleValue",280:"MinSampleValue",272:"Model",254:"NewSubfileType",274:"Orientation",262:"PhotometricInterpretation",284:"PlanarConfiguration",296:"ResolutionUnit",278:"RowsPerStrip",277:"SamplesPerPixel",305:"Software",279:"StripByteCounts",273:"StripOffsets",255:"SubfileType",263:"Threshholding",282:"XResolution",283:"YResolution",326:"BadFaxLines",327:"CleanFaxData",343:"ClipPath",328:"ConsecutiveBadFaxLines",433:"Decode",434:"DefaultImageColor",269:"DocumentName",336:"DotRange",321:"HalftoneHints",346:"Indexed",347:"JPEGTables",285:"PageName",297:"PageNumber",317:"Predictor",319:"PrimaryChromaticities",532:"ReferenceBlackWhite",339:"SampleFormat",340:"SMinSampleValue",341:"SMaxSampleValue",559:"StripRowCounts",330:"SubIFDs",292:"T4Options",293:"T6Options",325:"TileByteCounts",323:"TileLength",324:"TileOffsets",322:"TileWidth",301:"TransferFunction",318:"WhitePoint",344:"XClipPathUnits",286:"XPosition",529:"YCbCrCoefficients",531:"YCbCrPositioning",530:"YCbCrSubSampling",345:"YClipPathUnits",287:"YPosition",37378:"ApertureValue",40961:"ColorSpace",36868:"DateTimeDigitized",36867:"DateTimeOriginal",34665:"Exif IFD",36864:"ExifVersion",33434:"ExposureTime",41728:"FileSource",37385:"Flash",40960:"FlashpixVersion",33437:"FNumber",42016:"ImageUniqueID",37384:"LightSource",37500:"MakerNote",37377:"ShutterSpeedValue",37510:"UserComment",33723:"IPTC",34675:"ICC Profile",700:"XMP",42112:"GDAL_METADATA",42113:"GDAL_NODATA",34377:"Photoshop",33550:"ModelPixelScale",33922:"ModelTiepoint",34264:"ModelTransformation",34735:"GeoKeyDirectory",34736:"GeoDoubleParams",34737:"GeoAsciiParams",50674:"LercParameters"},s={};for(const e in r)r.hasOwnProperty(e)&&(s[r[e]]=parseInt(e,10));const n=[s.BitsPerSample,s.ExtraSamples,s.SampleFormat,s.StripByteCounts,s.StripOffsets,s.StripRowCounts,s.TileByteCounts,s.TileOffsets,s.SubIFDs],o={1:"BYTE",2:"ASCII",3:"SHORT",4:"LONG",5:"RATIONAL",6:"SBYTE",7:"UNDEFINED",8:"SSHORT",9:"SLONG",10:"SRATIONAL",11:"FLOAT",12:"DOUBLE",13:"IFD",16:"LONG8",17:"SLONG8",18:"IFD8"},a={};for(const e in o)o.hasOwnProperty(e)&&(a[o[e]]=parseInt(e,10));const l={WhiteIsZero:0,BlackIsZero:1,RGB:2,Palette:3,TransparencyMask:4,CMYK:5,YCbCr:6,CIELab:8,ICCLab:9},h={Unspecified:0,Assocalpha:1,Unassalpha:2},c={Version:0,AddCompression:1},f={None:0,Deflate:1,Zstandard:2},u={1024:"GTModelTypeGeoKey",1025:"GTRasterTypeGeoKey",1026:"GTCitationGeoKey",2048:"GeographicTypeGeoKey",2049:"GeogCitationGeoKey",2050:"GeogGeodeticDatumGeoKey",2051:"GeogPrimeMeridianGeoKey",2052:"GeogLinearUnitsGeoKey",2053:"GeogLinearUnitSizeGeoKey",2054:"GeogAngularUnitsGeoKey",2055:"GeogAngularUnitSizeGeoKey",2056:"GeogEllipsoidGeoKey",2057:"GeogSemiMajorAxisGeoKey",2058:"GeogSemiMinorAxisGeoKey",2059:"GeogInvFlatteningGeoKey",2060:"GeogAzimuthUnitsGeoKey",2061:"GeogPrimeMeridianLongGeoKey",2062:"GeogTOWGS84GeoKey",3072:"ProjectedCSTypeGeoKey",3073:"PCSCitationGeoKey",3074:"ProjectionGeoKey",3075:"ProjCoordTransGeoKey",3076:"ProjLinearUnitsGeoKey",3077:"ProjLinearUnitSizeGeoKey",3078:"ProjStdParallel1GeoKey",3079:"ProjStdParallel2GeoKey",3080:"ProjNatOriginLongGeoKey",3081:"ProjNatOriginLatGeoKey",3082:"ProjFalseEastingGeoKey",3083:"ProjFalseNorthingGeoKey",3084:"ProjFalseOriginLongGeoKey",3085:"ProjFalseOriginLatGeoKey",3086:"ProjFalseOriginEastingGeoKey",3087:"ProjFalseOriginNorthingGeoKey",3088:"ProjCenterLongGeoKey",3089:"ProjCenterLatGeoKey",3090:"ProjCenterEastingGeoKey",3091:"ProjCenterNorthingGeoKey",3092:"ProjScaleAtNatOriginGeoKey",3093:"ProjScaleAtCenterGeoKey",3094:"ProjAzimuthAngleGeoKey",3095:"ProjStraightVertPoleLongGeoKey",3096:"ProjRectifiedGridAngleGeoKey",4096:"VerticalCSTypeGeoKey",4097:"VerticalCitationGeoKey",4098:"VerticalDatumGeoKey",4099:"VerticalUnitsGeoKey"},g={};for(const e in u)u.hasOwnProperty(e)&&(g[u[e]]=parseInt(e,10))},8694:e=>{function t(e,t,i){const r=new RegExp(t).exec(e.slice(i));return r?i+r.index+r[0].length-1:-1}e.exports=t,e.exports.default=t},9633:(e,t,i)=>{"use strict";i.d(t,{A:()=>Ct});var r=i(8622);const s=new Map;function n(e,t){Array.isArray(e)||(e=[e]),e.forEach((e=>s.set(e,t)))}async function o(e){const t=s.get(e.Compression);if(!t)throw new Error(`Unknown compression method identifier: ${e.Compression}`);return new(await t())(e)}n([void 0,1],(()=>i.e(5121).then(i.bind(i,5121)).then((e=>e.default)))),n(5,(()=>i.e(2764).then(i.bind(i,2764)).then((e=>e.default)))),n(6,(()=>{throw new Error("old style JPEG compression is not supported.")})),n(7,(()=>i.e(6457).then(i.bind(i,6457)).then((e=>e.default)))),n([8,32946],(()=>Promise.all([i.e(3075),i.e(424)]).then(i.bind(i,424)).then((e=>e.default)))),n(32773,(()=>i.e(1030).then(i.bind(i,1030)).then((e=>e.default)))),n(34887,(()=>Promise.all([i.e(3075),i.e(1414)]).then(i.bind(i,1414)).then((async e=>(await e.zstd.init(),e))).then((e=>e.default)))),n(50001,(()=>i.e(6568).then(i.bind(i,6568)).then((e=>e.default))));const a="undefined"!=typeof navigator&&navigator.hardwareConcurrency||2,l=class{constructor(e=a,t){this.workers=null,this._awaitingDecoder=null,this.size=e,this.messageId=0,e&&(this._awaitingDecoder=t?Promise.resolve(t):new Promise((e=>{i.e(2098).then(i.bind(i,2098)).then((t=>{e(t.create)}))})),this._awaitingDecoder.then((t=>{this._awaitingDecoder=null,this.workers=[];for(let i=0;i<e;i++)this.workers.push({worker:t(),idle:!0})})))}async decode(e,t){return this._awaitingDecoder&&await this._awaitingDecoder,0===this.size?o(e).then((i=>i.decode(e,t))):new Promise((i=>{const r=this.workers.find((e=>e.idle))||this.workers[Math.floor(Math.random()*this.size)];r.idle=!1;const s=this.messageId++,n=e=>{e.data.id===s&&(r.idle=!0,i(e.data.decoded),r.worker.removeEventListener("message",n))};r.worker.addEventListener("message",n),r.worker.postMessage({fileDirectory:e,buffer:t,id:s},[t])}))}destroy(){this.workers&&(this.workers.forEach((e=>{e.worker.terminate()})),this.workers=null)}};function h(e){return(t,...i)=>f(e,t,i)}function c(e,t){return h(p(e,t).get)}const{apply:f,construct:u,defineProperty:g,get:d,getOwnPropertyDescriptor:p,getPrototypeOf:y,has:w,ownKeys:m,set:b,setPrototypeOf:S}=Reflect,{EPSILON:A,MAX_SAFE_INTEGER:I,isFinite:_,isNaN:T}=Number,{iterator:x,species:D,toStringTag:E,for:M}=Symbol,P=Object,{create:C,defineProperty:k,freeze:F,is:G}=P,R=P.prototype,O=(R.__lookupGetter__&&h(R.__lookupGetter__),P.hasOwn||h(R.hasOwnProperty),Array),U=(O.isArray,O.prototype),v=(h(U.join),h(U.push),h(U.toLocaleString),U[x]),L=h(v),{abs:B,trunc:z}=Math,N=ArrayBuffer,$=(N.isView,N.prototype),V=(h($.slice),c($,"byteLength"),"undefined"!=typeof SharedArrayBuffer?SharedArrayBuffer:null),K=(V&&c(V.prototype,"byteLength"),y(Uint8Array)),j=(K.from,K.prototype),q=(j[x],h(j.keys),h(j.values),h(j.entries),h(j.set),h(j.reverse),h(j.fill),h(j.copyWithin),h(j.sort),h(j.slice),h(j.subarray),c(j,"buffer"),c(j,"byteOffset"),c(j,"length"),c(j,E),Uint8Array),H=Uint16Array,W=Uint32Array,Y=Float32Array,X=y([][x]()),Z=h(X.next),J=h(function*(){}().next),Q=y(X),ee=DataView.prototype,te=h(ee.getUint16),ie=(h(ee.setUint16),TypeError,WeakSet.prototype),re=(h(ie.add),h(ie.has),WeakMap),se=re.prototype,ne=h(se.get),oe=(h(se.has),h(se.set)),ae=new re,le=C(null,{next:{value:function(){const e=ne(ae,this);return Z(e)}},[x]:{value:function(){return this}}}),he=new re,ce=C(Q,{next:{value:function(){const e=ne(he,this);return J(e)},writable:!0,configurable:!0}});for(const e of m(X))"next"!==e&&k(ce,e,p(X,e));const fe=new N(4),ue=new Y(fe),ge=new W(fe),de=new H(512),pe=new q(512);for(let e=0;e<256;++e){const t=e-127;t<-24?(de[e]=0,de[256|e]=32768,pe[e]=24,pe[256|e]=24):t<-14?(de[e]=1024>>-t-14,de[256|e]=1024>>-t-14|32768,pe[e]=-t-1,pe[256|e]=-t-1):t<=15?(de[e]=t+15<<10,de[256|e]=t+15<<10|32768,pe[e]=13,pe[256|e]=13):t<128?(de[e]=31744,de[256|e]=64512,pe[e]=24,pe[256|e]=24):(de[e]=31744,de[256|e]=64512,pe[e]=13,pe[256|e]=13)}const ye=new W(2048);for(let e=1;e<1024;++e){let t=e<<13,i=0;for(;!(8388608&t);)t<<=1,i-=8388608;t&=-8388609,i+=947912704,ye[e]=t|i}for(let e=1024;e<2048;++e)ye[e]=939524096+(e-1024<<13);const we=new W(64);for(let e=1;e<31;++e)we[e]=e<<23;we[31]=1199570944,we[32]=2147483648;for(let e=33;e<63;++e)we[e]=2147483648+(e-32<<23);we[63]=3347054592;const me=new H(64);for(let e=1;e<64;++e)32!==e&&(me[e]=1024);function be(e,t,...i){return function(e){const t=e>>10;return ge[0]=ye[me[t]+(1023&e)]+we[t],ue[0]}(te(e,t,...function(e){if(e[x]===v&&X.next===Z)return e;const t=C(le);return oe(ae,t,L(e)),t}(i)))}var Se=i(7379),Ae=i(563);function Ie(e,t,i,r=1){return new(Object.getPrototypeOf(e).constructor)(t*i*r)}function _e(e,t,i){return(1-i)*e+i*t}function Te(e,t,i){let r=0;for(let s=t;s<i;++s)r+=e[s];return r}function xe(e,t,i){switch(e){case 1:if(t<=8)return new Uint8Array(i);if(t<=16)return new Uint16Array(i);if(t<=32)return new Uint32Array(i);break;case 2:if(8===t)return new Int8Array(i);if(16===t)return new Int16Array(i);if(32===t)return new Int32Array(i);break;case 3:switch(t){case 16:case 32:return new Float32Array(i);case 64:return new Float64Array(i)}}throw Error("Unsupported data format/bitsPerSample")}const De=class{constructor(e,t,i,r,s,n){this.fileDirectory=e,this.geoKeys=t,this.dataView=i,this.littleEndian=r,this.tiles=s?{}:null,this.isTiled=!e.StripOffsets;const o=e.PlanarConfiguration;if(this.planarConfiguration=void 0===o?1:o,1!==this.planarConfiguration&&2!==this.planarConfiguration)throw new Error("Invalid planar configuration.");this.source=n}getFileDirectory(){return this.fileDirectory}getGeoKeys(){return this.geoKeys}getWidth(){return this.fileDirectory.ImageWidth}getHeight(){return this.fileDirectory.ImageLength}getSamplesPerPixel(){return void 0!==this.fileDirectory.SamplesPerPixel?this.fileDirectory.SamplesPerPixel:1}getTileWidth(){return this.isTiled?this.fileDirectory.TileWidth:this.getWidth()}getTileHeight(){return this.isTiled?this.fileDirectory.TileLength:void 0!==this.fileDirectory.RowsPerStrip?Math.min(this.fileDirectory.RowsPerStrip,this.getHeight()):this.getHeight()}getBlockWidth(){return this.getTileWidth()}getBlockHeight(e){return this.isTiled||(e+1)*this.getTileHeight()<=this.getHeight()?this.getTileHeight():this.getHeight()-e*this.getTileHeight()}getBytesPerPixel(){let e=0;for(let t=0;t<this.fileDirectory.BitsPerSample.length;++t)e+=this.getSampleByteSize(t);return e}getSampleByteSize(e){if(e>=this.fileDirectory.BitsPerSample.length)throw new RangeError(`Sample index ${e} is out of range.`);return Math.ceil(this.fileDirectory.BitsPerSample[e]/8)}getReaderForSample(e){const t=this.fileDirectory.SampleFormat?this.fileDirectory.SampleFormat[e]:1,i=this.fileDirectory.BitsPerSample[e];switch(t){case 1:if(i<=8)return DataView.prototype.getUint8;if(i<=16)return DataView.prototype.getUint16;if(i<=32)return DataView.prototype.getUint32;break;case 2:if(i<=8)return DataView.prototype.getInt8;if(i<=16)return DataView.prototype.getInt16;if(i<=32)return DataView.prototype.getInt32;break;case 3:switch(i){case 16:return function(e,t){return be(this,e,t)};case 32:return DataView.prototype.getFloat32;case 64:return DataView.prototype.getFloat64}}throw Error("Unsupported data format/bitsPerSample")}getSampleFormat(e=0){return this.fileDirectory.SampleFormat?this.fileDirectory.SampleFormat[e]:1}getBitsPerSample(e=0){return this.fileDirectory.BitsPerSample[e]}getArrayForSample(e,t){return xe(this.getSampleFormat(e),this.getBitsPerSample(e),t)}async getTileOrStrip(e,t,i,r,s){const n=Math.ceil(this.getWidth()/this.getTileWidth()),o=Math.ceil(this.getHeight()/this.getTileHeight());let a;const{tiles:l}=this;let h,c;1===this.planarConfiguration?a=t*n+e:2===this.planarConfiguration&&(a=i*n*o+t*n+e),this.isTiled?(h=this.fileDirectory.TileOffsets[a],c=this.fileDirectory.TileByteCounts[a]):(h=this.fileDirectory.StripOffsets[a],c=this.fileDirectory.StripByteCounts[a]);const f=(await this.source.fetch([{offset:h,length:c}],s))[0];let u;return null!==l&&l[a]?u=l[a]:(u=(async()=>{let e=await r.decode(this.fileDirectory,f);const i=this.getSampleFormat(),s=this.getBitsPerSample();return function(e,t){return(1!==e&&2!==e||!(t<=32)||t%8!=0)&&(3!==e||16!==t&&32!==t&&64!==t)}(i,s)&&(e=function(e,t,i,r,s,n,o){const a=new DataView(e),l=2===i?1:r,h=xe(t,s,2===i?o*n:o*n*r),c=parseInt("1".repeat(s),2);if(1===t){let e;e=1===i?r*s:s;let t=n*e;7&t&&(t=t+7&-8);for(let e=0;e<o;++e){const i=e*t;for(let t=0;t<n;++t){const r=i+t*l*s;for(let i=0;i<l;++i){const o=r+i*s,f=(e*n+t)*l+i,u=Math.floor(o/8),g=o%8;if(g+s<=8)h[f]=a.getUint8(u)>>8-s-g&c;else if(g+s<=16)h[f]=a.getUint16(u)>>16-s-g&c;else if(g+s<=24){const e=a.getUint16(u)<<8|a.getUint8(u+2);h[f]=e>>24-s-g&c}else h[f]=a.getUint32(u)>>32-s-g&c}}}}return h.buffer}(e,i,this.planarConfiguration,this.getSamplesPerPixel(),s,this.getTileWidth(),this.getBlockHeight(t))),e})(),null!==l&&(l[a]=u)),{x:e,y:t,sample:i,data:await u}}async _readRaster(e,t,i,r,s,n,o,a,l){const h=this.getTileWidth(),c=this.getTileHeight(),f=this.getWidth(),u=this.getHeight(),g=Math.max(Math.floor(e[0]/h),0),d=Math.min(Math.ceil(e[2]/h),Math.ceil(f/h)),p=Math.max(Math.floor(e[1]/c),0),y=Math.min(Math.ceil(e[3]/c),Math.ceil(u/c)),w=e[2]-e[0];let m=this.getBytesPerPixel();const b=[],S=[];for(let e=0;e<t.length;++e)1===this.planarConfiguration?b.push(Te(this.fileDirectory.BitsPerSample,0,t[e])/8):b.push(0),S.push(this.getReaderForSample(t[e]));const A=[],{littleEndian:I}=this;for(let n=p;n<y;++n)for(let o=g;o<d;++o){let a;1===this.planarConfiguration&&(a=this.getTileOrStrip(o,n,0,s,l));for(let g=0;g<t.length;++g){const d=g,p=t[g];2===this.planarConfiguration&&(m=this.getSampleByteSize(p),a=this.getTileOrStrip(o,n,p,s,l));const y=a.then((s=>{const n=s.data,o=new DataView(n),a=this.getBlockHeight(s.y),l=s.y*c,g=s.x*h,p=l+a,y=(s.x+1)*h,A=S[d],_=Math.min(a,a-(p-e[3]),u-l),T=Math.min(h,h-(y-e[2]),f-g);for(let s=Math.max(0,e[1]-l);s<_;++s)for(let n=Math.max(0,e[0]-g);n<T;++n){const a=(s*h+n)*m,c=A.call(o,a+b[d],I);let f;r?(f=(s+l-e[1])*w*t.length+(n+g-e[0])*t.length+d,i[f]=c):(f=(s+l-e[1])*w+n+g-e[0],i[d][f]=c)}}));A.push(y)}}if(await Promise.all(A),n&&e[2]-e[0]!==n||o&&e[3]-e[1]!==o){let s;return s=r?function(e,t,i,r,s,n,o="nearest"){switch(o.toLowerCase()){case"nearest":return function(e,t,i,r,s,n){const o=t/r,a=i/s,l=Ie(e,r,s,n);for(let h=0;h<s;++h){const s=Math.min(Math.round(a*h),i-1);for(let i=0;i<r;++i){const a=Math.min(Math.round(o*i),t-1);for(let o=0;o<n;++o){const c=e[s*t*n+a*n+o];l[h*r*n+i*n+o]=c}}}return l}(e,t,i,r,s,n);case"bilinear":case"linear":return function(e,t,i,r,s,n){const o=t/r,a=i/s,l=Ie(e,r,s,n);for(let h=0;h<s;++h){const s=a*h,c=Math.floor(s),f=Math.min(Math.ceil(s),i-1);for(let i=0;i<r;++i){const a=o*i,u=a%1,g=Math.floor(a),d=Math.min(Math.ceil(a),t-1);for(let o=0;o<n;++o){const a=e[c*t*n+g*n+o],p=e[c*t*n+d*n+o],y=e[f*t*n+g*n+o],w=e[f*t*n+d*n+o],m=_e(_e(a,p,u),_e(y,w,u),s%1);l[h*r*n+i*n+o]=m}}}return l}(e,t,i,r,s,n);default:throw new Error(`Unsupported resampling method: '${o}'`)}}(i,e[2]-e[0],e[3]-e[1],n,o,t.length,a):function(e,t,i,r,s,n="nearest"){switch(n.toLowerCase()){case"nearest":return function(e,t,i,r,s){const n=t/r,o=i/s;return e.map((e=>{const a=Ie(e,r,s);for(let l=0;l<s;++l){const s=Math.min(Math.round(o*l),i-1);for(let i=0;i<r;++i){const o=Math.min(Math.round(n*i),t-1),h=e[s*t+o];a[l*r+i]=h}}return a}))}(e,t,i,r,s);case"bilinear":case"linear":return function(e,t,i,r,s){const n=t/r,o=i/s;return e.map((e=>{const a=Ie(e,r,s);for(let l=0;l<s;++l){const s=o*l,h=Math.floor(s),c=Math.min(Math.ceil(s),i-1);for(let i=0;i<r;++i){const o=n*i,f=o%1,u=Math.floor(o),g=Math.min(Math.ceil(o),t-1),d=e[h*t+u],p=e[h*t+g],y=e[c*t+u],w=e[c*t+g],m=_e(_e(d,p,f),_e(y,w,f),s%1);a[l*r+i]=m}}return a}))}(e,t,i,r,s);default:throw new Error(`Unsupported resampling method: '${n}'`)}}(i,e[2]-e[0],e[3]-e[1],n,o,a),s.width=n,s.height=o,s}return i.width=n||e[2]-e[0],i.height=o||e[3]-e[1],i}async readRasters({window:e,samples:t=[],interleave:i,pool:r=null,width:s,height:n,resampleMethod:a,fillValue:l,signal:h}={}){const c=e||[0,0,this.getWidth(),this.getHeight()];if(c[0]>c[2]||c[1]>c[3])throw new Error("Invalid subsets");const f=(c[2]-c[0])*(c[3]-c[1]),u=this.getSamplesPerPixel();if(t&&t.length){for(let e=0;e<t.length;++e)if(t[e]>=u)return Promise.reject(new RangeError(`Invalid sample index '${t[e]}'.`))}else for(let e=0;e<u;++e)t.push(e);let g;if(i)g=xe(this.fileDirectory.SampleFormat?Math.max.apply(null,this.fileDirectory.SampleFormat):1,Math.max.apply(null,this.fileDirectory.BitsPerSample),f*t.length),l&&g.fill(l);else{g=[];for(let e=0;e<t.length;++e){const i=this.getArrayForSample(t[e],f);Array.isArray(l)&&e<l.length?i.fill(l[e]):l&&!Array.isArray(l)&&i.fill(l),g.push(i)}}const d=r||await o(this.fileDirectory);return await this._readRaster(c,t,g,i,d,s,n,a,h)}async readRGB({window:e,interleave:t=!0,pool:i=null,width:s,height:n,resampleMethod:o,enableAlpha:a=!1,signal:l}={}){const h=e||[0,0,this.getWidth(),this.getHeight()];if(h[0]>h[2]||h[1]>h[3])throw new Error("Invalid subsets");const c=this.fileDirectory.PhotometricInterpretation;if(c===r.ub.RGB){let h=[0,1,2];if(this.fileDirectory.ExtraSamples!==r.AC.Unspecified&&a){h=[];for(let e=0;e<this.fileDirectory.BitsPerSample.length;e+=1)h.push(e)}return this.readRasters({window:e,interleave:t,samples:h,pool:i,width:s,height:n,resampleMethod:o,signal:l})}let f;switch(c){case r.ub.WhiteIsZero:case r.ub.BlackIsZero:case r.ub.Palette:f=[0];break;case r.ub.CMYK:f=[0,1,2,3];break;case r.ub.YCbCr:case r.ub.CIELab:f=[0,1,2];break;default:throw new Error("Invalid or unsupported photometric interpretation.")}const u={window:h,interleave:!0,samples:f,pool:i,width:s,height:n,resampleMethod:o,signal:l},{fileDirectory:g}=this,d=await this.readRasters(u),p=2**this.fileDirectory.BitsPerSample[0];let y;switch(c){case r.ub.WhiteIsZero:y=function(e,t){const{width:i,height:r}=e,s=new Uint8Array(i*r*3);let n;for(let i=0,r=0;i<e.length;++i,r+=3)n=256-e[i]/t*256,s[r]=n,s[r+1]=n,s[r+2]=n;return s}(d,p);break;case r.ub.BlackIsZero:y=function(e,t){const{width:i,height:r}=e,s=new Uint8Array(i*r*3);let n;for(let i=0,r=0;i<e.length;++i,r+=3)n=e[i]/t*256,s[r]=n,s[r+1]=n,s[r+2]=n;return s}(d,p);break;case r.ub.Palette:y=function(e,t){const{width:i,height:r}=e,s=new Uint8Array(i*r*3),n=t.length/3,o=t.length/3*2;for(let i=0,r=0;i<e.length;++i,r+=3){const a=e[i];s[r]=t[a]/65536*256,s[r+1]=t[a+n]/65536*256,s[r+2]=t[a+o]/65536*256}return s}(d,g.ColorMap);break;case r.ub.CMYK:y=function(e){const{width:t,height:i}=e,r=new Uint8Array(t*i*3);for(let t=0,i=0;t<e.length;t+=4,i+=3){const s=e[t],n=e[t+1],o=e[t+2],a=e[t+3];r[i]=(255-s)/256*255*((255-a)/256),r[i+1]=(255-n)/256*255*((255-a)/256),r[i+2]=(255-o)/256*255*((255-a)/256)}return r}(d);break;case r.ub.YCbCr:y=function(e){const{width:t,height:i}=e,r=new Uint8ClampedArray(t*i*3);for(let t=0,i=0;t<e.length;t+=3,i+=3){const s=e[t],n=e[t+1],o=e[t+2];r[i]=s+1.402*(o-128),r[i+1]=s-.34414*(n-128)-.71414*(o-128),r[i+2]=s+1.772*(n-128)}return r}(d);break;case r.ub.CIELab:y=function(e){const{width:t,height:i}=e,r=new Uint8Array(t*i*3);for(let t=0,i=0;t<e.length;t+=3,i+=3){let s,n,o,a=(e[t+0]+16)/116,l=(e[t+1]<<24>>24)/500+a,h=a-(e[t+2]<<24>>24)/200;l=.95047*(l*l*l>.008856?l*l*l:(l-16/116)/7.787),a=1*(a*a*a>.008856?a*a*a:(a-16/116)/7.787),h=1.08883*(h*h*h>.008856?h*h*h:(h-16/116)/7.787),s=3.2406*l+-1.5372*a+-.4986*h,n=-.9689*l+1.8758*a+.0415*h,o=.0557*l+-.204*a+1.057*h,s=s>.0031308?1.055*s**(1/2.4)-.055:12.92*s,n=n>.0031308?1.055*n**(1/2.4)-.055:12.92*n,o=o>.0031308?1.055*o**(1/2.4)-.055:12.92*o,r[i]=255*Math.max(0,Math.min(1,s)),r[i+1]=255*Math.max(0,Math.min(1,n)),r[i+2]=255*Math.max(0,Math.min(1,o))}return r}(d);break;default:throw new Error("Unsupported photometric interpretation.")}if(!t){const e=new Uint8Array(y.length/3),t=new Uint8Array(y.length/3),i=new Uint8Array(y.length/3);for(let r=0,s=0;r<y.length;r+=3,++s)e[s]=y[r],t[s]=y[r+1],i[s]=y[r+2];y=[e,t,i]}return y.width=d.width,y.height=d.height,y}getTiePoints(){if(!this.fileDirectory.ModelTiepoint)return[];const e=[];for(let t=0;t<this.fileDirectory.ModelTiepoint.length;t+=6)e.push({i:this.fileDirectory.ModelTiepoint[t],j:this.fileDirectory.ModelTiepoint[t+1],k:this.fileDirectory.ModelTiepoint[t+2],x:this.fileDirectory.ModelTiepoint[t+3],y:this.fileDirectory.ModelTiepoint[t+4],z:this.fileDirectory.ModelTiepoint[t+5]});return e}getGDALMetadata(e=null){const t={};if(!this.fileDirectory.GDAL_METADATA)return null;const i=this.fileDirectory.GDAL_METADATA;let r=Ae(i,"Item");r=null===e?r.filter((e=>void 0===Se(e,"sample"))):r.filter((t=>Number(Se(t,"sample"))===e));for(let e=0;e<r.length;++e){const i=r[e];t[Se(i,"name")]=i.inner}return t}getGDALNoData(){if(!this.fileDirectory.GDAL_NODATA)return null;const e=this.fileDirectory.GDAL_NODATA;return Number(e.substring(0,e.length-1))}getOrigin(){const e=this.fileDirectory.ModelTiepoint,t=this.fileDirectory.ModelTransformation;if(e&&6===e.length)return[e[3],e[4],e[5]];if(t)return[t[3],t[7],t[11]];throw new Error("The image does not have an affine transformation.")}getResolution(e=null){const t=this.fileDirectory.ModelPixelScale,i=this.fileDirectory.ModelTransformation;if(t)return[t[0],-t[1],t[2]];if(i)return 0===i[1]&&0===i[4]?[i[0],-i[5],i[10]]:[Math.sqrt(i[0]*i[0]+i[4]*i[4]),-Math.sqrt(i[1]*i[1]+i[5]*i[5]),i[10]];if(e){const[t,i,r]=e.getResolution();return[t*e.getWidth()/this.getWidth(),i*e.getHeight()/this.getHeight(),r*e.getWidth()/this.getWidth()]}throw new Error("The image does not have an affine transformation.")}pixelIsArea(){return 1===this.geoKeys.GTRasterTypeGeoKey}getBoundingBox(e=!1){const t=this.getHeight(),i=this.getWidth();if(this.fileDirectory.ModelTransformation&&!e){const[e,r,s,n,o,a,l,h]=this.fileDirectory.ModelTransformation,c=[[0,0],[0,t],[i,0],[i,t]].map((([t,i])=>[n+e*t+r*i,h+o*t+a*i])),f=c.map((e=>e[0])),u=c.map((e=>e[1]));return[Math.min(...f),Math.min(...u),Math.max(...f),Math.max(...u)]}{const e=this.getOrigin(),r=this.getResolution(),s=e[0],n=e[1],o=s+r[0]*i,a=n+r[1]*t;return[Math.min(s,o),Math.min(n,a),Math.max(s,o),Math.max(n,a)]}}};class Ee{constructor(e){this._dataView=new DataView(e)}get buffer(){return this._dataView.buffer}getUint64(e,t){const i=this.getUint32(e,t),r=this.getUint32(e+4,t);let s;if(t){if(s=i+2**32*r,!Number.isSafeInteger(s))throw new Error(`${s} exceeds MAX_SAFE_INTEGER. Precision may be lost. Please report if you get this message to https://github.com/geotiffjs/geotiff.js/issues`);return s}if(s=2**32*i+r,!Number.isSafeInteger(s))throw new Error(`${s} exceeds MAX_SAFE_INTEGER. Precision may be lost. Please report if you get this message to https://github.com/geotiffjs/geotiff.js/issues`);return s}getInt64(e,t){let i=0;const r=(128&this._dataView.getUint8(e+(t?7:0)))>0;let s=!0;for(let n=0;n<8;n++){let o=this._dataView.getUint8(e+(t?n:7-n));r&&(s?0!==o&&(o=255&~(o-1),s=!1):o=255&~o),i+=o*256**n}return r&&(i=-i),i}getUint8(e,t){return this._dataView.getUint8(e,t)}getInt8(e,t){return this._dataView.getInt8(e,t)}getUint16(e,t){return this._dataView.getUint16(e,t)}getInt16(e,t){return this._dataView.getInt16(e,t)}getUint32(e,t){return this._dataView.getUint32(e,t)}getInt32(e,t){return this._dataView.getInt32(e,t)}getFloat16(e,t){return be(this._dataView,e,t)}getFloat32(e,t){return this._dataView.getFloat32(e,t)}getFloat64(e,t){return this._dataView.getFloat64(e,t)}}class Me{constructor(e,t,i,r){this._dataView=new DataView(e),this._sliceOffset=t,this._littleEndian=i,this._bigTiff=r}get sliceOffset(){return this._sliceOffset}get sliceTop(){return this._sliceOffset+this.buffer.byteLength}get littleEndian(){return this._littleEndian}get bigTiff(){return this._bigTiff}get buffer(){return this._dataView.buffer}covers(e,t){return this.sliceOffset<=e&&this.sliceTop>=e+t}readUint8(e){return this._dataView.getUint8(e-this._sliceOffset,this._littleEndian)}readInt8(e){return this._dataView.getInt8(e-this._sliceOffset,this._littleEndian)}readUint16(e){return this._dataView.getUint16(e-this._sliceOffset,this._littleEndian)}readInt16(e){return this._dataView.getInt16(e-this._sliceOffset,this._littleEndian)}readUint32(e){return this._dataView.getUint32(e-this._sliceOffset,this._littleEndian)}readInt32(e){return this._dataView.getInt32(e-this._sliceOffset,this._littleEndian)}readFloat32(e){return this._dataView.getFloat32(e-this._sliceOffset,this._littleEndian)}readFloat64(e){return this._dataView.getFloat64(e-this._sliceOffset,this._littleEndian)}readUint64(e){const t=this.readUint32(e),i=this.readUint32(e+4);let r;if(this._littleEndian){if(r=t+2**32*i,!Number.isSafeInteger(r))throw new Error(`${r} exceeds MAX_SAFE_INTEGER. Precision may be lost. Please report if you get this message to https://github.com/geotiffjs/geotiff.js/issues`);return r}if(r=2**32*t+i,!Number.isSafeInteger(r))throw new Error(`${r} exceeds MAX_SAFE_INTEGER. Precision may be lost. Please report if you get this message to https://github.com/geotiffjs/geotiff.js/issues`);return r}readInt64(e){let t=0;const i=(128&this._dataView.getUint8(e+(this._littleEndian?7:0)))>0;let r=!0;for(let s=0;s<8;s++){let n=this._dataView.getUint8(e+(this._littleEndian?s:7-s));i&&(r?0!==n&&(n=255&~(n-1),r=!1):n=255&~n),t+=n*256**s}return i&&(t=-t),t}readOffset(e){return this._bigTiff?this.readUint64(e):this.readUint32(e)}}function Pe(e){if(void 0!==Object.fromEntries)return Object.fromEntries(e);const t={};for(const[i,r]of e)t[i.toLowerCase()]=r;return t}function Ce(e){return Pe(e.split("\r\n").map((e=>{const t=e.split(":").map((e=>e.trim()));return t[0]=t[0].toLowerCase(),t})))}function ke(e){let t,i,r;return e&&([,t,i,r]=e.match(/bytes (\d+)-(\d+)\/(\d+)/),t=parseInt(t,10),i=parseInt(i,10),r=parseInt(r,10)),{start:t,end:i,total:r}}class Fe{async fetch(e,t=void 0){return Promise.all(e.map((e=>this.fetchSlice(e,t))))}async fetchSlice(e){throw new Error(`fetching of slice ${e} not possible, not implemented`)}get fileSize(){return null}async close(){}}class Ge extends Map{constructor(e={}){if(super(),!(e.maxSize&&e.maxSize>0))throw new TypeError("`maxSize` must be a number greater than 0");if("number"==typeof e.maxAge&&0===e.maxAge)throw new TypeError("`maxAge` must be a number greater than 0");this.maxSize=e.maxSize,this.maxAge=e.maxAge||Number.POSITIVE_INFINITY,this.onEviction=e.onEviction,this.cache=new Map,this.oldCache=new Map,this._size=0}_emitEvictions(e){if("function"==typeof this.onEviction)for(const[t,i]of e)this.onEviction(t,i.value)}_deleteIfExpired(e,t){return"number"==typeof t.expiry&&t.expiry<=Date.now()&&("function"==typeof this.onEviction&&this.onEviction(e,t.value),this.delete(e))}_getOrDeleteIfExpired(e,t){if(!1===this._deleteIfExpired(e,t))return t.value}_getItemValue(e,t){return t.expiry?this._getOrDeleteIfExpired(e,t):t.value}_peek(e,t){const i=t.get(e);return this._getItemValue(e,i)}_set(e,t){this.cache.set(e,t),this._size++,this._size>=this.maxSize&&(this._size=0,this._emitEvictions(this.oldCache),this.oldCache=this.cache,this.cache=new Map)}_moveToRecent(e,t){this.oldCache.delete(e),this._set(e,t)}*_entriesAscending(){for(const e of this.oldCache){const[t,i]=e;this.cache.has(t)||!1===this._deleteIfExpired(t,i)&&(yield e)}for(const e of this.cache){const[t,i]=e;!1===this._deleteIfExpired(t,i)&&(yield e)}}get(e){if(this.cache.has(e)){const t=this.cache.get(e);return this._getItemValue(e,t)}if(this.oldCache.has(e)){const t=this.oldCache.get(e);if(!1===this._deleteIfExpired(e,t))return this._moveToRecent(e,t),t.value}}set(e,t,{maxAge:i=this.maxAge}={}){const r="number"==typeof i&&i!==Number.POSITIVE_INFINITY?Date.now()+i:void 0;return this.cache.has(e)?this.cache.set(e,{value:t,expiry:r}):this._set(e,{value:t,expiry:r}),this}has(e){return this.cache.has(e)?!this._deleteIfExpired(e,this.cache.get(e)):!!this.oldCache.has(e)&&!this._deleteIfExpired(e,this.oldCache.get(e))}peek(e){return this.cache.has(e)?this._peek(e,this.cache):this.oldCache.has(e)?this._peek(e,this.oldCache):void 0}delete(e){const t=this.cache.delete(e);return t&&this._size--,this.oldCache.delete(e)||t}clear(){this.cache.clear(),this.oldCache.clear(),this._size=0}resize(e){if(!(e&&e>0))throw new TypeError("`maxSize` must be a number greater than 0");const t=[...this._entriesAscending()],i=t.length-e;i<0?(this.cache=new Map(t),this.oldCache=new Map,this._size=t.length):(i>0&&this._emitEvictions(t.slice(0,i)),this.oldCache=new Map(t.slice(i)),this.cache=new Map,this._size=0),this.maxSize=e}*keys(){for(const[e]of this)yield e}*values(){for(const[,e]of this)yield e}*[Symbol.iterator](){for(const e of this.cache){const[t,i]=e;!1===this._deleteIfExpired(t,i)&&(yield[t,i.value])}for(const e of this.oldCache){const[t,i]=e;this.cache.has(t)||!1===this._deleteIfExpired(t,i)&&(yield[t,i.value])}}*entriesDescending(){let e=[...this.cache];for(let t=e.length-1;t>=0;--t){const i=e[t],[r,s]=i;!1===this._deleteIfExpired(r,s)&&(yield[r,s.value])}e=[...this.oldCache];for(let t=e.length-1;t>=0;--t){const i=e[t],[r,s]=i;this.cache.has(r)||!1===this._deleteIfExpired(r,s)&&(yield[r,s.value])}}*entriesAscending(){for(const[e,t]of this._entriesAscending())yield[e,t.value]}get size(){if(!this._size)return this.oldCache.size;let e=0;for(const t of this.oldCache.keys())this.cache.has(t)||e++;return Math.min(this._size+e,this.maxSize)}entries(){return this.entriesAscending()}forEach(e,t=this){for(const[i,r]of this.entriesAscending())e.call(t,r,i,this)}get[Symbol.toStringTag](){return JSON.stringify([...this.entriesAscending()])}}class Re extends Error{constructor(e){super(e),Error.captureStackTrace&&Error.captureStackTrace(this,Re),this.name="AbortError"}}class Oe extends Error{constructor(e,t){super(t),this.errors=e,this.message=t,this.name="AggregateError"}}const Ue=Oe;class ve{constructor(e,t,i=null){this.offset=e,this.length=t,this.data=i}get top(){return this.offset+this.length}}class Le{constructor(e,t,i){this.offset=e,this.length=t,this.blockIds=i}}class Be extends Fe{constructor(e,{blockSize:t=65536,cacheSize:i=100}={}){super(),this.source=e,this.blockSize=t,this.blockCache=new Ge({maxSize:i,onEviction:(e,t)=>{this.evictedBlocks.set(e,t)}}),this.evictedBlocks=new Map,this.blockRequests=new Map,this.blockIdsToFetch=new Set,this.abortedBlockIds=new Set}get fileSize(){return this.source.fileSize}async fetch(e,t){const i=[],r=[],s=[];this.evictedBlocks.clear();for(const{offset:t,length:n}of e){let e=t+n;const{fileSize:o}=this;null!==o&&(e=Math.min(e,o));for(let n=Math.floor(t/this.blockSize)*this.blockSize;n<e;n+=this.blockSize){const e=Math.floor(n/this.blockSize);this.blockCache.has(e)||this.blockRequests.has(e)||(this.blockIdsToFetch.add(e),r.push(e)),this.blockRequests.has(e)&&i.push(this.blockRequests.get(e)),s.push(e)}}await async function(){return new Promise((e=>setTimeout(e,undefined)))}(),this.fetchBlocks(t);const n=[];for(const e of r)this.blockRequests.has(e)&&n.push(this.blockRequests.get(e));await Promise.allSettled(i),await Promise.allSettled(n);const o=[],a=s.filter((e=>this.abortedBlockIds.has(e)||!this.blockCache.has(e)));if(a.forEach((e=>this.blockIdsToFetch.add(e))),a.length>0&&t&&!t.aborted){this.fetchBlocks(null);for(const e of a){const t=this.blockRequests.get(e);if(!t)throw new Error(`Block ${e} is not in the block requests`);o.push(t)}await Promise.allSettled(o)}if(t&&t.aborted)throw new Re("Request was aborted");const l=s.map((e=>this.blockCache.get(e)||this.evictedBlocks.get(e))),h=l.filter((e=>!e));if(h.length)throw new Ue(h,"Request failed");const c=new Map(function(e,t){const i=Array.isArray(e)?e:Array.from(e),r=Array.isArray(t)?t:Array.from(t);return i.map(((e,t)=>[e,r[t]]))}(s,l));return this.readSliceData(e,c)}fetchBlocks(e){if(this.blockIdsToFetch.size>0){const t=this.groupBlocks(this.blockIdsToFetch),i=this.source.fetch(t,e);for(let r=0;r<t.length;++r){const s=t[r];for(const t of s.blockIds)this.blockRequests.set(t,(async()=>{try{const e=(await i)[r],s=t*this.blockSize,n=s-e.offset,o=Math.min(n+this.blockSize,e.data.byteLength),a=e.data.slice(n,o),l=new ve(s,a.byteLength,a,t);this.blockCache.set(t,l),this.abortedBlockIds.delete(t)}catch(i){if("AbortError"!==i.name)throw i;i.signal=e,this.blockCache.delete(t),this.abortedBlockIds.add(t)}finally{this.blockRequests.delete(t)}})())}this.blockIdsToFetch.clear()}}groupBlocks(e){const t=Array.from(e).sort(((e,t)=>e-t));if(0===t.length)return[];let i=[],r=null;const s=[];for(const e of t)null===r||r+1===e?(i.push(e),r=e):(s.push(new Le(i[0]*this.blockSize,i.length*this.blockSize,i)),i=[e],r=e);return s.push(new Le(i[0]*this.blockSize,i.length*this.blockSize,i)),s}readSliceData(e,t){return e.map((e=>{let i=e.offset+e.length;null!==this.fileSize&&(i=Math.min(this.fileSize,i));const r=Math.floor(e.offset/this.blockSize),s=Math.floor(i/this.blockSize),n=new ArrayBuffer(e.length),o=new Uint8Array(n);for(let n=r;n<=s;++n){const r=t.get(n),s=r.offset-e.offset;let a,l=0,h=0;s<0?l=-s:s>0&&(h=s),a=r.top-i<0?r.length-l:i-r.offset-l;const c=new Uint8Array(r.data,l,a);o.set(c,h)}return n}))}}class ze{get ok(){return this.status>=200&&this.status<=299}get status(){throw new Error("not implemented")}getHeader(e){throw new Error("not implemented")}async getData(){throw new Error("not implemented")}}class Ne{constructor(e){this.url=e}async request({headers:e,signal:t}={}){throw new Error("request is not implemented")}}class $e extends ze{constructor(e){super(),this.response=e}get status(){return this.response.status}getHeader(e){return this.response.headers.get(e)}async getData(){return this.response.arrayBuffer?await this.response.arrayBuffer():(await this.response.buffer()).buffer}}class Ve extends Ne{constructor(e,t){super(e),this.credentials=t}async request({headers:e,signal:t}={}){const i=await fetch(this.url,{headers:e,credentials:this.credentials,signal:t});return new $e(i)}}class Ke extends ze{constructor(e,t){super(),this.xhr=e,this.data=t}get status(){return this.xhr.status}getHeader(e){return this.xhr.getResponseHeader(e)}async getData(){return this.data}}class je extends Ne{constructRequest(e,t){return new Promise(((i,r)=>{const s=new XMLHttpRequest;s.open("GET",this.url),s.responseType="arraybuffer";for(const[t,i]of Object.entries(e))s.setRequestHeader(t,i);s.onload=()=>{const e=s.response;i(new Ke(s,e))},s.onerror=r,s.onabort=()=>r(new Re("Request aborted")),s.send(),t&&(t.aborted&&s.abort(),t.addEventListener("abort",(()=>s.abort())))}))}async request({headers:e,signal:t}={}){return await this.constructRequest(e,t)}}var qe=i(8625),He=i(6504),We=i(6580);class Ye extends ze{constructor(e,t){super(),this.response=e,this.dataPromise=t}get status(){return this.response.statusCode}getHeader(e){return this.response.headers[e]}async getData(){return await this.dataPromise}}class Xe extends Ne{constructor(e){super(e),this.parsedUrl=We.parse(this.url),this.httpApi="http:"===this.parsedUrl.protocol?qe:He}constructRequest(e,t){return new Promise(((i,r)=>{const s=this.httpApi.get({...this.parsedUrl,headers:e},(e=>{const t=new Promise((t=>{const i=[];e.on("data",(e=>{i.push(e)})),e.on("end",(()=>{const e=Buffer.concat(i).buffer;t(e)})),e.on("error",r)}));i(new Ye(e,t))}));s.on("error",r),t&&(t.aborted&&s.destroy(new Re("Request aborted")),t.addEventListener("abort",(()=>s.destroy(new Re("Request aborted")))))}))}async request({headers:e,signal:t}={}){return await this.constructRequest(e,t)}}class Ze extends Fe{constructor(e,t,i,r){super(),this.client=e,this.headers=t,this.maxRanges=i,this.allowFullFile=r,this._fileSize=null}async fetch(e,t){return this.maxRanges>=e.length?this.fetchSlices(e,t):(this.maxRanges>0&&e.length,Promise.all(e.map((e=>this.fetchSlice(e,t)))))}async fetchSlices(e,t){const i=await this.client.request({headers:{...this.headers,Range:`bytes=${e.map((({offset:e,length:t})=>`${e}-${e+t}`)).join(",")}`},signal:t});if(i.ok){if(206===i.status){const{type:r,params:s}=function(e){const[t,...i]=e.split(";").map((e=>e.trim()));return{type:t,params:Pe(i.map((e=>e.split("="))))}}(i.getHeader("content-type"));if("multipart/byteranges"===r){const e=function(e,t){let i=null;const r=new TextDecoder("ascii"),s=[],n=`--${t}`,o=`${n}--`;for(let t=0;t<10;++t)r.decode(new Uint8Array(e,t,n.length))===n&&(i=t);if(null===i)throw new Error("Could not find initial boundary");for(;i<e.byteLength;){const t=r.decode(new Uint8Array(e,i,Math.min(n.length+1024,e.byteLength-i)));if(0===t.length||t.startsWith(o))break;if(!t.startsWith(n))throw new Error("Part does not start with boundary");const a=t.substr(n.length+2);if(0===a.length)break;const l=a.indexOf("\r\n\r\n"),h=Ce(a.substr(0,l)),{start:c,end:f,total:u}=ke(h["content-range"]),g=i+n.length+l+4,d=parseInt(f,10)+1-parseInt(c,10);s.push({headers:h,data:e.slice(g,g+d),offset:c,length:d,fileSize:u}),i=g+d+4}return s}(await i.getData(),s.boundary);return this._fileSize=e[0].fileSize||null,e}const n=await i.getData(),{start:o,end:a,total:l}=ke(i.getHeader("content-range"));this._fileSize=l||null;const h=[{data:n,offset:o,length:a-o}];if(e.length>1){const i=await Promise.all(e.slice(1).map((e=>this.fetchSlice(e,t))));return h.concat(i)}return h}{if(!this.allowFullFile)throw new Error("Server responded with full file");const e=await i.getData();return this._fileSize=e.byteLength,[{data:e,offset:0,length:e.byteLength}]}}throw new Error("Error fetching data.")}async fetchSlice(e,t){const{offset:i,length:r}=e,s=await this.client.request({headers:{...this.headers,Range:`bytes=${i}-${i+r}`},signal:t});if(s.ok){if(206===s.status){const e=await s.getData(),{total:t}=ke(s.getHeader("content-range"));return this._fileSize=t||null,{data:e,offset:i,length:r}}{if(!this.allowFullFile)throw new Error("Server responded with full file");const e=await s.getData();return this._fileSize=e.byteLength,{data:e,offset:0,length:e.byteLength}}}throw new Error("Error fetching data.")}get fileSize(){return this._fileSize}}function Je(e,{blockSize:t,cacheSize:i}){return null===t?e:new Be(e,{blockSize:t,cacheSize:i})}function Qe(e,{forceXHR:t=!1,...i}={}){return"function"!=typeof fetch||t?"undefined"!=typeof XMLHttpRequest?function(e,{headers:t={},maxRanges:i=0,allowFullFile:r=!1,...s}={}){const n=new je(e);return Je(new Ze(n,t,i,r),s)}(e,i):function(e,{headers:t={},maxRanges:i=0,allowFullFile:r=!1,...s}={}){const n=new Xe(e);return Je(new Ze(n,t,i,r),s)}(e,i):function(e,{headers:t={},credentials:i,maxRanges:r=0,allowFullFile:s=!1,...n}={}){const o=new Ve(e,i);return Je(new Ze(o,t,r,s),n)}(e,i)}class et extends Fe{constructor(e){super(),this.file=e}async fetchSlice(e,t){return new Promise(((i,r)=>{const s=this.file.slice(e.offset,e.offset+e.length),n=new FileReader;n.onload=e=>i(e.target.result),n.onerror=r,n.onabort=r,n.readAsArrayBuffer(s),t&&t.addEventListener("abort",(()=>n.abort()))}))}}function tt(e){switch(e){case r.s$.BYTE:case r.s$.ASCII:case r.s$.SBYTE:case r.s$.UNDEFINED:return 1;case r.s$.SHORT:case r.s$.SSHORT:return 2;case r.s$.LONG:case r.s$.SLONG:case r.s$.FLOAT:case r.s$.IFD:return 4;case r.s$.RATIONAL:case r.s$.SRATIONAL:case r.s$.DOUBLE:case r.s$.LONG8:case r.s$.SLONG8:case r.s$.IFD8:return 8;default:throw new RangeError(`Invalid field type: ${e}`)}}function it(e,t,i,s){let n=null,o=null;const a=tt(t);switch(t){case r.s$.BYTE:case r.s$.ASCII:case r.s$.UNDEFINED:n=new Uint8Array(i),o=e.readUint8;break;case r.s$.SBYTE:n=new Int8Array(i),o=e.readInt8;break;case r.s$.SHORT:n=new Uint16Array(i),o=e.readUint16;break;case r.s$.SSHORT:n=new Int16Array(i),o=e.readInt16;break;case r.s$.LONG:case r.s$.IFD:n=new Uint32Array(i),o=e.readUint32;break;case r.s$.SLONG:n=new Int32Array(i),o=e.readInt32;break;case r.s$.LONG8:case r.s$.IFD8:n=new Array(i),o=e.readUint64;break;case r.s$.SLONG8:n=new Array(i),o=e.readInt64;break;case r.s$.RATIONAL:n=new Uint32Array(2*i),o=e.readUint32;break;case r.s$.SRATIONAL:n=new Int32Array(2*i),o=e.readInt32;break;case r.s$.FLOAT:n=new Float32Array(i),o=e.readFloat32;break;case r.s$.DOUBLE:n=new Float64Array(i),o=e.readFloat64;break;default:throw new RangeError(`Invalid field type: ${t}`)}if(t!==r.s$.RATIONAL&&t!==r.s$.SRATIONAL)for(let t=0;t<i;++t)n[t]=o.call(e,s+t*a);else for(let t=0;t<i;t+=2)n[t]=o.call(e,s+t*a),n[t+1]=o.call(e,s+(t*a+4));return t===r.s$.ASCII?new TextDecoder("utf-8").decode(n):n}class rt{constructor(e,t,i){this.fileDirectory=e,this.geoKeyDirectory=t,this.nextIFDByteOffset=i}}class st extends Error{constructor(e){super(`No image at index ${e}`),this.index=e}}class nt{async readRasters(e={}){const{window:t,width:i,height:r}=e;let{resX:s,resY:n,bbox:o}=e;const a=await this.getImage();let l=a;const h=await this.getImageCount(),c=a.getBoundingBox();if(t&&o)throw new Error('Both "bbox" and "window" passed.');if(i||r){if(t){const[e,i]=a.getOrigin(),[r,s]=a.getResolution();o=[e+t[0]*r,i+t[1]*s,e+t[2]*r,i+t[3]*s]}const e=o||c;if(i){if(s)throw new Error("Both width and resX passed");s=(e[2]-e[0])/i}if(r){if(n)throw new Error("Both width and resY passed");n=(e[3]-e[1])/r}}if(s||n){const e=[];for(let t=0;t<h;++t){const i=await this.getImage(t),{SubfileType:r,NewSubfileType:s}=i.fileDirectory;(0===t||2===r||1&s)&&e.push(i)}e.sort(((e,t)=>e.getWidth()-t.getWidth()));for(let t=0;t<e.length;++t){const i=e[t],r=(c[2]-c[0])/i.getWidth(),o=(c[3]-c[1])/i.getHeight();if(l=i,s&&s>r||n&&n>o)break}}let f=t;if(o){const[e,t]=a.getOrigin(),[i,r]=l.getResolution(a);f=[Math.round((o[0]-e)/i),Math.round((o[1]-t)/r),Math.round((o[2]-e)/i),Math.round((o[3]-t)/r)],f=[Math.min(f[0],f[2]),Math.min(f[1],f[3]),Math.max(f[0],f[2]),Math.max(f[1],f[3])]}return l.readRasters({...e,window:f})}}class ot extends nt{constructor(e,t,i,r,s={}){super(),this.source=e,this.littleEndian=t,this.bigTiff=i,this.firstIFDOffset=r,this.cache=s.cache||!1,this.ifdRequests=[],this.ghostValues=null}async getSlice(e,t){const i=this.bigTiff?4048:1024;return new Me((await this.source.fetch([{offset:e,length:void 0!==t?t:i}]))[0],e,this.littleEndian,this.bigTiff)}async parseFileDirectoryAt(e){const t=this.bigTiff?20:12,i=this.bigTiff?8:2;let s=await this.getSlice(e);const n=this.bigTiff?s.readUint64(e):s.readUint16(e),o=n*t+(this.bigTiff?16:6);s.covers(e,o)||(s=await this.getSlice(e,o));const a={};let l=e+(this.bigTiff?8:2);for(let e=0;e<n;l+=t,++e){const e=s.readUint16(l),t=s.readUint16(l+2),i=this.bigTiff?s.readUint64(l+4):s.readUint32(l+4);let n,o;const h=tt(t),c=l+(this.bigTiff?12:8);if(h*i<=(this.bigTiff?8:4))n=it(s,t,i,c);else{const e=s.readOffset(c),r=tt(t)*i;n=s.covers(e,r)?it(s,t,i,e):it(await this.getSlice(e,r),t,i,e)}o=1===i&&-1===r.NZ.indexOf(e)&&t!==r.s$.RATIONAL&&t!==r.s$.SRATIONAL?n[0]:n,a[r.$[e]]=o}const h=function(e){const t=e.GeoKeyDirectory;if(!t)return null;const i={};for(let s=4;s<=4*t[3];s+=4){const n=r.Hm[t[s]],o=t[s+1]?r.$[t[s+1]]:null,a=t[s+2],l=t[s+3];let h=null;if(o){if(h=e[o],null==h)throw new Error(`Could not get value of geoKey '${n}'.`);"string"==typeof h?h=h.substring(l,l+a-1):h.subarray&&(h=h.subarray(l,l+a),1===a&&(h=h[0]))}else h=l;i[n]=h}return i}(a),c=s.readOffset(e+i+t*n);return new rt(a,h,c)}async requestIFD(e){if(this.ifdRequests[e])return this.ifdRequests[e];if(0===e)return this.ifdRequests[e]=this.parseFileDirectoryAt(this.firstIFDOffset),this.ifdRequests[e];if(!this.ifdRequests[e-1])try{this.ifdRequests[e-1]=this.requestIFD(e-1)}catch(t){if(t instanceof st)throw new st(e);throw t}return this.ifdRequests[e]=(async()=>{const t=await this.ifdRequests[e-1];if(0===t.nextIFDByteOffset)throw new st(e);return this.parseFileDirectoryAt(t.nextIFDByteOffset)})(),this.ifdRequests[e]}async getImage(e=0){const t=await this.requestIFD(e);return new De(t.fileDirectory,t.geoKeyDirectory,this.dataView,this.littleEndian,this.cache,this.source)}async getImageCount(){let e=0,t=!0;for(;t;)try{await this.requestIFD(e),++e}catch(e){if(!(e instanceof st))throw e;t=!1}return e}async getGhostValues(){const e=this.bigTiff?16:8;if(this.ghostValues)return this.ghostValues;let t=await this.getSlice(e,130);if("GDAL_STRUCTURAL_METADATA_SIZE="===it(t,r.s$.ASCII,30,e)){const i=it(t,r.s$.ASCII,130,e).split("\n")[0],s=Number(i.split("=")[1].split(" ")[0])+i.length;s>130&&(t=await this.getSlice(e,s));const n=it(t,r.s$.ASCII,s,e);this.ghostValues={},n.split("\n").filter((e=>e.length>0)).map((e=>e.split("="))).forEach((([e,t])=>{this.ghostValues[e]=t}))}return this.ghostValues}static async fromSource(e,t,i){const r=(await e.fetch([{offset:0,length:1024}],i))[0],s=new Ee(r),n=s.getUint16(0,0);let o;if(18761===n)o=!0;else{if(19789!==n)throw new TypeError("Invalid byte order value.");o=!1}const a=s.getUint16(2,o);let l;if(42===a)l=!1;else{if(43!==a)throw new TypeError("Invalid magic number.");if(l=!0,8!==s.getUint16(4,o))throw new Error("Unsupported offset byte-size.")}const h=l?s.getUint64(8,o):s.getUint32(4,o);return new ot(e,o,l,h,t)}close(){return"function"==typeof this.source.close&&this.source.close()}}class at extends nt{constructor(e,t){super(),this.mainFile=e,this.overviewFiles=t,this.imageFiles=[e].concat(t),this.fileDirectoriesPerFile=null,this.fileDirectoriesPerFileParsing=null,this.imageCount=null}async parseFileDirectoriesPerFile(){const e=[this.mainFile.parseFileDirectoryAt(this.mainFile.firstIFDOffset)].concat(this.overviewFiles.map((e=>e.parseFileDirectoryAt(e.firstIFDOffset))));return this.fileDirectoriesPerFile=await Promise.all(e),this.fileDirectoriesPerFile}async getImage(e=0){await this.getImageCount(),await this.parseFileDirectoriesPerFile();let t=0,i=0;for(let r=0;r<this.imageFiles.length;r++){const s=this.imageFiles[r];for(let n=0;n<this.imageCounts[r];n++){if(e===t){const e=await s.requestIFD(i);return new De(e.fileDirectory,e.geoKeyDirectory,s.dataView,s.littleEndian,s.cache,s.source)}t++,i++}i=0}throw new RangeError("Invalid image index")}async getImageCount(){if(null!==this.imageCount)return this.imageCount;const e=[this.mainFile.getImageCount()].concat(this.overviewFiles.map((e=>e.getImageCount())));return this.imageCounts=await Promise.all(e),this.imageCount=this.imageCounts.reduce(((e,t)=>e+t),0),this.imageCount}}var lt=i(4422),ht=i(915),ct=i(1597),ft=i(8100),ut=i(6391),gt=i(6758),dt=i(9703),pt=i(7259);function yt(e,t){if(!e)return!1;if(!0===e)return!0;if(3!==t.getSamplesPerPixel())return!1;const i=t.fileDirectory.PhotometricInterpretation,s=r.ub;return i===s.CMYK||i===s.YCbCr||i===s.CIELab||i===s.ICCLab}const wt="STATISTICS_MAXIMUM",mt="STATISTICS_MINIMUM";let bt;function St(){return bt||(bt=new l),bt}function At(e){try{return e.getBoundingBox(!0)}catch{return[0,0,e.getWidth(),e.getHeight()]}}function It(e){try{return e.getOrigin().slice(0,2)}catch{return[0,e.getHeight()]}}function _t(e,t){try{return e.getResolution(t)}catch{return[t.getWidth()/e.getWidth(),t.getHeight()/e.getHeight()]}}function Tt(e){const t=e.geoKeys;if(!t)return null;if(t.ProjectedCSTypeGeoKey&&32767!==t.ProjectedCSTypeGeoKey){const e="EPSG:"+t.ProjectedCSTypeGeoKey;let i=(0,ut.Jt)(e);if(!i){const r=(0,ft.q)(t.ProjLinearUnitsGeoKey);r&&(i=new ut.MF({code:e,units:r}))}return i}if(t.GeographicTypeGeoKey&&32767!==t.GeographicTypeGeoKey){const e="EPSG:"+t.GeographicTypeGeoKey;let i=(0,ut.Jt)(e);if(!i){const r=(0,ft.q)(t.GeogAngularUnitsGeoKey);r&&(i=new ut.MF({code:e,units:r}))}return i}return null}function xt(e){return e.getImageCount().then((function(t){const i=new Array(t);for(let r=0;r<t;++r)i[r]=e.getImage(r);return Promise.all(i)}))}function Dt(e,t){let i;return i=e.blob?async function(e,t){return ot.fromSource(new et(e),t)}(e.blob):e.overviews?async function(e,t=[],i={},r){const s=await ot.fromSource(Qe(e,i),r),n=await Promise.all(t.map((e=>ot.fromSource(Qe(e,i)))));return new at(s,n)}(e.url,e.overviews,t):async function(e,t={},i){return ot.fromSource(Qe(e,t),i)}(e.url,t),i.then(xt)}function Et(e,t,i,r,s){if(Array.isArray(e)){const n=e.length;if(!Array.isArray(t)||n!=t.length){const e=new Error(r);throw s(e),e}for(let o=0;o<n;++o)Et(e[o],t[o],i,r,s)}else if(Math.abs(e-t)>i*e)throw new Error(r)}function Mt(e){return e instanceof Int8Array?127:e instanceof Uint8Array||e instanceof Uint8ClampedArray?255:e instanceof Int16Array?32767:e instanceof Uint16Array?6