/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["../../../../chunks/_rollupPluginBabelHelpers","../../../../chunks/tslib.es6","../../../../core/maybe","../../../../core/reactiveUtils","../../../../core/accessorSupport/decorators/property","../../../../core/arrayUtils","../../../../core/has","../../../../core/accessorSupport/ensureType","../../../../core/accessorSupport/decorators/subclass","../../../../layers/support/rasterFunctions/vectorFieldUtils","../../engine/imagery/RasterVFTileContainer","./BaseImageryTileSubView2D"],(function(e,t,i,r,o,l,s,a,n,c,p,u){"use strict";let y=function(t){function o(){var e;return(e=t.apply(this,arguments)||this)._handle=null,e.container=null,e.layer=null,e.type="rasterVF",e}e._inheritsLoose(o,t);var l=o.prototype;return l.canUseWebGLForProcessing=function(){return!1},l.fetchTile=function(){var t=e._asyncToGenerator((function*(e,t){t={...t,interpolation:"nearest",requestProjectedLocalDirections:!0};const i=yield this.layer.fetchTile(e.level,e.row,e.col,t);return"vector-magdir"===this.layer.rasterInfo.dataType&&null!=i&&i.pixelBlock&&(i.pixelBlock=yield this.layer.convertVectorFieldData(i.pixelBlock,t)),i}));function i(e,i){return t.apply(this,arguments)}return i}(),l.updateTileSource=function(e,t){const r=t.symbolizerParams,{tileData:o}=e;o.key=e.key,o.width=this._tileInfoView.tileInfo.size[0],o.height=this._tileInfoView.tileInfo.size[1];const{symbolTileSize:l}=r,{source:s}=t;if(o.offset=this._getTileSymbolOffset(o.key,l),i.isSome(s)&&i.isSome(s.pixelBlock)){const e={extent:s.extent,pixelBlock:s.pixelBlock};o.rawPixelData=e,o.symbolizerParameters=r,o.source=this._sampleVectorFieldData(s.pixelBlock,r,o.offset)}else{const e=[Math.round((this._tileInfoView.tileInfo[0]-o.offset[0])/l),Math.round((this._tileInfoView.tileInfo[1]-o.offset[1])/l)],t=this.createEmptyTilePixelBlock(e);o.source=t,o.symbolizerParameters=r}return o.invalidateVAO(),Promise.resolve(null)},l.updateTileSymbolizerParameters=function(e,t){var r;const o=t.local,{symbolTileSize:l}=o,{tileData:s}=e;s.offset=this._getTileSymbolOffset(s.key,l);const a=s.symbolizerParameters.symbolTileSize;return s.symbolizerParameters=o,i.isSome(null==(r=s.rawPixelData)?void 0:r.pixelBlock)&&a!==l&&(s.source=this._sampleVectorFieldData(s.rawPixelData.pixelBlock,s.symbolizerParameters,s.offset)),Promise.resolve(null)},l.attach=function(){t.prototype.attach.call(this),this.container=new p.RasterVFTileContainer(this._tileInfoView),this.container.isCustomTilingScheme=this._isCustomTilingScheme,this._updateSymbolType(this.layer.renderer),this._handle=r.watch((()=>this.layer.renderer),(e=>this._updateSymbolType(e)))},l.detach=function(){t.prototype.detach.call(this),this.container.removeAllChildren(),this._handle.remove(),this._handle=null},l._getTileSymbolOffset=function(e,t){const i=e.col*this._tileInfoView.tileInfo.size[0]%t,r=e.row*this._tileInfoView.tileInfo.size[1]%t;return[i>t/2?t-i:-i,r>t/2?t-r:-r]},l._sampleVectorFieldData=function(e,t,i){const{symbolTileSize:r}=t;return c.sampleVectorField(e,"vector-uv",r,i)},l._updateSymbolType=function(e){"vector-field"===e.type&&(this.container.symbolTypes="wind-barb"===e.style?["scalar","triangle"]:"simple-scalar"===e.style?["scalar"]:["triangle"])},o}(u.BaseImageryTileSubView2D);t.__decorate([o.property()],y.prototype,"container",void 0),t.__decorate([o.property()],y.prototype,"layer",void 0),t.__decorate([o.property()],y.prototype,"type",void 0),y=t.__decorate([n.subclass("esri.views.2d.layers.imagery.VectorFieldTileView2D")],y);return y}));
