// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://@sbaseurl@/jsapi/jsapi/esri/copyright.txt and http://www.arcgis.com/apps/webappbuilder/copyright.txt for details.

//>>built
define("dojo/_base/declare dojo/_base/array dojo/_base/Color esri/layers/GraphicsLayer esri/graphic esri/geometry/geometryEngine esri/geometry/Extent esri/geometry/Point esri/symbols/SimpleMarkerSymbol esri/symbols/SimpleLineSymbol esri/symbols/Font esri/symbols/TextSymbol".split(" "),function(x,y,m,z,p,A,B,u,q,v,C,D){return x("ClusterLayer",[z],{constructor:function(a){this.name=a.id;this.displayOnPan=a.displayOnPan||!1;this._map=a.map;this.clusterSize=a.clusterSize||100;this.color=a.color||"#ff0000";
this.countField=a.countField;this._features=[];try{this.setFeatures(a.features)}catch(b){console.log(b)}this.loaded=!0;this.onLoad(this)},setFeatures:function(a){this._map&&this._map.infoWindow.isShowing&&this._map.infoWindow.hide();this._features=a;this._clusterFeatures()},setColor:function(a){this.color=a;this._clusterFeatures()},_clusterFeatures:function(){this.clear();var a=this._features;if(0<a.length){var b=this.clusterSize,g=[],f=this._map.spatialReference,c=this._map.extent,d=c.normalize();
1<d.length&&(c=A.union(d).getExtent());d=new u(c.xmin,c.ymax,f);var h=Math.ceil(this._map.height/b),k=Math.ceil(this._map.width/b),e=c.getWidth()/this._map.width*b;b*=c.getHeight()/this._map.height;for(c=0;c<h;c++)for(var r=0;r<k;r++){var l=d.x+e*r,n=d.y-b*c;n=new B(l,n-b,l+e,n,f);l=[];for(var t in a){var w=a[t];n.contains(w.geometry)&&l.push(w)}0<l.length&&(n=this._getClusterCenter(l),g.push({center:n,graphics:l}))}for(var E in g)a=g[E],f=this._getClusterCount(a),d=a.graphics,h=f.toString(),k=19*
h.length,e=this._getSymbolColor(),b=new v(v.STYLE_NULL,new m(0,0,0,0),0),t=new q(q.STYLE_CIRCLE,1.6*k,b,new m([e[0],e[1],e[2],.4])),k=new q(q.STYLE_CIRCLE,k,b,new m([e[0],e[1],e[2],.8])),e=new C,e.family="Arial",e.size="12px",h=new D(h,e,"#ffffff"),h.setOffset(0,-4),d={Count:f,Data:d},1<f?(this.add(new p(a.center,t,d)),this.add(new p(a.center,k,d)),this.add(new p(a.center,h,d))):(a=a.graphics[0].geometry,this.add(new p(a,k,d)),this.add(new p(a,h,d)))}},_getSymbolColor:function(){var a=m.fromString(this.color),
b=m.fromString("#000000");return m.blendColors(a,b,.1).toRgb()},_getClusterCount:function(a){for(var b=0,g=0;g<a.graphics.length;g++){var f=a.graphics[g];b=this.countField&&f.attributes[this.countField]?b+f.attributes[this.countField]:b+1}return b},_getClusterCenter:function(a){var b=0,g=0,f=a.length;y.forEach(a,function(c){b+=c.geometry.x;g+=c.geometry.y},this);return new u(b/f,g/f,a[0].geometry.spatialReference)}})});