import BaseServer from '../BaseServer'
import { Zondy } from '../../base'
/**
* 地址服务,基地址:/igs/rest/services/{folder}/{serviceName}/AddressServer
* @class AddressServer
* @moduleEx ServiceModule
* @extends BaseServer
* @param {Object} options 构造参数
* @param {String} [options.url = 无] 服务基地址
* @example
* //初始化AddressServer服务对象
* // ES5引入方式
* const { AddressServer } = Zondy.Service
* // ES6引入方式
* import { AddressServer } from "@mapgis/webclient-common"
* const addressServer= new AddressServer({
* //服务地址
* url: 'http://localhost:8089/igs/rest/services/test/AddressServer'
* })
*/
class AddressServer extends BaseServer {
constructor(options) {
super(options)
}
/**
* @function AddressServer.prototype.getGeoCode
* @description 获取地理编码,后端接口:/igs/rest/services/{serviceName}/AddressServer/geocode
* @param options 查询参数
* @param {FetchMethod} [options.method = FetchMethod.get ] 请求类型
* @param {Function} [options.success = 无] 查询成功回调函数,若使用Promise方式则不必填写
* @param {Function} [options.failure = 无] 查询失败回调函数,若使用Promise方式则不必填写
* @param {String} [options.address = 无] 地址,必填
* @param {String} [options.province = 无] 指定查询的省
* @param {String} [options.city = 无] 指定查询的市
* @param {String} [options.country = 无] 指定查询的区/县
* @param {Polygon | Extent} [options.geometry = 无] 几何过滤信息
* @param {String} [options.where = 无] 属性过滤条件,示例:hotGroup='社区'
* @param {Number} [options.aggLevel = 5] 聚合等级,默认5
* @param {Number} [options.aggFormat = 1] 聚合结果格式,默认1(1--返回hash、矩形,其他返回hash、中心点)
* @param {Boolean} [options.fuzzy = true] 是否模糊,默认为true
* @param {Number} [options.page = 1] 分页参数,页码,默认1
* @param {Number} [options.pageSize = 100] 分页参数,每页大小,默认100
* @returns {Promise<Object>}
* @example
* //回调方式
* // ES5引入方式
* const { Extent } = Zondy.Geometry
* // ES6引入方式
* import { Extent } from "@mapgis/webclient-common"
* addressServer.getGeoCode({
* address:'小区',
* geometry:new Extent({
* xmin: 110.66,
* ymin: 29.61,
* xmax: 114.05,
* ymax: 32.43
* }),
* pageSize:3,
* success: function (result) {
* console.log('请求成功:', result)
* }
* })
* //promise方式
* addressServer.getGeoCode({
* address:'小区',
* geometry:new Extent({
* xmin: 110.66,
* ymin: 29.61,
* xmax: 114.05,
* ymax: 32.43
* }),
* pageSize:3,
* }).then(function (result) {
* console.log('请求成功:', result);
* }).catch(function (result) {
* console.log('请求失败:', result);
* });
*/
getGeoCode(options) {
// 设置PATH PARAMETERS校验
const checkPathOpts = {}
// 设置QUERY PARAMETERS校验
const checkQueryOpts = {
address: {
type: 'String',
required: true
},
province: {
type: 'String'
},
city: {
type: 'String'
},
country: {
type: 'String'
},
geometry: {
type: 'Polygon | Extent'
},
where: {
type: 'String'
},
aggLevel: {
type: 'Number'
},
aggFormat: {
type: 'Number'
},
fuzzy: {
type: 'Boolean'
},
page: {
type: 'Number'
},
pageSize: {
type: 'Number'
}
}
// 调用基类的查询信息方法
return this._queryByParameters(
options,
checkPathOpts,
checkQueryOpts,
// 拼装返回基地址
function (url) {
return `${url}/geocode?f=json`
}
)
}
/**
* @function AddressServer.prototype.getReverseGeoCode
* @description 获取逆地理编码,后端接口:/igs/rest/services/{serviceName}/AddressServer/reverseGeocode
* @param options 查询参数
* @param {FetchMethod} [options.method = FetchMethod.get ] 请求类型
* @param {Function} [options.success = 无] 查询成功回调函数,若使用Promise方式则不必填写
* @param {Function} [options.failure = 无] 查询失败回调函数,若使用Promise方式则不必填写
* @param {String} [options.location = 无] 坐标,格式 x,y,必填
* @param {String} [options.province = 无] 指定查询的省
* @param {String} [options.city = 无] 指定查询的市
* @param {String} [options.country = 无] 指定查询的区/县
* @param {Number} [options.radius = 0.1] 搜索半径,默认单位是千米,默认为0.1
* @param {Polygon | Extent} [options.geometry = 无] 几何过滤信息
* @param {String} [options.where = 无] 属性过滤条件,示例:hotGroup='社区'
* @param {Number} [options.page = 1] 分页参数,页码,默认1
* @param {Number} [options.pageSize = 100] 分页参数,每页大小,默认100
* @returns {Promise<Object>}
* @example
* //回调方式
* addressServer.getReverseGeoCode({
* location:'114.410418,30.400674',
* pageSize:1,
* success: function (result) {
* console.log('请求成功:', result)
* }
* })
* //promise方式
* addressServer.getReverseGeoCode({
* location:'114.410418,30.400674',
* pageSize:1,
* }).then(function (result) {
* console.log('请求成功:', result);
* }).catch(function (result) {
* console.log('请求失败:', result);
* });
*
*/
getReverseGeoCode(options) {
// 设置PATH PARAMETERS校验
const checkPathOpts = {}
// 设置QUERY PARAMETERS校验
const checkQueryOpts = {
location: {
type: 'String',
required: true
},
province: {
type: 'String'
},
city: {
type: 'String'
},
radius: {
type: 'Number'
},
geometry: {
type: 'Geometry'
},
where: {
type: 'String'
},
page: {
type: 'Number'
},
pageSize: {
type: 'Number'
}
}
// 调用基类的查询信息方法
return this._queryByParameters(
options,
checkPathOpts,
checkQueryOpts,
// 拼装返回基地址
function (url) {
return `${url}/reverseGeocode?f=json`
}
)
}
}
Zondy.Service.AddressServer = AddressServer
export default AddressServer