1import{b as Tt}from"./chunk-7L7LQWUQ.js";import{b as vt}from"./chunk-AJMYRDGM.js";import{a as Dt}from"./chunk-XOB4EQ2T.js";import{a as It}from"./chunk-QAUWK5ZP.js";import{g as ue}from"./chunk-MJE36VRY.js";import"./chunk-I2LACOYT.js";import{d as $}from"./chunk-ZPHOBEVG.js";import"./chunk-RBLEGQPK.js";import{a as H}from"./chunk-HOYTWQCF.js";import{a as Ee,b as ze}from"./chunk-MBIGII5X.js";import"./chunk-BYXBJQAS.js";import{b as wt,e as Be}from"./chunk-XHEXQ4WZ.js";import{a as I,c as L}from"./chunk-AKKUUEQK.js";import{a as v,b as j,c as gt,d as z,h as bt}from"./chunk-3WIR6N5K.js";import"./chunk-BYXBJQAS.js";import"./chunk-IXYJJ4D3.js";import"./chunk-Q4R7JTUT.js";import"./chunk-GFWX74CO.js";import{a as R}from"./chunk-67QB3CB7.js";import"./chunk-NOUYXRP4.js";import{j as he,k as ce}from"./chunk-LODTDSX4.js";import{a as P}from"./chunk-ZOOQQO74.js";import{n as _t,q as mt}from"./chunk-RCUJKXIP.js";import"./chunk-B7IX6UFG.js";import"./chunk-UZSTUBKI.js";import"./chunk-XAHD7XBV.js";import"./chunk-AIKSV6LF.js";import{a as yt}from"./chunk-DIZXR3D3.js";import"./chunk-W5OI4BJ2.js";import{c as G,i as Ue,j as F,l as ne,n as ft,r as D}from"./chunk-ZAQLF7TN.js";import"./chunk-S3DH7XZE.js";import"./chunk-QQX4FGZT.js";import{a as q,b as xt}from"./chunk-4KGZTO2H.js";import"./chunk-T3HRP72S.js";import"./chunk-IGLWZTM3.js";import{a as Ve}from"./chunk-ECZ7PBWU.js";import{a as le,b as pt}from"./chunk-H3HTOQNB.js";import"./chunk-RCTOGBGJ.js";import"./chunk-4D3QHJI2.js";import"./chunk-E2J2V7JN.js";import{a as C}from"./chunk-FRLOFI6C.js";import"./chunk-WFHAGO45.js";import"./chunk-37H4LYIE.js";import"./chunk-6I4ZS4ET.js";import"./chunk-HUYHDVA2.js";import"./chunk-6TDLGY7R.js";import{a as Y}from"./chunk-TUP2LBIE.js";import{b as St}from"./chunk-5AIUMSX2.js";import"./chunk-LJ5Q3KED.js";import"./chunk-UEJLHX2E.js";import{b as at,d as nt}from"./chunk-TNK2G5YD.js";import"./chunk-O7TMSX43.js";import{a as ke}from"./chunk-45365BH5.js";import"./chunk-KBUBAKBM.js";import"./chunk-TFCWMFOQ.js";import{a as dt}from"./chunk-MBFI6CGI.js";import"./chunk-U6WVZEYH.js";import"./chunk-GZKVZ4TD.js";import"./chunk-7QY3BMVN.js";import"./chunk-NWPYI2UP.js";import"./chunk-TNPL7MIN.js";import{f as ot}from"./chunk-ZJ3KJJ63.js";import"./chunk-PDBA6QOJ.js";import"./chunk-M2GLXRA2.js";import{c as lt,h as ht,i as ct,j as ut}from"./chunk-CF52RSJZ.js";import"./chunk-2ETHV3H2.js";import"./chunk-ZVHU7VE3.js";import{b as ae}from"./chunk-V5IFIIWL.js";import"./chunk-V2JYXY4D.js";import"./chunk-PNJVOMPP.js";import"./chunk-MIR5A3Z7.js";import"./chunk-5MU2G7HW.js";import"./chunk-EBWCXIFH.js";import"./chunk-5OX7OX74.js";import"./chunk-VJFR7CVY.js";import"./chunk-7LEM3RHH.js";import"./chunk-II4RWQI3.js";import"./chunk-5OZU24FS.js";import"./chunk-7Q3YF2MG.js";import"./chunk-SKQ7RYUF.js";import"./chunk-UNL5XY5B.js";import"./chunk-PLK75Q3A.js";import"./chunk-KNHCPC3N.js";import"./chunk-TGH4HSNW.js";import"./chunk-LSBFLPDJ.js";import"./chunk-AM3VOA32.js";import"./chunk-OQAEBRA5.js";import"./chunk-SAOUSUZE.js";import"./chunk-XFYGS4YQ.js";import"./chunk-XUA64EFT.js";import"./chunk-TCZU6JLS.js";import"./chunk-OG6NDV7Y.js";import"./chunk-HSLYIFR4.js";import"./chunk-M5DNT3MU.js";import"./chunk-4XBJYZ5W.js";import"./chunk-R4JFECO7.js";import"./chunk-SWOLYJBS.js";import"./chunk-LK4PFQLP.js";import"./chunk-QYC4ILGT.js";import"./chunk-JYRXWQX5.js";import"./chunk-N4C3TQXV.js";import"./chunk-3ZSPAYUG.js";import"./chunk-OEUDK4A7.js";import"./chunk-ZJQZEXV4.js";import"./chunk-VU5W7W6Y.js";import"./chunk-NOXQXPZQ.js";import"./chunk-WMLW3QJQ.js";import{a as E,c as it,p as rt}from"./chunk-5CEFM27D.js";import"./chunk-BCREO4Q5.js";import{k as st}from"./chunk-FYHO4ULB.js";import"./chunk-FUMVX7XQ.js";import"./chunk-YZHSVWQ6.js";import"./chunk-JDT5QXWG.js";import"./chunk-M52MQETK.js";import"./chunk-76YVRX2R.js";import"./chunk-OZF6BMOL.js";import"./chunk-GJP6PTKT.js";import"./chunk-RSDQHAJX.js";import{l as tt}from"./chunk-DOTYW6ST.js";import"./chunk-VOYK3LZF.js";import"./chunk-QGCCROOZ.js";
1import"./chunk-2BAXJKYK.js";import{Q as Oe,ca as et}from"./chunk-Z5Y2GXLN.js";import{L as Xe}from"./chunk-672GO22T.js";import"./chunk-SNFOAZZQ.js";import{S as Ze,t as $e}from"./chunk-RNRCJDVT.js";import"./chunk-OVHPPCBL.js";import{a as Le}from"./chunk-W3WDPWBE.js";import{n as Ye,o as je,s as K,u as Pe}from"./chunk-DE4UMQWQ.js";import{b as N,c as B,e as Ge}from"./chunk-MLSR6YE6.js";import"./chunk-GCWVITNF.js";import{b as Ke,r as Me}from"./chunk-JWWEG5TZ.js";import{G as Ae}from"./chunk-PXPVXIY2.js";import{a as U,b as V,g as x}from"./chunk-JEGVIFEP.js";var k=class{constructor(e,s){this._width=0,this._height=0,this._free=[],this._width=e,this._height=s,this._free.push(new P(0,0,e,s))}get width(){return this._width}get height(){return this._height}allocate(e,s){if(e>this._width||s>this._height)return new P;let t=null,i=-1;for(let r=0;r<this._free.length;++r){let o=this._free[r];e<=o.width&&s<=o.height&&(t===null||o.y<=t.y&&o.x<=t.x)&&(t=o,i=r)}return t===null?new P:(this._free.splice(i,1),t.width<t.height?(t.width>e&&this._free.push(new P(t.x+e,t.y,t.width-e,s)),t.height>s&&this._free.push(new P(t.x,t.y+s,t.width,t.height-s))):(t.width>e&&this._free.push(new P(t.x+e,t.y,t.width-e,t.height)),t.height>s&&this._free.push(new P(t.x,t.y+s,e,t.height-s))),new P(t.x,t.y,e,s))}release(e){for(let s=0;s<this._free.length;++s){let t=this._free[s];if(t.y===e.y&&t.height===e.height&&t.x+t.width===e.x)t.width+=e.width;else if(t.x===e.x&&t.width===e.width&&t.y+t.height===e.y)t.height+=e.height;else if(e.y===t.y&&e.height===t.height&&e.x+e.width===t.x)t.x=e.x,t.width+=e.width;else{if(e.x!==t.x||e.width!==t.width||e.y+e.height!==t.y)continue;t.y=e.y,t.height+=e.height}this._free.splice(s,1),this.release(e)}this._free.push(e)}};var X=class{constructor(e,s,t){this.width=0,this.height=0,this._dirties=[],this._glyphData=[],this._currentPage=0,this._glyphIndex={},this._textures=[],this._rangePromises=new Map,this.width=e,this.height=s,this._glyphSource=t,this._binPack=new k(e-4,s-4),this._glyphData.push(new Uint8Array(e*s)),this._dirties.push(!0),this._textures.push(void 0)}getGlyphItems(e,s){let t=[],i=this._glyphSource,r=new Set,o=1/256;for(let n of s){let l=Math.floor(n*o);r.add(l)}let a=[];return r.forEach(n=>{let l=e+n;if(this._rangePromises.has(l))a.push(this._rangePromises.get(l));else{let c=i.getRange(e,n).then(()=>{this._rangePromises.delete(l)},()=>{this._rangePromises.delete(l)});this._rangePromises.set(l,c),a.push(c)}}),Promise.all(a).then(()=>{let n=this._glyphIndex[e];n||(n={},this._glyphIndex[e]=n);for(let l of s){let c=n[l];if(c){t[l]={sdf:!0,rect:c.rect,metrics:c.metrics,page:c.page,code:l};continue}let y=i.getGlyph(e,l);if(!y?.metrics)continue;let d=y.metrics,u;if(d.width===0)u=new P(0,0,0,0);else{let p=d.width+6,m=d.height+2*3,_=p%4?4-p%4:4,g=m%4?4-m%4:4;_===1&&(_=5),g===1&&(g=5),u=this._binPack.allocate(p+_,m+g),u.isEmpty&&(this._dirties[this._currentPage]||(this._glyphData[this._currentPage]=null),this._currentPage=this._glyphData.length,this._glyphData.push(new Uint8Array(this.width*this.height)),this._dirties.push(!0),this._textures.push(void 0),this._binPack=new k(this.width-4,this.height-4),u=this._binPack.allocate(p+_,m+g));let b=this._glyphData[this._currentPage],S=y.bitmap,A,w;if(S)for(let T=0;T<m;T++){A=p*T,w=this.width*(u.y+T+1)+u.x;for(let O=0;O<p;O++)b[w+O+1]=S.at(A+O)}}n[l]={rect:u,metrics:d,tileIDs:null,page:this._currentPage},t[l]={sdf:!0,rect:u,metrics:d,page:this._currentPage,code:l},this._dirties[this._currentPage]=!0}return t})}removeGlyphs(e){for(let s in this._glyphIndex){let t=this._glyphIndex[s];if(!t)continue;let i;for(let r in t)if(i=t[r],i.tileIDs.delete(e),i.tileIDs.size===0){let o=this._glyphData[i.page],a=i.rect,n,l;for(let c=0;c<a.height;c++)for(n=this.width*(a.y+c)+a.x,l=0;l<a.width;l++)o[n+l]=0;delete t[r],this._dirties[i.page]=!0}}}bind(e,s,t,i=0){if(!this._textures[t]){let o=new he;o.pixelFormat=ft.ALPHA,o.wrapMode=ne.CLAMP_TO_EDGE,o.width=this.width,o.height=this.height,this._textures[t]=new ce(e,o,new Uint8Array(this.width*this.height))}let r=this._textures[t];r.setSamplingMode(s),this._dirties[t]&&r.setData(this._glyphData[t]),e.bindTexture(r,i),this._dirties[t]=!1}destroy(){this.dispose()}dispose(){this._glyphData.length=0,this._binPack=null;for(let e of this._textures)e&&e.dispose();this._textures.length=0}};var Z=class{constructor(e){if(this._metrics=[],!e)return void(this._allBitmaps=null);let s=new Map,t=0;for(;e.next();)switch(e.tag()){case 1:{let o=e.getMessage();for(;o.next();)switch(o.tag()){case 3:{let a=o.getMessage(),n,l,c,y,d,u,f;for(;a.next();)switch(a.tag()){case 1:n=a.getUInt32();break;
1case 2:l=a.getBytes();break;case 3:c=a.getUInt32();break;case 4:y=a.getUInt32();break;case 5:d=a.getSInt32();break;case 6:u=a.getSInt32();break;case 7:f=a.getUInt32();break;default:a.skip()}if(a.release(),n){let p=l?.length??0;this._metrics[n]={width:c,height:y,left:d,top:u,advance:f,startOffset:t,length:p},s.set(n,l),t+=p}break}default:o.skip()}o.release();break}default:e.skip()}let i=new Uint8Array(t),r=this._metrics;for(let[o,a]of s){let{startOffset:n,length:l}=r[o];if(a)for(let c=0;c<l;++c)i[n+c]=a[c]}this._allBitmaps=i}getMetrics(e){return this._metrics[e]}getBitmap(e){if(!this._allBitmaps)return;let s=this._metrics[e];if(s===void 0)return;let{startOffset:t,length:i}=s;return i!==0?new qe(this._allBitmaps,t,i):void 0}},Fe=class{constructor(){this._ranges=[]}get ranges(){return this._ranges}getRange(e){return this._ranges[e]}addRange(e,s){this._ranges[e]=s}},ee=class{constructor(e){this._glyphInfo={},this._baseURL=e}getRange(e,s){let t=this._getFontStack(e);if(t.getRange(s))return Promise.resolve();let i=256*s,r=i+255;if(this._baseURL){let o=this._baseURL.replace("{fontstack}",e).replace("{range}",i+"-"+r);return et(o,{responseType:"array-buffer"}).then(a=>{t.addRange(s,new Z(new Y(new Uint8Array(a.data),new DataView(a.data))))}).catch(()=>{t.addRange(s,new Z)})}return t.addRange(s,new Z),Promise.resolve()}getGlyph(e,s){let t=this._getFontStack(e);if(!t)return;let i=Math.floor(s/256),r=t.getRange(i);return r?{metrics:r.getMetrics(s),bitmap:r.getBitmap(s)}:void 0}_getFontStack(e){let s=this._glyphInfo[e];return s||(s=this._glyphInfo[e]=new Fe),s}},qe=class{constructor(e,s,t){this._array=e,this._start=s,this.length=t}at(e){return 0<=e&&e<this.length?this._array[this._start+e]:void 0}};var Vt="dasharray-",te=class h{constructor(e,s,t=0){this._size=[],this._mosaicsData=[],this._textures=[],this._dirties=[],this._maxItemSize=0,this._currentPage=0,this._pageWidth=0,this._pageHeight=0,this._mosaicRects={},this.pixelRatio=1,s<=0&&console.error("Sprites mosaic defaultWidth and defaultHeight must be greater than zero!"),this._pageWidth=e,this._pageHeight=s,t>0&&(this._maxItemSize=t),this._binPack=new k(e-4,s-4)}destroy(){this.dispose()}dispose(){this._binPack=null,this._mosaicsData.length=0,this._mosaicRects={};for(let e of this._textures)e&&e.dispose();this._textures.length=0}getWidth(e){return e>=this._size.length?-1:this._size[e][0]}getHeight(e){return e>=this._size.length?-1:this._size[e][1]}getPageSize(e){return e>=this._size.length?null:this._size[e]}setSpriteSource(e){if(this.dispose(),this.pixelRatio=e.devicePixelRatio,this._mosaicsData.length===0){this._binPack=new k(this._pageWidth-4,this._pageHeight-4);let s=Math.floor(this._pageWidth),t=Math.floor(this._pageHeight),i=new Uint32Array(s*t);this._mosaicsData[0]=i,this._dirties.push(!0),this._size.push([this._pageWidth,this._pageHeight]),this._textures.push(void 0)}this._sprites=e}getSpriteItem(e,s=!1){let t,i,r=this._mosaicRects[e];if(r)return r;if(!this._sprites||this._sprites.loadStatus!=="loaded"||(e&&e.startsWith(Vt)?([t,i]=this._rasterizeDash(e),s=!0):t=this._sprites.getSpriteInfo(e),!t?.width||!t.height||t.width<0||t.height<0))return null;let o=t.width,a=t.height,[n,l,c]=this._allocateImage(o,a);return n.width<=0?null:(this._copy(n,t,l,c,s,i),r={type:"sprite",rect:n,width:o,height:a,sdf:t.sdf,simplePattern:!1,rasterizationScale:t.pixelRatio,page:l},this._mosaicRects[e]=r,r)}getSpriteItems(e){let s={};for(let t of e)s[t.name]=this.getSpriteItem(t.name,t.repeat);return s}getMosaicItemPosition(e,s){let t=this.getSpriteItem(e,s),i=t?.rect;if(!i)return null;i.width=t.width,i.height=t.height;let r=t.width,o=t.height,a=2;return{tl:[i.x+a,i.y+a],br:[i.x+a+r,i.y+a+o],page:t.page}}bind(e,s,t=0,i=0){if(t>=this._size.length||t>=this._mosaicsData.length)return;if(!this._textures[t]){let o=new he;o.wrapMode=ne.CLAMP_TO_EDGE,o.width=this._size[t][0],o.height=this._size[t][1],this._textures[t]=new ce(e,o,new Uint8Array(this._mosaicsData[t].buffer))}let r=this._textures[t];r.setSamplingMode(s),this._dirties[t]&&r.setData(new Uint8Array(this._mosaicsData[t].buffer)),e.bindTexture(r,i),this._dirties[t]=!1}static _copyBits(e,s,t,i,r,o,a,n,l,c,y){let d=i*s+t,u=n*o+a;if(y){u-=o;for(let f=-1;f<=c;f++,d=((f+c)%c+i)*s+t,u+=o)for(let p=-1;p<=l;p++)r[u+p]=e[d+(p+l)%l]}else for(let f=0;f<c;f++){for(let p=0;p<l;p++)r[u+p]=e[d+p];d+=s,u+=o}}_copy(e,s,t,i,r,o){if(!this._sprites||this._sprites.loadStatus!=="loaded"||t>=this._mosaicsData.length)return;let a=new Uint32Array(o?o.buffer:this._sprites.image.buffer),n=this._mosaicsData[t],l=2,c=o?s.width:this._sprites.width;h._copyBits(a,c,s.x,s.y,n,i[0],e.x+l,e.y+l,s.width,s.height,r),this._dirties[t]=!0}_allocateImage(e,s){e+=2,s+=2;let t=Math.max(e,s);if(this._maxItemSize&&this._maxItemSize<t){let a=new P(0,0,e,s);return this._mosaicsData.push(new Uint32Array(e*s)),this._dirties.push(!0),this._size.push([e,s]),this._textures.push(void 0),[a,this._mosaicsData.length-1,[e,s]]}let i=e%4?4-e%4:4,r=s%4?4-s%4:4;i===1&&(i=5),r===1&&(r=5);let o=this._binPack.allocate(e+i,s+r);return o.width<=0?(this._dirties[this._currentPage]||(this._mosaicsData[this._currentPage]=null),this._currentPage=this._mosaicsData.length,this._mosaicsData.push(new Uint32Array(this._pageWidth*this._pageHeight)),this._dirties.push(!0),this._size.push([this._pageWidth,this._pageHeight]),this._textures.push(void 0),this._binPack=new k(this._pageWidth-4,this._pageHeight-4),this._allocateImage(e,s)):[o,this._currentPage,[this._pageWidth,this._pageHeight]]}_rasterizeDash(e){let s=/\[(.*?)\]/,t=e.match(s);if(!t)return null;let i=t[1].split(",").map(Number),r=e.slice(e.lastIndexOf("-")+1),[o,a,n]=Tt(i,r);return[{x:0,y:0,width:a,height:n,sdf:!0,pixelRatio:1},new Uint8Array(o.buffer)]}};var ye=class{constructor(e,s,t,i){this._layer=e,this._styleRepository=s,this.devicePixelRatio=t,this._sourceDataMaxLOD=i,this._spriteMosaic=null,this._glyphMosaic=null,this._connection=null,this._spriteSourceAbortController=null,this._startOptionsInputSignal=null,this._inputSignalEventListener=null}destroy(){this._connection?.close(),this._connection=null,this._styleRepository=null,this._layer=null,this._spriteMosaic?.destroy(),this._spriteMosaic=null,this._glyphMosaic=null,this._spriteSourceAbortController=Ge(this._spriteSourceAbortController),this._spriteSourcePromise=null,this._inputSignalEventListener&&this._startOptionsInputSignal?.removeEventListener("abort",this._inputSignalEventListener),this._startOptionsInputSignal=null,this._inputSignalEventListener=null}get spriteMosaic(){return this._spriteSourcePromise.then(()=>this._spriteMosaic)}get glyphMosaic(){return this._glyphMosaic}start(e){return x(this,null,function*(){this._requestSprite(e);let s=this._layer.currentStyleInfo.glyphsUrl,t=new ee(s?Oe(s,V(U({},this._layer.customParameters),{token:this._layer.apiKey})):null);this._glyphMosaic=new X(1024,1024,t),this._broadcastPromise=St("WorkerTileHandler",{client:this,schedule:e.schedule,signal:e.signal}).then(i=>{if(this._layer&&(this._connection?.close(),this._connection=i,this._layer&&!this._connection.closed)){let r=i.broadcast("setStyle",{style:this._layer.currentStyleInfo.style,sourceDataMaxLOD:this._sourceDataMaxLOD},e);
1Promise.all(r).catch(o=>je(o))}})})}_requestSprite(e){this._spriteSourceAbortController?.abort();let s=new AbortController;this._spriteSourceAbortController=s;let t=e?.signal;this._inputSignalEventListener&&this._startOptionsInputSignal?.removeEventListener("abort",this._inputSignalEventListener),this._startOptionsInputSignal=null,t&&(this._inputSignalEventListener=Et(s),t.addEventListener("abort",this._inputSignalEventListener,{once:!0}));let{signal:i}=s,r=V(U({},e),{signal:i});this._spriteSourcePromise=this._layer.loadSpriteSource(this.devicePixelRatio,r),this._spriteSourcePromise.then(o=>{Ye(i),this._spriteMosaic=new te(1024,1024,250),this._spriteMosaic.setSpriteSource(o)})}updateStyle(e){return x(this,null,function*(){return yield this._broadcastPromise,this._broadcastPromise=Promise.all(this._connection.broadcast("updateStyle",e)),this._broadcastPromise})}setSpriteSource(e){let s=new te(1024,1024,250);return s.setSpriteSource(e),this._spriteMosaic=s,this._spriteSourcePromise=Promise.resolve(e),this._spriteSourceAbortController=null,s}setStyle(e,s,t){return x(this,null,function*(){yield this._broadcastPromise,this._styleRepository=e,this._sourceDataMaxLOD=t,this._requestSprite();let i=new ee(this._layer.currentStyleInfo.glyphsUrl?Oe(this._layer.currentStyleInfo.glyphsUrl,V(U({},this._layer.customParameters),{token:this._layer.apiKey})):null);return this._glyphMosaic=new X(1024,1024,i),this._broadcastPromise=Promise.all(this._connection.broadcast("setStyle",{style:s,sourceDataMaxLOD:this._sourceDataMaxLOD})),this._broadcastPromise})}fetchTileData(e,s){return x(this,null,function*(){let t=yield this._getRefKeys(e,s);return this._getSourcesData(Object.keys(this._layer.sourceNameToSource),t,s)})}fetchTilePBFs(e){return x(this,null,function*(){let s=Object.keys(this._layer.sourceNameToSource),t={},i=yield this._getRefKeys(e,t),r=[],o=[];for(let a=0;a<i.length;a++)if(i[a].value==null||s[a]==null)o.push(null);else{let n=i[a].value,l=this._getTilePayload(n,s[a],t);l.then(c=>{r.push(V(U({},c),{key:n}))}),o.push(l)}return Promise.all(o).then(()=>r)})}parseTileData(e,s){return x(this,null,function*(){let t=e&&e.data;if(!t)return null;let{sourceName2DataAndRefKey:i,transferList:r}=t;return Object.keys(i).length===0?null:this._broadcastPromise.then(()=>this._connection.invoke("createTileAndParse",{key:e.key.id,sourceName2DataAndRefKey:i,styleLayerUIDs:e.styleLayerUIDs},V(U({},s),{transferList:r})))})}getSprites(e){return x(this,null,function*(){return yield this._spriteSourcePromise,this._spriteMosaic.getSpriteItems(e)})}getGlyphs(e){return this._glyphMosaic.getGlyphItems(e.font,e.codePoints)}_getTilePayload(e,s,t){return x(this,null,function*(){let i=C.pool.acquire(e.id),r=this._layer.sourceNameToSource[s],{level:o,row:a,col:n}=i;C.pool.release(i);try{return{protobuff:yield r.requestTile(o,a,n,t),sourceName:s}}catch(l){if(K(l))throw l;return{protobuff:null,sourceName:s}}})}_getRefKeys(e,s){return x(this,null,function*(){let t=this._layer.sourceNameToSource,i=new Array;for(let r in t){let o=t[r].getRefKey(e,s);i.push(o)}return Pe(i)})}_getSourcesData(e,s,t){let i=[];for(let r=0;r<s.length;r++)if(s[r].value==null||e[r]==null)i.push(null);else{let o=s[r].value,a=this._getTilePayload(o,e[r],t);i.push(a)}return Pe(i).then(r=>{let o={},a=[];for(let n=0;n<r.length;n++){let l=r[n].value;if(l&&l.protobuff&&l.protobuff.byteLength>0){let c=s[n].value.id;o[l.sourceName]={refKey:c,protobuff:l.protobuff},a.push(l.protobuff)}}return{sourceName2DataAndRefKey:o,transferList:a}})}};function Et(h){return()=>h.abort()}var Ct=512,zt=1e-6,Bt=(h,e)=>h+1/(1<<2*e),se=class{constructor(e,s){this._tiles=new Map,this._tileCache=new ot(40,t=>t.dispose()),this._viewSize=[0,0],this._visibleTiles=new Map,this.acquireTile=e.acquireTile,this.releaseTile=e.releaseTile,this.tileInfoView=e.tileInfoView,this._container=s}destroy(){for(let[e,s]of this._tiles)s.dispose();this._tiles=null,this._tileCache.clear(),this._tileCache=null}update(e){this._updateCacheSize(e);let s=this.tileInfoView,t=s.getTileCoverage(e.state,0,!0,"smallest");
1if(!t)return!0;let{spans:i,lodInfo:r}=t,{level:o}=r,a=this._tiles,n=new Set,l=new Set;for(let{row:y,colFrom:d,colTo:u}of i)for(let f=d;f<=u;f++){let p=C.getId(o,y,r.normalizeCol(f),r.getWorldForColumn(f)),m=this._getOrAcquireTile(p);n.add(p),m.processed()?this._addToContainer(m):l.add(new C(p))}for(let[y,d]of a)d.isCoverage=n.has(y);for(let y of l)this._findPlaceholdersForMissingTiles(y,n);let c=!1;for(let[y,d]of a)d.neededForCoverage=n.has(y),d.neededForCoverage||d.isHoldingForFade&&s.intersects(t,d.key)&&n.add(y),d.isFading&&(c=!0);for(let[y,d]of this._tiles)n.has(y)||this._releaseTile(y);return le.pool.release(t),!c}clear(){this._tiles.clear(),this._tileCache.clear(),this._visibleTiles.clear()}clearCache(){this._tileCache.clear()}getIntersectingTiles(e,s,t,i,r){let o=[0,0],a=[0,0];i.toMap(o,e-t,s+t),i.toMap(a,e+t,s-t);let n=Math.min(o[0],a[0]),l=Math.min(o[1],a[1]),c=Math.max(o[0],a[0]),y=Math.max(o[1],a[1]),d=it(n,l,c,y),u=E(),f=[];for(let[p,m]of this._visibleTiles)this.tileInfoView.getTileBounds(u,m.key),rt(d,u)&&f.push(m);if(r!=null&&r.length>0){let p=new Set(f.map(_=>_.id)),m=r.filter(_=>!p.has(_.tileKey.id)).map(_=>this._visibleTiles.get(_.tileKey.id)).filter(_=>_!==void 0);f.push(...m)}return f}_findPlaceholdersForMissingTiles(e,s){let t=[];for(let[r,o]of this._tiles)this._addPlaceholderChild(t,o,e,s);let i=t.reduce(Bt,0);Math.abs(1-i)<zt||this._addPlaceholderParent(e.id,s)}_addPlaceholderChild(e,s,t,i){s.key.level<=t.level||!s.hasData()||qt(t,s.key)&&(this._addToContainer(s),i.add(s.id),e.push(s.key.level-t.level))}_addPlaceholderParent(e,s){let t=this._tiles,i=e;for(;;){if(i=Ft(i),!i||s.has(i))return;let r=t.get(i);if(r?.hasData())return this._addToContainer(r),void s.add(r.id)}}_getOrAcquireTile(e){let s=this._tiles.get(e);return s||(s=this._tileCache.pop(e),s||(s=this.acquireTile(new C(e))),this._tiles.set(e,s),s)}_releaseTile(e){let s=this._tiles.get(e);this.releaseTile(s),this._removeFromContainer(s),this._tiles.delete(e),s.hasData()?this._tileCache.put(e,s,1):s.dispose()}_addToContainer(e){let s,t=[],i=this._container;if(i.contains(e))return;let r=this._visibleTiles;for(let[o,a]of r)this._canConnectDirectly(e,a)&&t.push(a),s==null&&this._canConnectDirectly(a,e)&&(s=a);if(s!=null){for(let o of t)s.childrenTiles.delete(o),e.childrenTiles.add(o),o.parentTile=e;s.childrenTiles.add(e),e.parentTile=s}else for(let o of t)e.childrenTiles.add(o),o.parentTile=e;r.set(e.id,e),i.addChild(e)}_removeFromContainer(e){if(this._visibleTiles.delete(e.id),this._container.removeChild(e),e.parentTile!=null){e.parentTile.childrenTiles.delete(e);for(let s of e.childrenTiles)e.parentTile!=null&&e.parentTile.childrenTiles.add(s)}for(let s of e.childrenTiles)s.parentTile=e.parentTile;e.parentTile=null,e.childrenTiles.clear()}_canConnectDirectly(e,s){let t=e.key,{level:i,row:r,col:o,world:a}=s.key,n=this._visibleTiles;for(;i>0;){if(i--,r>>=1,o>>=1,t.level===i&&t.row===r&&t.col===o&&t.world===a)return!0;if(n.has(`${i}/${r}/${o}/${a}`))return!1}return!1}_updateCacheSize(e){let s=e.state.size;if(s[0]===this._viewSize[0]&&s[1]===this._viewSize[1])return;let t=Math.ceil(s[0]/Ct)+1,i=Math.ceil(s[1]/Ct)+1;this._viewSize[0]=s[0],this._viewSize[1]=s[1],this._tileCache.maxSize=5*t*i}};function Ft(h){let[e,s,t,i]=h.split("/"),r=parseInt(e,10);return r===0?null:`${r-1}/${parseInt(s,10)>>1}/${parseInt(t,10)>>1}/${parseInt(i,10)}`}function qt(h,e){let s=e.level-h.level;return h.row===e.row>>s&&h.col===e.col>>s&&h.world===e.world}var de=class{constructor(e,s){this.sourceTile=s,this.xTile=0,this.yTile=0,this.hash=0,this.priority=1,this.featureIndex=0,this.colliders=[],this.textVertexRanges=[],this.iconVertexRanges=[],this.tile=e}},fe=class{constructor(){this.tileSymbols=[],this.parts=[{startTime:0,startOpacity:0,targetOpacity:0,show:!1},{startTime:0,startOpacity:0,targetOpacity:0,show:!1}],this.show=!1}};function He(h,e,s,t,i,r){let o=s-i;if(o>=0)return(e>>o)+(t-(r<<o))*(h>>o);let a=-o;return e-(r-(t<<a))*(h>>a)<<a}var W=class{constructor(e,s,t){this._rows=Math.ceil(s/t),this._columns=Math.ceil(e/t),this._cellSize=t,this.cells=new Array(this._rows);for(let i=0;i<this._rows;i++){this.cells[i]=new Array(this._columns);for(let r=0;r<this._columns;r++)this.cells[i][r]=[]}}getCell(e,s){let t=Math.min(Math.max(Math.floor(s/this._cellSize),0),this._rows-1),i=Math.min(Math.max(Math.floor(e/this._cellSize),0),this._columns-1);return this.cells[t]&&this.cells[t][i]||null}getCellSpan(e,s,t,i){return[Math.min(Math.max(Math.floor(e/this._cellSize),0),this.columns-1),Math.min(Math.max(Math.floor(s/this._cellSize),0),this.rows-1),Math.min(Math.max(Math.floor(t/this._cellSize),0),this.columns-1),Math.min(Math.max(Math.floor(i/this._cellSize),0),this.rows-1)]}get cellSize(){return this._cellSize}get columns(){return this._columns}get rows(){return this._rows}};function Rt(h,e,s,t,i,r,o){let a=e[t++];for(let n=0;n<a;n++){let l=new de(r,o);l.xTile=e[t++],l.yTile=e[t++],l.hash=e[t++],l.priority=e[t++],l.featureIndex=e[t++];let c=e[t++];for(let u=0;u<c;u++){let f=e[t++],p=e[t++],m=e[t++],_=e[t++],g=!!e[t++],b=e[t++],S=s[t++],A=s[t++],w=e[t++],T=e[t++];l.colliders.push({xTile:f,yTile:p,dxPixels:m,dyPixels:_,hard:g,partIndex:b,width:w,height:T,minLod:S,maxLod:A})}let y=h[t++];for(let u=0;u<y;u++)l.textVertexRanges.push([h[t++],h[t++]]);let d=h[t++];for(let u=0;u<d;u++)l.iconVertexRanges.push([h[t++],h[t++]]);i.push(l)}return t}function Lt(h,e,s){for(let[t,i]of h.symbols)Ht(h,e,s,i,t)}function Ht(h,e,s,t,i){let r=h.layerData.get(i);if(r.type===I.SYMBOL){for(let o of t){let a=o.unique,n;if(o.selectedForRendering){let l=a.parts[0],c=l.startOpacity,y=l.targetOpacity;h.allSymbolsFadingOut=h.allSymbolsFadingOut&&y===0;let d=s?Math.floor(127*c)|y<<7:y?255:0;n=d<<24|d<<16|d<<8|d}else n=0;for(let[l,c]of o.iconVertexRanges)for(let y=l;y<l+c;y+=4)r.iconOpacity[y/4]=n;if(o.selectedForRendering){let l=a.parts[1],c=l.startOpacity,y=l.targetOpacity;h.allSymbolsFadingOut=h.allSymbolsFadingOut&&y===0;let d=s?Math.floor(127*c)|y<<7:y?255:0;n=d<<24|d<<16|d<<8|d}else n=0;for(let[l,c]of o.textVertexRanges)for(let y=l;y<l+c;y+=4)r.textOpacity[y/4]=n}r.lastOpacityUpdate=e,r.opacityChanged=!0}}function At(h,e,s,t){let i=h.colliders,r,o,a,n;for(let l of i)if(h.unique.show&&h.unique.parts[l.partIndex].show&&(r=l.xScreen-t[0]+l.dxScreen,o=l.yScreen-t[1]+l.dyScreen,a=r+l.width,n=o+l.height,mt(s,e.x,e.y,r,o,a,n)))return!0;return!1}var Q=class{constructor(e,s){this.layerUIDs=[],this.isDestroyed=!1,this._data=e;let t=1,i=new Uint32Array(e);this.layerUIDs=[];let r=i[t++];for(let o=0;o<r;o++)this.layerUIDs[o]=i[t++];this.bufferDataOffset=t,s&&(this.layer=s.getStyleLayerByUID(this.layerUIDs[0]))}get isPreparedForRendering(){return this._data==null}get offset(){return this.bufferDataOffset}get data(){return this._data}destroy(){this.isDestroyed||(this.doDestroy(),this._data=null,this.isDestroyed=!0)}prepareForRendering(e){this._data!=null&&(this.doPrepareForRendering(e,this._data,this.bufferDataOffset),this._data=null)}},pe=class extends Q{constructor(e,s){super(e,s),this.type=I.LINE,this.lineIndexStart=0,this.lineIndexCount=0;let t=new Uint32Array(e),i=this.bufferDataOffset;this.lineIndexStart=t[i++],this.lineIndexCount=t[i++];let r=t[i++];if(r>0){this.patternMap=new Map;for(let o=0;o<r;o++){let a=t[i++],n=t[i++],l=t[i++];this.patternMap.set(a,[n,l])}}this.bufferDataOffset=i}get memoryUsed(){return(this.data?.byteLength??0)+(this.vao?.usedMemory??0)}hasData(){return this.lineIndexCount>0}triangleCount(){return this.lineIndexCount/3}doDestroy(){this.vao=B(this.vao)}doPrepareForRendering(e,s,t){let i=new Uint32Array(s),r=new Int32Array(i.buffer),o=i[t++],a=R.createVertex(e,D.STATIC_DRAW,new Int32Array(r.buffer,4*t,o));t+=o;let n=i[t++],l=R.createIndex(e,D.STATIC_DRAW,new Uint32Array(i.buffer,4*t,n));t+=n;let c=this.layer.lineMaterial;this.vao=new H(e,c.getAttributeLocations(),c.getLayoutInfo(),{geometry:a},l)}},_e=class extends Q{constructor(e,s){super(e,s),this.type=I.FILL,this.fillIndexStart=0,this.fillIndexCount=0,this.outlineIndexStart=0,this.outlineIndexCount=0;let t=new Uint32Array(e),i=this.bufferDataOffset;this.fillIndexStart=t[i++],this.fillIndexCount=t[i++],this.outlineIndexStart=t[i++],this.outlineIndexCount=t[i++];let r=t[i++];if(r>0){this.patternMap=new Map;for(let o=0;o<r;o++){let a=t[i++],n=t[i++],l=t[i++];this.patternMap.set(a,[n,l])}}this.bufferDataOffset=i}get memoryUsed(){return(this.data?.byteLength??0)+(this.fillVAO?.usedMemory??0)+(this.outlineVAO?.usedMemory??0)}hasData(){return this.fillIndexCount>0||this.outlineIndexCount>0}triangleCount(){return(this.fillIndexCount+this.outlineIndexCount)/3}doDestroy(){this.fillVAO=B(this.fillVAO),this.outlineVAO=B(this.outlineVAO)}doPrepareForRendering(e,s,t){let i=new Uint32Array(s),r=new Int32Array(i.buffer),o=i[t++],a=R.createVertex(e,D.STATIC_DRAW,new Int32Array(r.buffer,4*t,o));t+=o;let n=i[t++],l=R.createIndex(e,D.STATIC_DRAW,new Uint32Array(i.buffer,4*t,n));t+=n;let c=i[t++],y=R.createVertex(e,D.STATIC_DRAW,new Int32Array(r.buffer,4*t,c));t+=c;let d=i[t++],u=R.createIndex(e,D.STATIC_DRAW,new Uint32Array(i.buffer,4*t,d));t+=d;let f=this.layer,p=f.fillMaterial,m=f.outlineMaterial;this.fillVAO=new H(e,p.getAttributeLocations(),p.getLayoutInfo(),{geometry:a},l),this.outlineVAO=new H(e,m.getAttributeLocations(),m.getLayoutInfo(),{geometry:y},u)}},me=class extends Q{constructor(e,s,t){super(e,s),this.type=I.SYMBOL,this.iconPerPageElementsMap=new Map,this.glyphPerPageElementsMap=new Map,this.symbolInstances=[],this.isIconSDF=!1,this.opacityChanged=!1,this.lastOpacityUpdate=0,this.symbols=[];let i=new Uint32Array(e),r=new Int32Array(e),o=new Float32Array(e),a=this.bufferDataOffset;this.isIconSDF=!!i[a++];
1let n=i[a++],l=i[a++],c=i[a++],y=new C(n,l,c,0),d=i[a++];for(let m=0;m<d;m++){let _=i[a++],g=i[a++],b=i[a++];this.iconPerPageElementsMap.set(_,[g,b])}let u=i[a++];for(let m=0;m<u;m++){let _=i[a++],g=i[a++],b=i[a++];this.glyphPerPageElementsMap.set(_,[g,b])}let f=i[a++],p=i[a++];this.iconOpacity=new Int32Array(f),this.textOpacity=new Int32Array(p),a=Rt(i,r,o,a,this.symbols,t,y),this.bufferDataOffset=a}get memoryUsed(){return(this.data?.byteLength??0)+(this.iconVAO?.usedMemory??0)+(this.textVAO?.usedMemory??0)+Ae(this.iconOpacity)+Ae(this.textOpacity)}hasData(){return this.iconPerPageElementsMap.size>0||this.glyphPerPageElementsMap.size>0}triangleCount(){let e=0;for(let[s,t]of this.iconPerPageElementsMap)e+=t[1];for(let[s,t]of this.glyphPerPageElementsMap)e+=t[1];return e/3}doDestroy(){this.iconVAO=B(this.iconVAO),this.textVAO=B(this.textVAO)}updateOpacityInfo(){if(!this.opacityChanged)return;this.opacityChanged=!1;let e=this.iconOpacity,s=this.iconVAO.vertexBuffers.opacity;e.length>0&&e.byteLength===s.usedMemory&&s.setSubData(e,0,0,e.length);let t=this.textOpacity,i=this.textVAO.vertexBuffers.opacity;t.length>0&&t.byteLength===i.usedMemory&&i.setSubData(t,0,0,t.length)}doPrepareForRendering(e,s,t){let i=new Uint32Array(s),r=new Int32Array(i.buffer),o=i[t++],a=R.createVertex(e,D.STATIC_DRAW,new Int32Array(r.buffer,4*t,o));t+=o;let n=i[t++],l=R.createIndex(e,D.STATIC_DRAW,new Uint32Array(i.buffer,4*t,n));t+=n;let c=i[t++],y=R.createVertex(e,D.STATIC_DRAW,new Int32Array(r.buffer,4*t,c));t+=c;let d=i[t++],u=R.createIndex(e,D.STATIC_DRAW,new Uint32Array(i.buffer,4*t,d));t+=d;let f=R.createVertex(e,D.STATIC_DRAW,this.iconOpacity.buffer),p=R.createVertex(e,D.STATIC_DRAW,this.textOpacity.buffer),m=this.layer,_=m.iconMaterial,g=m.textMaterial;this.iconVAO=new H(e,_.getAttributeLocations(),_.getLayoutInfo(),{geometry:a,opacity:f},l),this.textVAO=new H(e,g.getAttributeLocations(),g.getLayoutInfo(),{geometry:y,opacity:p},u)}},ge=class extends Q{constructor(e,s){super(e,s),this.type=I.CIRCLE,this.circleIndexStart=0,this.circleIndexCount=0;let t=new Uint32Array(e),i=this.bufferDataOffset;this.circleIndexStart=t[i++],this.circleIndexCount=t[i++],this.bufferDataOffset=i}get memoryUsed(){return(this.data?.byteLength??0)+(this.vao?.usedMemory??0)}hasData(){return this.circleIndexCount>0}triangleCount(){return this.circleIndexCount/3}doDestroy(){this.vao=B(this.vao)}doPrepareForRendering(e,s,t){let i=new Uint32Array(s),r=new Int32Array(i.buffer),o=i[t++],a=R.createVertex(e,D.STATIC_DRAW,new Int32Array(r.buffer,4*t,o));t+=o;let n=i[t++],l=R.createIndex(e,D.STATIC_DRAW,new Uint32Array(i.buffer,4*t,n));t+=n;let c=this.layer.circleMaterial;this.vao=new H(e,c.getAttributeLocations(),c.getLayoutInfo(),{geometry:a},l)}};var be=class h extends ue{constructor(e,s,t,i,r,o,a,n=null){super(e,s,t,i,r,o,4096,4096),this.styleRepository=a,this._memCache=n,this.type="vector-tile",this._referenced=0,this._hasSymbolBuckets=!1,this._memoryUsedByLayerData=0,this.layerData=new Map,this.status="loading",this.allSymbolsFadingOut=!1,this.lastOpacityUpdate=0,this.symbols=new Map,this.isCoverage=!1,this.neededForCoverage=!1,this.decluttered=!1,this.parentTile=null,this.childrenTiles=new Set,this.featureIndex=null,this.triangleCount=0,this._processed=!1,this._referenced=1,this.id=e.id}get hasSymbolBuckets(){return this._hasSymbolBuckets}get isFading(){return this._hasSymbolBuckets&&performance.now()-this.lastOpacityUpdate<200}get isHoldingForFade(){return this._hasSymbolBuckets&&(!this.allSymbolsFadingOut||performance.now()-this.lastOpacityUpdate<200)}get wasRequested(){return this.status==="errored"||this.status==="loaded"||this.status==="reloading"}setData(e){this.changeDataImpl(e),this.requestRender(),this.ready(),this._processed=!0}deleteLayerData(e){let s=!1;for(let t of e){let i=this.layerData.get(t);i&&(this._memoryUsedByLayerData-=i.memoryUsed,i.type===I.SYMBOL&&this.symbols.delete(t)&&(s=!0),i.destroy(),this.layerData.delete(t))}this._memCache?.updateSize(this.key.id,this,this._memoryUsedByLayerData),s&&(this.featureIndex?.clear(),this.emit("symbols-changed")),this.requestRender()}processed(){return this._processed}hasData(){return this.layerData.size>0}dispose(){this.status!=="unloaded"&&(this.featureIndex=null,Nt.delete(this),h._destroyRenderBuckets(this.layerData),this.layerData.clear(),this._memoryUsedByLayerData=0,this.destroy(),this.status="unloaded")}release(){return--this._referenced==0&&(this.dispose(),this.stage=null,!0)}retain(){++this._referenced}get referenced(){return this._referenced}get usedMemory(){return this._memoryUsedByLayerData+256}changeDataImpl(e){this.featureIndex?.clear();let s=!1;if(e){let{bucketsWithData:t,emptyBuckets:i}=e,r=this._createRenderBuckets(t);if(i&&i.byteLength>0){let o=new Uint32Array(i);for(let a of o)this._deleteLayerData(a)}
1for(let[o,a]of r)this._deleteLayerData(o),a.type===I.SYMBOL&&(this.symbols.set(o,a.symbols),s=!0),this._memoryUsedByLayerData+=a.memoryUsed,this.layerData.set(o,a);this._memCache?.updateSize(this.key.id,this,this.usedMemory)}this._hasSymbolBuckets=!1;for(let[t,i]of this.layerData)i.type===I.SYMBOL&&(this._hasSymbolBuckets=!0);s&&this.emit("symbols-changed")}attachWithContext(e){this.stage={context:e,trashDisplayObject(s){s.processDetach()},untrashDisplayObject:()=>!1}}setTransform(e){super.setTransform(e);let s=this.resolution/(e.resolution*e.pixelRatio),t=this.width/this.rangeX*s,i=this.height/this.rangeY*s,r=[0,0];e.toScreen(r,[this.x,this.y]);let o=this.transforms.tileUnitsToPixels;lt(o),ht(o,o,r),ct(o,o,Math.PI*e.rotation/180),ut(o,o,[t,i,1])}_createTransforms(){return{displayViewScreenMat3:q(),tileMat3:q(),tileUnitsToPixels:q()}}static _destroyRenderBuckets(e){if(!e)return;let s=new Set;for(let t of e.values())s.has(t)||(t.destroy(),s.add(t));e.clear()}_createRenderBuckets(e){let s=new Map,t=new Map;for(let i of e){let r=this._deserializeBucket(i,t);for(let o of r.layerUIDs)s.set(o,r)}return s}_deserializeBucket(e,s){let t=s.get(e);if(t)return t;switch(new Uint32Array(e)[0]){case I.FILL:t=new _e(e,this.styleRepository);break;case I.LINE:t=new pe(e,this.styleRepository);break;case I.SYMBOL:t=new me(e,this.styleRepository,this);break;case I.CIRCLE:t=new ge(e,this.styleRepository)}return s.set(e,t),t}_deleteLayerData(e){if(!this.layerData.has(e))return;let s=this.layerData.get(e);this._memoryUsedByLayerData-=s.memoryUsed,s.destroy(),this.layerData.delete(e)}},Nt=new Map;function Qt(h,e,s,t,i,r){let{iconRotationAlignment:o,textRotationAlignment:a,iconTranslate:n,iconTranslateAnchor:l,textTranslate:c,textTranslateAnchor:y}=t,d=0;for(let u of h.colliders){let[f,p]=u.partIndex===0?n:c,m=u.partIndex===0?l:y,_=u.minLod<=r&&r<=u.maxLod;d+=_?0:1,u.enabled=_,u.xScreen=u.xTile*i[0]+u.yTile*i[3]+i[6],u.yScreen=u.xTile*i[1]+u.yTile*i[4]+i[7],m===bt.MAP?(u.xScreen+=s*f-e*p,u.yScreen+=e*f+s*p):(u.xScreen+=f,u.yScreen+=p),z.VIEWPORT===(u.partIndex===0?o:a)?(u.dxScreen=u.dxPixels,u.dyScreen=u.dyPixels):(u.dxScreen=s*(u.dxPixels+u.width/2)-e*(u.dyPixels+u.height/2)-u.width/2,u.dyScreen=e*(u.dxPixels+u.width/2)+s*(u.dyPixels+u.height/2)-u.height/2)}h.colliders.length>0&&d===h.colliders.length&&(h.unique.show=!1)}var we=class{constructor(e,s,t,i,r,o){this._symbols=e,this._styleRepository=i,this._zoom=r,this._currentLayerCursor=0,this._currentSymbolCursor=0,this._styleProps=new Map,this._allNeededMatrices=new Map,this._gridIndex=new W(s,t,32),this._si=Math.sin(Math.PI*o/180),this._co=Math.cos(Math.PI*o/180);for(let a of e)for(let n of a.symbols)this._allNeededMatrices.has(n.tile)||this._allNeededMatrices.set(n.tile,xt(n.tile.transforms.tileUnitsToPixels))}work(e){let s=this._gridIndex;function t(r){let o=r.xScreen+r.dxScreen,a=r.yScreen+r.dyScreen,n=o+r.width,l=a+r.height,[c,y,d,u]=s.getCellSpan(o,a,n,l);for(let f=y;f<=u;f++)for(let p=c;p<=d;p++){let m=s.cells[f][p];for(let _ of m){let g=_.xScreen+_.dxScreen,b=_.yScreen+_.dyScreen,S=g+_.width,A=b+_.height;if(!(n<g||o>S||l<b||a>A))return!0}}return!1}let i=performance.now();for(;this._currentLayerCursor<this._symbols.length;this._currentLayerCursor++,this._currentSymbolCursor=0){let r=this._symbols[this._currentLayerCursor],o=this._getProperties(r.styleLayerUID);for(;this._currentSymbolCursor<r.symbols.length;this._currentSymbolCursor++){if(this._currentSymbolCursor%100==99&&performance.now()-i>e)return!1;let a=r.symbols[this._currentSymbolCursor];if(!a.unique.show)continue;Qt(a,this._si,this._co,o,this._allNeededMatrices.get(a.tile),this._zoom);let n=a.unique;if(!n.show)continue;let{iconAllowOverlap:l,iconIgnorePlacement:c,textAllowOverlap:y,textIgnorePlacement:d}=o;for(let u of a.colliders){if(!u.enabled)continue;let f=n.parts[u.partIndex];f.show&&!(u.partIndex?y:l)&&t(u)&&(u.hard?n.show=!1:f.show=!1)}if(n.show)for(let u of a.colliders){if(!u.enabled||(u.partIndex?d:c)||!n.parts[u.partIndex].show)continue;let f=u.xScreen+u.dxScreen,p=u.yScreen+u.dyScreen,m=f+u.width,_=p+u.height,[g,b,S,A]=this._gridIndex.getCellSpan(f,p,m,_);for(let w=b;w<=A;w++)for(let T=g;T<=S;T++)this._gridIndex.cells[w][T].push(u)}}}return!0}_getProperties(e){let s=this._styleProps.get(e);if(s)return s;let t=this._zoom,i=this._styleRepository.getStyleLayerByUID(e),r=i.getLayoutValue("symbol-placement",t)!==gt.POINT,o=i.getLayoutValue("icon-rotation-alignment",t);o===z.AUTO&&(o=r?z.MAP:z.VIEWPORT);let a=i.getLayoutValue("text-rotation-alignment",t);a===z.AUTO&&(a=r?z.MAP:z.VIEWPORT);let n=i.getPaintValue("icon-translate",t),l=i.getPaintValue("icon-translate-anchor",t),c=i.getPaintValue("text-translate",t),y=i.getPaintValue("text-translate-anchor",t),d={iconAllowOverlap:i.getLayoutValue("icon-allow-overlap",t),iconIgnorePlacement:i.getLayoutValue("icon-ignore-placement",t),textAllowOverlap:i.getLayoutValue("text-allow-overlap",t),textIgnorePlacement:i.getLayoutValue("text-ignore-placement",t),iconRotationAlignment:o,textRotationAlignment:a,iconTranslateAnchor:l,iconTranslate:n,textTranslateAnchor:y,textTranslate:c};return this._styleProps.set(e,d),d}};function Jt(h,e){if(h.priority-e.priority)return h.priority-e.priority;let s=h.tile.key,t=e.tile.key;return s.world-t.world?s.world-t.world:s.level-t.level?s.level-t.level:s.row-t.row?s.row-t.row:s.col-t.col?s.c
1ol-t.col:h.xTile-e.xTile?h.xTile-e.xTile:h.yTile-e.yTile}var Se=class{get running(){return this._running}constructor(e,s,t,i,r,o){this._visibleTiles=e,this._symbolRepository=s,this._createCollisionJob=t,this._assignTileSymbolsOpacity=i,this._symbolLayerSorter=r,this._isLayerVisible=o,this._selectionJob=null,this._selectionJobCompleted=!1,this._collisionJob=null,this._collisionJobCompleted=!1,this._opacityJob=null,this._opacityJobCompleted=!1,this._running=!0}setScreenSize(e,s){this._screenWidth===e&&this._screenHeight===s||this.restart(),this._screenWidth=e,this._screenHeight=s}restart(){this._selectionJob=null,this._selectionJobCompleted=!1,this._collisionJob=null,this._collisionJobCompleted=!1,this._opacityJob=null,this._opacityJobCompleted=!1,this._running=!0}continue(e){if(this._selectionJob||(this._selectionJob=this._createSelectionJob()),!this._selectionJobCompleted){let s=performance.now();if(!this._selectionJob.work(e)||(this._selectionJobCompleted=!0,(e=Math.max(0,e-(performance.now()-s)))===0))return!1}if(this._collisionJob||(this._collisionJob=this._createCollisionJob(this._selectionJob.sortedSymbols,this._screenWidth,this._screenHeight)),!this._collisionJobCompleted){let s=performance.now();if(!this._collisionJob.work(e)||(this._collisionJobCompleted=!0,(e=Math.max(0,e-(performance.now()-s)))===0))return!1}if(this._opacityJob||(this._opacityJob=this._createOpacityJob()),!this._opacityJobCompleted){let s=performance.now();if(!this._opacityJob.work(e)||(this._opacityJobCompleted=!0,(e=Math.max(0,e-(performance.now()-s)))===0))return!1}return this._running=!1,!0}_createSelectionJob(){let e=this._symbolRepository.uniqueSymbols;for(let n=0;n<e.length;n++){let l=e[n];for(let c=0;c<l.uniqueSymbols.length;c++){let y=l.uniqueSymbols[c];for(let d of y.tileSymbols)d.selectedForRendering=!1}}let s=[],t=0,i=0,r=this._isLayerVisible;function o(n){let l,c=performance.now();for(;i<e.length;i++,t=0){let y=e[i],d=y.styleLayerUID;if(!r(d)){s[i]||(s[i]={styleLayerUID:d,symbols:[]});continue}s[i]=s[i]||{styleLayerUID:d,symbols:[]};let u=s[i];for(;t<y.uniqueSymbols.length;t++){if(l=y.uniqueSymbols[t],t%100==99&&performance.now()-c>n)return!1;let f=null,p=!1,m=!1;for(let _ of l.tileSymbols)if(!m||!p){let g=_.tile;(!f||g.isCoverage||g.neededForCoverage&&!p)&&(f=_,(g.neededForCoverage||g.isCoverage)&&(m=!0),g.isCoverage&&(p=!0))}if(f.selectedForRendering=!0,m){u.symbols.push(f),l.show=!0;for(let _ of l.parts)_.show=!0}else l.show=!1}}for(let y of s)y.symbols.sort(Jt);return!0}let a=this._symbolLayerSorter;return{work:o,get sortedSymbols(){return s.sort(a)}}}_createOpacityJob(){let e=this._assignTileSymbolsOpacity,s=this._visibleTiles,t=0;function i(r,o){let a=r.symbols;for(let[n,l]of a)Kt(l,o);e(r,o);for(let n of r.childrenTiles)i(n,o)}return{work(r){let o=performance.now();for(;t<s.length;t++){if(performance.now()-o>r)return!1;let a=s[t];a.parentTile==null&&i(a,performance.now())}return!0}}}};function Kt(h,e){for(let s of h){let t=s.unique;for(let i of t.parts){let r=i.targetOpacity>.5?1:-1;i.startOpacity+=r*((e-i.startTime)/200),i.startOpacity=Math.min(Math.max(i.startOpacity,0),1),i.startTime=e,i.targetOpacity=t.show&&i.show?1:0}}}var Gt=32,Yt=8,jt=64,$t=20,xe=class{constructor(e,s,t){this.tileCoordRange=e,this._visibleTiles=s,this._createUnique=t,this._tiles=new Map,this._uniqueSymbolsReferences=new Map}get uniqueSymbols(){return this._uniqueSymbolLayerArray==null&&(this._uniqueSymbolLayerArray=this._createUniqueSymbolLayerArray()),this._uniqueSymbolLayerArray}get uniqueSymbolsReferences(){return this._uniqueSymbolsReferences}add(e,s){this._uniqueSymbolLayerArray=null;let t=this._tiles.get(e.id);t||(t={symbols:new Map},this._tiles.set(e.id,t));let i=new Map;if(s)for(let a of s)t.symbols.has(a)&&(i.set(a,t.symbols.get(a)),t.symbols.delete(a));else for(let[a,n]of e.layerData)t.symbols.has(a)&&(i.set(a,t.symbols.get(a)),t.symbols.delete(a));this._removeSymbols(i);let r=e.symbols,o=new Map;for(let[a,n]of r){let l=n.length;if(l>=Gt){let c=this.tileCoordRange;do c/=2,l/=4;while(l>Yt&&c>jt);let y=new W(this.tileCoordRange,this.tileCoordRange,c);o.set(a,{flat:n,index:y}),t.symbols.set(a,{flat:n,index:y});for(let d of n)y.getCell(d.xTile,d.yTile).push(d)}else o.set(a,{flat:n}),t.symbols.set(a,{flat:n})}
1this._addSymbols(e.key,r)}deleteStyleLayers(e){this._uniqueSymbolLayerArray=null;for(let[s,t]of this._tiles){let i=new Map;for(let r of e)t.symbols.has(r)&&(i.set(r,t.symbols.get(r)),t.symbols.delete(r));this._removeSymbols(i),t.symbols.size===0&&this._tiles.delete(s)}}removeTile(e){this._uniqueSymbolLayerArray=null;let s=this._tiles.get(e.id);if(!s)return;let t=new Map;for(let[i,r]of e.symbols)s.symbols.has(i)&&(t.set(i,s.symbols.get(i)),s.symbols.delete(i));this._removeSymbols(t),s.symbols.size===0&&this._tiles.delete(e.id)}querySymbols(e,s,t,i){let r=[],o=this.uniqueSymbols;for(let a of o){let n=a.styleLayerUID,l=a.uniqueSymbols;for(let c of l){let y=c.tileSymbols.find(d=>d.selectedForRendering);y&&At(y,e,s*(window.devicePixelRatio||1),t)&&r.push({vtlSymbol:y,styleLayerUID:n,tileKey:y.tile.key})}}return r}_removeSymbols(e){for(let[s,{flat:t}]of e)for(let i of t){let r=i.unique,o=r.tileSymbols,a=o.length-1;for(let n=0;n<a;n++)if(o[n]===i){o[n]=o[a];break}if(o.length=a,a===0){let n=this._uniqueSymbolsReferences.get(s);n.delete(r),n.size===0&&this._uniqueSymbolsReferences.delete(s)}i.unique=null}}_addSymbols(e,s){if(s.size===0)return;let t=this._visibleTiles;for(let i of t)i.parentTile||i.key.world!==e.world||i.key.level===e.level&&!i.key.equals(e)||this._matchSymbols(i,e,s);for(let[i,r]of s)for(let o of r)if(o.unique==null){let a=this._createUnique();o.unique=a,a.tileSymbols.push(o);let n=this._uniqueSymbolsReferences.get(i);n||(n=new Set,this._uniqueSymbolsReferences.set(i,n)),n.add(a)}}_matchSymbols(e,s,t){if(e.key.level>s.level){let r=e.key.level-s.level;if(e.key.row>>r!==s.row||e.key.col>>r!==s.col)return}if(s.level>e.key.level){let r=s.level-e.key.level;if(s.row>>r!==e.key.row||s.col>>r!==e.key.col)return}if(s.equals(e.key)){for(let r of e.childrenTiles)this._matchSymbols(r,s,t);return}let i=new Map;for(let[r,o]of t){let a=[];for(let y of o){let d=He(this.tileCoordRange,y.xTile,s.level,s.col,e.key.level,e.key.col),u=He(this.tileCoordRange,y.yTile,s.level,s.row,e.key.level,e.key.row);d>=0&&d<this.tileCoordRange&&u>=0&&u<this.tileCoordRange&&a.push({symbol:y,xTransformed:d,yTransformed:u})}let n=[],l=(e.key.level<s.level?1:1<<e.key.level-s.level)+$t,c=this._tiles.get(e.id).symbols.get(r);if(c){let y=c.flat;for(let d of a){let u,f=!1,p=d.xTransformed,m=d.yTransformed;u=c.index!=null?c.index.getCell(p,m):y;let _=d.symbol,g=_.hash;for(let b of u)if(g===b.hash&&Math.abs(p-b.xTile)<=l&&Math.abs(m-b.yTile)<=l){let S=b.unique;_.unique=S,S.tileSymbols.push(_),f=!0;break}f||n.push(_)}}n.length>0&&i.set(r,n)}for(let r of e.childrenTiles)this._matchSymbols(r,s,i)}_createUniqueSymbolLayerArray(){let e=this._uniqueSymbolsReferences,s=new Array(e.size),t,i=0;for(let[r,o]of e){let a=new Array(o.size);t=0;for(let n of o)a[t++]=n;s[i]={styleLayerUID:r,uniqueSymbols:a},i++}return s}};var Zt=.5,Mt=1e-6,Te=class{constructor(e,s){this.styleRepository=e,this._tileToHandle=new Map,this._viewState={scale:0,rotation:0,center:[0,0],size:[0,0]},this._declutterViewState={scale:0,rotation:0,center:[0,0],size:[0,0]},this._offsetFromScreenCenter=[0,0],this._completed=!1,this._fading=dt(!1),this._symbolRepository=new xe(4096,s,()=>new fe),this._symbolDeclutterer=new Se(s,this._symbolRepository,(t,i,r)=>this._createCollisionJob(t,i,r),(t,i)=>{t.allSymbolsFadingOut=!0,t.lastOpacityUpdate=i,Lt(t,i,!0),t.decluttered=!0,t.requestRender()},(t,i)=>this.styleRepository.getStyleLayerByUID(t.styleLayerUID).z-this.styleRepository.getStyleLayerByUID(i.styleLayerUID).z,t=>{let i=this.styleRepository.getStyleLayerByUID(t);if(this._zoom+Mt<i.minzoom||this._zoom-Mt>=i.maxzoom)return!1;let r=i.getLayoutProperty("visibility");return!r||r.getValue()!==j.NONE})}get symbolRepository(){return this._symbolRepository}_createCollisionJob(e,s,t){return this.updateDecluttererViewState(),new we(e,s,t,this.styleRepository,this._zoom,this._viewState.rotation)}get fading(){return this._fading.value}get decluttererOffset(){return this._offsetFromScreenCenter}addTile(e){e.decluttered=!1,this._tileToHandle.set(e,e.on("symbols-changed",()=>{this._symbolRepository.add(e),this.restartDeclutter()})),this._symbolRepository.add(e),this.restartDeclutter()}removeTile(e){let s=this._tileToHandle.get(e);s&&(this._symbolRepository.removeTile(e),this.restartDeclutter(),s.remove(),this._tileToHandle.delete(e))}update(e,s){this._zoom=e,this._viewState={scale:s.scale,rotation:s.rotation,center:[s.center[0],s.center[1]],size:[s.size[0],s.size[1]]};let t=[0,0];s.toScreen(t,s.center);let i=[0,0];return s.toScreen(i,this._declutterViewState.center),this._offsetFromScreenCenter[0]=t[0]-i[0],this._offsetFromScreenCenter[1]=t[1]-i[1],this._continueDeclutter(),this._completed}restartDeclutter(){this._completed=!1,this._symbolDeclutterer.restart(),this._notifyUnstable()}clear(){this._completed=!1,this._symbolRepository=null,this._symbolDeclutterer.restart(),this._tileToHandle.forEach(e
1=>e.remove()),this._tileToHandle.clear()}get stale(){return this._zoom!==this._declutterZoom||this._viewState.size[0]!==this._declutterViewState.size[0]||this._viewState.size[1]!==this._declutterViewState.size[1]||this._viewState.scale!==this._declutterViewState.scale||this._viewState.rotation!==this._declutterViewState.rotation}deleteStyleLayers(e){this._symbolRepository.deleteStyleLayers(e)}_continueDeclutter(){this._completed&&!this.stale||(this._symbolDeclutterer.running||(this.updateDecluttererViewState(),this._symbolDeclutterer.restart()),this._symbolDeclutterer.setScreenSize(this._viewState.size[0],this._viewState.size[1]),this._completed=this._symbolDeclutterer.continue(1.5),this._completed&&this._scheduleNotifyStable())}_scheduleNotifyStable(){this._stableNotificationHandle!=null&&clearTimeout(this._stableNotificationHandle),this._stableNotificationHandle=setTimeout(()=>{this._stableNotificationHandle=null,this._fading.value=!1},(1+Zt)*200)}_notifyUnstable(){this._stableNotificationHandle!=null&&(clearTimeout(this._stableNotificationHandle),this._stableNotificationHandle=null),this._fading.value=!0}updateDecluttererViewState(){this._declutterZoom=this._zoom,this._declutterViewState.center[0]=this._viewState.center[0],this._declutterViewState.center[1]=this._viewState.center[1],this._declutterViewState.rotation=this._viewState.rotation,this._declutterViewState.scale=this._viewState.scale,this._declutterViewState.size[0]=this._viewState.size[0],this._declutterViewState.size[1]=this._viewState.size[1],this._offsetFromScreenCenter[0]=0,this._offsetFromScreenCenter[1]=0}};var Ie=class extends ue{_createTransforms(){return{displayViewScreenMat3:q(),tileMat3:q()}}};var ve=1e-6;function Pt(h,e){if(h){let s=h.getLayoutProperty("visibility");if(!s||s.getValue()!==j.NONE&&(h.minzoom===void 0||h.minzoom<e+ve)&&(h.maxzoom===void 0||h.maxzoom>=e-ve))return!0}return!1}var De=class extends It{constructor(e){super(e),this._backgroundTiles=[],this._computeDisplayInfoView(e)}destroy(){this.removeAllChildren(),this._spriteMosaic?.dispose(),this._spriteMosaic=null,this._glyphMosaic?.dispose(),this._glyphMosaic=null,this._symbolFader!=null&&(this._symbolFader.clear(),this._symbolFader=null),this._styleRepository=null,this._backgroundTiles=[]}get fading(){return this._symbolFader?.fading??!1}get symbolFader(){return this._symbolFader}get symbolRepository(){return this._symbolFader?.symbolRepository}setStyleResources(e,s,t,i){this._spriteMosaic=e,this._glyphMosaic=s,this._styleRepository=t,this._tileInfoView=i,this._computeDisplayInfoView(i),this._symbolFader==null&&(this._symbolFader=new Te(this._styleRepository,this.children)),this._symbolFader.styleRepository=t}setSpriteMosaic(e){this._spriteMosaic?.dispose(),this._spriteMosaic=e}deleteStyleLayers(e){this._symbolFader!=null&&this._symbolFader.deleteStyleLayers(e)}createRenderParams(e){return V(U({},super.createRenderParams(e)),{renderPass:null,styleLayer:null,styleLayerUID:-1,glyphMosaic:this._glyphMosaic,spriteMosaic:this._spriteMosaic,hasClipping:!!this._clippingInfos})}doRender(e){!this.visible||e.drawPhase!==$.MAP&&e.drawPhase!==$.DEBUG||this._spriteMosaic===void 0||super.doRender(e)}addChild(e){return super.addChild(e),this._symbolFader!=null?this._symbolFader.addTile(e):e.decluttered=!0,this.requestRender(),e}removeChild(e){return this._symbolFader!=null&&this._symbolFader.removeTile(e),this.requestRender(),super.removeChild(e)}renderChildren(e){let{drawPhase:s}=e;s!==$.DEBUG?this._doRender(e):super.renderChildren(e)}removeAllChildren(){for(let e=0;e<this.children.length;e++){let s=this.children[e];this._symbolFader!=null&&this._symbolFader.removeTile(s),s.dispose()}super.removeAllChildren()}getStencilTarget(){return this.children.filter(e=>e.neededForCoverage&&e.hasData())}restartDeclutter(){this._symbolFader!=null&&this._symbolFader.restartDeclutter()}_doRender(e){let{context:s,state:t}=e,i=this._styleRepository;if(!i)return;let r=i.layers,o=this._displayInfo.scaleToZoom(t.scale);i.backgroundBucketIds.length>0&&(e.renderPass="background",this._renderBackgroundLayers(e,i.backgroundBucketIds,o)),super.renderChildren(e),e.drawPhase===$.MAP&&this._fade(o,t);let a=this.children.filter(n=>n.visible&&n.hasData());if(!a||a.length===0)return s.bindVAO(),s.setStencilTestEnabled(!0),void s.setBlendingEnabled(!0);for(let n of a)n.triangleCount=0;
1s.setStencilWriteMask(0),s.setColorMask(!0,!0,!0,!0),s.setStencilOp(F.KEEP,F.KEEP,F.REPLACE),s.setStencilTestEnabled(!0),s.setBlendingEnabled(!1),s.setDepthTestEnabled(!0),s.setDepthWriteEnabled(!0),s.setDepthFunction(Ue.LEQUAL),s.setClearDepth(1),s.clear(s.gl.DEPTH_BUFFER_BIT),e.renderPass="opaque";for(let n=r.length-1;n>=0;n--)this._renderStyleLayer(r[n],e,a);s.setDepthWriteEnabled(!1),s.setBlendingEnabled(!0),s.setBlendFunctionSeparate(G.ONE,G.ONE_MINUS_SRC_ALPHA,G.ONE,G.ONE_MINUS_SRC_ALPHA),e.renderPass="translucent";for(let n=0;n<r.length;n++)this._renderStyleLayer(r[n],e,a);s.bindVAO(),s.setStencilTestEnabled(!0),s.setBlendingEnabled(!0);for(let n of a)n.debugInfo.display.triangleCount=n.triangleCount}_fade(e,s){this._symbolFader!=null&&(this._symbolFader.update(e,s)||this.requestRender())}_renderStyleLayer(e,s,t){let{displayLevel:i,painter:r,renderPass:o}=s;if(e===void 0)return;let a=e.getLayoutProperty("visibility");if(a&&a.getValue()===j.NONE)return;let n;switch(e.type){case v.BACKGROUND:return;case v.FILL:if(o!=="opaque"&&s.renderPass!=="translucent")return;n="vtlFill";break;case v.LINE:if(o!=="translucent")return;n="vtlLine";break;case v.CIRCLE:if(o!=="translucent")return;n="vtlCircle";break;case v.SYMBOL:if(o!=="translucent")return;n="vtlSymbol"}if(t=e.type===v.SYMBOL?t.filter(c=>c.decluttered):t.filter(c=>c.neededForCoverage),n!=="vtlSymbol"&&(t.length===0||e.minzoom!==void 0&&e.minzoom>=i+ve||e.maxzoom!==void 0&&e.maxzoom<i-ve))return;let l=e.uid;s.styleLayerUID=l,s.styleLayer=e;for(let c of t)if(c.layerData.has(l)){r.renderObjects(s,t,n);break}}_renderBackgroundLayers(e,s,t){let{context:i,painter:r,state:o}=e,a=this._styleRepository,n=!1;for(let b of s)if(a.getLayerById(b).type===v.BACKGROUND&&Pt(a.getLayerById(b),t)){n=!0;break}if(!n)return;let l=this._tileInfoView,c=l.getTileCoverage(e.state,0,!0,"smallest"),{spans:y,lodInfo:d}=c,{level:u}=d,f=E(),p=[];if(this._renderPasses){let b=this._renderPasses[0];this._clippingInfos!=null&&(b.brushes[0].prepareState(e),b.brushes[0].drawMany(e,this._clippingInfos))}let m=this._backgroundTiles,_,g=0;for(let{row:b,colFrom:S,colTo:A}of y)for(let w=S;w<=A;w++){if(g<m.length)_=m[g],_.key.set(u,b,d.normalizeCol(w),d.getWorldForColumn(w)),l.getTileBounds(f,_.key,!1),_.x=f[0],_.y=f[3],_.resolution=l.getTileResolution(u);else{let T=new C(u,b,d.normalizeCol(w),d.getWorldForColumn(w)),O=l.getTileBounds(E(),T),re=l.getTileResolution(u);_=new Ie(T,re,O[0],O[3],512,512,4096,4096),m.push(_)}_.setTransform(o),p.push(_),g++}i.setStencilWriteMask(0),i.setColorMask(!0,!0,!0,!0),i.setStencilOp(F.KEEP,F.KEEP,F.REPLACE),i.setStencilFunction(Ue.EQUAL,0,255),i.setStencilTestEnabled(!0);for(let b of s){let S=a.getLayerById(b);S.type===v.BACKGROUND&&Pt(S,t)&&(e.styleLayerUID=S.uid,e.styleLayer=S,r.renderObjects(e,p,"vtlBackground"))}le.pool.release(c)}_computeDisplayInfoView(e){let s=e.tileInfo.lods[0].scale,t=Math.max(25,e.tileInfo.lods.length),i=[];for(let r=0;r<=t;r++)i.push(s),s/=2;this._displayInfo=ae.create({scales:i,size:512,spatialReference:e.spatialReference,numLODs:t})}};var es=8,ts=512,Ot=4096,ss=(h,e)=>{let s=h.vtlSymbol.sourceTile,t=e.vtlSymbol.sourceTile;return s.level!==t.level?s.level-t.level:s.row!==t.row?s.row-t.row:s.col!==t.col?s.col-t.col:h.styleLayerUID-e.styleLayerUID},Ce=class h{constructor(e,s,t,i,r){this.tileKey=e,this._index=null,this._styleRepository=null,this._tileHandler=null,this._tileKeyToPBF=new Map,this._tileLayerData=s,this._styleRepository=t,this._tileHandler=i,this._parentLayer=r}static create(e,s,t,i,r){return new h(e,s,t,i,r)}clear(){this._index?.clear(),this._tileKeyToPBF.clear()}queryAttributes(e,s,t,i,r){return x(this,null,function*(){if(this._tileLayerData.size===0||!this._styleRepository||!this._tileHandler)return[];this._index===null&&(this._index=new yt(100,is),yield this._indexLayers());let o=[];return this._queryIndex(o,e,s,t,this.tileKey.level,i),r&&r?.length>0&&(yield this._getSymbolsAttributes(o,r)),o})}_indexLayers(){return x(this,null,function*(){let e=this.tileKey,s=this._styleRepository.layers,t=yield this._getTilePayload(e);for(let[i,r]of this._tileLayerData){let o=s[i],a=t.find(c=>c.sourceName===o.source);if(!a)continue;let{protobuff:n,key:l}=a;if(r.type!==I.SYMBOL){let c=1<<e.level-l.level,y=e.row-l.row*c,d=e.col-l.col*c;this._indexLayer(o,n,e.level,c,y,d)}}})}_indexLayer(e,s,t,i,r,o){let a=e.sourceLayer,n=e.getFeatureFilter(),l=t,c=t+1,y=_t(l),d=new Y(new Uint8Array(s),new DataView(s));for(;d.next();)switch(d.tag()){case 3:{let u=d.getMessage(),f=new ze(u);if(u.release(),f.name!==a)continue;let p=f.getData(),m=f.extent/i,_=m*o-y,g=m*r-y,b=_+m+2*y,S=g+m+2*y,A=m/ts,w=Ot/m,T=m*o,O=m*r;for(;p.nextTag(2);){let re=p.getMessage(),oe=new Ee(re,f);if(re.release(),n&&!n.filter(oe,t))continue;let We=oe.values||{},Qe=We._minzoom,Je=We._maxzoom;if(Qe&&Qe>=10*c||Je&&Je<=10*l)continue;let M=e.getFeatureInflatedBounds(oe,l,f.extent,A);M==null||M[0]>b||M[1]>S||M[2]<_||M[3]<g||(M[0]=(M[0]-T)*w,M[1]=(M[1]-O)*w,M[2]=(M[2]-T)*w,M[3]=(M[3]-O)*w,this._index.insert(new wt(e,oe,M,w,T,O)))}break}
1default:d.skip()}}_getSymbolsAttributes(e,s){return x(this,null,function*(){if(!s||s.length===0)return e;let t=[];s.sort(ss);let i=s[0].styleLayerUID,r=0;for(let l=0;l<s.length;l++)i!==s[l].styleLayerUID&&(t.push({from:r,to:l,styleLayerUID:i,sourceTileKey:s[l].vtlSymbol.sourceTile}),r=l,i=s[l].styleLayerUID);t.push({from:r,to:s.length,styleLayerUID:i,sourceTileKey:s[s.length-1].vtlSymbol.sourceTile});let o=this._styleRepository.layers,a,n=null;for(let l of t){let c=yield this._getTilePayload(l.sourceTileKey);a=o[l.styleLayerUID],n=!!a&&c.find(y=>y.sourceName===a.source),n&&this._addSymbolsAttributes(e,s.slice(l.from,l.to).map(y=>y.vtlSymbol),i,n)}return e})}_addSymbolsAttributes(e,s,t,i){let r=this._styleRepository.layers,o=i.key,a=this.tileKey,n=1<<a.level-o.level,l=a.row-o.row*n,c=a.col-o.col*n;this._getSymbolAttributes(i.protobuff,s,t,n,l,c).forEach(y=>{let{attributes:d,tilePoint:u}=y;e.push({layerId:r[t].id,layerIndex:t,graphic:new ke({attributes:d,origin:{type:"vector-tile",layerId:r[t].id,layerIndex:t,layer:this._parentLayer}}),tilePoint:u})})}_getSymbolAttributes(e,s,t,i,r,o){let a=[],n=this._styleRepository.layers,l=0;s.sort((y,d)=>y.featureIndex-d.featureIndex);let c=new Y(new Uint8Array(e),new DataView(e));for(;c.next();)switch(c.tag()){case 3:{let y=c.getMessage(),d=new ze(y);if(y.release(),d.name!==n[t].sourceLayer)continue;let u=d.getData(),f=d.extent/i,p=Ot/f,m=f*o,_=f*r,g=0;for(;u.nextTag(2);){let b=u.getMessage();if(g++===s[l].featureIndex){let S=new Ee(b,d),A=S.values,w=S.getGeometry(),T=w!=null?[p*(w[0][0].x-m),p*(w[0][0].y-_)]:null;a.push({attributes:A,tilePoint:T}),l++}if(b.release(),l===s.length)return a}break}default:c.skip()}return a}_queryIndex(e,s,t,i,r,o){let a=es*i*(window.devicePixelRatio||1);return this._index?.search({minX:s-a,minY:t-a,maxX:s+a,maxY:t+a},n=>{let{layer:l,feature:c}=n;l.isIntersectingFeature(s,t,i,c,r,o,n)&&e.push({layerId:l.id,layerIndex:l.uid,tilePoint:null,graphic:new ke({attributes:c.values,origin:{type:"vector-tile",layerId:n.layer.id,layerIndex:n.layer.uid,layer:this._parentLayer}})})}),e}_getTilePayload(e){return x(this,null,function*(){return $e(this._tileKeyToPBF,e.id,(
1)=>this._tileHandler.fetchTilePBFs(e)).then(s=>s)})}},is=h=>({minX:h.bounds[0],minY:h.bounds[1],maxX:h.bounds[2],maxY:h.bounds[3]});var ie=class extends pt{constructor(){super(...arguments),this._fullCacheLodInfos=null,this._levelByScale={}}getTileParentId(e){let s=C.pool.acquire(e),t=s.level===0?null:C.getId(s.level-1,s.row>>1,s.col>>1,s.world);return C.pool.release(s),t}getTileCoverage(e,s,t=!0,i){let r=super.getTileCoverage(e,s,t,i);if(!r)return r;let o=1<<r.lodInfo.level;return r.spans=r.spans.filter(a=>a.row>=0&&a.row<o),r}scaleToLevel(e){if(this._fullCacheLodInfos||this._initializeFullCacheLODs(this._lodInfos),this._levelByScale[e])return this._levelByScale[e];{let s=this._fullCacheLodInfos;if(e>s[0].scale)return s[0].level;let t,i;for(let r=0;r<s.length-1;r++)if(i=s[r+1],e>i.scale)return t=s[r],t.level+(t.scale-e)/(t.scale-i.scale);return s[s.length-1].level}}_initializeFullCacheLODs(e){let s;if(e[0].level===0)s=e.map(t=>({level:t.level,resolution:t.resolution,scale:t.scale}));else{let t=this.tileInfo.size[0],i=this.tileInfo.spatialReference;s=ae.create({size:t,spatialReference:i}).lods.map(r=>({level:r.level,resolution:r.resolution,scale:r.scale}))}for(let t=0;t<s.length;t++)this._levelByScale[s[t].scale]=s[t].level;this._fullCacheLodInfos=s}};var Ne=2,kt=8,Ut=512,Re=class extends vt(Dt){constructor(){super(...arguments),this._styleChanges=[],this._fetchQueue=null,this._parseQueue=null,this._tileHandlerPromise=null,this._isTileHandlerReady=!1}get fading(){return this._vectorTileContainer?.fading??!1}
1hitTest(h,e){return x(this,null,function*(){let s=this._tileHandlerPromise,t=this._vectorTileContainer?.symbolFader;if(!s||!this._isTileHandlerReady||!t)return;yield s;let i=null,r=this._vectorTileContainer?.symbolRepository;r&&(i=r.querySymbols(e,Ne,t.decluttererOffset,{}));let o=this.view.state,a=this._tileManager.getIntersectingTiles(e.x,e.y,Ne,o,i);if((!a||a.length===0)&&i?.length===0)return null;h=h.clone().normalize();let n=[],l=[];for(let c of a)n.push(this._queryTile(l,h,Ne,this.view.state.rotation,c,i?.filter(y=>y.tileKey.id===c.id)));return yield Promise.all(n),l})}update(h){if(this._tileHandlerPromise&&this._isTileHandlerReady)return h.pixelRatio!==this._tileHandler.devicePixelRatio?(this._start(),void(this._tileHandler.devicePixelRatio=h.pixelRatio)):void(this._styleChanges.length>0?this._tileHandlerPromise=this._applyStyleChanges():(this._fetchQueue.pause(),this._parseQueue.pause(),this._fetchQueue.state=h.state,this._parseQueue.state=h.state,this._tileManager.update(h)||this.requestUpdate(),this._parseQueue.resume(),this._fetchQueue.resume()))}attach(){let{style:h}=this.layer.currentStyleInfo;this._styleRepository=new Be(h),this._tileInfoView=new ie(this.layer.tileInfo,this.layer.fullExtent),this._vectorTileContainer=new De(this._tileInfoView),this._tileHandler=new ye(this.layer,this._styleRepository,window.devicePixelRatio||1,this.layer.tileInfo.lods.length-1),this.container.addChild(this._vectorTileContainer),this._start(),this.addAttachHandles([this.layer.on("paint-change",e=>{if(e.isDataDriven)this._styleChanges.push({type:L.PAINTER_CHANGED,data:e}),this.requestUpdate();else{let s=this._styleRepository,t=s.getLayerById(e.layer);if(!t)return;let i=t.type===v.SYMBOL;s.setPaintProperties(e.layer,e.paint),i&&this._vectorTileContainer?.restartDeclutter(),this._vectorTileContainer?.requestRender()}}),this.layer.on("layout-change",e=>{let s=this._styleRepository,t=s.getLayerById(e.layer);if(!t)return;let i=nt(t.layout,e.layout);if(i!=null){if(at(i,"visibility")&&rs(i)===1)return s.setLayoutProperties(e.layer,e.layout),t.type===v.SYMBOL&&this._vectorTileContainer?.restartDeclutter(),void this._vectorTileContainer?.requestRender();this._styleChanges.push({type:L.LAYOUT_CHANGED,data:e}),this.requestUpdate()}}),this.layer.on("style-layer-visibility-change",e=>{let s=this._styleRepository,t=s.getLayerById(e.layer);t&&(s.setStyleLayerVisibility(e.layer,e.visibility),t.type===v.SYMBOL&&this._vectorTileContainer?.restartDeclutter(),this._vectorTileContainer?.requestRender())}),this.layer.on("style-layer-change",e=>{this._styleChanges.push({type:L.LAYER_CHANGED,data:e}),this.requestUpdate()}),this.layer.on("delete-style-layer",e=>{this._styleChanges.push({type:L.LAYER_REMOVED,data:e}),this.requestUpdate()}),this.layer.on("load-style",()=>this._loadStyle()),this.layer.on("spriteSource-change",e=>{this._styleChanges.push({type:L.SPRITES_CHANGED,data:e});let s=this._styleRepository.layers;for(let t of s)switch(t.type){case v.SYMBOL:t.getLayoutProperty("icon-image")&&this._styleChanges.push({type:L.LAYOUT_CHANGED,data:{layer:t.id,layout:t.layout}});break;case v.LINE:t.getPaintProperty("line-pattern")&&this._styleChanges.push({type:L.PAINTER_CHANGED,data:{layer:t.id,paint:t.paint,isDataDriven:t.isPainterDataDriven()}});break;case v.FILL:t.getLayoutProperty("fill-pattern")&&this._styleChanges.push({type:L.PAINTER_CHANGED,data:{layer:t.id,paint:t.paint,isDataDriven:t.isPainterDataDriven()}})}this.requestUpdate()})])}detach(){this._stop(),this.container.removeAllChildren(),this._vectorTileContainer=N(this._vectorTileContainer),this._tileHandler=N(this._tileHandler)}viewChange(){this.requestUpdate()}moveEnd(){this.requestUpdate()}supportsSpatialReference(h){return tt(this.layer.tileInfo?.spatialReference,h)}canResume(){let h=super.canResume(),{currentStyleInfo:e}=this.layer;if(h&&e?.layerDefinition){let s=this.view.scale,{minScale:t,maxScale:i}=e.layerDefinition;e?.layerDefinition&&(t&&t<s&&(h=!1),i&&i>s&&(h=!1))}return h}isUpdating(){return this.fading}acquireTile(h){let e=this._createVectorTile(h);return this._updatingHandles.addPromise(this._fetchQueue.push(e.key).then(s=>this._parseQueue.push({key:e.key,data:s})).then(s=>{e.once("attach",()=>this.requestUpdate()),e.setData(s),this.requestUpdate()}).catch(s=>{K(s)||Me.getLogger(this).error(s)})),e}releaseTile(h){let e=h.key.id;this._fetchQueue.abort(e),this._parseQueue.abort(e),this.requestUpdate()}
1_start(){if(this._stop(),this._tileManager=new se({acquireTile:s=>this.acquireTile(s),releaseTile:s=>this.releaseTile(s),tileInfoView:this._tileInfoView},this._vectorTileContainer),!this.layer.currentStyleInfo)return;let h=new AbortController,e=this._tileHandler.start({signal:h.signal}).then(()=>{this._fetchQueue=new Ve({tileInfoView:this._tileInfoView,process:(s,t)=>this._getTileData(s,t),concurrency:15}),this._parseQueue=new Ve({tileInfoView:this._tileInfoView,process:(s,t)=>this._parseTileData(s,t),concurrency:8}),this.requestUpdate(),this._isTileHandlerReady=!0});this._tileHandler.spriteMosaic.then(s=>{this._vectorTileContainer.setStyleResources(s,this._tileHandler.glyphMosaic,this._styleRepository,this._tileInfoView),this.requestUpdate()}),this._tileHandlerAbortController=h,this._tileHandlerPromise=e}_stop(){if(!this._tileHandlerAbortController||!this._vectorTileContainer)return;let h=this._tileHandlerAbortController;h&&h.abort(),this._tileHandlerPromise=null,this._isTileHandlerReady=!1,this._fetchQueue=N(this._fetchQueue),this._parseQueue=N(this._parseQueue),this._tileManager=N(this._tileManager),this._vectorTileContainer.removeAllChildren()}_getTileData(h,e){return x(this,null,function*(){return this._tileHandler.fetchTileData(h,e)})}_parseTileData(h,e){return x(this,null,function*(){return this._tileHandler.parseTileData(h,e)})}_applyStyleChanges(){return x(this,null,function*(){this._isTileHandlerReady=!1,this._fetchQueue.pause(),this._parseQueue.pause(),this._fetchQueue.clear(),this._parseQueue.clear(),this._tileManager.clearCache();let h=this._styleChanges;try{yield this._tileHandler.updateStyle(h)}catch(r){Me.getLogger(this).error("error applying vector-tiles style update",r.message),this._fetchQueue.resume(),this._parseQueue.resume(),this._isTileHandlerReady=!0}let e=this._styleRepository,s=new Set;h.forEach(r=>{if(r.type!==L.LAYER_REMOVED)return;let o=r.data,a=e.getLayerById(o.layer);a&&s.add(a.uid)});let t=new Set;h.forEach(r=>{let o;switch(r.type){case L.PAINTER_CHANGED:e.setPaintProperties(r.data.layer,r.data.paint),o=r.data.layer;break;case L.LAYOUT_CHANGED:e.setLayoutProperties(r.data.layer,r.data.layout),o=r.data.layer;break;case L.LAYER_REMOVED:return void e.deleteStyleLayer(r.data.layer);case L.LAYER_CHANGED:e.setStyleLayer(r.data.layer,r.data.index),o=r.data.layer.id;break;case L.SPRITES_CHANGED:this._vectorTileContainer.setSpriteMosaic(this._tileHandler.setSpriteSource(r.data.spriteSource))}if(o){let a=e.getLayerById(o);a&&t.add(a.uid)}});let i=this._vectorTileContainer.children;if(s.size>0){let r=Array.from(s);this._vectorTileContainer.deleteStyleLayers(r);for(let o of i)o.deleteLayerData(r)}if(this._fetchQueue.resume(),this._parseQueue.resume(),t.size>0){let r=Array.from(t),o=[];for(let a of i){let n=this._updatingHandles.addPromise(this._fetchQueue.push(a.key).then(l=>this._parseQueue.push({key:a.key,data:l,styleLayerUIDs:r})).then(l=>a.setData(l)));o.push(n)}yield Promise.all(o)}this._styleChanges=[],this._isTileHandlerReady=!0,this.requestUpdate()})}_loadStyle(){return x(this,null,function*(){let{style:h}=this.layer.currentStyleInfo,e=Ke(h);this._isTileHandlerReady=!1,this._fetchQueue.pause(),this._parseQueue.pause(),this._fetchQueue.clear(),this._parseQueue.clear(),this._styleRepository=new Be(e),this._vectorTileContainer.destroy(),this._tileManager.clear(),this._tileHandlerAbortController.abort(),this._tileHandlerAbortController=new AbortController;let{signal:s}=this._tileHandlerAbortController;try{this._tileHandlerPromise=this._tileHandler.setStyle(this._styleRepository,e,this.layer.tileInfo.lods.length-1),yield this._tileHandlerPromise}catch(r){if(!K(r))throw r}if(s.aborted)return this._fetchQueue.resume(),this._parseQueue.resume(),this._isTileHandlerReady=!0,void this.requestUpdate();let t=yield this._tileHandler.spriteMosaic,i=this._vectorTileContainer;this._tileInfoView=new ie(this.layer.tileInfo,this.layer.fullExtent),i.setStyleResources(t,this._tileHandler.glyphMosaic,this._styleRepository,this._tileInfoView),this._tileManager=new se({acquireTile:r=>this.acquireTile(r),releaseTile:r=>this.releaseTile(r),tileInfoView:this._tileInfoView},this._vectorTileContainer),this._fetchQueue.resume(),this._parseQueue.resume(),this._isTileHandlerReady=!0,this.requestUpdate()})}_createVectorTile(h){let e=this._tileInfoView.getTileBounds(E(),h),s=this._tileInfoView.getTileResolution(h.level);return new be(h,s,e[0],e[3],512,512,this._styleRepository)}_queryTile(h,e,s,t,i,r){return x(this,null,function*(){if(i.layerData.size===0)return;let o=this._ensureTileIndex(i),a=this._tileInfoView.getTileBounds(E(),i.key,!0),n=kt*Ut*((e.x-a[0])/(a[2]-a[0])),l=kt*Ut*(1-(e.y-a[1])/(a[3]-a[1])),c=yield o.queryAttributes(n,l,
1s,t,r);for(let y of c)y.graphic.geometry=this._tileToMapPoint(y.tilePoint,i.transforms.tileUnitsToPixels),h.push({type:"graphic",layer:this.layer,graphic:y.graphic,mapPoint:e.clone()});h.sort((y,d)=>d.graphic.origin.layerIndex-y.graphic.origin.layerIndex)})}_tileToMapPoint(h,e){if(!h)return null;let s=h[0]*e[0]+h[1]*e[3]+e[6],t=h[0]*e[1]+h[1]*e[4]+e[7],i=this.view.state,r=[0,0];return i.toMap(r,[s,t]),new st({x:r[0],y:r[1],spatialReference:i.spatialReference})}_ensureTileIndex(h){let e=h.featureIndex;return e||(e=Ce.create(h.key,h.layerData,this._styleRepository,this._tileHandler,this.layer),h.featureIndex=e),e}};function rs(h){if(h==null)return 0;switch(h.type){case"partial":return Object.keys(h.diff).length;case"complete":return Math.max(Object.keys(h.oldValue).length,Object.keys(h.newValue).length);case"collection":return Object.keys(h.added).length+Object.keys(h.changed).length+Object.keys(h.removed).length}}Le([Xe()],Re.prototype,"_isTileHandlerReady",void 0),Re=Le([Ze("esri.views.2d.layers.VectorTileLayerView2D")],Re);var Rr=Re;export{Rr as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.