import store from '@/store'
class QueryUtil {
constructor(options) {
this.options = options ? options : {};
this.map = store.getters.Map;
this.mapModular = store.getters.mapModular;
}
/**
* 关键字:查询 支持(where,geometry)
* @param {Object} this
* @param {String} queryTaskUrl 服务地址
* @param {String} condition 筛选条件
* @param {Function} callBack 回调函数
*
* 通过condition类型 object、string 区分查询条件
* condition类型 object {where:'xx',geometry:'xx'}
* condition类型 string 'xxxxx'
*/
getQuery(queryTaskUrl, condition) {
let query = new this.mapModular.Query();
query.outFields = ["*"];
query.outSpatialReference = this.mapModular.SpatialReference.WGS84; // 空间参考
query.returnGeometry = true; // 查询返回Geometry
if (typeof (condition) == 'object') {
query.where = condition.where; // 筛选条件
query.geometry = condition.geometry;
} else {
query.where = condition; // 筛选条件
}
//实例化查询对象
// var queryTask = new this.QueryTask("http://192.168.124.14:6080/arcgis/rest/services/shanxi/scene_type/MapServer/12");
var queryTask = new this.mapModular.QueryTask({url:queryTaskUrl});
//进行查询
let promise = new Promise((resolve, reject) => {
queryTask.execute(query).then(queryResult => {
resolve(queryResult)
}).catch(err=>{
reject(err)
})
})
return promise
}
}
const queryUtil = (options) => new QueryUtil(options)
export default queryUtil
页面调用
this.utils.queryUtil().getQuery(layer.url, where).then(queryResult => {
if (queryResult.features.length) {
console.log(queryResult.features[0]);
}
});