/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{__decorate as e}from"tslib";import t from"../../core/Accessor.js";import has from"../../core/has.js";import{property as s,subclass as r}from"../../core/accessorSupport/decorators.js";import{SymbolFader as o}from"./engine/vectorTiles/decluttering/SymbolFader.js";import{tileSize as a}from"./engine/webgl/definitions.js";const i=64;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)}removeContainer(e){for(const[t,s]of this.layerContexts.entries())s===e&&this.layerContexts.delete(t)}}let l=class extends t{constructor(e){super(e),this._faderWorkingSet=[],this._styleRepository=new n,this.lastUpdateId=-1,this.updateRequested=!1,this.view=null;const t=(e,t)=>{e.updateLabelVisibility(),e.requestRender(),e.isReady&&(e.decluttered=!0)};this.symbolFader=new o("feature-tile",this._styleRepository,t,this._faderWorkingSet,a,i)}get updating(){return has("esri-2d-log-updating")&&console.log(`Updating LabelManager ${this.updateRequested}:\n-> updateRequested: ${this.updateRequested}`),this.updateRequested}viewChange(){this.requestUpdate()}requestUpdate(){this.updateRequested||(this.updateRequested=!0,this.view?.requestUpdate())}processUpdate(e){this.doUpdate(e)?this.updateRequested=!1:(this.updateRequested=!0,this.view?.requestUpdate())}setLabelSchemaStyles(e,t){let s;switch(e.type){case"label":s=e.classes;break;case"subtype":s=Array.from(Object.values(e.renderers).flatMap(e=>e.classes));break;case"cluster":s=[...e.cluster.classes,...e.feature.classes];break;case"track":s=[...e.latestObservation.classes,...e.previousObservation.classes,...e.trackLine.classes]}for(const r of s){const e=c(r);this._styleRepository.setLabelClassStyle(r.labelClassId,t,e)}}removeContainer(e){this._styleRepository.removeContainer(e),this.requestUpdate()}doUpdate(e){this._faderWorkingSet.length=0;const t=this.view;if(!t)return!1;const s=t.allLayerViews.map(e=>e.featureContainer).filter(e=>!!e&&e?.hasLabels);if(s.length>0){for(const t of s)for(const s of t.tiles||[])s.setTransform(e.state),this._faderWorkingSet.push(s);const r=e.state.scale,o=t.featuresTilingScheme.scaleToZoom(r);return this.symbolFader.update(o,e.state)}return!0}};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()],l.prototype,"updateRequested",void 0),e([s()],l.prototype,"updating",null),e([s()],l.prototype,"view",void 0),l=e([r("esri.views.2d.LabelManager")],l);export{n as LabelClassStyleRepository,l as LabelManager};
