/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{__decorate as e}from"tslib";import{watch as t}from"../../../../core/reactiveUtils.js";import{property as i,subclass as r}from"../../../../core/accessorSupport/decorators.js";import{sampleVectorField as s}from"../../../../layers/raster/functions/vectorFieldUtils.js";import{RasterVFTileContainer as l}from"../../engine/imagery/RasterVFTileContainer.js";import{BaseImageryTileSubView2D as o}from"./BaseImageryTileSubView2D.js";let a=class extends o{constructor(){super(...arguments),this._handle=null,this.type="rasterVF"}async fetchTile(e,t){t={...t,interpolation:"nearest",requestProjectedLocalDirections:!0};const i=await this.layer.fetchTile(e.level,e.row,e.col,t);return"vector-magdir"===this.layer.serviceRasterInfo?.dataType&&i?.pixelBlock&&(i.pixelBlock=await this.layer.convertVectorFieldData(i.pixelBlock,"vector-magdir",t)),i}updateTileSource(e,t){const i=t.symbolizerParams,{tileData:r}=e;r.key=e.key,r.width=this._tileInfoView.size[0],r.height=this._tileInfoView.size[1];const{symbolTileSize:s}=i,{source:l}=t;if(r.offset=this._getTileSymbolOffset(r.key,s),null!=l?.pixelBlock){const e={extent:l.extent,pixelBlock:l.pixelBlock,srcExtent:l.srcExtent,srcPixelSize:l.srcTilePixelSize};r.rawPixelData=e,r.symbolizerParameters=i,r.source=this._sampleVectorFieldData(l.pixelBlock,i,r.offset)}else{const e=[Math.round((this._tileInfoView.size[0]-r.offset[0])/s),Math.round((this._tileInfoView.size[1]-r.offset[1])/s)],t=this.createEmptyTilePixelBlock(e);r.source=t,r.symbolizerParameters=i}return r.invalidateMeshes(),Promise.resolve()}updateTileSymbolizerParameters(e,t){const i=t.local,{symbolTileSize:r}=i,{tileData:s}=e;s.offset=this._getTileSymbolOffset(s.key,r);const l=s.symbolizerParameters.symbolTileSize;s.symbolizerParameters=i;const o=s.rawPixelData?.pixelBlock;return null!=o&&l!==r&&(s.source=this._sampleVectorFieldData(o,s.symbolizerParameters,s.offset)),Promise.resolve()}attach(){super.attach(),this.container=new l(this._tileInfoView),this.container.isCustomTilingScheme=this._isCustomTilingScheme,this._updateSymbolType(this.layer.renderer),this._handle=t(()=>this.layer.renderer,e=>this._updateSymbolType(e))}detach(){super.detach(),this.container.removeAllChildren(),this._handle?.remove(),this._handle=null,this.container=null}_getTileSymbolOffset(e,t){const i=e.col*this._tileInfoView.size[0]%t,r=e.row*this._tileInfoView.size[1]%t;return[i>t/2?t-i:-i,r>t/2?t-r:-r]}_sampleVectorFieldData(e,t,i){const{symbolTileSize:r}=t;return s(e,"vector-uv",r,i)}_updateSymbolType(e){"vector-field"===e?.type&&(this.container.symbolTypes="wind-barb"===e.style?["scalar","triangle"]:"simple-scalar"===e.style?["scalar"]:["triangle"])}};e([i()],a.prototype,"container",void 0),e([i()],a.prototype,"layer",void 0),e([i()],a.prototype,"type",void 0),a=e([r("esri.views.2d.layers.imagery.VectorFieldTileView2D")],a);export{a as default};
