// 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("esri/geometry/Point esri/geometry/Polygon esri/geometry/geometryEngine esri/graphic esri/geometry/webMercatorUtils esri/SpatialReference esri/geometry/Circle esri/request dojo/json ./geometryUtils".split(" "),function(y,R,l,M,N,U,Y,S,V,t){var K={createGRG:function(a,b,d,h,u,f,E,g,m,z,c,q,D,F){var H=[],w=0,A=0,B=h/2/Math.cos(30*Math.PI/180),W,L=a;switch(E){case "upperLeft":if("horizontal"===m){var n=b-1;var p=-1;if("numeric"!==g)var e=0;else e=(b-1)*a,"hexagon"===z&&(e+=Math.floor(b/2))}else n=
-1,p=b-1,"numeric"!==g&&(e=b);break;case "upperRight":"horizontal"===m?(n=b-1,p=a,"numeric"!==g?e=a+1:(e=b*a+1,"hexagon"===z&&(e+=Math.floor(b/2)))):(e="numeric"!==g?b:b*(a+1),n=a,p=b-1);break;case "lowerRight":"horizontal"===m?(n=0,p=a,e=a+1):(n=a,p=0,e=1);break;case "lowerLeft":"horizontal"===m?(e=n=0,p=-1):(n=-1,e=1,p=0)}var I=a*h/2;var J="hexagon"===z?1===b%2?((b-1)/2*3*B+B)/2:(b/2*3*B-B/2)/2:b*u/2;var k=null;k=null;for(var r=1;r<=b;r++){for(var x=1;x<=a;x++){if(q){k=new R;if(1===r&&1===x)switch(102100===
d.spatialReference.wkid&&(d=N.webMercatorToGeographic(d)),c){case "center":var v=t.getDestinationPoint(d,180+f,J);v=t.getDestinationPoint(v,270+f,I);break;case "upperLeft":v=t.getDestinationPoint(d,180+f,2*J);break;case "upperRight":v=t.getDestinationPoint(d,180+f,2*J);v=t.getDestinationPoint(v,270+f,2*I);break;case "lowerRight":v=t.getDestinationPoint(d,270+f,2*I);break;case "lowerLeft":v=d}if("default"===z){var O=t.getDestinationPoint(v,0+f,u);var G=t.getDestinationPoint(O,90+f,h);var C=t.getDestinationPoint(G,
180+f,u);k.addRing([[v.x,v.y],[O.x,O.y],[G.x,G.y],[C.x,C.y]]);v=C}else{C=v;var P=t.getDestinationPoint(C,0+f,B);var Q=t.getDestinationPoint(P,60+f,B);G=t.getDestinationPoint(Q,120+f,B);var T=t.getDestinationPoint(G,180+f,B);var X=t.getDestinationPoint(T,240+f,B);k.addRing([[C.x,C.y],[P.x,P.y],[Q.x,Q.y],[G.x,G.y],[T.x,T.y],[X.x,X.y]]);v=t.getDestinationPoint(v,90+f,h)}k=l.simplify(k);D.spatialReference.wkid&&4326!==D.spatialReference.wkid&&(k=F.isLoaded()?F.project(k,D.spatialReference):N.geographicToWebMercator(k));
k=new M(k);1===x&&(W="hexagon"===z?L===a?t.getDestinationPoint(P,300+f,B):Q:O)}else{k=new R(new U({wkid:102100}));4326===d.spatialReference.wkid&&(d=N.geographicToWebMercator(d));switch(c){case "center":w=d.x-I;A=d.y-J;break;case "upperLeft":w=d.x;A=d.y-2*J;break;case "upperRight":w=d.x-2*I;A=d.y-2*J;break;case "lowerRight":w=d.x-2*I;A=d.y;break;case "lowerLeft":w=d.x,A=d.y}"default"===z?k.addRing([[w+(x-1)*h,A+(r-1)*u],[w+(x-1)*h,A+r*u],[w+x*h,A+r*u],[w+x*h,A+(r-1)*u],[w+(x-1)*h,A+(r-1)*u]]):(w=
L===a?w+(x-1)*h+h/2:w+(x-1)*h,A=A+B+1.5*(r-1)*B,C=new y([w,A],new U({wkid:102100})),G=new Y(C,{radius:B,numberOfPoints:6}),C=l.rotate(G,90,C),k.addRing(C.rings[0]));k=l.rotate(k,-1*f,d);D.spatialReference.wkid&&102100!==D.spatialReference.wkid&&(k=F.isLoaded()?F.project(k,D.spatialReference):N.webMercatorToGeographic(k));k=new M(k)}switch(E){case "upperLeft":"horizontal"===m?(p+=1,e+=1):(n+=1,"numeric"===g&&(e=b*x-(r-1)));break;case "lowerLeft":"horizontal"===m?(p+=1,e+=1):(n+=1,"numeric"===g&&(e=
b*(x-1)+r));break;case "upperRight":"horizontal"===m?(--e,--p):(--n,"numeric"===g&&(e-=a));break;case "lowerRight":"horizontal"===m?(--e,--p):(--n,"numeric"===g&&(e=b*(a-x)+r))}H.push(K.addGraphicLabel(k,g,e,n,p))}v=W;"hexagon"===z&&(L===a?a++:a--);switch(E){case "upperLeft":"horizontal"===m?(--n,e="numeric"!==g?0:"hexagon"===z?e-2*L-1:e-2*a,p=-1):(n=-1,p=b-(r+1),"numeric"!==g&&(e=b-r));break;case "upperRight":"horizontal"===m?(--n,"numeric"!==g&&(e=a+1),p=a):(e="numeric"!==g?e-1:b*(a+1)-r,n=a,--p);
break;case "lowerRight":"horizontal"===m?(n+=1,e="numeric"!==g?a+1:"hexagon"===z?e+2*L+1:e+2*a,p=a):(n=a,p+=1,e="numeric"!==g?e+1:a*r);break;case "lowerLeft":"horizontal"===m?(n+=1,"numeric"!==g&&(e=0),p=-1):(n=-1,"numeric"!==g&&(e+=1),p=r)}}return H},convertNumberToLetters:function(a){for(var b="";0<=a;)b=String.fromCharCode(a%26+65)+b,a=Math.floor(a/26)-1;return b},checkGridSize:function(a,b){return 2E3>a*b},getFeatureServiceParams:function(a,b){return{name:a,serviceDescription:"",hasStaticData:!1,
maxRecordCount:1E3,supportedQueryFormats:"JSON",capabilities:"Create,Delete,Query,Update,Editing",tags:"GRG",description:"",copyrightText:"",spatialReference:{wkid:102100},initialExtent:{xmin:b.extent.xmin,ymin:b.extent.ymin,xmax:b.extent.xmax,ymax:b.extent.ymax,spatialReference:{wkid:102100}},allowGeometryUpdates:!0,units:"esriMeters",xssPreventionInfo:{xssPreventionEnabled:!0,xssPreventionRule:"InputOnly",xssInputRule:"rejectInvalid"}}},getLayerParams:function(a,b,d,h){return{layers:[{adminLayerInfo:{geometryField:{name:"Shape"},
xssTrustedFields:""},id:0,name:a,type:"Feature Layer",displayField:"",description:"A GRG (Gridded Reference Graphic) is a grid overlay used for a commonreference point in many situations - from cordon and search operations to securityfor presidential inaugurations.",tags:"GRG",copyrightText:"",defaultVisibility:!0,ownershipBasedAccessControlForFeatures:{allowOthersToQuery:!1,allowOthersToDelete:!1,allowOthersToUpdate:!1},relationships:[],isDataVersioned:!1,supportsCalculate:!0,supportsAttachmentsByUploadId:!0,
supportsRollbackOnFailureParameter:!0,supportsStatistics:!0,supportsAdvancedQueries:!0,supportsValidateSql:!0,supportsCoordinatesQuantization:!0,supportsApplyEditsWithGlobalIds:!0,advancedQueryCapabilities:{supportsPagination:!0,supportsQueryWithDistance:!0,supportsReturningQueryExtent:!0,supportsStatistics:!0,supportsOrderBy:!0,supportsDistinct:!0,supportsQueryWithResultType:!0,supportsSqlExpression:!0,supportsReturningGeometryCentroid:!0},useStandardizedQueries:!1,geometryType:"esriGeometryPolygon",
minScale:0,maxScale:0,extent:{xmin:b.extent.xmin,ymin:b.extent.ymin,xmax:b.extent.xmax,ymax:b.extent.ymax,spatialReference:{wkid:102100}},drawingInfo:{renderer:{type:"simple",symbol:h},transparency:0,labelingInfo:[{labelExpression:"[grid]",labelExpressionInfo:{value:"{grid}"},format:null,fieldInfos:null,useCodedValues:!1,maxScale:0,minScale:0,where:null,sizeInfo:null,labelPlacement:"esriServerPolygonPlacementAlwaysHorizontal",symbol:d}]},allowGeometryUpdates:!0,hasAttachments:!1,htmlPopupType:"esriServerHTMLPopupTypeNone",
hasM:!1,hasZ:!1,objectIdField:"OBJECTID",globalIdField:"",typeIdField:"",fields:[{name:"OBJECTID",type:"esriFieldTypeOID",actualType:"int",alias:"OBJECTID",sqlType:"sqlTypeOther",nullable:!1,editable:!1,domain:null,defaultValue:null},{name:"grid",type:"esriFieldTypeString",alias:"grid",actualType:"nvarchar",nullable:!0,editable:!0,domain:null,defaultValue:null,sqlType:"sqlTypeNVarchar",length:256}],indexes:[],types:[],templates:[{name:"New Feature",description:"",drawingTool:"esriFeatureEditToolPolygon",
prototype:{attributes:{grid:""}}}],supportedQueryFormats:"JSON",hasStaticData:!1,maxRecordCount:1E4,standardMaxRecordCount:4E3,tileMaxRecordCount:4E3,maxRecordCountFactor:1,exceedsLimitFactor:1,capabilities:"Query,Editing,Create,Update,Delete"}]}},isNameAvailable:function(a,b,d){return S({url:a,content:{name:d,type:"Feature Service",token:b,f:"json"},handleAs:"json",callbackParamName:"callback"},{usePost:!0})},createFeatureService:function(a,b,d){return S({url:a,content:{f:"json",token:b,typeKeywords:"ArcGIS Server,Data,Feature Access,Feature Service,Service,Hosted Service",
createParameters:V.stringify(d),outputType:"featureService"},handleAs:"json",callbackParamName:"callback"},{usePost:!0})},addDefinitionToService:function(a,b,d){return S({url:a,content:{token:b,addToDefinition:V.stringify(d),f:"json"},handleAs:"json",callbackParamName:"callback"},{usePost:!0})},labelReferenceGrid:function(a,b,d,h){for(var u=-1,f=1,E,g=!0,m=null,z=[],c;0<a.length;)if(g){u++;"alphaNumeric"===b?f=1:"alphaAlpha"===b&&(E=0);var q=l.union(a);c=q.getExtent();switch(d){case "lowerLeft":var D=
l.nearestCoordinate(q,new y(c.xmin,c.ymin,c.spatialReference));break;case "lowerRight":D=l.nearestCoordinate(q,new y(c.xmax,c.ymin,c.spatialReference));break;case "upperLeft":D=l.nearestCoordinate(q,new y(c.xmin,c.ymax,c.spatialReference));break;case "upperRight":D=l.nearestCoordinate(q,new y(c.xmax,c.ymax,c.spatialReference))}for(c=0;c<a.length;c++)if(l.touches(a[c],D.coordinate)){m=a[c];z.push(K.addGraphicLabel(new M(a[c]),b,f,u,E));f++;E++;g=a.indexOf(a[c]);a.splice(g,1);g=!1;break}}else{g=!0;
c=m.getExtent();switch(d){case "lowerLeft":var F=l.nearestCoordinate(m,new y(c.xmax,c.ymin,c.spatialReference));break;case "lowerRight":F=l.nearestCoordinate(m,new y(c.xmin,c.ymin,c.spatialReference));break;case "upperLeft":F=l.nearestCoordinate(m,new y(c.xmax,c.ymax,c.spatialReference));break;case "upperRight":F=l.nearestCoordinate(m,new y(c.xmin,c.ymax,c.spatialReference))}for(q=0;q<a.length;q++){c=a[q].getExtent();switch(d){case "lowerLeft":var H=l.nearestCoordinate(a[q],new y(c.xmin,c.ymin,c.spatialReference));
break;case "lowerRight":H=l.nearestCoordinate(a[q],new y(c.xmax,c.ymin,c.spatialReference));break;case "upperLeft":H=l.nearestCoordinate(a[q],new y(c.xmin,c.ymax,c.spatialReference));break;case "upperRight":H=l.nearestCoordinate(a[q],new y(c.xmax,c.ymax,c.spatialReference))}c=l.buffer(H.coordinate,"UTM"===h?1E4:h/5,9001);if(l.contains(c,F.coordinate)){m=a[q];z.push(K.addGraphicLabel(new M(a[q]),b,f,u,E));f++;E++;g=a.indexOf(a[q]);a.splice(g,1);g=!1;break}}}return z},addGraphicLabel:function(a,b,d,
h,u){h=K.convertNumberToLetters(h);u=K.convertNumberToLetters(u);var f={};switch(b){case "alphaNumeric":f.grid=h.toString()+d.toString();break;case "alphaAlpha":f.grid=h.toString()+"-"+u.toString();break;case "numeric":f.grid=d.toString()}a.setAttributes(f);return a},checkPolarRegion:function(a){var b=new R({rings:[[[-180,84],[-180,90],[180,90],[180,84],[-180,84]],[[-180,-90],[-180,-80],[180,-80],[180,-90],[-180,-90]]],spatialReference:{wkid:4326}});return l.intersects(a,b)}};return K});