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
159 lines (142 loc) · 5.43 KB
/
QueryService.js
File metadata and controls
159 lines (142 loc) · 5.43 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import L from "leaflet";
import '../core/Base';
import {ServiceBase} from './ServiceBase';
import * as Util from '../core/Util';
import {CommontypesConversion} from '../core/CommontypesConversion';
import {
GeometryPoint,
DataFormat,
QueryByBoundsService,
QueryByDistanceService,
QueryBySQLService,
QueryByGeometryService
} from '@supermap/iclient-common';
/**
* @class L.supermap.queryService
* @classdesc 地图查询服务类。
* @category iServer Map QueryResults
* @extends L.supermap.ServiceBase
* @param url - {string} 地图查询服务访问地址。
* @param - options - {Object} 服务交互时所需的可选参数。如:<br>
* serverType - {{@link SuperMap.ServerType}} 服务来源 iServer|iPortal|online
* @example
* L.supermap.queryService(url).queryByBounds(param,function(result){
* //doSomething
* })
*/
export var QueryService = ServiceBase.extend({
initialize: function (url, options) {
ServiceBase.prototype.initialize.call(this, url, options);
},
/**
* @function L.supermap.queryService.prototype.queryByBounds
* @description bounds查询地图服务
* @param params - {SuperMap.QueryByBoundsParameters} 通过Bounds查询的相关参数类
* @param callback -{function} 回掉函数
* @param resultFormat - {SuperMap.DataFormat} 返回结果类型
*/
queryByBounds: function (params, callback, resultFormat) {
var me = this;
var queryService = new QueryByBoundsService(me.url, {
proxy: me.options.proxy,
serverType: me.options.serverType,
eventListeners: {
scope: me,
processCompleted: callback,
processFailed: callback
},
format: me._processFormat(resultFormat)
});
queryService.processAsync(me._processParams(params));
},
/**
* @function L.supermap.queryService.prototype.queryByDistance
* @description 地图距离查询服务
* @param params - {SuperMap.QueryByDistanceParameters} Distance查询相关参数类
* @param callback - {function} 回调函数
* @param resultFormat -{SuperMap.DataFormat} 返回结果类型
*/
queryByDistance: function (params, callback, resultFormat) {
var me = this;
var queryByDistanceService = new QueryByDistanceService(me.url, {
proxy: me.options.proxy,
serverType: me.options.serverType,
eventListeners: {
scope: me,
processCompleted: callback,
processFailed: callback
},
format: me._processFormat(resultFormat)
});
queryByDistanceService.processAsync(me._processParams(params));
},
/**
* @function L.supermap.queryService.prototype.queryBySQL
* @description 地图SQL查询服务
* @param params - {SuperMap.QueryBySQLParameters} SQL查询相关参数类
* @param callback -{function} 回调函数
* @param resultFormat -{SuperMap.DataFormat} 返回结果类型
*/
queryBySQL: function (params, callback, resultFormat) {
var me = this;
var queryBySQLService = new QueryBySQLService(me.url, {
proxy: me.options.proxy,
serverType: me.options.serverType,
eventListeners: {
scope: me,
processCompleted: callback,
processFailed: callback
},
format: me._processFormat(resultFormat)
});
queryBySQLService.processAsync(me._processParams(params));
},
/**
* @function L.supermap.queryService.prototype.queryByGeometry
* @description 地图几何查询服务
* @param params - {SuperMap.QueryByGeometryParameters} Geometry查询相关参数类
* @param callback - {function} 回调函数
* @param resultFormat - {SuperMap.DataFormat} 返回结果类型
*/
queryByGeometry: function (params, callback, resultFormat) {
var me = this;
var queryByGeometryService = new QueryByGeometryService(me.url, {
proxy: me.options.proxy,
serverType: me.options.serverType,
eventListeners: {
scope: me,
processCompleted: callback,
processFailed: callback
},
format: me._processFormat(resultFormat)
});
queryByGeometryService.processAsync(me._processParams(params));
},
_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;
},
_processFormat: function (resultFormat) {
return (resultFormat) ? resultFormat : DataFormat.GEOJSON;
}
});
export var queryService = function (url, options) {
return new QueryService(url, options);
};
L.supermap.queryService = queryService;