forked from SuperMap/iClient-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddressMatchService.js
More file actions
95 lines (88 loc) · 3.48 KB
/
AddressMatchService.js
File metadata and controls
95 lines (88 loc) · 3.48 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
90
91
92
93
94
/* Copyright© 2000 - 2024 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 { CommonServiceBase } from './CommonServiceBase';
import { GeoCodingParameter } from './GeoCodingParameter';
import { GeoDecodingParameter } from './GeoDecodingParameter';
/**
* @class AddressMatchService
* @deprecatedclass SuperMap.AddressMatchService
* @category iServer AddressMatch
* @classdesc 地址匹配服务类。此类提供了地址的正向匹配和反向匹配功能,正向匹配即通过地点名称关键词查找地址位置,反向匹配即根据位置坐标查询地点。
* @param {string} url - 服务地址。
* @param {Object} options - 可选参数。
* @param {boolean} [options.crossOrigin] - 是否允许跨域请求。
* @param {Object} [options.headers] - 请求头。
* @usage
*/
export class AddressMatchService extends CommonServiceBase {
constructor(url, options) {
super(url, options);
this.options = options || {};
this.CLASS_NAME = 'SuperMap.AddressMatchService';
}
/**
* @function AddressMatchService.prototype.destroy
* @override
*/
destroy() {
super.destroy();
}
/**
* @function AddressMatchService.prototype.code
* @param {string} url - 正向地址匹配服务地址。
* @param {GeoCodingParameter} params - 正向地址匹配服务参数。
* @param {RequestCallback} [callback] - 回调函数,该参数未传时可通过返回的 promise 获取结果。
* @returns {Promise} Promise 对象。
*/
code(url, params, callback) {
if (!(params instanceof GeoCodingParameter)) {
return;
}
return this.processAsync(url, params, callback);
}
/**
* @function AddressMatchService.prototype.decode
* @param {string} url - 反向地址匹配服务地址。
* @param {GeoDecodingParameter} params - 反向地址匹配服务参数。
* @param {RequestCallback} [callback] - 回调函数,该参数未传时可通过返回的 promise 获取结果。
* @returns {Promise} Promise 对象。
*/
decode(url, params, callback) {
if (!(params instanceof GeoDecodingParameter)) {
return;
}
return this.processAsync(url, params, callback);
}
/**
* @function AddressMatchService.prototype.processAsync
* @description 负责将客户端的动态分段服务参数传递到服务端。
* @param {string} url - 服务地址。
* @param {Object} params - 参数。
* @param {RequestCallback} [callback] - 回调函数,该参数未传时可通过返回的 promise 获取结果。
* @returns {Promise} Promise 对象。
*/
processAsync(url, params, callback) {
return this.request({
method: 'GET',
url,
params,
scope: this,
success: callback,
failure: callback
});
}
/**
* @function AddressMatchService.prototype.transformResult
* @param {Object} result - 服务器返回的结果对象。
* @param {Object} options - 请求参数。
* @return {Object} 转换结果。
* @description 状态完成时转换结果。
*/
transformResult(result, options) {
if (result.succeed) {
delete result.succeed;
}
return { result, options };
}
}