queryUtils.js
2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import {loadModules} from 'esri-loader'
export default{
methods: {
queryByWhere(url,queryWhere,geometry,returnGeometry,outFields ,outSpatialReference ,callBackFunction){
var self = this;
loadModules([
"esri/tasks/QueryTask",
"esri/tasks/support/Query"
]).then(([
QueryTask,
Query
]) => {
var queryTask = new QueryTask({
url: url
}),
query = new Query(),
where = "";
if (queryWhere){
var parames = self.parseObj2Arr(queryWhere);
//var isFrist = false;
for(var i = 0;i < parames.length; i++ ){
if(i == 0){
}else {
where += " and ";
}
if(Array.isArray(parames[i].value)){
where += parames[i].name + " in (" + parames[i].value.toString + ")";
}else if(typeof parames[i].value == 'number'){
where += parames[i].name + " =" + parames[i].value ;
}else{
where += parames[i].name + " =" + "'" + parames[i].value +"'";
}
}
} else {
where = "1=1";
}
query.where = where;
if(geometry){
query.geometry = geometry;
}
query.outSpatialReference = outSpatialReference ? outSpatialReference : {wkid:3857}
query.returnGeometry = returnGeometry ? true : false;
query.outFields = outFields ? outFields : ["*"];
queryTask.execute(query).then(function(results){
if(callBackFunction && typeof callBackFunction == 'function'){
callBackFunction(results);
}
});
}).catch( err => {
throw(err);
})
},
parseObj2Arr(object){
var arr = [];
for(var key in object){
var obj = {};
obj.name = key;
obj.value = object[key];
arr.push(obj);
}
return arr;
}
},
}