Skip to content

Commit 0f37f41

Browse files
author
潘卓然Y7000P
committed
【SDK】【新增】【补充PostGIS对应的查询接口&实现多继承机制】
1 parent c6e8300 commit 0f37f41

6 files changed

Lines changed: 300 additions & 8 deletions

File tree

src/service/common/Mixin.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* @author 基础平台-潘卓然
3+
* @param {...any} mixins 混合的对象
4+
* @example
5+
* class DistributedEdit extends mix(Loggable, Serializable) {
6+
// ...
7+
}
8+
*/
9+
export function mix(...mixins) {
10+
class Mix {
11+
constructor() {
12+
for (let mixin of mixins) {
13+
mixin && copyProperties(this, new mixin()); // 拷贝实例属性
14+
}
15+
}
16+
}
17+
18+
for (let mixin of mixins) {
19+
mixin && copyProperties(Mix, mixin); // 拷贝静态属性
20+
mixin && copyProperties(Mix.prototype, mixin.prototype); // 拷贝原型属性
21+
}
22+
23+
return Mix;
24+
}
25+
26+
/**
27+
* @description 将要拷贝的源对象属性拷贝到对应的目标对象里面
28+
* @param {*} target 目标对象
29+
* @param {*} source 源对象
30+
*/
31+
export function copyProperties(target, source) {
32+
for (let key of Reflect.ownKeys(source)) {
33+
if (key !== 'constructor' && key !== 'prototype' && key !== 'name') {
34+
let desc = Object.getOwnPropertyDescriptor(source, key);
35+
Object.defineProperty(target, key, desc);
36+
}
37+
}
38+
}
39+
40+
export default mix;

src/service/datastore/ServiceBase.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,29 @@ export class DataStoreService extends ServiceBase {
2121
delete this.params.port;
2222
delete this.params.domain;
2323
delete this.params.baseUrl;
24-
delete this.params.networkProtocol;
24+
delete this.params.protocol;
2525
delete this.params.partUrl;
2626
}
2727

2828
/**
29-
* @function module:DataStore服务.DataStoreService.prototype.getBaseUrl
29+
* @function module:DataStore.DataStoreService.prototype.getBaseUrl
3030
* @description 获取基地址url
3131
*/
3232
getBaseUrl() {
3333
let url = '';
34-
const { baseUrl, ip, port, domain, networkProtocol } = this;
34+
const { baseUrl, ip, port, domain, protocol } = this;
3535
if (baseUrl) {
3636
url = baseUrl;
3737
} else if (domain) {
3838
url = domain;
39-
} else if (networkProtocol && ip && port) {
40-
url = `${networkProtocol}://${ip}:${port}`;
39+
} else if (protocol && ip && port) {
40+
url = `${protocol}://${ip}:${port}`;
4141
}
4242
return url;
4343
}
4444

4545
/**
46-
* @function module:DataStore服务.DataStoreService.prototype.getFullUrl
46+
* @function module:DataStore.DataStoreService.prototype.getFullUrl
4747
* @description 获取完整的url地址
4848
* @param {String}
4949
* @param {Object}
@@ -57,7 +57,7 @@ export class DataStoreService extends ServiceBase {
5757

5858
/**
5959
* @description 向服务器发送GET请求
60-
* @function module:DataStore服务.DataStoreService.prototype.get
60+
* @function module:DataStore.DataStoreService.prototype.get
6161
* @param {String} url 完整的请求地址。
6262
* @param {Function} onSuccess 查询成功回调函数。
6363
* @param {Function} onError 查询失败回调函数。
@@ -76,7 +76,7 @@ export class DataStoreService extends ServiceBase {
7676

7777
/**
7878
* @description 向服务器发送POST请求
79-
* @function module:DataStore服务.DataStoreService.prototype.post
79+
* @function module:DataStore.DataStoreService.prototype.post
8080
* @param {String} url 完整的请求地址。
8181
* @param {Function} onSuccess 查询成功回调函数。
8282
* @param {Function} onError 查询失败回调函数。
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { Zondy } from '../common/Base';
2+
3+
/**
4+
* @author 创新中心-潘卓然
5+
* @class module:PostGIS.ServiceParameter
6+
* @param option - {Object} 查询条件
7+
* @param {string} [option.domain=null] dataStore服务地址域名 (domain和[protocol,ip,port],二选一)
8+
* @param {string} [option.protocol="http"] dataStore服务地址网络协议 (domain和[protocol,ip,port],二选一)
9+
* @param {string} [option.ip =null] dataStore服务地址ip (domain和[protocol,ip,port],二选一)
10+
* @param {string} [option.port=null] dataStore服务地址port (domain和[protocol,ip,port],二选一)
11+
* @param {String} [option.pageSize = 10] 每页大小。默认10
12+
* @param {String} [option.pageNo] 页码,从1开始
13+
*/
14+
export class ServiceParameter {
15+
constructor(option) {
16+
/**
17+
* @member module:PostGIS.ServiceParameter.prototype.domain
18+
* @description 域地址
19+
*/
20+
this.domain = option.domain;
21+
/**
22+
* @member module:PostGIS.ServiceParameter.prototype.protocol
23+
* @description 网络协议
24+
*/
25+
this.protocol = option.protocol;
26+
/**
27+
* @member module:PostGIS.ServiceParameter.prototype.ip
28+
* @description IP地址
29+
*/
30+
this.ip = option.ip;
31+
/**
32+
* @member module:PostGIS.ServiceParameter.prototype.port
33+
* @description 端口
34+
*/
35+
this.port = option.port;
36+
/**
37+
* @member module:PostGIS.ServiceParameter.prototype.pageSize
38+
* @description 页大小
39+
*/
40+
this.pageSize = option.pageSize || 10;
41+
/**
42+
* @member module:PostGIS.ServiceParameter.prototype.pageNo
43+
* @description 页数量
44+
*/
45+
this.pageNo = option.pageNo;
46+
}
47+
}
48+
49+
export default ServiceParameter;
50+
Zondy.DataStore.ServiceParameter = ServiceParameter;
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
import { Zondy } from '../../common/Base';
2+
import BaseQueryParameter from '../ServiceParameter';
3+
4+
/**
5+
* @author 创新中心-潘卓然
6+
* @class module:PostGIS.PostgisQueryParameter
7+
* @param {Object} option 查询条件
8+
* @param {String} [option.gdbp] 发布在igs上的pg图层gdbp地址,可以从中解析libName(数据库名)、schemas(工作空间名)、tableName(表名)
9+
* @param {Boolean} [option.includeProperites = true] 查询结果中是否包含属性
10+
* @param {String} [option.where] 属性条件 (例如:id>5,id<10)
11+
* @param {String} [option.fields] 统计计算中用于分组字段名列表
12+
* @param {String} [option.geometry] 几何信息,圆、多边形等
13+
* @param {String} [option.geoFormat="wkt"] 几何类型,wkt、wkb、geojson、自定义等
14+
* @param {String} [option.sref] 动态投影坐标系 ID,支持 MapGIS 和 EPSG 标准编号,其中 MapGIS 只支持当前库中自带的坐标系的 ID,EPSG 标准请 使用 EPSG:4326 格式,若指定了该参数,则系统认为 geometry 的坐标系为此坐标系
15+
*/
16+
export class PostgisQueryParameter extends BaseQueryParameter {
17+
constructor(option) {
18+
super(option);
19+
/**
20+
* @member module:PostGIS.PostgisQueryParameter.prototype.gdbp
21+
* @description 发布在igs上的pg图层gdbp地址,可以从中解析libName(数据库名)、schemas(工作空间名)、tableName(表名)
22+
* @type String
23+
*/
24+
this.gdbp = option.gdbp;
25+
/**
26+
* @member module:PostGIS.PostgisQueryParameter.prototype.includeProperites
27+
* @description 查询结果中是否包含属性
28+
* @type Boolean
29+
* @default true
30+
*/
31+
this.includeProperites = option.includeProperites;
32+
/**
33+
* @member module:PostGIS.PostgisQueryParameter.prototype.where
34+
* @description 属性条件 (例如:id>5,id<10)
35+
* @type String
36+
*/
37+
this.where = option.where;
38+
/**
39+
* @member module:PostGIS.PostgisQueryParameter.prototype.fields
40+
* @description 统计计算中用于分组字段名列表
41+
* @type String
42+
*/
43+
this.fields = option.fields;
44+
/**
45+
* @member module:PostGIS.PostgisQueryParameter.prototype.geometry
46+
* @description 几何信息,圆、多边形等
47+
* @type String
48+
*/
49+
this.geometry = option.geometry;
50+
/**
51+
* @member module:PostGIS.PostgisQueryParameter.prototype.geoFormat
52+
* @description 几何类型,wkt、wkb、geojson、自定义等
53+
* @type String
54+
*/
55+
this.geoFormat = option.geoFormat;
56+
/**
57+
* @member module:PostGIS.PostgisQueryParameter.prototype.sref
58+
* @description 动态投影坐标系 ID,支持 MapGIS 和 EPSG 标准编号,
59+
* 其中 MapGIS 只支持当前库中自带的坐标系的 ID,EPSG 标准请 使用 EPSG:4326 格式,
60+
* 若指定了该参数,则系统认为 geometry 的坐标系为此坐标系
61+
* @type String
62+
*/
63+
this.sref = option.sref;
64+
}
65+
66+
fixParams() {
67+
const { gdbp, pageNo, pageSize, includeProperites, where, fields, sref } = this;
68+
const vecStr = gdbp.split('/');
69+
if (vecStr.length < 5) return;
70+
let queryParam = {};
71+
queryParam.libName = vecStr[vecStr.length - 5];
72+
queryParam.tableName = vecStr[vecStr.length - 1];
73+
queryParam.schemas = vecStr[vecStr.length - 5];
74+
queryParam.pageNo = pageNo !== undefined ? pageNo : 1;
75+
queryParam.pageSize = pageSize || 10;
76+
queryParam.includeProperites = includeProperites;
77+
queryParam.filter = where;
78+
queryParam.fields = fields;
79+
queryParam.sref = sref;
80+
queryParam.geometry = this.fixGeometry();
81+
}
82+
83+
fixGeometry() {
84+
let { geometry } = this;
85+
if (geometry) {
86+
queryParam.geoFormat = 'wkt';
87+
const geometryType = geometry.getGeometryType();
88+
const arr = [];
89+
let str;
90+
if (geometryType === 'rect') {
91+
arr.push(`${option.geometry.xmin} ${option.geometry.ymin}`);
92+
arr.push(`${option.geometry.xmin} ${option.geometry.ymax}`);
93+
arr.push(`${option.geometry.xmax} ${option.geometry.ymax}`);
94+
arr.push(`${option.geometry.xmax} ${option.geometry.ymin}`);
95+
arr.push(`${option.geometry.xmin} ${option.geometry.ymin}`);
96+
} else if (geometryType === 'polygon' || geometryType === 'polygon') {
97+
const { pointArr } = option.geometry;
98+
for (let i = 0; i < pointArr.length; i += 1) {
99+
arr.push(`${pointArr[i].x} ${pointArr[i].y}`);
100+
}
101+
str = arr.join(',');
102+
if (geometryType === 'polygon') {
103+
queryParam.geometry = `POLYGON(( ${str}))`;
104+
} else if (geometryType === 'line') {
105+
queryParam.geometry = `LINESTRING(${str})`;
106+
}
107+
} else if (geometryType === 'point') {
108+
queryParam.geometry = `POINT(${option.geometry.x} ${option.geometry.y})`;
109+
}
110+
}
111+
}
112+
}
113+
114+
export default PostgisQueryParameter;
115+
Zondy.DataStore.PostGIS.PostgisQueryParameter = PostgisQueryParameter;
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { Zondy } from '../../common/Base';
2+
import { DataStoreService } from '../ServiceBase';
3+
4+
/**
5+
* @author 创新中心-潘卓然
6+
* @class module:PostGIS.PostgisQueryService
7+
* @param {PostgisQueryParameter} option 查询条件
8+
* @param {String} [option.gdbp] 发布在igs上的pg图层gdbp地址,可以从中解析libName(数据库名)、schemas(工作空间名)、tableName(表名)
9+
* @param {Boolean} [option.includeProperites = true] 查询结果中是否包含属性
10+
* @param {String} [option.where] 属性条件 (例如:id>5,id<10)
11+
* @param {String} [option.fields] 统计计算中用于分组字段名列表
12+
* @param {String} [option.geometry] 几何信息,圆、多边形等
13+
* @param {String} [option.geoFormat="wkt"] 几何类型,wkt、wkb、geojson、自定义等
14+
* @param {String} [option.sref] 动态投影坐标系 ID,支持 MapGIS 和 EPSG 标准编号,其中 MapGIS 只支持当前库中自带的坐标系的 ID,EPSG 标准请 使用 EPSG:4326 格式,若指定了该参数,则系统认为 geometry 的坐标系为此坐标系
15+
*/
16+
export class PostgisQueryService extends DataStoreService {
17+
constructor(option) {
18+
super(option);
19+
20+
/**
21+
* @member module:PostGIS.PostgisQueryService.prototype.gdbp
22+
* @description 发布在igs上的pg图层gdbp地址,可以从中解析libName(数据库名)、schemas(工作空间名)、tableName(表名)
23+
* @type String
24+
*/
25+
this.gdbp = option.gdbp;
26+
/**
27+
* @member module:PostGIS.PostgisQueryService.prototype.includeProperites
28+
* @description 查询结果中是否包含属性
29+
* @type Boolean
30+
* @default true
31+
*/
32+
this.includeProperites = option.includeProperites;
33+
/**
34+
* @member module:PostGIS.PostgisQueryService.prototype.where
35+
* @description 属性条件 (例如:id>5,id<10)
36+
* @type String
37+
*/
38+
this.where = option.where;
39+
/**
40+
* @member module:PostGIS.PostgisQueryService.prototype.fields
41+
* @description 统计计算中用于分组字段名列表
42+
* @type String
43+
*/
44+
this.fields = option.fields;
45+
/**
46+
* @member module:PostGIS.PostgisQueryService.prototype.geometry
47+
* @description 几何信息,圆、多边形等
48+
* @type String
49+
*/
50+
this.geometry = option.geometry;
51+
/**
52+
* @member module:PostGIS.PostgisQueryService.prototype.geoFormat
53+
* @description 几何类型,wkt、wkb、geojson、自定义等
54+
* @type String
55+
*/
56+
this.geoFormat = option.geoFormat;
57+
/**
58+
* @member module:PostGIS.PostgisQueryService.prototype.sref
59+
* @description 动态投影坐标系 ID,支持 MapGIS 和 EPSG 标准编号,
60+
* 其中 MapGIS 只支持当前库中自带的坐标系的 ID,EPSG 标准请 使用 EPSG:4326 格式,
61+
* 若指定了该参数,则系统认为 geometry 的坐标系为此坐标系
62+
* @type String
63+
*/
64+
this.sref = option.sref;
65+
}
66+
/**
67+
* @description 查询函数,向服务器发送请求,返回地名地址格式数据
68+
* @function module:PostGIS.PostgisQueryService.prototype.query
69+
* @param {Function} onSuccess 查询成功回调函数。
70+
* @param {Function} onError 查询失败回调函数。
71+
*/
72+
query(onSuccess, onError) {
73+
let { serviceUrl, options } = this;
74+
let url = this.getFullUrl(serviceUrl, options);
75+
this.get(url, onSuccess, onError);
76+
}
77+
}
78+
79+
export default PostgisQueryService;
80+
Zondy.DataStore.PostGIS.PostgisQueryService = PostgisQueryService;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* @module PostGIS
3+
*/
4+
import { PostgisQueryParameter } from './PostgisQueryParameter';
5+
import { PostgisQueryService } from './PostgisQueryService';
6+
7+
export { PostgisQueryParameter, PostgisQueryService };

0 commit comments

Comments
 (0)