text: // All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  // See http://js.arcgis.com/3.15/esri/copyright.txt and http://www.arcgis.com/apps/webappbuilder/copyright.txt for details.
  
  //>>built
  define("dojo/_base/declare dojo/_base/lang dojo/_base/array dojo/promise/all dojo/Deferred jimu/utils jimu/ServiceDefinitionManager esri/tasks/query esri/tasks/QueryTask esri/tasks/FeatureSet".split(" "),function(m,c,h,n,k,l,p,f,g,q){var e=m(null,{queryType:0,nextPageIndex:1,pageSizeOption:null,layerDefinition:null,layerDefinitionDef:null,type1CountDef:null,type2ObjectIdsDef:null,type3QueryDef:null,sdf:null,url:null,query:null,pageSize:1E3,constructor:function(a){this.sdf=p.getInstance();this.url=
  a.url;this.query=a.query;this.pageSizeOption=a.pageSize;this.query.outFields&&0!==this.query.outFields.length||(this.query.outFields=["*"]);this.pageSize=0<a.pageSize?a.pageSize:1E3;this.getFeatureCount()},getFeatureCount:function(){return this._getQueryType().then(c.hitch(this,function(a){return 1===a?this._getCountForQueryType1():2===a?this._getCountForQueryType2():this._getCountForQueryType3()}))},getPageCount:function(){return this.getFeatureCount().then(c.hitch(this,function(a){return 0===a?
  0:Math.ceil(a/this.pageSize)}))},getAllFeatures:function(){return this.getPageCount().then(c.hitch(this,function(a){if(0<a){for(var b=[],d=1;d<=a;d++)b.push(this.queryByPage(d));return n(b).then(c.hitch(this,function(a){for(var b=[],d=0;d<a.length;d++)a[d].features&&0<a[d].features.length&&(b=b.concat(a[d].features));a=a[0];a.features=b;return a}))}this._getEmptyFeatureSet().then(c.hitch(this,function(a){return a}))}))},_getEmptyFeatureSet:function(){var a=new k;this.layerDefinition&&this.layerDefinition.geometryType?
  a.resolve(this._getEmptyFeatureSetHandler()):this._getLayerDefinition().then(c.hitch(this,function(){a.resolve(this._getEmptyFeatureSetHandler())}));return a},_getEmptyFeatureSetHandler:function(){var a=new q;a.features=[];a.geometryType=this.layerDefinition.geometryType;a.fields=[];var b=c.clone(this.layerDefinition.fields);0<=this.query.outFields.indexOf("*")?a.fields=b:a.fields=h.filter(b,c.hitch(this,function(a){return 0<=this.query.outFields.indexOf(a.name)}));return a},getCurrentPageIndex:function(){return this.nextPageIndex},
  queryNextPage:function(){var a=this.nextPageIndex;this.nextPageIndex++;return this.queryByPage(a)},queryByPage:function(a){var b=null;0>=a?(b=new k,this._getEmptyFeatureSet().then(c.hitch(this,function(a){b.resolve(a)}))):b=this.getPageCount().then(c.hitch(this,function(b){a>b&&this._getEmptyFeatureSet().then(c.hitch(this,function(a){return a}));return 1===this.queryType?this._queryPageForType1(a):2===this.queryType?this._queryPageForType2(a):this._queryPageForType3(a)}));return b},_getQueryType:function(){var a=
  new k;if(0<this.queryType)a.resolve(this.queryType);else return this._getLayerDefinition().then(c.hitch(this,function(a){return this.queryType=e.getQueryType(a)}));return a},_getDefStatus:function(a){return a?a.isFulfilled()?a.isResolved()?2:-1:1:0},_getLayerDefinition:function(){0>=this._getDefStatus(this.layerDefinitionDef)&&(this.layerDefinitionDef=this.sdf.getServiceDefinition(this.url).then(c.hitch(this,function(a){this.layerDefinition=a;var b=a.maxRecordCount;0<b&&(!(0<this.pageSizeOption)||
  this.pageSize>a.maxRecordCount)&&(this.pageSize=b);return this.layerDefinition})));return this.layerDefinitionDef},_getCountForQueryType1:function(){0>=this._getDefStatus(this.type1CountDef)&&(this.type1CountDef=this._queryCount());return this.type1CountDef},_getCountForQueryType2:function(){return this._getObjectIdsForQueryType2().then(c.hitch(this,function(a){return a.length}))},_getObjectIdsForQueryType2:function(){0>=this._getDefStatus(this.type2ObjectIdsDef)&&(this.type2ObjectIdsDef=this._queryIds());
  return this.type2ObjectIdsDef},_getCountForQueryType3:function(){return this._doQueryForQueryType3().then(c.hitch(this,function(a){return(a.features||[]).length}))},_doQueryForQueryType3:function(){0>=this._getDefStatus(this.type3QueryDef)&&(this.type3QueryDef=this._query());return this.type3QueryDef},_queryPageForType1:function(a){return this._queryWithPaginationAndOrder((a-1)*this.pageSize)},_queryPageForType2:function(a){return this._getObjectIdsForQueryType2().then(c.hitch(this,function(b){var d=
  (a-1)*this.pageSize;b=b.slice(d,d+this.pageSize);return this._queryByObjectIds(b)}))},_queryPageForType3:function(a){return this._doQueryForQueryType3().then(c.hitch(this,function(b){var d=c.mixin({},b);d.features=[];var e=(a-1)*this.pageSize;d.features=(b.features||[]).slice(e,e+this.pageSize);return d}))},_tryLocaleNumber:function(a){var b=l.localizeNumber(a);if(null===b||void 0===b)b=a;return b},_tryLocaleDate:function(a){var b=l.localizeDate(a);b||(b=a.toLocaleDateString());return b},_getLayerIndexByLayerUrl:function(a){var b=
  a.lastIndexOf("/");a=a.slice(b+1,a.length);return parseInt(a,10)},_getServiceUrlByLayerUrl:function(a){var b=a.lastIndexOf("/");return a.slice(0,b)},_isImageServiceLayer:function(a){return-1<a.indexOf("/ImageServer")},_isTable:function(a){return"Table"===a.type},_getObjectIdField:function(){return this.layerDefinition.objectIdField},_query:function(a){var b=new f;b.where=a||this.query.where;b.geometry=this.query.geometry;b.outSpatialReference=this.query.outSpatialReference;b.returnGeometry=this.query.returnGeometry;
  b.spatialRelationship=this.query.spatialRelationship;b.outFields=this.query.outFields;b.returnDistinctValues=this.query.returnDistinctValues;return(new g(this.url)).execute(b)},_queryIds:function(){var a=new f;a.where=this.query.where;a.geometry=this.query.geometry;a.returnGeometry=!1;a.spatialRelationship=this.query.spatialRelationship;a.outSpatialReference=this.query.outSpatialReference;return(new g(this.url)).executeForIds(a).then(c.hitch(this,function(a){a||(a=[]);return a}))},_queryByObjectIds:function(a){var b=
  new k,d=new f;d.returnGeometry=this.query.returnGeometry;d.outSpatialReference=this.query.outSpatialReference;d.spatialRelationship=this.query.spatialRelationship;d.outFields=this.query.outFields;d.objectIds=a;(new g(this.url)).execute(d).then(c.hitch(this,function(a){b.resolve(a)}),c.hitch(this,function(d){if(400===d.code){var e=this._getObjectIdField(),f="",g=a.length;h.forEach(a,c.hitch(this,function(a,b){f+=e+" \x3d "+a;b!==g-1&&(f+=" OR ")}));this._query(f).then(c.hitch(this,function(a){b.resolve(a)}),
  c.hitch(this,function(a){b.reject(a)}))}else b.reject(d)}));return b},_queryCount:function(){var a=new f;a.where=this.query.where;a.geometry=this.query.geometry;a.outSpatialReference=this.query.outSpatialReference;a.spatialRelationship=this.query.spatialRelationship;a.returnGeometry=!1;return(new g(this.url)).executeForCount(a)},_queryWithPaginationAndOrder:function(a){var b=new f;b.where=this.query.where;b.geometry=this.query.geometry;b.outSpatialReference=this.query.outSpatialReference;b.returnGeometry=
  this.query.returnGeometry;b.spatialRelationship=this.query.spatialRelationship;b.outFields=this.query.outFields;b.returnDistinctValues=this.query.returnDistinctValues;b.start=a;b.num=this.pageSize;(a=this.query.orderByFields)&&0<a.length&&(b.orderByFields=a,a=h.map(a,c.hitch(this,function(a){return a.split(" ")[0]})),h.forEach(a,c.hitch(this,function(a){0>b.outFields.indexOf(a)&&b.outFields.push(a)})));return(new g(this.url)).execute(b)}});e._isServiceSupportsOrderBy=function(a){var b=!1;a.advancedQueryCapabilities&&
  a.advancedQueryCapabilities.supportsOrderBy&&(b=!0);return b};e._isServiceSupportsPagination=function(a){var b=!1;a.advancedQueryCapabilities&&a.advancedQueryCapabilities.supportsPagination&&(b=!0);return b};e._isSupportObjectIds=function(a){var b=0;a.currentVersion&&(b=parseFloat(a.currentVersion));return 10<=b||a.hasOwnProperty("typeIdField")};e.getQueryType=function(a){var b=-1;return b=e._isServiceSupportsOrderBy(a)&&e._isServiceSupportsPagination(a)?1:e._isSupportObjectIds(a)?2:3};return e});