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
85 lines (78 loc) · 2.93 KB
/
MeasureService.js
File metadata and controls
85 lines (78 loc) · 2.93 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
import L from 'leaflet';
import {ServiceBase} from './ServiceBase';
import '../core/Base';
import * as Util from '../core/Util';
import {MeasureMode, MeasureService as CommonMeasureService, MeasureParameters} from '@supermap/iclient-common';
/**
* @class L.supermap.measureService
* @classdesc 量算服务服务类
* @category iServer Map Measure
* @augments L.supermap.ServiceBase
* @example
* 用法:
* L.supermap.measureService(url).measureDistance({
* geometry:xxx
* },function(result){
* //doSomething
* })
* @param url - {string} 服务访问的地址。如:http://localhost:8090/iserver/services/map-world/rest/maps/World 。
* @param options - {Object} 交互服务时所需可选参数。如:<br>
* serverType - {{@link SuperMap.ServerType}} 服务来源 iServer|iPortal|online。<br>
* eventListeners - {Object} 需要被注册的监听器对象。<br>
* measureMode - {SuperMap.MeasureMode} 量算模式,包括距离量算模式和面积量算模式。
*/
export var MeasureService = ServiceBase.extend({
initialize: function (url, options) {
ServiceBase.prototype.initialize.call(this, url, options);
},
/**
* @function L.supermap.measureService.prototype.measureDistance
* @description 测距
* @param params -{SuperMap.MeasureParameters} 测量相关参数类
* @param callback - {function} 回调函数
*/
measureDistance: function (params, callback) {
this.measure(MeasureMode.DISTANCE, params, callback);
return this;
},
/**
* @function L.supermap.measureService.prototype.measureArea
* @description 测面积
* @param params -{SuperMap.MeasureParameters} 测量相关参数类
* @param callback - {function} 回调函数
*/
measureArea: function (params, callback) {
this.measure(MeasureMode.AREA, params, callback);
return this;
},
/**
* @function L.supermap.measureService.measure
* @param type -{SuperMap.MeasureMode} 量算模式
* @param params -{SuperMap.MeasureParameters} 测量相关参数类
* @param callback - {function} 回调函数
*/
measure: function (type, params, callback) {
if (!(params instanceof MeasureParameters)) {
return;
}
var me = this;
if (params.geometry) {
params.geometry = Util.toSuperMapGeometry(params.geometry);
}
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(params);
}
});
export var measureService = function (url, options) {
return new MeasureService(url, options);
};
L.supermap.measureService = measureService;