-
Notifications
You must be signed in to change notification settings - Fork 288
Expand file tree
/
Copy pathMeasureService.js
More file actions
82 lines (73 loc) · 3.3 KB
/
MeasureService.js
File metadata and controls
82 lines (73 loc) · 3.3 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
/* Copyright© 2000 - 2025 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 '../core/Base';
import {Util} from '../core/Util';
import {ServiceBase} from './ServiceBase';
import { Geometry } from '@supermapgis/iclient-common/commontypes/Geometry';
import { MeasureService as CommonMeasureService } from '@supermapgis/iclient-common/iServer/MeasureService';
/**
* @class MeasureService
* @category iServer Map Measure
* @classdesc 量算服务类。提供方法:面积量算、距离量算等。
* @modulecategory Services
* @extends {ServiceBase}
* @param {string} url - 服务地址。如:http://localhost:8090/iserver/services/map-world/rest/maps/World+Map。
* @param {Object} options - 参数。
* @param {string} [options.proxy] - 服务代理地址。
* @param {boolean} [options.withCredentials] - 请求是否携带凭据。默认情况下,仅同源请求包含凭据。
* @param {boolean} [options.crossOrigin] - 是否允许跨域请求。
* @param {Object} [options.headers] - 请求头。
* @param {MeasureMode} [options.measureMode=MeasureMode.DISTANCE] - 量算模式,包括距离量算模式和面积量算模式。
* @usage
*/
export class MeasureService extends ServiceBase {
constructor(url, options) {
super(url, options);
}
/**
* @function MeasureService.prototype.measureDistance
* @description 距离量算。
* @param {MeasureParameters} params - 量算参数类。
* @param {RequestCallback} [callback] - 回调函数,该参数未传时可通过返回的 promise 获取结果。
* @returns {Promise} Promise 对象。
*/
measureDistance(params, callback) {
return this.measure(params, 'DISTANCE', callback);
}
/**
* @function MeasureService.prototype.measureArea
* @description 面积量算。
* @param {MeasureParameters} params - 量算参数类。
* @param {RequestCallback} [callback] - 回调函数,该参数未传时可通过返回的 promise 获取结果。
* @returns {Promise} Promise 对象。
*/
measureArea(params, callback) {
return this.measure(params, 'AREA', callback);
}
/**
* @function MeasureService.prototype.measure
* @description 量算。
* @param {MeasureParameters} params - 量算参数类。
* @param {string} type - 量算类型。
* @param {RequestCallback} [callback] - 回调函数,该参数未传时可通过返回的 promise 获取结果。
* @returns {MeasureService} 量算服务。
*/
measure(params, type, callback) {
var me = this;
var measureService = new CommonMeasureService(me.url, {
proxy: me.options.proxy,
withCredentials: me.options.withCredentials,
crossOrigin: me.options.crossOrigin,
headers: me.options.headers,
measureMode: type
});
return measureService.processAsync(me._processParam(params), callback);
}
_processParam(params) {
if (params && !(params.geometry instanceof Geometry)) {
params.geometry = Util.toSuperMapGeometry(params.geometry);
}
return params;
}
}