Skip to content

Commit 3fc0751

Browse files
committed
添加mapbox-gl下LayerInfoService,MapService,QueryService。 review by caoxinke
1 parent 3315b11 commit 3fc0751

File tree

3 files changed

+375
-0
lines changed

3 files changed

+375
-0
lines changed
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
import mapboxgl from 'mapbox-gl';
2+
import ServiceBase from './ServiceBase';
3+
import GetLayersInfoService from '../../common/iServer/GetLayersInfoService';
4+
import SetLayerInfoService from '../../common/iServer/SetLayerInfoService';
5+
import SetLayersInfoService from '../../common/iServer/SetLayersInfoService';
6+
import SetLayerStatusService from '../../common/iServer/SetLayerStatusService';
7+
8+
/**
9+
* @class mapboxgl.supermap.LayerInfoService
10+
* @classdesc 图层信息服务类
11+
* @extends mapboxgl.supermap.ServiceBase
12+
* @example
13+
* new mapboxgl.supermap.LayerInfoService(url).getLayersInfo(function(result){
14+
* //doSomething
15+
* })
16+
* @param url - {string} 与客户端交互的地图服务地址。请求地图服务,URL 应为:<br>
17+
* http://{服务器地址}:{服务端口号}/iserver/services/{地图服务名}/rest/maps/{地图名}/tempLayersSet/{tempLayerID}/Rivers@World@@World";
18+
* @param options - {Object} 服务所需可选参数。如:<br>
19+
* eventListeners - {Object} 需要被注册的监听器对象。
20+
*/
21+
export default class LayerInfoService extends ServiceBase {
22+
23+
constructor(url, options) {
24+
super(url, options);
25+
}
26+
27+
/**
28+
* @function mapboxgl.supermap.LayerInfoService.prototype.getLayersInfo
29+
* @description 获取图层信息服务
30+
* @param callback - {function} 回调函数
31+
* @return {mapboxgl.supermap.LayerInfoService} 返回图层信息类
32+
*/
33+
getLayersInfo(callback) {
34+
var me = this;
35+
var getLayersInfoService = new GetLayersInfoService(me.url, {
36+
serverType: me.options.serverType,
37+
eventListeners: {
38+
processCompleted: callback,
39+
processFailed: callback
40+
}
41+
});
42+
getLayersInfoService.processAsync();
43+
return me;
44+
}
45+
46+
/**
47+
* @function mapboxgl.supermap.LayerInfoService.prototype.setLayerInfo
48+
* @description 设置图层信息服务。可以实现临时图层中子图层的修改
49+
* @param params - {SuperMap.SetLayerInfoParameters} 设置图层信息参数类
50+
* @param callback - {function} 回调函数
51+
*/
52+
setLayerInfo(params, callback) {
53+
if (!params) {
54+
return;
55+
}
56+
var me = this,
57+
tempLayerID = params.tempLayerID,
58+
layerPath = params.layerPath,
59+
resourceID = params.resourceID,
60+
layerInfoParams = params.layerInfo;
61+
if (!tempLayerID || !layerPath || !resourceID) {
62+
return;
63+
}
64+
var url = me.url.concat();
65+
url += "/tempLayersSet/" + tempLayerID + "/" + layerPath;
66+
var setLayerInfoService = new SetLayerInfoService(url, {
67+
serverType: me.options.serverType,
68+
eventListeners: {
69+
processCompleted: callback,
70+
processFailed: callback
71+
},
72+
resourceID: resourceID
73+
});
74+
setLayerInfoService.processAsync(layerInfoParams);
75+
return me;
76+
}
77+
78+
/**
79+
* @function mapboxgl.supermap.LayerInfoService.prototype.setLayersInfo
80+
* @description 设置图层信息服务。可以实现创建新的临时图层和对现有临时图层的修改
81+
* @param params - {SuperMap.SetLayersInfoParameters} 设置图层信息参数类,包括临时图层。
82+
* @param callback - {function} 回调函数
83+
*/
84+
setLayersInfo(params, callback) {
85+
if (!params) {
86+
return;
87+
}
88+
var me = this,
89+
resourceID = params.resourceID,
90+
isTempLayers = params.isTempLayers ? params.isTempLayers : false,
91+
layersInfo = params.layersInfo;
92+
if (!resourceID || !layersInfo) {
93+
return;
94+
}
95+
var layersInfoParam = {};
96+
layersInfoParam.subLayers = {};
97+
layersInfoParam.subLayers.layers = layersInfo;
98+
var setLayersInfoService = new SetLayersInfoService(me.url, {
99+
serverType: me.options.serverType,
100+
eventListeners: {
101+
processCompleted: callback,
102+
processFailed: callback
103+
},
104+
resourceID: resourceID,
105+
isTempLayers: isTempLayers
106+
});
107+
setLayersInfoService.processAsync(layersInfoParam);
108+
return me;
109+
}
110+
111+
/**
112+
* @function mapboxgl.supermap.LayerInfoService.prototype.setLayerStatus
113+
* @description 子图层显示控制服务。负责将子图层显示控制参数传递到服务端,并获取服务端返回的图层显示状态。
114+
* @param params - {SuperMap.SetLayerStatusParameters} 子图层显示控制参数类
115+
* @param callback - {function} 回调函数
116+
*/
117+
setLayerStatus(params, callback) {
118+
if (!params) {
119+
return;
120+
}
121+
var me = this;
122+
var setLayerStatusService = new SetLayerStatusService(me.url, {
123+
serverType: me.options.serverType,
124+
eventListeners: {
125+
processCompleted: callback,
126+
processFailed: callback
127+
}
128+
});
129+
setLayerStatusService.processAsync(params);
130+
return me;
131+
}
132+
}
133+
mapboxgl.supermap.LayerInfoService = LayerInfoService;
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import mapboxgl from 'mapbox-gl';
2+
import ServiceBase from './ServiceBase';
3+
import CommonMapService from '../../common/iServer/MapService';
4+
import TilesetsService from '../../common/iServer/TilesetsService';
5+
/**
6+
* @class mapboxgl.supermap.MapService
7+
* @classdesc 地图信息服务类
8+
* @extends mapboxgl.supermap.ServiceBase
9+
* @param url -{string} 地图服务地址
10+
* @param options -{Object} 地图服务信息相关参数。如:<br>
11+
* serverType - {string} 服务来源 iServer|iPortal|online。
12+
* @example
13+
* new mapboxgl.supermap.MapService(url)
14+
* .getMapInfo(function(result){
15+
* //doSomething
16+
* })
17+
*/
18+
export default class MapService extends ServiceBase {
19+
20+
constructor(url, options) {
21+
super(url, options);
22+
}
23+
24+
/**
25+
* @function mapboxgl.supermap.MapService.prototype.getMapInfo
26+
* @description 地图信息查询服务
27+
* @param callback -{function} 回调函数
28+
* @return {mapboxgl.supermap.MapService} 获取服务信息
29+
*/
30+
getMapInfo(callback) {
31+
var me = this;
32+
var getMapStatusService = new CommonMapService(me.url, {
33+
serverType: me.options.serverType,
34+
eventListeners: {
35+
scope: me,
36+
processCompleted: callback,
37+
processFailed: callback
38+
}, projection: me.options.projection
39+
});
40+
getMapStatusService.processAsync();
41+
return me;
42+
}
43+
44+
/**
45+
* @function mapboxgl.supermap.MapService.prototype.getTilesets
46+
* @description 切片列表信息查询服务
47+
* @param callback -{function} 回调函数
48+
* @return {mapboxgl.supermap.MapService} 获取服务信息
49+
*/
50+
getTilesets(callback) {
51+
var me = this;
52+
var tilesetsService = new TilesetsService(me.url, {
53+
serverType: me.options.serverType,
54+
eventListeners: {
55+
scope: me,
56+
processCompleted: callback,
57+
processFailed: callback
58+
}
59+
});
60+
tilesetsService.processAsync();
61+
return me;
62+
}
63+
}
64+
mapboxgl.supermap.MapService = MapService;
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
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

Comments
 (0)