/*
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","../../../../Graphic","../../../../request","../../../../core/HandleOwner","../../../../core/maybe","../../../../core/reactiveUtils","../../../../core/accessorSupport/decorators/property","../../../../core/arrayUtils","../../../../core/has","../../../../core/accessorSupport/ensureType","../../../../core/accessorSupport/decorators/subclass","../../../../geometry/Extent","../../../../layers/support/rasterFunctions/rasterProjectionHelper","../../../../layers/support/rasterFunctions/vectorFieldUtils","../../engine/imagery/RasterVFContainer","./ImageryVFStrategy"],(function(e,t,r,i,a,n,o,s,l,c,p,u,y,d,h,m,x){"use strict";let _=function(t){function a(){var r;return(r=t.apply(this,arguments)||this).attached=!1,r.container=new m.RasterVFContainer,r.type="imageryVF",r._dataParameters={exportParametersVersion:0,bbox:"",symbolTileSize:0,time:""},r._fetchpixels=function(){var t=e._asyncToGenerator((function*(e,t,i,a){const o=yield r._projectFullExtentPromise,{symbolTileSize:s}=r.layer.renderer,{extent:l,width:c,height:p}=h.snapImageToSymbolTile(e,t,i,s,o);if(n.isSome(o)&&!o.intersects(e))return{extent:l,pixelBlock:null};const u={bbox:`${l.xmin}, ${l.ymin}, ${l.xmax}, ${l.ymax}`,exportParametersVersion:r.layer.exportImageServiceParameters.version,symbolTileSize:s,time:JSON.stringify(r.timeExtent||"")};if(r._canReuseVectorFieldData(u)){const e=r.getPixelData();if(n.isSome(e)){if(`${e.extent.xmin}, ${e.extent.ymin}, ${e.extent.xmax}, ${e.extent.ymax}`===u.bbox)return e}}const{pixelData:y}=yield r.layer.fetchImage(l,c,p,{timeExtent:r.timeExtent,requestAsImageElement:!1,signal:a});if(r._dataParameters=u,n.isNone(y.pixelBlock))return{extent:l,pixelBlock:null};return{extent:l,pixelBlock:"vector-uv"===r.layer.rasterInfo.dataType?n.unwrap(h.convertVectorFieldData(y.pixelBlock,"vector-uv")):y.pixelBlock}}));return function(e,r,i,a){return t.apply(this,arguments)}}(),r}e._inheritsLoose(a,t);var s=a.prototype;return s.attach=function(){this._projectFullExtentPromise=this._getProjectedFullExtent(this.view.spatialReference),this._strategy=new x({container:this.container,fetchPixels:this._fetchpixels}),this.handles.add(o.watch((()=>this.layer.renderer),(e=>this._updateSymbolizerParams(e)),o.syncAndInitial),"vector-field-view-update")},s.detach=function(){this._strategy.destroy(),this.container.children.forEach((e=>e.destroy())),this.container.removeAllChildren(),this.handles.remove("vector-field-view-update"),this._strategy=this.container=this._projectFullExtentPromise=null},s.getPixelData=function(){if(this.updating||!this.container.children.length)return null;const{extent:e,pixelBlock:t}=this.container.children[0].rawPixelData;return{extent:e,pixelBlock:t}},s.hitTest=function(e){return new r({attributes:{},geometry:e.clone(),layer:this.layer})},s.update=function(e){this._strategy.update(e,this._symbolizerParams)},s.redraw=function(){this._updateSymbolizerParams(this.layer.renderer),this._strategy.redraw(this._symbolizerParams)},s._canReuseVectorFieldData=function(e){const t=this._dataParameters.exportParametersVersion===e.exportParametersVersion,r=this._dataParameters.time===e.time,i=this._dataParameters.symbolTileSize===e.symbolTileSize,a=this._dataParameters.bbox===e.bbox;return t&&r&&i&&a},s._getProjectedFullExtent=function(){var t=e._asyncToGenerator((function*(e){try{return yield d.projectExtent(this.layer.fullExtent,e)}catch(t){try{const t=(yield i(this.layer.url,{query:{option:"footprints",outSR:e.wkid||JSON.stringify(e.toJSON()),f:"json"}})).data.featureCollection.layers[0].layerDefinition.extent;return t?y.fromJSON(t):null}catch{return null}}}));function r(e){return t.apply(this,arguments)}return r}(),s._updateSymbolizerParams=function(e){"vector-field"===e.type&&(this._symbolizerParams=this.layer.symbolizer.generateWebGLParameters({pixelBlock:null}))},e._createClass(a,[{key:"updating",get:function(){return!this.attached||this._strategy.updating}}]),a}(a.HandleOwner);t.__decorate([s.property()],_.prototype,"attached",void 0),t.__decorate([s.property()],_.prototype,"container",void 0),t.__decorate([s.property()],_.prototype,"layer",void 0),t.__decorate([s.property()],_.prototype,"timeExtent",void 0),t.__decorate([s.property()],_.prototype,"type",void 0),t.__decorate([s.property()],_.prototype,"view",void 0),t.__decorate([s.property()],_.prototype,"updating",null),_=t.__decorate([u.subclass("esri.views.2d.layers.imagery.VectorFieldView2D")],_);return _}));
