runStaWithParam: function (classifyField, staField, staType) {//classifyField:分类字段、staField:统计字段、staType:统计类型
require(["esri/tasks/query","esri/tasks/StatisticDefinition","esri/tasks/QueryTask"],
function (Query,StatisticDefinition, QueryTask) {
var query = new esri.tasks.Query();
query.groupByFieldsForStatistics = [classifyField];//按照某个字段分组
query.outSpatialReference = map.spatialReference;
query.geometry = geometry;
query.spatialRelationship = esri.tasks.Query.SPATIAL_REL_CONTAINS;
var staDef = new esri.tasks.StatisticDefinition();
staDef.onStatisticField = staField;
staDef.outStatisticFieldName = "outSta";
staDef.statisticType = staType; //'count'|'sum'|'min'|'max'|'avg'|'stddev'
query.outStatistics = [staDef];
var queryTask = new esri.tasks.QueryTask(mapAddres);//mapAddres动态地图服务地址,到MapServer下面的具体的图层,例子:xxx/MapServer/1
queryTask.execute(query,
function (result) {
if (console && console.log)
console.log("sta result", result);
},
function (error) {
if (console && console.log)
console.log("sta error", error);
});
});
}