/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{__decorate as e}from"tslib";import t from"../../core/Accessor.js";import"../../core/has.js";import{property as s,subclass as r}from"../../core/accessorSupport/decorators.js";import{SymbolFader as l}from"./engine/vectorTiles/decluttering/SymbolFader.js";import{tileSize as o}from"./engine/webgl/definitions.js";const i=8;class n{constructor(){this.styles=new Map,this.layerContexts=new Map}get cachedStyles(){return this.styles}setLabelClassStyle(e,t,s){this.layerContexts.set(e,t),this.styles.set(e,s)}clear(){this.layerContexts.clear(),this.styles.clear()}}let a=class extends t{constructor(e){super(e),this._styleRepository=new n,this.decluttering=!1,this.declutterRequested=!1,this.featuresTilingScheme=null;const t=(e,t)=>{};this.symbolFader=new l("feature-tile",this._styleRepository,t,[],o,i,()=>this.requestDeclutter())}get updating(){return this.decluttering||this.declutterRequested}requestDeclutter(){this.declutterRequested=!0}declutter(e,t){if(this.declutterRequested&&!this.decluttering&&(this._updateRepository(e),this.symbolFader.restartDeclutter(),this.decluttering=!0,this.declutterRequested=!1),this.decluttering&&null!=this.featuresTilingScheme){for(const s of this.symbolFader.tiles)s.setTransform(t);const e=this.symbolFader.update(this.featuresTilingScheme.scaleToZoom(t.scale),t);this.decluttering=!e}return this.decluttering}_updateRepository(e){this._styleRepository.clear(),this.symbolFader.tiles.length=0,this.symbolFader.symbolRepository?.flushFeatureTileUpdateMessages();for(const t of e)if(t.labelSchema){const e=this._getLabelSchemaStyles(t);if(!e.length)continue;for(const s of e){const e=c(s);this._styleRepository.setLabelClassStyle(s.labelClassId,t,e)}for(const s of t.tiles||[])s.decluttering&&this.symbolFader.tiles.push(s)}}_getLabelSchemaStyles(e){const t=e.labelSchema;if(!t)return[];switch(t.type){case"label":return t.classes;case"subtype":return Array.from(Object.values(t.renderers).flatMap(e=>e.classes));case"cluster":return[...t.cluster.classes,...t.feature.classes];case"track":return[...t.latestObservation.classes,...t.previousObservation.classes,...t.trackLine.classes]}}};function c(e){const t="esriGeometryPolyline"===e.geometryType?0:1,s="esriGeometryPolyline"===e.geometryType?0:1;return{geometryType:e.geometryType,iconAllowOverlap:!e.deconflictionEnabled,iconIgnorePlacement:!1,textAllowOverlap:!e.deconflictionEnabled,textIgnorePlacement:!1,iconRotationAlignment:t,textRotationAlignment:t,iconTranslateAnchor:s,iconTranslate:[0,0],textTranslateAnchor:s,textTranslate:[0,0]}}e([s()],a.prototype,"decluttering",void 0),e([s()],a.prototype,"declutterRequested",void 0),e([s()],a.prototype,"updating",null),e([s()],a.prototype,"featuresTilingScheme",void 0),a=e([r("esri.views.2d.LabelManager")],a);export{n as LabelClassStyleRepository,a as LabelManager};
