Files
ADHA_mobile_project/assets/VectorTileLayerView2D-85308a27.js
2024-02-28 17:06:42 +05:00

2 lines
61 KiB
JavaScript

import{ar as me,eu as be,bd as K,eq as we,eP as Se,bv as Te,x as P,v as Q,di as ve,ks as ce,eA as U,gW as j,eC as xe,eD as Ie,eG as Ce,eF as De,ez as V,kt as Re,jS as Ae,aj as Pe,eL as J,q as Le,c3 as Me,K as Oe,eg as ke,gv as Ue,J as z,d as Ee,z as Z,y as X,bb as ze,A as ee,B as Ve,C as He}from"./index-b5c8f851.js";import{E as C,I as T}from"./enums-fb086c25.js";import{t as A}from"./Rect-ea14f53a.js";import{G as $e,D as ue,F as x,I as k,O as te,R as $}from"./enums-bdecffa2.js";import{e as de,T as ye}from"./Texture-507d5ea8.js";import{r as Be}from"./pbf-eb90fa42.js";import{e as qe}from"./rasterizingUtils-99212870.js";import{h as I}from"./FramebufferObject-4be671ef.js";import{f as E}from"./ProgramTemplate-a9187eb2.js";import{e as q,t as Fe,c as Ne}from"./config-1337d16e.js";import{r as _e}from"./TiledDisplayObject-a2315f25.js";import{n as We,l as O,r as Qe,i as G,a as v}from"./StyleDefinition-29c49b98.js";import{T as M}from"./color-0916c686.js";import{i as Je}from"./TileContainer-1c596b67.js";import{l as se}from"./StyleRepository-e9463ac2.js";import{m as Ge,u as Ye}from"./LayerView-c5a0067c.js";import"./floatRGBA-ba8d5dad.js";import"./Container-f991c035.js";import"./definitions-1467ba4a.js";import"./enums-f1a6a48a.js";import"./VertexElementDescriptor-2925c6af.js";import"./WGLContainer-21aabd6b.js";import"./GeometryUtils-7a7937c3.js";import"./earcut-d423749e.js";import"./featureConversionUtils-6aca8295.js";import"./OptimizedGeometry-d94e541f.js";import"./OptimizedFeatureSet-1d1ac4b9.js";import"./colorUtils-23771bca.js";import"./GeometryUtils-984e8446.js";import"./scaleUtils-7ebacf58.js";let H=class{constructor(e,s){this._width=0,this._height=0,this._free=[],this._width=e,this._height=s,this._free.push(new A(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 A;let t=null,i=-1;for(let r=0;r<this._free.length;++r){const 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 A:(this._free.splice(i,1),t.width<t.height?(t.width>e&&this._free.push(new A(t.x+e,t.y,t.width-e,s)),t.height>s&&this._free.push(new A(t.x,t.y+s,t.width,t.height-s))):(t.width>e&&this._free.push(new A(t.x+e,t.y,t.width-e,t.height)),t.height>s&&this._free.push(new A(t.x,t.y+s,e,t.height-s))),new A(t.x,t.y,e,s))}release(e){for(let s=0;s<this._free.length;++s){const 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)}},ie=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 H(e-4,s-4),this._glyphData.push(new Uint8Array(e*s)),this._dirties.push(!0),this._textures.push(void 0)}getGlyphItems(e,s){const t=[],i=this._glyphSource,r=new Set,o=1/256;for(const a of s){const h=Math.floor(a*o);r.add(h)}const n=[];return r.forEach(a=>{const h=e+a;if(this._rangePromises.has(h))n.push(this._rangePromises.get(h));else{const d=i.getRange(e,a).then(()=>{this._rangePromises.delete(h)},()=>{this._rangePromises.delete(h)});this._rangePromises.set(h,d),n.push(d)}}),Promise.all(n).then(()=>{let a=this._glyphIndex[e];a||(a={},this._glyphIndex[e]=a);for(const h of s){const d=a[h];if(d){t[h]={sdf:!0,rect:d.rect,metrics:d.metrics,page:d.page,code:h};continue}const y=i.getGlyph(e,h);if(!(y!=null&&y.metrics))continue;const u=y.metrics;let c;if(u.width===0)c=new A(0,0,0,0);else{const _=u.width+6,f=u.height+2*3;let g=_%4?4-_%4:4,m=f%4?4-f%4:4;g===1&&(g=5),m===1&&(m=5),c=this._binPack.allocate(_+g,f+m),c.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 H(this.width-4,this.height-4),c=this._binPack.allocate(_+g,f+m));const b=this._glyphData[this._currentPage],w=y.bitmap;let R,S;if(w)for(let D=0;D<f;D++){R=_*D,S=this.width*(c.y+D+1)+c.x;for(let L=0;L<_;L++)b[S+L+1]=w.at(R+L)}}a[h]={rect:c,metrics:u,tileIDs:null,page:this._currentPage},t[h]={sdf:!0,rect:c,metrics:u,page:this._currentPage,code:h},this._dirties[this._currentPage]=!0}return t})}removeGlyphs(e){for(const s in this._glyphIndex){const t=this._glyphIndex[s];if(!t)continue;let i;for(const r in t)if(i=t[r],i.tileIDs.delete(e),i.tileIDs.size===0){const o=this._glyphData[i.page],n=i.rect;let a,h;for(let d=0;d<n.height;d++)for(a=this.width*(n.y+d)+n.x,h=0;h<n.width;h++)o[a+h]=0;delete t[r],this._dirties[i.page]=!0}}}bind(e,s,t,i=0){if(!this._textures[t]){const o=new de;o.pixelFormat=$e.ALPHA,o.wrapMode=ue.CLAMP_TO_EDGE,o.width=this.width,o.height=this.height,this._textures[t]=new ye(e,o,new Uint8Array(this.width*this.height))}const 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(const e of this._textures)e&&e.dispose();this._textures.length=0}},W=class{constructor(e){if(this._metrics=[],!e)return void(this._allBitmaps=null);const s=new Map;let t=0;for(;e.next();)switch(e.tag()){case 1:{const o=e.getMessage();for(;o.next();)switch(o.tag()){case 3:{const n=o.getMessage();let a,h,d,y,u,c,p;for(;n.next();)switch(n.tag()){case 1:a=n.getUInt32();break;case 2:h=n.getBytes();break;case 3:d=n.getUInt32();break;case 4:y=n.getUInt32();break;case 5:u=n.getSInt32();break;case 6:c=n.getSInt32();break;case 7:p=n.getUInt32();break;default:n.skip()}if(n.release(),a){const _=(h==null?void 0:h.length)??0;this._metrics[a]={width:d,height:y,left:u,top:c,advance:p,startOffset:t,length:_},s.set(a,h),t+=_}break}default:o.skip()}o.release();break}default:e.skip()}const i=new Uint8Array(t),r=this._metrics;for(const[o,n]of s){const{startOffset:a,length:h}=r[o];if(n)for(let d=0;d<h;++d)i[a+d]=n[d]}this._allBitmaps=i}getMetrics(e){return this._metrics[e]}getBitmap(e){if(!this._allBitmaps)return;const s=this._metrics[e];if(s===void 0)return;const{startOffset:t,length:i}=s;return i!==0?new je(this._allBitmaps,t,i):void 0}},Ke=class{constructor(){this._ranges=[]}get ranges(){return this._ranges}getRange(e){return this._ranges[e]}addRange(e,s){this._ranges[e]=s}},re=class{constructor(e){this._glyphInfo={},this._baseURL=e}getRange(e,s){const t=this._getFontStack(e);if(t.getRange(s))return Promise.resolve();const i=256*s,r=i+255;if(this._baseURL){const o=this._baseURL.replace("{fontstack}",e).replace("{range}",i+"-"+r);return me(o,{responseType:"array-buffer"}).then(n=>{t.addRange(s,new W(new Be(new Uint8Array(n.data),new DataView(n.data))))}).catch(()=>{t.addRange(s,new W)})}return t.addRange(s,new W),Promise.resolve()}getGlyph(e,s){const t=this._getFontStack(e);if(!t)return;const 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 Ke),s}},je=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}};const Ze="dasharray-";let oe=class pe{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,(e<=0||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 H(e-4,s-4)}destroy(){this.dispose()}dispose(){this._binPack=null,this._mosaicsData.length=0,this._mosaicRects={};for(const 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 H(this._pageWidth-4,this._pageHeight-4);const 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(Ze)?([t,i]=this._rasterizeDash(e),s=!0):t=this._sprites.getSpriteInfo(e),!(t!=null&&t.width)||!t.height||t.width<0||t.height<0))return null;const o=t.width,n=t.height,[a,h,d]=this._allocateImage(o,n);return a.width<=0?null:(this._copy(a,t,h,d,s,i),r={rect:a,width:o,height:n,sdf:t.sdf,simplePattern:!1,pixelRatio:t.pixelRatio,page:h},this._mosaicRects[e]=r,r)}getSpriteItems(e){const s={};for(const t of e)s[t.name]=this.getSpriteItem(t.name,t.repeat);return s}getMosaicItemPosition(e,s){const t=this.getSpriteItem(e,s),i=t&&t.rect;if(!i)return null;i.width=t.width,i.height=t.height;const r=t.width,o=t.height,n=2;return{tl:[i.x+n,i.y+n],br:[i.x+n+r,i.y+n+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]){const o=new de;o.wrapMode=ue.CLAMP_TO_EDGE,o.width=this._size[t][0],o.height=this._size[t][1],this._textures[t]=new ye(e,o,new Uint8Array(this._mosaicsData[t].buffer))}const 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,n,a,h,d,y){let u=i*s+t,c=a*o+n;if(y){c-=o;for(let p=-1;p<=d;p++,u=((p+d)%d+i)*s+t,c+=o)for(let _=-1;_<=h;_++)r[c+_]=e[u+(_+h)%h]}else for(let p=0;p<d;p++){for(let _=0;_<h;_++)r[c+_]=e[u+_];u+=s,c+=o}}_copy(e,s,t,i,r,o){if(!this._sprites||this._sprites.loadStatus!=="loaded"||t>=this._mosaicsData.length)return;const n=new Uint32Array(o?o.buffer:this._sprites.image.buffer),a=this._mosaicsData[t];a&&n||console.error("Source or target images are uninitialized!");const h=2,d=o?s.width:this._sprites.width;pe._copyBits(n,d,s.x,s.y,a,i[0],e.x+h,e.y+h,s.width,s.height,r),this._dirties[t]=!0}_allocateImage(e,s){e+=2,s+=2;const t=Math.max(e,s);if(this._maxItemSize&&this._maxItemSize<t){const n=new A(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),[n,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);const 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 H(this._pageWidth-4,this._pageHeight-4),this._allocateImage(e,s)):[o,this._currentPage,[this._pageWidth,this._pageHeight]]}_rasterizeDash(e){const s=/\[(.*?)\]/,t=e.match(s);if(!t)return null;const i=t[1].split(",").map(Number),r=e.slice(e.lastIndexOf("-")+1),[o,n,a]=qe(i,r);return[{x:0,y:0,width:n,height:a,sdf:!0,pixelRatio:1},new Uint8Array(o.buffer)]}};class Xe{constructor(e,s,t){this._layer=e,this._styleRepository=s,this.devicePixelRatio=t,this._spriteMosaic=null,this._glyphMosaic=null,this._connection=null,this._spriteSourceAbortController=null,this._startOptionsInputSignal=null,this._inputSignalEventListener=null}destroy(){var e,s,t;(e=this._connection)==null||e.close(),this._connection=null,this._styleRepository=null,this._layer=null,(s=this._spriteMosaic)==null||s.destroy(),this._spriteMosaic=null,this._glyphMosaic=null,this._spriteSourceAbortController=be(this._spriteSourceAbortController),this._spriteSourcePromise=null,this._inputSignalEventListener&&((t=this._startOptionsInputSignal)==null||t.removeEventListener("abort",this._inputSignalEventListener)),this._startOptionsInputSignal=null,this._inputSignalEventListener=null}get spriteMosaic(){return this._spriteSourcePromise.then(()=>this._spriteMosaic)}get glyphMosaic(){return this._glyphMosaic}async start(e){this._requestSprite(e);const s=this._layer.currentStyleInfo.glyphsUrl,t=new re(s?K(s,{...this._layer.customParameters,token:this._layer.apiKey}):null);this._glyphMosaic=new ie(1024,1024,t),this._broadcastPromise=we("WorkerTileHandler",{client:this,schedule:e.schedule,signal:e.signal}).then(i=>{var r;if(this._layer&&((r=this._connection)==null||r.close(),this._connection=i,this._layer&&!this._connection.closed)){const o=i.broadcast("setStyle",this._layer.currentStyleInfo.style,e);Promise.all(o).catch(n=>Se(n))}})}_requestSprite(e){var o,n;(o=this._spriteSourceAbortController)==null||o.abort();const s=new AbortController;this._spriteSourceAbortController=s;const t=e==null?void 0:e.signal;this._inputSignalEventListener&&((n=this._startOptionsInputSignal)==null||n.removeEventListener("abort",this._inputSignalEventListener)),this._startOptionsInputSignal=null,t&&(this._inputSignalEventListener=et(s),t.addEventListener("abort",this._inputSignalEventListener,{once:!0}));const{signal:i}=s,r={...e,signal:i};this._spriteSourcePromise=this._layer.loadSpriteSource(this.devicePixelRatio,r),this._spriteSourcePromise.then(a=>{Te(i),this._spriteMosaic=new oe(1024,1024,250),this._spriteMosaic.setSpriteSource(a)})}async updateStyle(e){return await this._broadcastPromise,this._broadcastPromise=Promise.all(this._connection.broadcast("updateStyle",e)),this._broadcastPromise}setSpriteSource(e){const s=new oe(1024,1024,250);return s.setSpriteSource(e),this._spriteMosaic=s,this._spriteSourcePromise=Promise.resolve(e),this._spriteSourceAbortController=null,s}async setStyle(e,s){await this._broadcastPromise,this._styleRepository=e,this._requestSprite();const t=new re(this._layer.currentStyleInfo.glyphsUrl?K(this._layer.currentStyleInfo.glyphsUrl,{...this._layer.customParameters,token:this._layer.apiKey}):null);return this._glyphMosaic=new ie(1024,1024,t),this._broadcastPromise=Promise.all(this._connection.broadcast("setStyle",s)),this._broadcastPromise}fetchTileData(e,s){return this._getRefKeys(e,s).then(t=>{const i=this._layer.sourceNameToSource,r=[];for(const o in i)r.push(o);return this._getSourcesData(r,t,s)})}parseTileData(e,s){const t=e&&e.data;if(!t)return Promise.resolve(null);const{sourceName2DataAndRefKey:i,transferList:r}=t;return Object.keys(i).length===0?Promise.resolve(null):this._broadcastPromise.then(()=>this._connection.invoke("createTileAndParse",{key:e.key.id,sourceName2DataAndRefKey:i,styleLayerUIDs:e.styleLayerUIDs},{...s,transferList:r}))}async getSprites(e){return await this._spriteSourcePromise,this._spriteMosaic.getSpriteItems(e)}getGlyphs(e){return this._glyphMosaic.getGlyphItems(e.font,e.codePoints)}async _getTilePayload(e,s,t){const i=P.pool.acquire(e.id),r=this._layer.sourceNameToSource[s],{level:o,row:n,col:a}=i;P.pool.release(i);try{return{protobuff:await r.requestTile(o,n,a,t),sourceName:s}}catch(h){if(Q(h))throw h;return{protobuff:null,sourceName:s}}}_getRefKeys(e,s){const t=this._layer.sourceNameToSource,i=new Array;for(const r in t){const o=t[r].getRefKey(e,s);i.push(o)}return Promise.allSettled(i)}_getSourcesData(e,s,t){const i=[];for(let r=0;r<s.length;r++){const o=s[r],n=o.status==="fulfilled"?o.value:null;if(n==null||e[r]==null)i.push(null);else{const a=this._getTilePayload(n,e[r],t);i.push(a)}}return Promise.allSettled(i).then(r=>{const o={},n=[];for(let a=0;a<r.length;a++){const h=r[a],d=h.status==="fulfilled"?h.value:null,y=d==null?void 0:d.protobuff;if(!d||!(y!=null&&y.byteLength))continue;const u=s[a],c=u.status==="fulfilled"?u.value:null;if(c){const p=c.id;o[d.sourceName]={refKey:p,protobuff:y},n.push(y)}}return{sourceName2DataAndRefKey:o,transferList:n}})}}function et(l){return()=>l.abort()}const ne=512,tt=1e-6,st=(l,e)=>l+1/(1<<2*e);let it=class{constructor(e,s){this._tiles=new Map,this._tileCache=new ve(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(const[e,s]of this._tiles)s.dispose();this._tiles=null,this._tileCache.clear(),this._tileCache=null}update(e){this._updateCacheSize(e);const s=this.tileInfoView,t=s.getTileCoverage(e.state,0,!0,"smallest");if(!t)return!0;const{spans:i,lodInfo:r}=t,{level:o}=r,n=this._tiles,a=new Set,h=new Set;for(const{row:y,colFrom:u,colTo:c}of i)for(let p=u;p<=c;p++){const _=P.getId(o,y,r.normalizeCol(p),r.getWorldForColumn(p)),f=this._getOrAcquireTile(_);a.add(_),f.processed()?this._addToContainer(f):h.add(new P(_))}for(const[y,u]of n)u.isCoverage=a.has(y);for(const y of h)this._findPlaceholdersForMissingTiles(y,a);let d=!1;for(const[y,u]of n)u.neededForCoverage=a.has(y),u.neededForCoverage||u.isHoldingForFade&&s.intersects(t,u.key)&&a.add(y),u.isFading&&(d=!0);for(const[y,u]of this._tiles)a.has(y)||this._releaseTile(y);return ce.pool.release(t),!d}clear(){this._tiles.clear(),this._tileCache.clear(),this._visibleTiles.clear()}clearCache(){this._tileCache.clear()}_findPlaceholdersForMissingTiles(e,s){const t=[];for(const[r,o]of this._tiles)this._addPlaceholderChild(t,o,e,s);const i=t.reduce(st,0);Math.abs(1-i)<tt||this._addPlaceholderParent(e.id,s)}_addPlaceholderChild(e,s,t,i){s.key.level<=t.level||!s.hasData()||ot(t,s.key)&&(this._addToContainer(s),i.add(s.id),e.push(s.key.level-t.level))}_addPlaceholderParent(e,s){const t=this._tiles;let i=e;for(;;){if(i=rt(i),!i||s.has(i))return;const r=t.get(i);if(r&&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 P(e))),this._tiles.set(e,s),s)}_releaseTile(e){const 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;const t=[],i=this._container;if(i.contains(e))return;const r=this._visibleTiles;for(const[o,n]of r)this._canConnectDirectly(e,n)&&t.push(n),s==null&&this._canConnectDirectly(n,e)&&(s=n);if(s!=null){for(const o of t)s.childrenTiles.delete(o),e.childrenTiles.add(o),o.parentTile=e;s.childrenTiles.add(e),e.parentTile=s}else for(const 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(const s of e.childrenTiles)e.parentTile!=null&&e.parentTile.childrenTiles.add(s)}for(const s of e.childrenTiles)s.parentTile=e.parentTile;e.parentTile=null,e.childrenTiles.clear()}_canConnectDirectly(e,s){const t=e.key;let{level:i,row:r,col:o,world:n}=s.key;const a=this._visibleTiles;for(;i>0;){if(i--,r>>=1,o>>=1,t.level===i&&t.row===r&&t.col===o&&t.world===n)return!0;if(a.has(`${i}/${r}/${o}/${n}`))return!1}return!1}_updateCacheSize(e){const s=e.state.size;if(s[0]===this._viewSize[0]&&s[1]===this._viewSize[1])return;const t=Math.ceil(s[0]/ne)+1,i=Math.ceil(s[1]/ne)+1;this._viewSize[0]=s[0],this._viewSize[1]=s[1],this._tileCache.maxSize=5*t*i}};function rt(l){const[e,s,t,i]=l.split("/"),r=parseInt(e,10);return r===0?null:`${r-1}/${parseInt(s,10)>>1}/${parseInt(t,10)>>1}/${parseInt(i,10)}`}function ot(l,e){const s=e.level-l.level;return l.row===e.row>>s&&l.col===e.col>>s&&l.world===e.world}let nt=class{constructor(e){this.xTile=0,this.yTile=0,this.hash=0,this.priority=1,this.colliders=[],this.textVertexRanges=[],this.iconVertexRanges=[],this.tile=e}},at=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 ae(l,e,s,t,i,r){const o=s-i;if(o>=0)return(e>>o)+(t-(r<<o))*(l>>o);const n=-o;return e-(r-(t<<n))*(l>>n)<<n}let fe=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){const 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 lt(l,e,s,t,i,r){const o=e[t++];for(let n=0;n<o;n++){const a=new nt(r);a.xTile=e[t++],a.yTile=e[t++],a.hash=e[t++],a.priority=e[t++];const h=e[t++];for(let u=0;u<h;u++){const c=e[t++],p=e[t++],_=e[t++],f=e[t++],g=!!e[t++],m=e[t++],b=s[t++],w=s[t++],R=e[t++],S=e[t++];a.colliders.push({xTile:c,yTile:p,dxPixels:_,dyPixels:f,hard:g,partIndex:m,width:R,height:S,minLod:b,maxLod:w})}const d=l[t++];for(let u=0;u<d;u++)a.textVertexRanges.push([l[t++],l[t++]]);const y=l[t++];for(let u=0;u<y;u++)a.iconVertexRanges.push([l[t++],l[t++]]);i.push(a)}return t}function ht(l,e,s){for(const[t,i]of l.symbols)ct(l,e,s,i,t)}function ct(l,e,s,t,i){const r=l.layerData.get(i);if(r.type===C.SYMBOL){for(const o of t){const n=o.unique;let a;if(o.selectedForRendering){const h=n.parts[0],d=h.startOpacity,y=h.targetOpacity;l.allSymbolsFadingOut=l.allSymbolsFadingOut&&y===0;const u=s?Math.floor(127*d)|y<<7:y?255:0;a=u<<24|u<<16|u<<8|u}else a=0;for(const[h,d]of o.iconVertexRanges)for(let y=h;y<h+d;y+=4)r.iconOpacity[y/4]=a;if(o.selectedForRendering){const h=n.parts[1],d=h.startOpacity,y=h.targetOpacity;l.allSymbolsFadingOut=l.allSymbolsFadingOut&&y===0;const u=s?Math.floor(127*d)|y<<7:y?255:0;a=u<<24|u<<16|u<<8|u}else a=0;for(const[h,d]of o.textVertexRanges)for(let y=h;y<h+d;y+=4)r.textOpacity[y/4]=a}r.lastOpacityUpdate=e,r.opacityChanged=!0}}let N=class{constructor(e,s){this.layerUIDs=[],this.isDestroyed=!1,this._data=e;let t=1;const i=new Uint32Array(e);this.layerUIDs=[];const 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)}};class ut extends N{constructor(e,s){super(e,s),this.type=C.LINE,this.lineIndexStart=0,this.lineIndexCount=0;const t=new Uint32Array(e);let i=this.bufferDataOffset;this.lineIndexStart=t[i++],this.lineIndexCount=t[i++];const r=t[i++];if(r>0){this.patternMap=new Map;for(let o=0;o<r;o++){const n=t[i++],a=t[i++],h=t[i++];this.patternMap.set(n,[a,h])}}this.bufferDataOffset=i}get memoryUsed(){var e,s;return(((e=this.data)==null?void 0:e.byteLength)??0)+(((s=this.vao)==null?void 0:s.usedMemory)??0)}hasData(){return this.lineIndexCount>0}triangleCount(){return this.lineIndexCount/3}doDestroy(){this.vao=U(this.vao)}doPrepareForRendering(e,s,t){const i=new Uint32Array(s),r=new Int32Array(i.buffer),o=i[t++],n=I.createVertex(e,x.STATIC_DRAW,new Int32Array(r.buffer,4*t,o));t+=o;const a=i[t++],h=I.createIndex(e,x.STATIC_DRAW,new Uint32Array(i.buffer,4*t,a));t+=a;const d=this.layer.lineMaterial;this.vao=new E(e,d.getAttributeLocations(),d.getLayoutInfo(),{geometry:n},h)}}class dt extends N{constructor(e,s){super(e,s),this.type=C.FILL,this.fillIndexStart=0,this.fillIndexCount=0,this.outlineIndexStart=0,this.outlineIndexCount=0;const t=new Uint32Array(e);let i=this.bufferDataOffset;this.fillIndexStart=t[i++],this.fillIndexCount=t[i++],this.outlineIndexStart=t[i++],this.outlineIndexCount=t[i++];const r=t[i++];if(r>0){this.patternMap=new Map;for(let o=0;o<r;o++){const n=t[i++],a=t[i++],h=t[i++];this.patternMap.set(n,[a,h])}}this.bufferDataOffset=i}get memoryUsed(){var e,s,t;return(((e=this.data)==null?void 0:e.byteLength)??0)+(((s=this.fillVAO)==null?void 0:s.usedMemory)??0)+(((t=this.outlineVAO)==null?void 0:t.usedMemory)??0)}hasData(){return this.fillIndexCount>0||this.outlineIndexCount>0}triangleCount(){return(this.fillIndexCount+this.outlineIndexCount)/3}doDestroy(){this.fillVAO=U(this.fillVAO),this.outlineVAO=U(this.outlineVAO)}doPrepareForRendering(e,s,t){const i=new Uint32Array(s),r=new Int32Array(i.buffer),o=i[t++],n=I.createVertex(e,x.STATIC_DRAW,new Int32Array(r.buffer,4*t,o));t+=o;const a=i[t++],h=I.createIndex(e,x.STATIC_DRAW,new Uint32Array(i.buffer,4*t,a));t+=a;const d=i[t++],y=I.createVertex(e,x.STATIC_DRAW,new Int32Array(r.buffer,4*t,d));t+=d;const u=i[t++],c=I.createIndex(e,x.STATIC_DRAW,new Uint32Array(i.buffer,4*t,u));t+=u;const p=this.layer,_=p.fillMaterial,f=p.outlineMaterial;this.fillVAO=new E(e,_.getAttributeLocations(),_.getLayoutInfo(),{geometry:n},h),this.outlineVAO=new E(e,f.getAttributeLocations(),f.getLayoutInfo(),{geometry:y},c)}}let yt=class extends N{constructor(e,s,t){super(e,s),this.type=C.SYMBOL,this.iconPerPageElementsMap=new Map,this.glyphPerPageElementsMap=new Map,this.symbolInstances=[],this.isIconSDF=!1,this.opacityChanged=!1,this.lastOpacityUpdate=0,this.symbols=[];const i=new Uint32Array(e),r=new Int32Array(e),o=new Float32Array(e);let n=this.bufferDataOffset;this.isIconSDF=!!i[n++];const a=i[n++];for(let u=0;u<a;u++){const c=i[n++],p=i[n++],_=i[n++];this.iconPerPageElementsMap.set(c,[p,_])}const h=i[n++];for(let u=0;u<h;u++){const c=i[n++],p=i[n++],_=i[n++];this.glyphPerPageElementsMap.set(c,[p,_])}const d=i[n++],y=i[n++];this.iconOpacity=new Int32Array(d),this.textOpacity=new Int32Array(y),n=lt(i,r,o,n,this.symbols,t),this.bufferDataOffset=n}get memoryUsed(){var e,s,t;return(((e=this.data)==null?void 0:e.byteLength)??0)+(((s=this.iconVAO)==null?void 0:s.usedMemory)??0)+(((t=this.textVAO)==null?void 0:t.usedMemory)??0)+j(this.iconOpacity)+j(this.textOpacity)}hasData(){return this.iconPerPageElementsMap.size>0||this.glyphPerPageElementsMap.size>0}triangleCount(){let e=0;for(const[s,t]of this.iconPerPageElementsMap)e+=t[1];for(const[s,t]of this.glyphPerPageElementsMap)e+=t[1];return e/3}doDestroy(){this.iconVAO=U(this.iconVAO),this.textVAO=U(this.textVAO)}updateOpacityInfo(){if(!this.opacityChanged)return;this.opacityChanged=!1;const e=this.iconOpacity,s=this.iconVAO.vertexBuffers.opacity;e.length>0&&e.byteLength===s.byteLength&&s.setSubData(e,0,0,e.length);const t=this.textOpacity,i=this.textVAO.vertexBuffers.opacity;t.length>0&&t.byteLength===i.byteLength&&i.setSubData(t,0,0,t.length)}doPrepareForRendering(e,s,t){const i=new Uint32Array(s),r=new Int32Array(i.buffer),o=i[t++],n=I.createVertex(e,x.STATIC_DRAW,new Int32Array(r.buffer,4*t,o));t+=o;const a=i[t++],h=I.createIndex(e,x.STATIC_DRAW,new Uint32Array(i.buffer,4*t,a));t+=a;const d=i[t++],y=I.createVertex(e,x.STATIC_DRAW,new Int32Array(r.buffer,4*t,d));t+=d;const u=i[t++],c=I.createIndex(e,x.STATIC_DRAW,new Uint32Array(i.buffer,4*t,u));t+=u;const p=I.createVertex(e,x.STATIC_DRAW,this.iconOpacity.buffer),_=I.createVertex(e,x.STATIC_DRAW,this.textOpacity.buffer),f=this.layer,g=f.iconMaterial,m=f.textMaterial;this.iconVAO=new E(e,g.getAttributeLocations(),g.getLayoutInfo(),{geometry:n,opacity:p},h),this.textVAO=new E(e,m.getAttributeLocations(),m.getLayoutInfo(),{geometry:y,opacity:_},c)}},_t=class extends N{constructor(e,s){super(e,s),this.type=C.CIRCLE,this.circleIndexStart=0,this.circleIndexCount=0;const t=new Uint32Array(e);let i=this.bufferDataOffset;this.circleIndexStart=t[i++],this.circleIndexCount=t[i++],this.bufferDataOffset=i}get memoryUsed(){var e,s;return(((e=this.data)==null?void 0:e.byteLength)??0)+(((s=this.vao)==null?void 0:s.usedMemory)??0)}hasData(){return this.circleIndexCount>0}triangleCount(){return this.circleIndexCount/3}doDestroy(){this.vao=U(this.vao)}doPrepareForRendering(e,s,t){const i=new Uint32Array(s),r=new Int32Array(i.buffer),o=i[t++],n=I.createVertex(e,x.STATIC_DRAW,new Int32Array(r.buffer,4*t,o));t+=o;const a=i[t++],h=I.createIndex(e,x.STATIC_DRAW,new Uint32Array(i.buffer,4*t,a));t+=a;const d=this.layer.circleMaterial;this.vao=new E(e,d.getAttributeLocations(),d.getLayoutInfo(),{geometry:n},h)}};class Y extends _e{constructor(e,s,t,i,r,o,n,a=null){super(e,s,t,i,r,o,4096,4096),this.styleRepository=n,this._memCache=a,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._processed=!1,this._referenced=1,this.id=e.id}get hasSymbolBuckets(){return this._hasSymbolBuckets}get isFading(){return this._hasSymbolBuckets&&performance.now()-this.lastOpacityUpdate<q}get isHoldingForFade(){return this._hasSymbolBuckets&&(!this.allSymbolsFadingOut||performance.now()-this.lastOpacityUpdate<q)}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){var t;let s=!1;for(const i of e){const r=this.layerData.get(i);r&&(this._memoryUsedByLayerData-=r.memoryUsed,r.type===C.SYMBOL&&this.symbols.delete(i)&&(s=!0),r.destroy(),this.layerData.delete(i))}(t=this._memCache)==null||t.updateSize(this.key.id,this,this._memoryUsedByLayerData),s&&this.emit("symbols-changed"),this.requestRender()}processed(){return this._processed}hasData(){return this.layerData.size>0}dispose(){this.status!=="unloaded"&&(pt.delete(this),Y._destroyRenderBuckets(this.layerData),this.layerData=null,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 memoryUsed(){return this._memoryUsedByLayerData+256}changeDataImpl(e){var t;let s=!1;if(e){const{bucketsWithData:i,emptyBuckets:r}=e,o=this._createRenderBuckets(i);if(r&&r.byteLength>0){const n=new Uint32Array(r);for(const a of n)this._deleteLayerData(a)}for(const[n,a]of o)this._deleteLayerData(n),a.type===C.SYMBOL&&(this.symbols.set(n,a.symbols),s=!0),this._memoryUsedByLayerData+=a.memoryUsed,this.layerData.set(n,a);(t=this._memCache)==null||t.updateSize(this.key.id,this,this.memoryUsed)}this._hasSymbolBuckets=!1;for(const[i,r]of this.layerData)r.type===C.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);const 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]);const o=this.transforms.tileUnitsToPixels;xe(o),Ie(o,o,r),Ce(o,o,Math.PI*e.rotation/180),De(o,o,[t,i,1])}_createTransforms(){return{dvs:V(),tileMat3:V(),tileUnitsToPixels:V()}}static _destroyRenderBuckets(e){if(!e)return;const s=new Set;for(const t of e.values())s.has(t)||(t.destroy(),s.add(t));e.clear()}_createRenderBuckets(e){const s=new Map,t=new Map;for(const i of e){const r=this._deserializeBucket(i,t);for(const 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 C.FILL:t=new dt(e,this.styleRepository);break;case C.LINE:t=new ut(e,this.styleRepository);break;case C.SYMBOL:t=new yt(e,this.styleRepository,this);break;case C.CIRCLE:t=new _t(e,this.styleRepository)}return s.set(e,t),t}_deleteLayerData(e){if(!this.layerData.has(e))return;const s=this.layerData.get(e);this._memoryUsedByLayerData-=s.memoryUsed,s.destroy(),this.layerData.delete(e)}}const pt=new Map;function ft(l,e,s,t,i,r){const{iconRotationAlignment:o,textRotationAlignment:n,iconTranslate:a,iconTranslateAnchor:h,textTranslate:d,textTranslateAnchor:y}=t;let u=0;for(const c of l.colliders){const[p,_]=c.partIndex===0?a:d,f=c.partIndex===0?h:y,g=c.minLod<=r&&r<=c.maxLod;u+=g?0:1,c.enabled=g,c.xScreen=c.xTile*i[0]+c.yTile*i[3]+i[6],c.yScreen=c.xTile*i[1]+c.yTile*i[4]+i[7],f===Qe.MAP?(c.xScreen+=s*p-e*_,c.yScreen+=e*p+s*_):(c.xScreen+=p,c.yScreen+=_),O.VIEWPORT===(c.partIndex===0?o:n)?(c.dxScreen=c.dxPixels,c.dyScreen=c.dyPixels):(c.dxScreen=s*(c.dxPixels+c.width/2)-e*(c.dyPixels+c.height/2)-c.width/2,c.dyScreen=e*(c.dxPixels+c.width/2)+s*(c.dyPixels+c.height/2)-c.height/2)}l.colliders.length>0&&u===l.colliders.length&&(l.unique.show=!1)}let gt=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 fe(s,t,Fe),this._si=Math.sin(Math.PI*o/180),this._co=Math.cos(Math.PI*o/180);for(const n of e)for(const a of n.symbols)this._allNeededMatrices.has(a.tile)||this._allNeededMatrices.set(a.tile,Re(a.tile.transforms.tileUnitsToPixels))}work(e){const s=this._gridIndex;function t(r){const o=r.xScreen+r.dxScreen,n=r.yScreen+r.dyScreen,a=o+r.width,h=n+r.height,[d,y,u,c]=s.getCellSpan(o,n,a,h);for(let p=y;p<=c;p++)for(let _=d;_<=u;_++){const f=s.cells[p][_];for(const g of f){const m=g.xScreen+g.dxScreen,b=g.yScreen+g.dyScreen,w=m+g.width,R=b+g.height;if(!(a<m||o>w||h<b||n>R))return!0}}return!1}const i=performance.now();for(;this._currentLayerCursor<this._symbols.length;this._currentLayerCursor++,this._currentSymbolCursor=0){const 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;const n=r.symbols[this._currentSymbolCursor];if(!n.unique.show)continue;ft(n,this._si,this._co,o,this._allNeededMatrices.get(n.tile),this._zoom);const a=n.unique;if(!a.show)continue;const{iconAllowOverlap:h,iconIgnorePlacement:d,textAllowOverlap:y,textIgnorePlacement:u}=o;for(const c of n.colliders){if(!c.enabled)continue;const p=a.parts[c.partIndex];p.show&&!(c.partIndex?y:h)&&t(c)&&(c.hard?a.show=!1:p.show=!1)}if(a.show)for(const c of n.colliders){if(!c.enabled||(c.partIndex?u:d)||!a.parts[c.partIndex].show)continue;const p=c.xScreen+c.dxScreen,_=c.yScreen+c.dyScreen,f=p+c.width,g=_+c.height,[m,b,w,R]=this._gridIndex.getCellSpan(p,_,f,g);for(let S=b;S<=R;S++)for(let D=m;D<=w;D++)this._gridIndex.cells[S][D].push(c)}}}return!0}_getProperties(e){const s=this._styleProps.get(e);if(s)return s;const t=this._zoom,i=this._styleRepository.getStyleLayerByUID(e),r=i.getLayoutValue("symbol-placement",t)!==We.POINT;let o=i.getLayoutValue("icon-rotation-alignment",t);o===O.AUTO&&(o=r?O.MAP:O.VIEWPORT);let n=i.getLayoutValue("text-rotation-alignment",t);n===O.AUTO&&(n=r?O.MAP:O.VIEWPORT);const a=i.getPaintValue("icon-translate",t),h=i.getPaintValue("icon-translate-anchor",t),d=i.getPaintValue("text-translate",t),y=i.getPaintValue("text-translate-anchor",t),u={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:n,iconTranslateAnchor:h,iconTranslate:a,textTranslateAnchor:y,textTranslate:d};return this._styleProps.set(e,u),u}};function mt(l,e){if(l.priority-e.priority)return l.priority-e.priority;const s=l.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.col-t.col:l.xTile-e.xTile?l.xTile-e.xTile:l.yTile-e.yTile}class bt{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){const 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){const 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){const 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(){const e=this._symbolRepository.uniqueSymbols;for(let a=0;a<e.length;a++){const h=e[a];for(let d=0;d<h.uniqueSymbols.length;d++){const y=h.uniqueSymbols[d];for(const u of y.tileSymbols)u.selectedForRendering=!1}}const s=[];let t=0,i=0;const r=this._isLayerVisible;function o(a){let h;const d=performance.now();for(;i<e.length;i++,t=0){const y=e[i],u=y.styleLayerUID;if(!r(u)){s[i]||(s[i]={styleLayerUID:u,symbols:[]});continue}s[i]=s[i]||{styleLayerUID:u,symbols:[]};const c=s[i];for(;t<y.uniqueSymbols.length;t++){if(h=y.uniqueSymbols[t],t%100==99&&performance.now()-d>a)return!1;let p=null,_=!1,f=!1;for(const g of h.tileSymbols)if(!f||!_){const m=g.tile;(!p||m.isCoverage||m.neededForCoverage&&!_)&&(p=g,(m.neededForCoverage||m.isCoverage)&&(f=!0),m.isCoverage&&(_=!0))}if(p.selectedForRendering=!0,f){c.symbols.push(p),h.show=!0;for(const g of h.parts)g.show=!0}else h.show=!1}}for(const y of s)y.symbols.sort(mt);return!0}const n=this._symbolLayerSorter;return{work:o,get sortedSymbols(){return s.sort(n)}}}_createOpacityJob(){const e=this._assignTileSymbolsOpacity,s=this._visibleTiles;let t=0;function i(r,o){const n=r.symbols;for(const[a,h]of n)wt(h,o);e(r,o);for(const a of r.childrenTiles)i(a,o)}return{work(r){const o=performance.now();for(;t<s.length;t++){if(performance.now()-o>r)return!1;const n=s[t];n.parentTile==null&&i(n,performance.now())}return!0}}}}function wt(l,e){for(const s of l){const t=s.unique;for(const i of t.parts){const r=i.targetOpacity>.5?1:-1;i.startOpacity+=r*((e-i.startTime)/q),i.startOpacity=Math.min(Math.max(i.startOpacity,0),1),i.startTime=e,i.targetOpacity=t.show&&i.show?1:0}}}const St=32,Tt=8,vt=64;class xt{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}add(e,s){this._uniqueSymbolLayerArray=null;let t=this._tiles.get(e.id);t||(t={symbols:new Map},this._tiles.set(e.id,t));const i=new Map;if(s)for(const n of s)t.symbols.has(n)&&(i.set(n,t.symbols.get(n)),t.symbols.delete(n));else for(const[n,a]of e.layerData)t.symbols.has(n)&&(i.set(n,t.symbols.get(n)),t.symbols.delete(n));this._removeSymbols(i);const r=e.symbols,o=new Map;for(const[n,a]of r){let h=a.length;if(h>=St){let d=this.tileCoordRange;do d/=2,h/=4;while(h>Tt&&d>vt);const y=new fe(this.tileCoordRange,this.tileCoordRange,d);o.set(n,{flat:a,index:y}),t.symbols.set(n,{flat:a,index:y});for(const u of a)y.getCell(u.xTile,u.yTile).push(u)}else o.set(n,{flat:a}),t.symbols.set(n,{flat:a})}this._addSymbols(e.key,r)}deleteStyleLayers(e){this._uniqueSymbolLayerArray=null;for(const[s,t]of this._tiles){const i=new Map;for(const 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;const s=this._tiles.get(e.id);if(!s)return;const t=new Map;for(const[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)}_removeSymbols(e){for(const[s,{flat:t}]of e)for(const i of t){const r=i.unique,o=r.tileSymbols,n=o.length-1;for(let a=0;a<n;a++)if(o[a]===i){o[a]=o[n];break}if(o.length=n,n===0){const a=this._uniqueSymbolsReferences.get(s);a.delete(r),a.size===0&&this._uniqueSymbolsReferences.delete(s)}i.unique=null}}_addSymbols(e,s){if(s.size===0)return;const t=this._visibleTiles;for(const 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(const[i,r]of s)for(const o of r)if(o.unique==null){const n=this._createUnique();o.unique=n,n.tileSymbols.push(o);let a=this._uniqueSymbolsReferences.get(i);a||(a=new Set,this._uniqueSymbolsReferences.set(i,a)),a.add(n)}}_matchSymbols(e,s,t){if(e.key.level>s.level){const 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){const 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(const r of e.childrenTiles)this._matchSymbols(r,s,t);return}const i=new Map;for(const[r,o]of t){const n=[];for(const y of o){const u=ae(this.tileCoordRange,y.xTile,s.level,s.col,e.key.level,e.key.col),c=ae(this.tileCoordRange,y.yTile,s.level,s.row,e.key.level,e.key.row);u>=0&&u<this.tileCoordRange&&c>=0&&c<this.tileCoordRange&&n.push({symbol:y,xTransformed:u,yTransformed:c})}const a=[],h=e.key.level<s.level?1:1<<e.key.level-s.level,d=this._tiles.get(e.id).symbols.get(r);if(d){const y=d.flat;for(const u of n){let c,p=!1;const _=u.xTransformed,f=u.yTransformed;c=d.index!=null?d.index.getCell(_,f):y;const g=u.symbol,m=g.hash;for(const b of c)if(m===b.hash&&Math.abs(_-b.xTile)<=h&&Math.abs(f-b.yTile)<=h){const w=b.unique;g.unique=w,w.tileSymbols.push(g),p=!0;break}p||a.push(g)}}a.length>0&&i.set(r,a)}for(const r of e.childrenTiles)this._matchSymbols(r,s,i)}_createUniqueSymbolLayerArray(){const e=this._uniqueSymbolsReferences,s=new Array(e.size);let t,i=0;for(const[r,o]of e){const n=new Array(o.size);t=0;for(const a of o)n[t++]=a;s[i]={styleLayerUID:r,uniqueSymbols:n},i++}return s}}const It=.5,le=1e-6;class Ct{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._completed=!1,this._fading=Ae(!1),this._symbolRepository=new xt(4096,s,()=>new at),this._symbolDeclutterer=new bt(s,this._symbolRepository,(t,i,r)=>new gt(t,i,r,this.styleRepository,this._zoom,this._viewState.rotation),(t,i)=>{t.allSymbolsFadingOut=!0,t.lastOpacityUpdate=i,ht(t,i,!0),t.decluttered=!0,t.requestRender()},(t,i)=>this.styleRepository.getStyleLayerByUID(t.styleLayerUID).z-this.styleRepository.getStyleLayerByUID(i.styleLayerUID).z,t=>{const i=this.styleRepository.getStyleLayerByUID(t);if(this._zoom+le<i.minzoom||this._zoom-le>=i.maxzoom)return!1;const r=i.getLayoutProperty("visibility");return!r||r.getValue()!==G.NONE})}get fading(){return this._fading.value}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){const s=this._tileToHandle.get(e);s&&(this._symbolRepository.removeTile(e),this.restartDeclutter(),s.remove(),this._tileToHandle.delete(e))}update(e,s){return 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]]},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=>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._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._symbolDeclutterer.restart()),this._symbolDeclutterer.setScreenSize(this._viewState.size[0],this._viewState.size[1]),this._completed=this._symbolDeclutterer.continue(Ne),this._completed&&this._scheduleNotifyStable())}_scheduleNotifyStable(){this._stableNotificationHandle!=null&&clearTimeout(this._stableNotificationHandle),this._stableNotificationHandle=setTimeout(()=>{this._stableNotificationHandle=null,this._fading.value=!1},(1+It)*q)}_notifyUnstable(){this._stableNotificationHandle!=null&&(clearTimeout(this._stableNotificationHandle),this._stableNotificationHandle=null),this._fading.value=!0}}let Dt=class extends _e{_createTransforms(){return{dvs:V(),tileMat3:V()}}};const F=1e-6;function he(l,e){if(l){const s=l.getLayoutProperty("visibility");if(!s||s.getValue()!==G.NONE&&(l.minzoom===void 0||l.minzoom<e+F)&&(l.maxzoom===void 0||l.maxzoom>=e-F))return!0}return!1}class Rt extends Je{constructor(e){super(e),this._backgroundTiles=[],this._pointToCallbacks=new Map}destroy(){var e,s;this.removeAllChildren(),(e=this._spriteMosaic)==null||e.dispose(),this._spriteMosaic=null,(s=this._glyphMosaic)==null||s.dispose(),this._glyphMosaic=null,this._symbolFader!=null&&(this._symbolFader.clear(),this._symbolFader=null),this._styleRepository=null,this._backgroundTiles=[],this._pointToCallbacks.clear()}get fading(){var e;return((e=this._symbolFader)==null?void 0:e.fading)??!1}setStyleResources(e,s,t){this._spriteMosaic=e,this._glyphMosaic=s,this._styleRepository=t,this._symbolFader==null&&(this._symbolFader=new Ct(this._styleRepository,this.children)),this._symbolFader.styleRepository=t}setSpriteMosaic(e){var s;(s=this._spriteMosaic)==null||s.dispose(),this._spriteMosaic=e}deleteStyleLayers(e){this._symbolFader!=null&&this._symbolFader.deleteStyleLayers(e)}async hitTest(e){const s=Pe();return this._pointToCallbacks.set(e,s),this.requestRender(),s.promise}createRenderParams(e){return{...super.createRenderParams(e),renderPass:null,styleLayer:null,styleLayerUID:-1,glyphMosaic:this._glyphMosaic,spriteMosaic:this._spriteMosaic,hasClipping:!!this._clippingInfos}}doRender(e){!this.visible||e.drawPhase!==M.MAP&&e.drawPhase!==M.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){const{drawPhase:s}=e;if(s!==M.DEBUG){if(this._doRender(e),this._pointToCallbacks.size>0){e.drawPhase=M.HITTEST;const t=e.painter.effects.hittestVTL;t.bind(e),this._doRender(e),t.draw(e,this._pointToCallbacks),t.unbind(e),e.drawPhase=s}}else super.renderChildren(e)}removeAllChildren(){for(let e=0;e<this.children.length;e++){const 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){const{context:s}=e,t=this._styleRepository;if(!t)return;const i=t.layers;let r=!0;e.drawPhase===M.HITTEST&&(r=!1),t.backgroundBucketIds.length>0&&(e.renderPass="background",this._renderBackgroundLayers(e,t.backgroundBucketIds)),super.renderChildren(e),e.drawPhase===M.MAP&&this._fade(e.displayLevel,e.state);const o=this.children.filter(n=>n.visible&&n.hasData());if(!o||o.length===0)return s.bindVAO(),s.setStencilTestEnabled(!0),void s.setBlendingEnabled(!0);for(const n of o)n.triangleCount=0;s.setStencilWriteMask(0),s.setColorMask(!0,!0,!0,!0),s.setStencilOp(k.KEEP,k.KEEP,k.REPLACE),s.setStencilTestEnabled(!0),s.setBlendingEnabled(!1),s.setDepthTestEnabled(!0),s.setDepthWriteEnabled(!0),s.setDepthFunction(te.LEQUAL),s.setClearDepth(1),s.clear(s.gl.DEPTH_BUFFER_BIT),e.renderPass="opaque";for(let n=i.length-1;n>=0;n--)this._renderStyleLayer(i[n],e,o);s.setDepthWriteEnabled(!1),s.setBlendingEnabled(r),s.setBlendFunctionSeparate($.ONE,$.ONE_MINUS_SRC_ALPHA,$.ONE,$.ONE_MINUS_SRC_ALPHA),e.renderPass="translucent";for(let n=0;n<i.length;n++)this._renderStyleLayer(i[n],e,o);s.bindVAO(),s.setStencilTestEnabled(!0),s.setBlendingEnabled(!0)}_fade(e,s){this._symbolFader!=null&&(this._symbolFader.update(e,s)||this.requestRender())}_renderStyleLayer(e,s,t){const{painter:i,renderPass:r}=s;if(e===void 0)return;const o=e.getLayoutProperty("visibility");if(o&&o.getValue()===G.NONE)return;let n;switch(e.type){case v.BACKGROUND:return;case v.FILL:if(r!=="opaque"&&s.renderPass!=="translucent")return;n="vtlFill";break;case v.LINE:if(r!=="translucent")return;n="vtlLine";break;case v.CIRCLE:if(r!=="translucent")return;n="vtlCircle";break;case v.SYMBOL:if(r!=="translucent")return;n="vtlSymbol"}if(t=e.type===v.SYMBOL?t.filter(h=>h.decluttered):t.filter(h=>h.neededForCoverage),n!=="vtlSymbol"){const h=s.displayLevel;if(t.length===0||e.minzoom!==void 0&&e.minzoom>=h+F||e.maxzoom!==void 0&&e.maxzoom<h-F)return}const a=e.uid;s.styleLayerUID=a,s.styleLayer=e;for(const h of t)if(h.layerData.has(a)){i.renderObjects(s,t,n);break}}_renderBackgroundLayers(e,s){const{context:t,displayLevel:i,painter:r,state:o}=e,n=this._styleRepository;let a=!1;for(const b of s)if(n.getLayerById(b).type===v.BACKGROUND&&he(n.getLayerById(b),i)){a=!0;break}if(!a)return;const h=this._tileInfoView.getTileCoverage(e.state,0,!0,"smallest"),{spans:d,lodInfo:y}=h,{level:u}=y,c=J(),p=[];if(this._renderPasses){const b=this._renderPasses[0];this._clippingInfos!=null&&(b.brushes[0].prepareState(e),b.brushes[0].drawMany(e,this._clippingInfos))}const _=this._backgroundTiles;let f,g=0;for(const{row:b,colFrom:w,colTo:R}of d)for(let S=w;S<=R;S++){if(g<_.length)f=_[g],f.key.set(u,b,y.normalizeCol(S),y.getWorldForColumn(S)),this._tileInfoView.getTileBounds(c,f.key,!1),f.x=c[0],f.y=c[3],f.resolution=this._tileInfoView.getTileResolution(u);else{const D=new P(u,b,y.normalizeCol(S),y.getWorldForColumn(S)),L=this._tileInfoView.getTileBounds(J(),D),ge=this._tileInfoView.getTileResolution(u);f=new Dt(D,ge,L[0],L[3],512,512,4096,4096),_.push(f)}f.setTransform(o),p.push(f),g++}t.setStencilWriteMask(0),t.setColorMask(!0,!0,!0,!0),t.setStencilOp(k.KEEP,k.KEEP,k.REPLACE),t.setStencilFunction(te.EQUAL,0,255);let m=!0;e.drawPhase===M.HITTEST&&(m=!1),t.setStencilTestEnabled(m);for(const b of s){const w=n.getLayerById(b);w.type===v.BACKGROUND&&he(w,i)&&(e.styleLayerUID=w.uid,e.styleLayer=w,r.renderObjects(e,p,"vtlBackground"))}ce.pool.release(h)}}class At extends Le{constructor(){super(...arguments),this._fullCacheLodInfos=null,this._levelByScale={}}getTileParentId(e){const s=P.pool.acquire(e),t=s.level===0?null:P.getId(s.level-1,s.row>>1,s.col>>1,s.world);return P.pool.release(s),t}getTileCoverage(e,s,t=!0,i){const r=super.getTileCoverage(e,s,t,i);if(!r)return r;const o=1<<r.lodInfo.level;return r.spans=r.spans.filter(n=>n.row>=0&&n.row<o),r}scaleToLevel(e){if(this._fullCacheLodInfos||this._initializeFullCacheLODs(this._lodInfos),this._levelByScale[e])return this._levelByScale[e];{const 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{const t=this.tileInfo.size[0],i=this.tileInfo.spatialReference;s=Me.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}}let B=class extends Ge(Ye){constructor(){super(...arguments),this._styleChanges=[],this._fetchQueue=null,this._parseQueue=null,this._tileHandlerPromise=null,this._isTileHandlerReady=!1}get fading(){var l;return((l=this._vectorTileContainer)==null?void 0:l.fading)??!1}async hitTest(l,e){if(!this._tileHandlerPromise)return null;await this._tileHandlerPromise;const s=await this._vectorTileContainer.hitTest(e);if(!s||s.length===0)return null;const t=s[0]-1,i=this._styleRepository,r=i.getStyleLayerByUID(t);if(!r)return null;const o=i.getStyleLayerIndex(r.id);return[{type:"graphic",mapPoint:l,layer:this.layer,graphic:new Oe({attributes:{layerId:o,layerName:r.id,layerUID:t},layer:this.layer,sourceLayer:this.layer})}]}update(l){if(this._tileHandlerPromise&&this._isTileHandlerReady)return l.pixelRatio!==this._tileHandler.devicePixelRatio?(this._start(),void(this._tileHandler.devicePixelRatio=l.pixelRatio)):void(this._styleChanges.length>0?this._tileHandlerPromise=this._applyStyleChanges():(this._fetchQueue.pause(),this._parseQueue.pause(),this._fetchQueue.state=l.state,this._parseQueue.state=l.state,this._tileManager.update(l)||this.requestUpdate(),this._parseQueue.resume(),this._fetchQueue.resume()))}attach(){const{style:l}=this.layer.currentStyleInfo;this._styleRepository=new se(l),this._tileInfoView=new At(this.layer.tileInfo,this.layer.fullExtent),this._vectorTileContainer=new Rt(this._tileInfoView),this._tileHandler=new Xe(this.layer,this._styleRepository,window.devicePixelRatio||1),this.container.addChild(this._vectorTileContainer),this._start(),this.addAttachHandles([this.layer.on("paint-change",e=>{var s,t;if(e.isDataDriven)this._styleChanges.push({type:T.PAINTER_CHANGED,data:e}),this.requestUpdate();else{const i=this._styleRepository,r=i.getLayerById(e.layer);if(!r)return;const o=r.type===v.SYMBOL;i.setPaintProperties(e.layer,e.paint),o&&((s=this._vectorTileContainer)==null||s.restartDeclutter()),(t=this._vectorTileContainer)==null||t.requestRender()}}),this.layer.on("layout-change",e=>{var r,o;const s=this._styleRepository,t=s.getLayerById(e.layer);if(!t)return;const i=ke(t.layout,e.layout);if(i!=null){if(Ue(i,"visibility")&&Pt(i)===1)return s.setLayoutProperties(e.layer,e.layout),t.type===v.SYMBOL&&((r=this._vectorTileContainer)==null||r.restartDeclutter()),void((o=this._vectorTileContainer)==null?void 0:o.requestRender());this._styleChanges.push({type:T.LAYOUT_CHANGED,data:e}),this.requestUpdate()}}),this.layer.on("style-layer-visibility-change",e=>{var i,r;const s=this._styleRepository,t=s.getLayerById(e.layer);t&&(s.setStyleLayerVisibility(e.layer,e.visibility),t.type===v.SYMBOL&&((i=this._vectorTileContainer)==null||i.restartDeclutter()),(r=this._vectorTileContainer)==null||r.requestRender())}),this.layer.on("style-layer-change",e=>{this._styleChanges.push({type:T.LAYER_CHANGED,data:e}),this.requestUpdate()}),this.layer.on("delete-style-layer",e=>{this._styleChanges.push({type:T.LAYER_REMOVED,data:e}),this.requestUpdate()}),this.layer.on("load-style",()=>this._loadStyle()),this.layer.on("spriteSource-change",e=>{this._styleChanges.push({type:T.SPRITES_CHANGED,data:e});const s=this._styleRepository.layers;for(const t of s)switch(t.type){case v.SYMBOL:t.getLayoutProperty("icon-image")&&this._styleChanges.push({type:T.LAYOUT_CHANGED,data:{layer:t.id,layout:t.layout}});break;case v.LINE:t.getPaintProperty("line-pattern")&&this._styleChanges.push({type:T.PAINTER_CHANGED,data:{layer:t.id,paint:t.paint,isDataDriven:t.isPainterDataDriven()}});break;case v.FILL:t.getLayoutProperty("fill-pattern")&&this._styleChanges.push({type:T.PAINTER_CHANGED,data:{layer:t.id,paint:t.paint,isDataDriven:t.isPainterDataDriven()}})}this.requestUpdate()})])}detach(){this._stop(),this.container.removeAllChildren(),this._vectorTileContainer=z(this._vectorTileContainer),this._tileHandler=z(this._tileHandler)}moveStart(){this.requestUpdate()}viewChange(){this.requestUpdate()}moveEnd(){this.requestUpdate()}supportsSpatialReference(l){var e;return Ee((e=this.layer.tileInfo)==null?void 0:e.spatialReference,l)}canResume(){let l=super.canResume();const{currentStyleInfo:e}=this.layer;if(l&&(e!=null&&e.layerDefinition)){const s=this.view.scale,{minScale:t,maxScale:i}=e.layerDefinition;e!=null&&e.layerDefinition&&(t&&t<s&&(l=!1),i&&i>s&&(l=!1))}return l}isUpdating(){return this.fading}acquireTile(l){const e=this._createVectorTile(l);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=>{Q(s)||Z.getLogger(this).error(s)})),e}releaseTile(l){const e=l.key.id;this._fetchQueue.abort(e),this._parseQueue.abort(e),this.requestUpdate()}_start(){if(this._stop(),this._tileManager=new it({acquireTile:s=>this.acquireTile(s),releaseTile:s=>this.releaseTile(s),tileInfoView:this._tileInfoView},this._vectorTileContainer),!this.layer.currentStyleInfo)return;const l=new AbortController,e=this._tileHandler.start({signal:l.signal}).then(()=>{this._fetchQueue=new X({tileInfoView:this._tileInfoView,process:(s,t)=>this._getTileData(s,t),concurrency:15}),this._parseQueue=new X({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.requestUpdate()}),this._tileHandlerAbortController=l,this._tileHandlerPromise=e}_stop(){if(!this._tileHandlerAbortController||!this._vectorTileContainer)return;const l=this._tileHandlerAbortController;l&&l.abort(),this._tileHandlerPromise=null,this._isTileHandlerReady=!1,this._fetchQueue=z(this._fetchQueue),this._parseQueue=z(this._parseQueue),this._tileManager=z(this._tileManager),this._vectorTileContainer.removeAllChildren()}async _getTileData(l,e){return this._tileHandler.fetchTileData(l,e)}async _parseTileData(l,e){return this._tileHandler.parseTileData(l,e)}async _applyStyleChanges(){this._isTileHandlerReady=!1,this._fetchQueue.pause(),this._parseQueue.pause(),this._fetchQueue.clear(),this._parseQueue.clear(),this._tileManager.clearCache();const l=this._styleChanges;try{await this._tileHandler.updateStyle(l)}catch(r){Z.getLogger(this).error("error applying vector-tiles style update",r.message),this._fetchQueue.resume(),this._parseQueue.resume(),this._isTileHandlerReady=!0}const e=this._styleRepository,s=new Set;l.forEach(r=>{if(r.type!==T.LAYER_REMOVED)return;const o=r.data,n=e.getLayerById(o.layer);n&&s.add(n.uid)});const t=new Set;l.forEach(r=>{let o;switch(r.type){case T.PAINTER_CHANGED:e.setPaintProperties(r.data.layer,r.data.paint),o=r.data.layer;break;case T.LAYOUT_CHANGED:e.setLayoutProperties(r.data.layer,r.data.layout),o=r.data.layer;break;case T.LAYER_REMOVED:return void e.deleteStyleLayer(r.data.layer);case T.LAYER_CHANGED:e.setStyleLayer(r.data.layer,r.data.index),o=r.data.layer.id;break;case T.SPRITES_CHANGED:this._vectorTileContainer.setSpriteMosaic(this._tileHandler.setSpriteSource(r.data.spriteSource))}if(o){const n=e.getLayerById(o);n&&t.add(n.uid)}});const i=this._vectorTileContainer.children;if(s.size>0){const r=Array.from(s);this._vectorTileContainer.deleteStyleLayers(r);for(const o of i)o.deleteLayerData(r)}if(this._fetchQueue.resume(),this._parseQueue.resume(),t.size>0){const r=Array.from(t),o=[];for(const n of i){const a=this._updatingHandles.addPromise(this._fetchQueue.push(n.key).then(h=>this._parseQueue.push({key:n.key,data:h,styleLayerUIDs:r})).then(h=>n.setData(h)));o.push(a)}await Promise.all(o)}this._styleChanges=[],this._isTileHandlerReady=!0,this.requestUpdate()}async _loadStyle(){const{style:l}=this.layer.currentStyleInfo,e=ze(l);this._isTileHandlerReady=!1,this._fetchQueue.pause(),this._parseQueue.pause(),this._fetchQueue.clear(),this._parseQueue.clear(),this._styleRepository=new se(e),this._vectorTileContainer.destroy(),this._tileManager.clear(),this._tileHandlerAbortController.abort(),this._tileHandlerAbortController=new AbortController;const{signal:s}=this._tileHandlerAbortController;try{this._tileHandlerPromise=this._tileHandler.setStyle(this._styleRepository,e),await this._tileHandlerPromise}catch(i){if(!Q(i))throw i}if(s.aborted)return this._fetchQueue.resume(),this._parseQueue.resume(),this._isTileHandlerReady=!0,void this.requestUpdate();const t=await this._tileHandler.spriteMosaic;this._vectorTileContainer.setStyleResources(t,this._tileHandler.glyphMosaic,this._styleRepository),this._fetchQueue.resume(),this._parseQueue.resume(),this._isTileHandlerReady=!0,this.requestUpdate()}_createVectorTile(l){const e=this._tileInfoView.getTileBounds(J(),l),s=this._tileInfoView.getTileResolution(l.level);return new Y(l,s,e[0],e[3],512,512,this._styleRepository)}};function Pt(l){if(l==null)return 0;switch(l.type){case"partial":return Object.keys(l.diff).length;case"complete":return Math.max(Object.keys(l.oldValue).length,Object.keys(l.newValue).length);case"collection":return Object.keys(l.added).length+Object.keys(l.changed).length+Object.keys(l.removed).length}}ee([Ve()],B.prototype,"_isTileHandlerReady",void 0),B=ee([He("esri.views.2d.layers.VectorTileLayerView2D")],B);const Ts=B;export{Ts as default};