forked from SuperMap/iClient-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueryService.js
More file actions
116 lines (106 loc) · 4.88 KB
/
QueryService.js
File metadata and controls
116 lines (106 loc) · 4.88 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/* Copyright© 2000 - 2025 SuperMap Software Co.Ltd. All rights reserved.
* This program are made available under the terms of the Apache License, Version 2.0
* which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
import L from 'leaflet';
import '../core/Base';
import { ServiceBase } from './ServiceBase';
import { QueryService as CommonQueryService } from '@supermapgis/iclient-common/iServer/QueryService';
import * as Util from '../core/Util';
import { CommontypesConversion } from '../core/CommontypesConversion';
import { Point as GeometryPoint } from '@supermapgis/iclient-common/commontypes/geometry/Point';
/**
* @class QueryService
* @deprecatedclassinstance L.supermap.queryService
* @classdesc 地图查询服务类。
* @category iServer Map QueryResults
* @modulecategory Services
* @extends {ServiceBase}
* @param {string} url - 服务地址。
* @param {Object} options - 参数。
* @param {string} [options.proxy] - 服务代理地址。
* @param {boolean} [options.withCredentials=false] - 请求是否携带 cookie。
* @param {boolean} [options.crossOrigin] - 是否允许跨域请求。
* @param {Object} [options.headers] - 请求头。
* @example
* new QueryService(url).queryByBounds(param,function(result){
* //doSomething
* })
* @usage
*/
export var QueryService = ServiceBase.extend({
initialize: function(url, options) {
ServiceBase.prototype.initialize.call(this, url, options);
this._queryService = new CommonQueryService(url, options);
},
/**
* @function QueryService.prototype.queryByBounds
* @description 范围查询地图服务。
* @param {QueryByBoundsParameters} params - 范围查询参数类。
* @param {RequestCallback} [callback] - 回调函数,该参数未传时可通过返回的 promise 获取结果。
* @param {DataFormat} [resultFormat=DataFormat.GEOJSON] - 返回结果类型。
* @returns {Promise} Promise 对象。
*/
queryByBounds: function(params, callback, resultFormat) {
params = this._processParams(params);
return this._queryService.queryByBounds(params, callback, resultFormat);
},
/**
* @function QueryService.prototype.queryByDistance
* @description 地图距离查询服务。
* @param {QueryByDistanceParameters} params - 距离查询参数类。
* @param {RequestCallback} [callback] - 回调函数,该参数未传时可通过返回的 promise 获取结果。
* @param {DataFormat} [resultFormat=DataFormat.GEOJSON] - 返回结果类型。
* @returns {Promise} Promise 对象。
*/
queryByDistance: function(params, callback, resultFormat) {
params = this._processParams(params);
return this._queryService.queryByDistance(params, callback, resultFormat);
},
/**
* @function QueryService.prototype.queryBySQL
* @description 地图 SQL 查询服务。
* @param {QueryBySQLParameters} params - SQL 查询参数类。
* @param {RequestCallback} [callback] - 回调函数,该参数未传时可通过返回的 promise 获取结果。
* @param {DataFormat} [resultFormat=DataFormat.GEOJSON] - 返回结果类型。
* @returns {Promise} Promise 对象。
*/
queryBySQL: function(params, callback, resultFormat) {
params = this._processParams(params);
return this._queryService.queryBySQL(params, callback, resultFormat);
},
/**
* @function QueryService.prototype.queryByGeometry
* @description 地图几何查询服务。
* @param {QueryByGeometryParameters} params - 几何查询相关参数类。
* @param {RequestCallback} [callback] - 回调函数,该参数未传时可通过返回的 promise 获取结果。
* @param {DataFormat} [resultFormat=DataFormat.GEOJSON] - 返回结果类型。
* @returns {Promise} Promise 对象。
*/
queryByGeometry: function(params, callback, resultFormat) {
params = this._processParams(params);
return this._queryService.queryByGeometry(params, callback, resultFormat);
},
_processParams: function(params) {
if (!params) {
return {};
}
params.returnContent = params.returnContent == null ? true : params.returnContent;
if (params.queryParams && !L.Util.isArray(params.queryParams)) {
params.queryParams = [params.queryParams];
}
if (params.bounds) {
params.bounds = CommontypesConversion.toSuperMapBounds(params.bounds);
}
if (params.geometry) {
if (params.geometry instanceof L.Point) {
params.geometry = new GeometryPoint(params.geometry.x, params.geometry.y);
} else {
params.geometry = Util.toSuperMapGeometry(params.geometry);
}
}
return params;
}
});
export var queryService = function(url, options) {
return new QueryService(url, options);
};