forked from SuperMap/iClient-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMeasureService.js
More file actions
76 lines (66 loc) · 2.56 KB
/
MeasureService.js
File metadata and controls
76 lines (66 loc) · 2.56 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
import mapboxgl from 'mapbox-gl';
import '../core/Base';import {Util} from '../core/Util';
import {ServiceBase} from './ServiceBase';
import {Geometry, MeasureService as CommonMeasureService} from '@supermap/iclient-common';
/**
* @class mapboxgl.supermap.MeasureService
* @category iServer Map Measure
* @classdesc 测量服务
* @extends mapboxgl.supermap.ServiceBase
* @param url - {string} 服务访问的地址。如:http://localhost:8090/iserver/services/map-world/rest/maps/World+Map 。
* @param options - {Object} 交互服务时所需可选参数。如:<br>
* eventListeners - {Object} 需要被注册的监听器对象。
* measureMode - {MeasureMode} 量算模式,包括距离量算模式和面积量算模式。
*/
export class MeasureService extends ServiceBase {
constructor(url, options) {
super(url, options);
}
/**
* @function mapboxgl.supermap.MeasureService.prototype.measureDistance
* @description 测距
* @param params -{SuperMap.MeasureParameters} 测量相关参数类
* @param callback - {function} 回调函数
*/
measureDistance(params, callback) {
this.measure(params, 'DISTANCE', callback);
}
/**
* @function mapboxgl.supermap.MeasureService.prototype.measureArea
* @description 测面积
* @param params -{SuperMap.MeasureParameters} 测量相关参数类
* @param callback - {function} 回调函数
*/
measureArea(params, callback) {
this.measure(params, 'AREA', callback);
}
/**
* @function mapboxgl.supermap.MeasureService.prototype.measure
* @description 测量
* @param params -{SuperMap.MeasureParameters} 测量相关参数类
* @param type - {string} 类型
* @param callback - {function} 回调函数
* @return {mapboxgl.supermap.MeasureService} 测量服务
*/
measure(params, type, callback) {
var me = this;
var measureService = new CommonMeasureService(me.url, {
proxy: me.options.proxy,
serverType: me.options.serverType,
measureMode: type,
eventListeners: {
scope: me,
processCompleted: callback,
processFailed: callback
}
});
measureService.processAsync(me._processParam(params));
}
_processParam(params) {
if (params && !(params.geometry instanceof Geometry)) {
params.geometry = Util.toSuperMapGeometry(params.geometry);
}
return params;
}
}
mapboxgl.supermap.MeasureService = MeasureService;