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
158 lines (145 loc) · 5.37 KB
/
QueryService.js
File metadata and controls
158 lines (145 loc) · 5.37 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
import ol from 'openlayers';
import {
DataFormat,
Bounds,
GeometryPoint,
QueryByBoundsService,
QueryByDistanceService,
QueryBySQLService,
QueryByGeometryService
} from '@supermap/iclient-common';
import {Util} from '../core/Util';
import {ServiceBase} from './ServiceBase';
/**
* @class ol.supermap.QueryService
* @category iServer Map QueryResults
* @classdesc 地图查询服务类。
* 提供:范围查询,SQL查询,几何查询,距离查询
* @extends ol.supermap.ServiceBase
* @param url - {string} 地图查询服务访问地址。
* @param options - {Object} 服务交互时所需的可选参数。
* @example
* new ol.supermap.QueryService(url)
* .queryByBounds(param,function(result){
* //doSomething
* })
*/
export class QueryService extends ServiceBase {
constructor(url, options) {
super(url, options);
}
/**
* @function ol.supermap.QueryService.prototype.queryByBounds
* @description bounds查询地图服务
* @param params - {SuperMap.QueryByBoundsParameters} 通过Bounds查询的相关参数类
* @param callback - {function} 回调函数
* @param resultFormat - {SuperMap.DataFormat} 返回结果类型
* @return ol.supermap.QueryService}
*/
queryByBounds(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 ol.supermap.QueryService.prototype.queryByDistance
* @description 地图距离查询服务
* @param params - {QueryByDistanceParameters} Distance查询相关参数类
* @param callback - {function} 回调函数
* @param resultFormat - {SuperMap.DataFormat} 返回结果类型
*/
queryByDistance(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 ol.supermap.QueryService.prototype.queryBySQL
* @description 地图SQL查询服务
* @param params - {SuperMap.QueryBySQLParameters} SQL查询相关参数类
* @param callback - {function} 回调函数
* @param resultFormat - {SuperMap.DataFormat} 返回结果类型
*/
queryBySQL(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 ol.supermap.QueryService.prototype.queryByGeometry
* @description 地图几何查询服务
* @param params - {SuperMap.QueryByGeometryParameters} Geometry查询相关参数类
* @param callback - {function} 回调函数
* @param resultFormat - {SuperMap.DataFormat} 返回结果类型
*/
queryByGeometry(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(params) {
if (!params) {
return {};
}
params.returnContent = (params.returnContent == null) ? true : params.returnContent;
if (params.queryParams && !Util.isArray(params.queryParams)) {
params.queryParams = [params.queryParams];
}
if (params.bounds) {
params.bounds = new Bounds(
params.bounds[0],
params.bounds[1],
params.bounds[2],
params.bounds[3]
);
}
if (params.geometry) {
if (params.geometry instanceof ol.geom.Point) {
params.geometry = new GeometryPoint(params.geometry.getCoordinates()[0], params.geometry.getCoordinates()[1]);
} else {
params.geometry = Util.toSuperMapGeometry(JSON.parse((new ol.format.GeoJSON()).writeGeometry(params.geometry)));
}
}
return params;
}
_processFormat(resultFormat) {
return (resultFormat) ? resultFormat : DataFormat.GEOJSON;
}
}
ol.supermap.QueryService = QueryService;