text: // COPYRIGHT © 2018 Esri
  //
  // All rights reserved under the copyright laws of the United States
  // and applicable international laws, treaties, and conventions.
  //
  // This material is licensed for use under the Esri Master License
  // Agreement (MLA), and is bound by the terms of that agreement.
  // You may redistribute and use this code without modification,
  // provided you adhere to the terms of the MLA and include this
  // copyright notice.
  //
  // See use restrictions at http://www.esri.com/legal/pdfs/mla_e204_e300/english
  //
  // For additional information, contact:
  // Environmental Systems Research Institute, Inc.
  // Attn: Contracts and Legal Services Department
  // 380 New York Street
  // Redlands, California, USA 92373
  // USA
  //
  // email: contracts@esri.com
  //
  // See http://js.arcgis.com/4.10/esri/copyright.txt for details.
  
  define(["require","exports","../../../../../../core/tsSupport/extendsHelper","../../../../../../core/Error","../../../../../../core/Logger","../../../../../../geometry/support/jsonUtils","../../../../../../symbols/SimpleLineSymbol","../../definitions","../../enums","../../WGLDisplayObject","../../collisions/LayerCollisionInfo","../MeshData","../VertexVector","./VVFactory","../templates/WGLLabelTemplate","../templates/WGLLineTemplate","../templates/WGLMarkerTemplate","../../util/vvFlagUtils"],function(e,t,r,h,l,d,a,T,n,G,g,p,u,m,b,i,o,f){Object.defineProperty(t,"__esModule",{value:!0});var c=l.getLogger("esri.views.2d.engine.webgl.WGLMeshFactory"),s={esriGeometryPoint:["above-right","above-center","above-left","center-center","center-left","center-right","below-center","below-left","below-right"],esriGeometryPolygon:["always-horizontal"],esriGeometryPolyline:["center-along"],esriGeometryMultipoint:null,esriGeometryEnvelope:null};var y=function(){function e(e,t,r,l,a,i,o,s,n,p){var u=this;if(this._labelsDebugTemplate=null,this._labelsDebugVVEval=null,this._materials=o,this._geometryType=e,this._idField=t,this._pixelRatio=a,this._vvFlags=f.getVVFlags(r),this._vvFactory=new m.default(r,l),this._vvBuf=new ArrayBuffer(16),this._vvBufU32=new Uint32Array(this._vvBuf),this._vvBufF32=new Float32Array(this._vvBuf),this._templateStore=s,n)if(T.DEBUG_LABELS&&(this._labelsDebugVVEval=r&&g.createLabelVVEvaluator(r)),this._validateLabelingInfo(n)){var y=f.getLabelVVFlags(this._vvFlags);this._labelTemplates=n.map(function(e){return b.default.fromLabelClass(u._materials,y,e,a,p)})}else c.error(new h("mapview-labeling:unsupported-geometry","LabelingInfo failed validation - unable to create labels for layer."))}return Object.defineProperty(e.prototype,"materials",{get:function(){return this._materials},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"templates",{get:function(){return this._templateStore},enumerable:!0,configurable:!0}),e.prototype.createMeshData=function(e){var t=new Array(5),r=new Array,l=!!f.getMarkerVVFlags(this._vvFlags),a=!!f.getFillVVFlags(this._vvFlags),i=!!f.getLineVVFlags(this._vvFlags,"esriGeometryPolyline"!==this._geometryType),o=!!f.getTextVVFlags(this._vvFlags),s="esriGeometryPolyline"===this._geometryType?T.HEURISTIC_GLYPHS_PER_LINE:T.HEURISTIC_GLYPHS_PER_FEATURE;return t[n.WGLGeometryType.MARKER]=new u.VertexVectors(n.WGLGeometryType.MARKER,l,e),t[n.WGLGeometryType.FILL]=new u.VertexVectors(n.WGLGeometryType.FILL,a,e),t[n.WGLGeometryType.LINE]=new u.VertexVectors(n.WGLGeometryType.LINE,i,e),t[n.WGLGeometryType.TEXT]=new u.VertexVectors(n.WGLGeometryType.TEXT,o,e),t[n.WGLGeometryType.LABEL]=new u.VertexVectors(n.WGLGeometryType.LABEL,!1,this._labelTemplates&&0<this._labelTemplates.length?s:0),new p.default(r,t,this._materials)},e.prototype.analyze=function(e,t,r,l){for(var a=e,i=0,o=a;i<o.length;i++){var s=o[i],n=-1;null!=s.symbol?n=this._templateStore.createTemplateGroup(s.symbol,null,this._materials,0):t&&(n=t.match(s,r,l)),s.groupId=n}return this._templateStore.finalize().then(function(){return a})},e.prototype.write=function(e,t,r,l,a,i,o){var s=this._templateStore.getTemplateGroup(t.groupId),n=e,p=t.attributes[this._idField],u=new G(p),y=!!i&&!!this._labelTemplates&&i.has(p);if(s&&(t.geometry||t.centroid)){this._vvFactory.computeVV(this._vvBufF32,t,r,l);var h=u.displayRecords,g=t.insertAfter;void 0!==g&&(u.insertAfter=g);var m=this._geometryType;m||(m=null!=t.centroid?"esriGeometryPolygon":d.getJsonType(t.geometry));for(var b=0,f=s;b<f.length;b++){var c=f[b],v=n.get(c.geometryType);c.writeMesh(h,v,m,p,t,this._pixelRatio,this._vvBufU32)}if(y){var _=this._getLabelReference(s),L=i.get(p);this._writeLabelMesh(u,n,p,t,o,L,_,a,m)}n.pushDisplayObject(u)}},e.prototype._hasBadLabelClass=function(e,t){var r=e.labelPlacement,l=s[t];if(!l)return c.error(new h("mapview-labeling:unsupported-geometry-type","Unable to create labels for WebGL Feature Layer, "+t+" is not supported")),!0;if(!l.some(function(e){return e===r})){var a=l[0];r&&c.warn("Found invalid label placement type "+r+" for "+t+". Defaulting to "+a),e.labelPlacement=a}return!1},e.prototype._validateLabelingInfo=function(e){var t=this;return!e.some(function(e){return t._hasBadLabelClass(e,t._geometryType)})},e.prototype._getLabelReference=function(e){for(var t=0,r=e;t<r.length;t++){var l=r[t];if(l instanceof o.default)return l}return null},e.prototype._writeLabelMesh=function(e,t,r,l,a,i,o,s,n){for(var p=e.displayRecords,u=[],y=this._pixelRatio,h=this._vvBufU32,g=0;g<i.length;g++){var m=i[g],b=m.id,f=m.text,c=m.rtl,v=this._labelTemplates[b],_=t.get(v.geometryType),L=a.get(v.symbolId).glyphMosaicItems;v.bindReferenceTemplate(o),v.bindTextInfo(L,f,c),v.writeMesh(p,_,n,r,l,y,h,s,u)}e.metrics=u,T.DEBUG_LABELS&&this._debugLabels(e,t)},e.prototype._debugLabels=function(e,t){for(var r=e.displayRecords,l=e.id,a=0,i=e.metrics;a<i.length;a++){var o=i[a],s=o.boxes?o.boxes.concat([o.bounds]):[o.bounds];this._labelsDebugVVEval&&o.computeOffset(this._labelsDebugVVEval);for(var n=0,p=s;n<p.length;n++){var u=p[n],y=o.anchor[0]+o.offsetX+u.center[0],h=o.anchor[1]+o.offsetY+u.center[1],g={geometry:{paths:[[[y-u.width/2,h+u.height/2],[0,-u.height],[u.width,0],[0,u.height],[-u.width,0]]]},attributes:{}},m=this._getLabelDebugTemplate(),b=t.get(m.geometryType);m.writeMesh(r,b,"esriGeometryPolyline",l,g,this._pixelRatio,null)}}},e.prototype._getLabelDebugTemplate=function(){return this._labelsDebugTemplate||(this._labelsDebugTemplate=this._createLabelsDebugTemplate()),this._labelsDebugTemplate},e.prototype._createLabelsDebugTemplate=function(){var e=new a({style:"solid",width:1,color:[255,0,0,1]});return i.default.fromSimpleLine(this._materials,0,e,null,this._pixelRatio)},e}();t.default=y});