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
128 lines (118 loc) · 5.17 KB
/
QueryService.js
File metadata and controls
128 lines (118 loc) · 5.17 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
/* Copyright© 2000 - 2023 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 mapboxgl from 'mapbox-gl';
import '../core/Base';
import { Util } from '../core/Util';
import { ServiceBase } from './ServiceBase';
import { QueryService as CommonQueryService } from '@supermap/iclient-common/iServer/QueryService';
import { Bounds } from '@supermap/iclient-common/commontypes/Bounds';
import { Geometry } from '@supermap/iclient-common/commontypes/Geometry';
import { Point as GeometryPoint } from '@supermap/iclient-common/commontypes/geometry/Point';
/**
* @class QueryService
* @category iServer Map QueryResults
* @classdesc 地图查询服务类。
* 提供:范围查询,SQL 查询,几何查询,距离查询。
* @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 class QueryService extends ServiceBase {
constructor(url, options) {
super(url, options);
this._queryService = new CommonQueryService(url, options);
}
/**
* @function QueryService.prototype.queryByBounds
* @description Bounds 查询地图服务。
* @param {QueryByBoundsParameters} params - Bounds 查询参数类。
* @param {RequestCallback} callback - 回调函数。
* @param {DataFormat} [resultFormat=DataFormat.GEOJSON] - 返回结果类型。
*/
queryByBounds(params, callback, resultFormat) {
params = this._processParams(params);
this._queryService.queryByBounds(params, callback, resultFormat);
}
/**
* @function QueryService.prototype.queryByDistance
* @description 地图距离查询服务。
* @param {QueryByDistanceParameters} params - Distance 查询参数类。
* @param {RequestCallback} callback - 回调函数。
* @param {DataFormat} [resultFormat=DataFormat.GEOJSON] - 返回结果类型
*/
queryByDistance(params, callback, resultFormat) {
params = this._processParams(params);
this._queryService.queryByDistance(params, callback, resultFormat);
}
/**
* @function QueryService.prototype.queryBySQL
* @description 地图 SQL 查询服务。
* @param {QueryBySQLParameters} params - SQL 查询参数类。
* @param {RequestCallback} callback - 回调函数。
* @param {DataFormat} [resultFormat=DataFormat.GEOJSON] - 返回结果类型。
*/
queryBySQL(params, callback, resultFormat) {
params = this._processParams(params);
this._queryService.queryBySQL(params, callback, resultFormat);
}
/**
* @function QueryService.prototype.queryByGeometry
* @description 地图几何查询服务。
* @param {QueryByGeometryParameters} params - Geometry 查询参数类。
* @param {RequestCallback} callback - 回调函数。
* @param {DataFormat} [resultFormat=DataFormat.GEOJSON] - 返回结果类型。
*/
queryByGeometry(params, callback, resultFormat) {
params = this._processParams(params);
this._queryService.queryByGeometry(params, callback, resultFormat);
}
_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) {
if (params.bounds instanceof Array) {
params.bounds = new Bounds(params.bounds[0], params.bounds[1], params.bounds[2], params.bounds[3]);
}
if (params.bounds instanceof mapboxgl.LngLatBounds) {
params.bounds = new Bounds(
params.bounds.getSouthWest().lng,
params.bounds.getSouthWest().lat,
params.bounds.getNorthEast().lng,
params.bounds.getNorthEast().lat
);
}
}
if (params.geometry) {
if (params.geometry instanceof mapboxgl.LngLat) {
params.geometry = new GeometryPoint(params.geometry.lng, params.geometry.lat);
}
if (params.geometry instanceof mapboxgl.Point) {
params.geometry = new GeometryPoint(params.geometry.x, params.geometry.y);
}
if (params.geometry instanceof mapboxgl.LngLatBounds) {
params.geometry = Util.toSuperMapPolygon(params.geometry);
}
if (!(params.geometry instanceof Geometry)) {
params.geometry = Util.toSuperMapGeometry(params.geometry);
}
}
return params;
}
}