Skip to content

Commit b21bba4

Browse files
author
潘卓然ParnDeedlit
committed
【SDK】【服务】【新增OGC通用服务】
1 parent a474c63 commit b21bba4

File tree

5 files changed

+315
-1
lines changed

5 files changed

+315
-1
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { MapGIS } from '../Base';
2+
import { ServiceBase } from '../ServiceBase';
3+
4+
/**
5+
* @author 基础平台-潘卓然
6+
* @class module:OGC服务.OGCService
7+
* @classdesc OGC服务类
8+
* @description Mapgis.OGC.OGCService
9+
* @extends ServiceBase
10+
* @param option - {Object} 属性键值对。<br>
11+
* @param {String} [option.baseUrl = igs/rest/ogc] 基本地址
12+
* @param {String} [option.url = ""] 必选。服务url
13+
*/
14+
class OGCService extends ServiceBase {
15+
constructor(option) {
16+
var options = option || {};
17+
options.baseUrl = 'igs/rest/ogc';
18+
super(options);
19+
}
20+
21+
/**
22+
* @description 向服务器发送GET请求
23+
* @function module:OGC.OGCService.prototype.get
24+
* @param {String} url 完整的请求地址。
25+
* @param {Function} onSuccess 查询成功回调函数。
26+
* @param {Function} onError 查询失败回调函数。
27+
*/
28+
get(url, onSuccess, onError) {
29+
var me = this;
30+
var service = new IgsServiceBase(url, {
31+
eventListeners: {
32+
scope: me,
33+
processCompleted: onSuccess,
34+
processFailed: onError
35+
}
36+
});
37+
service.processAsync();
38+
}
39+
40+
/**
41+
* @description 向服务器发送POST请求
42+
* @function module:OGC.OGCService.prototype.post
43+
* @param {String} url 完整的请求地址。
44+
* @param {Function} onSuccess 查询成功回调函数。
45+
* @param {Function} onError 查询失败回调函数。
46+
*/
47+
post(url, param, onSuccess, onError) {
48+
var me = this;
49+
var service = new IgsServiceBase(url, {
50+
eventListeners: {
51+
scope: me,
52+
processCompleted: onSuccess,
53+
processFailed: onError
54+
}
55+
});
56+
service.processAsync({
57+
method: 'POST',
58+
data: JSON.stringify(param),
59+
headers: { 'Content-Type': 'text/plain;charset=UTF-8' }
60+
});
61+
}
62+
}
63+
export { OGCService };
64+
MapGIS.OGC.OGCService = OGCService;
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
import { MapGIS } from '../Base';
2+
import { OGCService } from './OGCService';
3+
import xml from 'fast-xml-parser';
4+
import axios from 'axios';
5+
import qs from 'qs';
6+
7+
/**
8+
* @author 基础平台-潘卓然
9+
* @class module:OGC服务.OGCService
10+
* @classdesc OGC服务类
11+
* @description MapGIS.OGC.OGCService
12+
* @extends OGCService
13+
* @link https://www.ogc.org/standards/wfs
14+
* @param option - {Object} 属性键值对。<br>
15+
* @param {String} [option.url = ""] 必选。服务url
16+
* @param {String} [option.version = "1.1.1"] 请求的版本号,1.1.1或1.3.0,服务默认版本为1.1.1。(getWMSInfo,getFeatureInfo)
17+
*/
18+
class WFS extends OGCService {
19+
constructor(option) {
20+
var options = option || {};
21+
super(options);
22+
this.url = options.url;
23+
this.featureTypes = [];
24+
this.layers = [];
25+
}
26+
27+
isBaseUrl() {
28+
let valid = false;
29+
const name = 'WFSServer';
30+
const length = this.url.length;
31+
const index = this.url.indexOf(name) + name.length;
32+
let fullurl;
33+
if (index === length) {
34+
fullurl = `${this.url}?request=GetCapabilities&service=WFS`;
35+
valid = true;
36+
} else if (index === length - 1) {
37+
fullurl = `${this.url}request=GetCapabilities&service=WFS`;
38+
valid = true;
39+
}
40+
return valid;
41+
}
42+
43+
setVersion(version) {
44+
this.version = version;
45+
return this;
46+
}
47+
48+
setCrs(crs) {
49+
this.srsname = crs;
50+
return this;
51+
}
52+
53+
setName(name) {
54+
this.typename = name;
55+
return this;
56+
}
57+
58+
setOutputFormat(format) {
59+
this.outputFormat = format;
60+
}
61+
62+
async getCapabilities() {
63+
const name = 'WFSServer';
64+
const length = this.url.length;
65+
const index = this.url.indexOf(name) + name.length;
66+
let fullurl = this.url;
67+
if (index === length) {
68+
fullurl = `${this.url}?request=GetCapabilities&service=WFS`;
69+
} else if (index === length - 1) {
70+
fullurl = `${this.url}request=GetCapabilities&service=WFS`;
71+
}
72+
let res = await axios.get(fullurl);
73+
let data = res.data;
74+
let obj = xml.getTraversalObj(data, {});
75+
let json = xml.convertToJson(obj, {});
76+
let version = json['wfs:WFS_Capabilities']['ows:ServiceIdentification']['ows:ServiceTypeVersion'];
77+
if (version === '1.1.0') {
78+
// MapGIS 10.3.5 10.5.0
79+
this.featureTypes = json['wfs:WFS_Capabilities']['FeatureTypeList']['FeatureType'];
80+
let crs;
81+
let name = '';
82+
this.featureTypes.forEach((f, i) => {
83+
if (i == 0) {
84+
crs = f['DefaultSRS'];
85+
name = `${f['Name']}`;
86+
}
87+
});
88+
this.layers = this.featureTypes.map((f) => f['Name']);
89+
this.setName(name).setCrs(crs).setVersion(version).setOutputFormat('text/xml; subtype=gml/3.2');
90+
} else if (version === '2.0.0') {
91+
let featureType = json['wfs:WFS_Capabilities']['wfs:FeatureTypeList']['wfs:FeatureType'];
92+
let crs = featureType['wfs:DefaultCRS'];
93+
let name = featureType['wfs:Name'];
94+
this.setName(name).setCrs(crs).setVersion(version);
95+
}
96+
return json;
97+
}
98+
99+
async getFeature() {
100+
const name = 'WFSServer';
101+
const length = this.url.length;
102+
const index = this.url.indexOf(name) + name.length;
103+
let fullurl = this.url;
104+
105+
let { maxFeatures = 100, version = '1.1.0', typename = '', outputFormat, srsname = 'EPSG:4326', bbox } = this;
106+
let object = {
107+
service: 'WFS',
108+
request: 'GetFeature',
109+
version,
110+
typename,
111+
outputFormat,
112+
srsname,
113+
maxFeatures
114+
};
115+
116+
if (version === '1.1.0') {
117+
if (bbox) {
118+
object = { ...object, bbox: `${bbox},${srsname}` };
119+
} else {
120+
object = { ...object };
121+
}
122+
} else if (version === '2.0.0') {
123+
object = { ...object, Envelope: `${bbox},${srsname}` };
124+
}
125+
126+
if (index === length) {
127+
fullurl = `${this.url}?${qs.stringify(object)}`;
128+
} else if (index === length - 1) {
129+
fullurl = `${this.url}${qs.stringify(object)}`;
130+
}
131+
132+
let res = await axios.get(fullurl);
133+
let data = res.data;
134+
let obj = xml.getTraversalObj(data, {});
135+
let json = xml.convertToJson(obj, {});
136+
137+
let result = {
138+
geojson: undefined,
139+
xml: json
140+
};
141+
let geojson;
142+
switch (version) {
143+
case '1.1.0':
144+
geojson = convert
145+
break;
146+
case '2.0.0':
147+
break;
148+
}
149+
return result;
150+
}
151+
}
152+
export { WFS };
153+
MapGIS.OGC.WFS = WFS;
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import { MapGIS } from '../Base';
2+
import { OGCService } from './OGCService';
3+
import xml from 'fast-xml-parser';
4+
import axios from 'axios';
5+
import qs from 'qs';
6+
7+
/**
8+
* @author 基础平台-潘卓然
9+
* @class module:OGC服务.WMS
10+
* @classdesc OGC服务类
11+
* @description MapGIS.OGC.WMS
12+
* @extends OGCService
13+
* @param option - {Object} 属性键值对。<br>
14+
* @param {String} [option.url = ""] 必选。服务url
15+
* @param {String} [option.version = "1.1.1"] 请求的版本号,1.1.1或1.3.0,服务默认版本为1.1.1。(getWMSInfo,getFeatureInfo)
16+
* @param {String} [option.layers] 请求的图层名,用逗号分隔多个图层;既支持单纯的图层名,也支持服务名称(图层名)。(getFeatureInfo)
17+
* @param {String} [option.srs] 空间坐标参考系。(getFeatureInfo)
18+
* @param {String} [option.bbox] 显示范围,坐标用minx,miny,maxx,maxy表示(1.1.1版本),坐标用miny,minx,maxy,maxx表示(1.3.0版本),与srs对应设置可以达到动态投影的效果。(getFeatureInfo)
19+
* @param {String} [option.width = "1024"] 输出地图图片的象素宽。(getFeatureInfo)
20+
* @param {String} [option.height = "768"] 输出地图图片的象素高。(getFeatureInfo)
21+
* @param {String} [option.style = "default"] 图层样式,用逗号分隔各图层对应的样式。(getFeatureInfo)
22+
* @param {String} [option.format = "image/png"] 输出图象的类型,支持三种格式gif、png、jpg。(getFeatureInfo)
23+
*/
24+
class WMS extends OGCService {
25+
constructor(option) {
26+
var options = option || {};
27+
super(options);
28+
29+
this.url = options.url;
30+
}
31+
32+
isBaseUrl() {
33+
let valid = false;
34+
const name = 'WMSServer';
35+
const length = this.url.length;
36+
const index = this.url.indexOf(name) + name.length;
37+
let fullurl = this.url;
38+
if (index === length) {
39+
fullurl = `${this.url}?request=GetCapabilities&service=WMS`;
40+
valid = true;
41+
} else if (index === length - 1) {
42+
fullurl = `${this.url}request=GetCapabilities&service=WMS`;
43+
valid = true;
44+
}
45+
return valid;
46+
}
47+
48+
async makeFullUrl() {
49+
if (this.isBaseUrl()) {
50+
let json = await this.getCapabilities();
51+
let { height, width, crs, format, version, styles } = this;
52+
let layers = json.WMT_MS_Capabilities.Capability.Layer.Layer.map((l) => l.Name).toString();
53+
let object = {
54+
service: 'WMS',
55+
request: 'GetMap',
56+
layers,
57+
styles: styles || '',
58+
format: format || 'image/png',
59+
transparent: true,
60+
version: version || '1.1.1',
61+
height: height || 256,
62+
width: width || 256,
63+
srs: crs || 'EPSG:4326'
64+
};
65+
let fullurl = `${this.url}?${qs.stringify(object)}`;
66+
return fullurl;
67+
}
68+
}
69+
70+
async getCapabilities() {
71+
const name = 'WMSServer';
72+
const length = this.url.length;
73+
const index = this.url.indexOf(name) + name.length;
74+
let fullurl = this.url;
75+
if (index === length) {
76+
fullurl = `${this.url}?request=GetCapabilities&service=WMS`;
77+
} else if (index === length - 1) {
78+
fullurl = `${this.url}request=GetCapabilities&service=WMS`;
79+
}
80+
let res = await axios.get(fullurl);
81+
let data = res.data;
82+
let obj = xml.getTraversalObj(data, {});
83+
let json = xml.convertToJson(obj, {});
84+
return json;
85+
}
86+
}
87+
export { WMS };
88+
MapGIS.OGC.WMS = WMS;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
*@module OpenGeospatialConsortium服务
3+
*/
4+
import { WMS } from './WMS';
5+
import { WFS } from './WFS';
6+
export { WMS, WFS };

src/service/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,12 +424,15 @@ export const Info = {
424424
};
425425

426426
import { WMSCapabilities, WMTSCapabilities, OGCWMTSInfo, OGCWMSInfo } from './OGC';
427+
import { WMS, WFS } from './OpenGeospatialConsortium';
427428

428429
export const OGC = {
429430
WMSCapabilities,
430431
WMTSCapabilities,
431432
OGCWMTSInfo,
432-
OGCWMSInfo
433+
OGCWMSInfo,
434+
WMS,
435+
WFS
433436
};
434437

435438
import {

0 commit comments

Comments
 (0)