text: // All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  // See https://js.arcgis.com/3.38/esri/copyright.txt for details.
  //>>built
  define("esri/layers/vectorTiles/views/2d/engine/webgl/WGLFeatureView","require exports ../../../../core/tsSupport/assignHelper ../../../../core/tsSupport/extendsHelper ../../../../core/promiseUtils ../../../../core/promiseUtils ../../../../core/libs/gl-matrix/mat4 ../../../../core/libs/gl-matrix/vec3 ../../../../geometry/Point ../Container ../StageGL ../../engine/webgl/TileData ./enums ./GeometryUtils ./TextureManager ./Utils ./WGLPainter ./WGLRendererInfo".split(" "),function(q,r,v,w,x,y,l,n,z,A,
  B,t,p,C,D,u,E,F){Object.defineProperty(r,"__esModule",{value:!0});q=function(m){function d(a){var b=m.call(this)||this;b._rendererInfo=new F;b._stage=new B;b._container=null;b._tileCoordinateScale=n.create();b._orientationVec=n.fromValues(0,0,1);b._displayScale=n.create();b._defaultTransform=l.create();b._pointToCallbacks=new Map;b._highlightIDs=new Set;b._tileId=void 0;b._patches={};b._displayWidth=0;b._displayHeight=0;b._highlightOptionsUpToDate=!1;b.layer=null;b.textureManager=new D;b.highlightOptions=
  a.highlightOptions;b.tileInfoView=a.tileInfoView;b._stage.useContextVersion("webgl");b.layer=a.layer;b._layerView=a.layerView;return b}w(d,m);d.prototype.dispose=function(){this.textureManager&&(this.textureManager.dispose(),this.textureManager=null);this.removeAllChildren();for(var a=0,b=this.children;a<b.length;a++)b[a].dispose()};d.prototype.disposeWebGLResources=function(){for(var a=0,b=this.children;a<b.length;a++)b[a].clear()};d.prototype.displayWidth=function(){return this._displayWidth};Object.defineProperty(d.prototype,
  "displayHeight",{get:function(){return this._displayHeight},enumerable:!0,configurable:!0});Object.defineProperty(d.prototype,"highlightOptions",{get:function(){return this._highlightOptions},set:function(a){this._highlightOptions=a;this._highlightOptionsUpToDate=!1},enumerable:!0,configurable:!0});Object.defineProperty(d.prototype,"visualVariablesInfo",{get:function(){return this._visualVariablesInfo},set:function(a){this._visualVariablesInfo=a;this.requestRender()},enumerable:!0,configurable:!0});
  d.prototype.install=function(a){a.addChild(this._stage);this._stage.addChild(this);this._container=a};d.prototype.uninstall=function(a){a.removeChild(this._stage);this._stage.removeChild(this);this.dispose();this._container=null};d.prototype.hitTest=function(a,b){var c=this,e=[a,b];return x.create(function(f,h){c._pointToCallbacks.set(e,{resolve:f,reject:h});c.requestRender()},function(){c._pointToCallbacks.has(e)&&c._pointToCallbacks.delete(e)})};d.prototype.highlight=function(a){var b=this;b.addHighlight(a);
  return{remove:function(){b.removeHighlight(a)}}};d.prototype.setHighlight=function(a){this._highlightIDs.clear();this.addHighlight(a)};d.prototype.setVisibility=function(a,b){for(var c=function(h){if(h.data){var g=h.data.tileDisplayData.displayObjectRegistry,k=a.filter(function(G){return g.has(G.id)});h.setVisibility(k,b)}},e=0,f=this.children;e<f.length;e++)c(f[e])};d.prototype.setVisibilityRange=function(a,b,c,e){for(var f=0,h=this.children;f<h.length;f++){var g=h[f];g.data&&g.data.tileDisplayData.displayObjectRegistry.has(a)&&
  g.setVisibilityRange(a,b,c,e)}};d.prototype.addHighlight=function(a){for(var b=0;b<a.length;b++)this._highlightIDs.add(a[b]);this._buildHLList()};d.prototype.removeHighlight=function(a){for(var b=0;b<a.length;b++)this._highlightIDs.delete(a[b]);this._buildHLList()};d.prototype.getMaterialItems=function(a){if(a&&0!==a.length){for(var b=[],c=0;c<a.length;c++){var e=a[c];b.push(this.textureManager.rasterizeItem(e.symbol,e.glyphIds))}return y.all(b).then(function(f){return f.map(function(h,g){return{id:g,
  mosaicItem:h}})})}};d.prototype.onTileData=function(a,b){var c=null;b&&(c=t.decode(b));a.setData(c,null!=this.visualVariablesInfo.vvFields,this.layer.labelsVisible);a.buildHLList(this._highlightIDs);this._layerView&&this._layerView.view.labelManager.requestUpdate();this.addChild(a);this._stage.fadeInLabels();this.requestRender()};d.prototype.onTileDataUpdate=function(a,b){this._patches[a.key.id]=this._patches[a.key.id]||[];this._patches[a.key.id].push({tile:a,patch:b});this._stage.fadeInLabels();
  this.requestRender()};d.prototype.onTileError=function(a){a.clear();a.buildHLList(this._highlightIDs);this.addChild(a);this.requestRender()};d.prototype.addChild=function(a){var b=m.prototype.addChild.call(this,a);this.layer.labelingInfo&&this._layerView&&this._layerView.view.labelManager.addTile(this.layer.uid,a);this._buildHLList();return b};d.prototype.removeChild=function(a){var b=m.prototype.removeChild.call(this,a);this.layer.labelingInfo&&this._layerView&&this._layerView.view.labelManager.removeTile(this.layer.uid,
  a.key.id);this._buildHLList();return b};d.prototype.prepareChildrenRenderParameters=function(a){this._rendererInfo.updateVisualVariables(this._visualVariablesInfo.vvRanges,a.state);var b=this.tileInfoView.getClosestInfoForScale(a.state.scale).level,c=this.tileInfoView.tileInfo.scaleToZoom(a.state.scale);return v({},a,{rendererInfo:this._rendererInfo,requiredLevel:b,displayLevel:c})};d.prototype.renderChildren=function(a){for(var b=this,c=0;this._nextTile()&&4>c;){for(var e=0,f=this._patches[this._tileId];e<
  f.length;e++){var h=f[e];this._patchTileVisuals(h.tile,h.patch)}delete this._patches[this._tileId];++c}c=a.painter;c.bindTextureManager(this.textureManager);this._rendererInfo.updateVisualVariables(this._visualVariablesInfo.vvRanges,a.state);this.sortChildren(function(g,k){return 0!==g.key.level-k.key.level?g.key.level-k.key.level:0!==g.key.row-k.key.row?g.key.row-k.key.row:g.key.col-k.key.col});e=E.default.toWGLDrawPhases(a.drawPhase);if(0<e.length&&e[0]===p.WGLDrawPhase.LABEL||e[0]===p.WGLDrawPhase.LABEL_ALPHA){f=
  this.layer;if(!(f.labelsVisible&&f.labelingInfo&&0<f.labelingInfo.length))return;this._updateTilesTransform(a.state,a.requiredLevel);c.update(a.state,a.pixelRatio)}c.draw(a,this.children,e,this._painterOptions);0<this._highlightIDs.size&&c.highlight(a,this.children);0!==this._pointToCallbacks.size&&(this._pointToCallbacks.forEach(function(g,k){g.resolve(b._hitTest(a,k[0],k[1]))}),this._pointToCallbacks.clear())};d.prototype.attachChild=function(a,b){return a.attach(b)};d.prototype.detachChild=function(a,
  b){a.detach(b)};d.prototype.renderChild=function(a,b){a.doRender(b)};d.prototype.beforeRenderChildren=function(a,b){this._updateTilesTransform(a.state,this.tileInfoView.getClosestInfoForScale(a.state.scale).level);this._updateHighlightOptions();this._stage.opacity=this._container.opacity};d.prototype._hitTest=function(a,b,c){var e=a.painter,f=a.requiredLevel,h=[0,0];a.state.toMap(h,[b,c]);b=a.state.clone();c=b.viewpoint.clone();c.targetGeometry=new z(h[0],h[1],a.state.spatialReference);b.viewpoint=
  c;b.size=[u.C_HITTEST_SEARCH_SIZE,u.C_HITTEST_SEARCH_SIZE];this._updateTilesTransform(b,f);e.update(b,a.pixelRatio);return e.hitTest({context:a.context,drawPhase:p.WGLDrawPhase.HITTEST,painter:e,pixelRatio:a.pixelRatio,displayLevel:a.displayLevel,rendererInfo:this._rendererInfo,requiredLevel:f,state:b,stationary:a.stationary},this.children)};d.prototype._updateTilesTransform=function(a,b){var c=1/a.width,e=1/a.height,f=[0,0];this._calculateRelativeViewProjMat(this.tileInfoView.tileInfo.lods[b].resolution,
  a.resolution,a.rotation,this.tileInfoView.tileInfo.size[0],a.width,a.height,this._defaultTransform);for(var h=0,g=this.children;h<g.length;h++){var k=g[h];a.toScreen(f,k.coords);f[1]=a.height-f[1];k.tileTransform.displayCoord[0]=2*f[0]*c-1;k.tileTransform.displayCoord[1]=2*f[1]*e-1;k.key.level===b?k.tileTransform.transform.set(this._defaultTransform):this._calculateRelativeViewProjMat(this.tileInfoView.tileInfo.lods[k.key.level].resolution,a.resolution,a.rotation,this.tileInfoView.tileInfo.size[0],
  a.width,a.height,k.tileTransform.transform)}};d.prototype._calculateRelativeViewProjMat=function(a,b,c,e,f,h,g){a/=b;this._tileCoordinateScale.set([a,a,1]);if(f!==this._displayWidth||h!==this._displayHeight)this._displayScale.set([2/f,-2/h,1]),this._displayWidth=f,this._displayHeight=h;l.identity(g);l.scale(g,g,this._tileCoordinateScale);l.rotate(g,g,-c*C.C_DEG_TO_RAD,this._orientationVec);l.scale(g,g,this._displayScale);l.transpose(g,g)};d.prototype._updateHighlightOptions=function(){if(!this._highlightOptionsUpToDate&&
  this.parent){var a=this.parent.glPainter,b=this._highlightOptions;if(a){var c=b.color.toRgba();c[0]/=255;c[1]/=255;c[2]/=255;var e=c.slice();c[3]*=b.fillOpacity;e[3]*=b.haloOpacity;a.setHighlightOptions({fillColor:c,outlineColor:e,outlineWidth:2,outerHaloWidth:.3,innerHaloWidth:.3,outlinePosition:0})}}};d.prototype._buildHLList=function(){for(var a=0,b=this.children;a<b.length;a++)b[a].buildHLList(this._highlightIDs);this.requestRender()};d.prototype._nextTile=function(){var a=Object.keys(this._patches);
  if(0===a.length)return this._tileId=void 0,!1;if(!this._tileId)return this._tileId=a[0],!0;var b=a.indexOf(this._tileId);b=(b+1)%a.length;this._tileId=a[b];return!0};d.prototype._patchTileVisuals=function(a,b){var c=b.addOrUpdate?t.decode(b.addOrUpdate):null;a.patchData({remove:b.remove||[],addOrUpdate:c},this.layer.labelsVisible);a.buildHLList(this._highlightIDs);this.contains(a)||this.addChild(a)};return d}(A);r.default=q});