-
Notifications
You must be signed in to change notification settings - Fork 288
Expand file tree
/
Copy pathMeasureService.js
More file actions
89 lines (83 loc) · 3.52 KB
/
MeasureService.js
File metadata and controls
89 lines (83 loc) · 3.52 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
86
87
88
89
/* 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 {ServiceBase} from './ServiceBase';
import '../core/Base';
import * as Util from '../core/Util';
import { MeasureMode } from '@supermapgis/iclient-common/REST';
import { MeasureService as CommonMeasureService } from '@supermapgis/iclient-common/iServer/MeasureService';
import { MeasureParameters } from '@supermapgis/iclient-common/iServer/MeasureParameters';
/**
* @class MeasureService
* @deprecatedclassinstance L.supermap.measureService
* @classdesc 量算服务类。提供方法:面积量算、距离量算等。
* @category iServer Map Measure
* @modulecategory Services
* @example
* 用法:
* new MeasureService(url).measureDistance({
* geometry:xxx
* },function(result){
* //doSomething
* })
* @param {string} url - 服务地址。
* @param {Object} options - 参数。
* @param {string} [options.proxy] - 服务代理地址。
* @param {boolean} [options.withCredentials] - 请求是否携带凭据。默认情况下,仅同源请求包含凭据。
* @param {boolean} [options.crossOrigin] - 是否允许跨域请求。
* @param {Object} [options.headers] - 请求头。
* @extends {ServiceBase}
* @usage
*/
export var MeasureService = ServiceBase.extend({
initialize: function (url, options) {
ServiceBase.prototype.initialize.call(this, url, options);
},
/**
* @function MeasureService.prototype.measureDistance
* @description 距离量算。
* @param {MeasureParameters} params - 量算参数类。
* @param {RequestCallback} [callback] - 回调函数,该参数未传时可通过返回的 promise 获取结果。
* @returns {Promise} Promise 对象。
*/
measureDistance: function (params, callback) {
return this.measure(MeasureMode.DISTANCE, params, callback);
},
/**
* @function MeasureService.prototype.measureArea
* @description 面积量算。
* @param {MeasureParameters} params - 量算参数类。
* @param {RequestCallback} [callback] - 回调函数,该参数未传时可通过返回的 promise 获取结果。
* @returns {Promise} Promise 对象。
*/
measureArea: function (params, callback) {
return this.measure(MeasureMode.AREA, params, callback);
},
/**
* @function MeasureService.measure
* @param {MeasureMode} [type=MeasureMode.DISTANCE] - 量算模式。
* @param {MeasureParameters} params - 量算参数类。
* @param {RequestCallback} [callback] - 回调函数,该参数未传时可通过返回的 promise 获取结果。
* @returns {Promise} Promise 对象。
*/
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,
withCredentials: me.options.withCredentials,
crossOrigin: me.options.crossOrigin,
headers: me.options.headers,
measureMode: type
});
return measureService.processAsync(params, callback);
}
});
export var measureService = function (url, options) {
return new MeasureService(url, options);
};