1+ import mapboxgl from 'mapbox-gl' ;
2+ import SuperMap from '../../common/SuperMap' ;
3+ import Util from '../core/Util' ;
4+ import ServiceBase from './ServiceBase' ;
5+ import QueryByBoundsService from '../../common/iServer/QueryByBoundsService' ;
6+ import QueryByDistanceService from '../../common/iServer/QueryByDistanceService' ;
7+ import QueryBySQLService from '../../common/iServer/QueryBySQLService' ;
8+ import QueryByGeometryService from '../../common/iServer/QueryByGeometryService' ;
9+
10+ /**
11+ * @class mapboxgl.supermap.QueryService
12+ * @classdesc 地图查询服务类。
13+ * 提供:范围查询,SQL查询,几何查询,距离查询
14+ * @extends mapboxgl.supermap.ServiceBase
15+ * @param url - {string} 地图查询服务访问地址。
16+ * @param options - {Object} 服务交互时所需的可选参数。
17+ * @example
18+ * new mapboxgl.supermap.QueryService(url)
19+ * .queryByBounds(param,function(result){
20+ * //doSomething
21+ * })
22+ */
23+ export default class QueryService extends ServiceBase {
24+
25+ constructor ( url , options ) {
26+ super ( url , options ) ;
27+ }
28+
29+ /**
30+ * @function mapboxgl.supermap.QueryService.prototype.queryByBounds
31+ * @description bounds查询地图服务
32+ * @param params - {SuperMap.QueryByBoundsParameters} 通过Bounds查询的相关参数类
33+ * @param callback - {function} 回调函数
34+ * @param resultFormat - {SuperMap.DataFormat} 返回结果类型
35+ * @return {mapboxgl.supermap.QueryService }
36+ */
37+ queryByBounds ( params , callback , resultFormat ) {
38+ var me = this ;
39+ var queryService = new QueryByBoundsService ( me . url , {
40+ serverType : me . options . serverType ,
41+ eventListeners : {
42+ scope : me ,
43+ processCompleted : callback ,
44+ processFailed : callback
45+ } ,
46+
47+ format : me . _processFormat ( resultFormat )
48+ } ) ;
49+
50+ queryService . processAsync ( me . _processParams ( params ) ) ;
51+ return me ;
52+ }
53+
54+ /**
55+ * @function mapboxgl.supermap.QueryService.prototype.queryByDistance
56+ * @description 地图距离查询服务
57+ * @param params - {QueryByDistanceParameters} Distance查询相关参数类
58+ * @param callback - {function} 回调函数
59+ * @param resultFormat - {SuperMap.DataFormat} 返回结果类型
60+ * @return {mapboxgl.supermap.QueryService }
61+ */
62+ queryByDistance ( params , callback , resultFormat ) {
63+ var me = this ;
64+ var queryByDistanceService = new QueryByDistanceService ( me . url , {
65+ serverType : me . options . serverType ,
66+ eventListeners : {
67+ scope : me ,
68+ processCompleted : callback ,
69+ processFailed : callback
70+ } ,
71+ format : me . _processFormat ( resultFormat )
72+ } ) ;
73+
74+ queryByDistanceService . processAsync ( me . _processParams ( params ) ) ;
75+ return me ;
76+ }
77+
78+ /**
79+ * @function mapboxgl.supermap.QueryService.prototype.queryBySQL
80+ * @description 地图SQL查询服务
81+ * @param params - {SuperMap.QueryBySQLParameters} SQL查询相关参数类
82+ * @param callback - {function} 回调函数
83+ * @param resultFormat - {SuperMap.DataFormat} 返回结果类型
84+ * @return {mapboxgl.supermap.QueryService }
85+ */
86+ queryBySQL ( params , callback , resultFormat ) {
87+ var me = this ;
88+ var queryBySQLService = new QueryBySQLService ( me . url , {
89+ serverType : me . options . serverType ,
90+ eventListeners : {
91+ scope : me ,
92+ processCompleted : callback ,
93+ processFailed : callback
94+ } ,
95+ format : me . _processFormat ( resultFormat )
96+ } ) ;
97+
98+ queryBySQLService . processAsync ( me . _processParams ( params ) ) ;
99+ return me ;
100+ }
101+
102+ /**
103+ * @function mapboxgl.supermap.QueryService.prototype.queryByGeometry
104+ * @description 地图几何查询服务
105+ * @param params - {SuperMap.QueryByGeometryParameters} Geometry查询相关参数类
106+ * @param callback - {function} 回调函数
107+ * @param resultFormat - {SuperMap.DataFormat} 返回结果类型
108+ * @return {mapboxgl.supermap.QueryService }
109+ */
110+ queryByGeometry ( params , callback , resultFormat ) {
111+ var me = this ;
112+ var queryByGeometryService = new QueryByGeometryService ( me . url , {
113+ serverType : me . options . serverType ,
114+ eventListeners : {
115+ scope : me ,
116+ processCompleted : callback ,
117+ processFailed : callback
118+ } ,
119+ format : me . _processFormat ( resultFormat )
120+ } ) ;
121+
122+ queryByGeometryService . processAsync ( me . _processParams ( params ) ) ;
123+ return me ;
124+ }
125+
126+
127+ _processParams ( params ) {
128+
129+ if ( ! params ) {
130+ return { } ;
131+ }
132+ params . returnContent = ( params . returnContent == null ) ? true : params . returnContent ;
133+ if ( params . queryParams && ! Util . isArray ( params . queryParams ) ) {
134+ params . queryParams = [ params . queryParams ] ;
135+ }
136+ if ( params . bounds ) {
137+ if ( params . bounds instanceof Array ) {
138+ params . bounds = new SuperMap . Bounds (
139+ params . bounds [ 0 ] ,
140+ params . bounds [ 1 ] ,
141+ params . bounds [ 2 ] ,
142+ params . bounds [ 3 ]
143+ ) ;
144+ }
145+ if ( params . bounds instanceof mapboxgl . LngLatBounds ) {
146+ params . bounds = new SuperMap . Bounds (
147+ params . bounds . getSouthWest ( ) . lng ,
148+ params . bounds . getSouthWest ( ) . lat ,
149+ params . bounds . getNorthEast ( ) . lng ,
150+ params . bounds . getNorthEast ( ) . lat
151+ ) ;
152+ }
153+
154+ }
155+
156+ if ( params . geometry ) {
157+
158+ if ( params . geometry instanceof mapboxgl . LngLat ) {
159+ params . geometry = new SuperMap . Geometry . Point ( params . geometry . lng , params . geometry . lat ) ;
160+ }
161+
162+ if ( params . geometry instanceof mapboxgl . Point ) {
163+ params . geometry = new SuperMap . Geometry . Point ( params . geometry . x , params . geometry . y ) ;
164+ }
165+
166+ if ( params && ! ( params . geometry instanceof SuperMap . Geometry ) ) {
167+
168+ params . geometry = Util . toSuperMapGeometry ( params . geometry ) ;
169+ }
170+ }
171+ return params ;
172+ }
173+
174+ _processFormat ( resultFormat ) {
175+ return ( resultFormat ) ? resultFormat : SuperMap . DataFormat . GEOJSON ;
176+ }
177+ }
178+ mapboxgl . supermap . QueryService = QueryService ;
0 commit comments