Skip to content

Commit a2dcd94

Browse files
committed
重构对接iPortal rest API的js类结构,新增资源请求参数类、资源结果封装类以及单个资源详情类(具体实现还没完成)。--reviewed by 许佳明
1 parent 012391e commit a2dcd94

File tree

4 files changed

+216
-0
lines changed

4 files changed

+216
-0
lines changed

src/common/iPortal/iPortal.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import { IPortalScene } from "./iPortalScene";
1414
import { IPortalServiceBase } from "./iPortalServiceBase";
1515
import { IPortalMapdashboard } from "./iPortalMapdashboard";
1616
import { IPortalMapdashboardsQueryParam } from "./iPortalMapdashboardsQueryParam";
17+
import { IPortalQueryParam } from "./iPortalQueryParam";
18+
import { IPortalQueryResult } from "./iPortalQueryResult";
19+
import { IPortalResource } from "./iPortalResource";
1720

1821
/**
1922
* @class SuperMap.iPortal
@@ -39,6 +42,32 @@ export class IPortal extends IPortalServiceBase {
3942
return FetchRequest.get(this.iportalUrl + "/web");
4043
}
4144

45+
/**
46+
* @function SuperMap.iPortal.prototype.queryResources
47+
* @description 查询资源。
48+
* @param {SuperMap.iPortalQueryParam} queryParams - 查询参数。
49+
* @returns {Promise} 返回包含所有资源结果的 Promise 对象。
50+
*/
51+
queryResources(queryParams) {
52+
if (!(queryParams instanceof IPortalQueryParam)) {
53+
return null;
54+
}
55+
//http://rdc.ispeco.com/gateway/catalog/resource/search.json?aggregationTypes=%5B%22TYPE%22%5D&t=1574736505796&pageSize=12&currentPage=1&orderBy=UPDATETIME&orderType=DESC&tags=%5B%5D&dirIds=%5B%5D&searchType=PUBLIC&resourceSubTypes=%5B%5D
56+
var resourceUrl = this.iportalUrl + "/gateway/catalog/resource/search.json";
57+
return this.request("GET", resourceUrl, queryParams).then(function(result) {
58+
var content = [];
59+
result.content.forEach(function(item) {
60+
content.push(new IPortalResource(resourceUrl, item));
61+
});
62+
let queryResult = new IPortalQueryResult();
63+
queryResult.content = content;
64+
queryResult.total = result.total;
65+
66+
return queryResult;
67+
});
68+
}
69+
70+
4271
/**
4372
* @function SuperMap.iPortal.prototype.queryServices
4473
* @description 查询服务。
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/* Copyright© 2000 - 2019 SuperMap Software Co.Ltd. All rights reserved.
2+
* This program are made available under the terms of the Apache License, Version 2.0
3+
* which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
4+
import {SuperMap} from '../SuperMap';
5+
import {Util} from '../commontypes/Util';
6+
7+
/**
8+
* @class SuperMap.IPortalQueryParam
9+
* @classdesc iPortal 资源查询参数。
10+
* @category iPortal/Online
11+
* @param {Object} params - iPortal 资源查询具体参数。
12+
*
13+
*/
14+
export class IPortalQueryParam {
15+
16+
constructor(params) {
17+
params = params || {};
18+
this.userNames = null;
19+
this.tags = null;
20+
this.suggest = false;
21+
this.sourceTypes = null;
22+
this.keywords = null;
23+
this.epsgCode = null;
24+
this.orderBy = null;
25+
this.currentPage = null;
26+
this.pageSize = null;
27+
this.dirIds = null;
28+
this.isNotInDir = false;
29+
this.updateStart = null;
30+
this.updateEnd = null;
31+
this.visitStart = null;
32+
this.visitEnd = null;
33+
this.filterFields = null;
34+
Util.extend(this, params);
35+
}
36+
37+
}
38+
39+
SuperMap.iPortalQueryParam = IPortalQueryParam;
40+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/* Copyright© 2000 - 2019 SuperMap Software Co.Ltd. All rights reserved.
2+
* This program are made available under the terms of the Apache License, Version 2.0
3+
* which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
4+
import {SuperMap} from '../SuperMap';
5+
import {Util} from '../commontypes/Util';
6+
7+
/**
8+
* @class SuperMap.iPortalQueryResult
9+
* @classdesc iPortal 资源结果集封装类。
10+
* @category iPortal/Online
11+
* @param {string} resourceUrl - 资源地址。
12+
* @param {Object} [params] - 资源参数。
13+
*
14+
*/
15+
export class IPortalQueryResult {
16+
constructor(mapUrl, params) {
17+
super(mapUrl);
18+
params = params || {};
19+
this.authorizeSetting = [];
20+
this.center = "";
21+
this.controls = null;
22+
this.checkStatus = "";
23+
this.createTime = 0;
24+
this.description = "";
25+
this.epsgCode = 0;
26+
this.extent = "";
27+
this.id = 0;
28+
this.isDefaultBottomMap = false;
29+
this.layers = [];
30+
this.level = null;
31+
this.nickname = "";
32+
this.sourceType = "";
33+
this.status = null;
34+
this.tags = [];
35+
this.thumbnail = "";
36+
this.title = "";
37+
this.units = null;
38+
this.updateTime = 0;
39+
this.userName = "";
40+
this.visitCount = 0;
41+
Util.extend(this, params);
42+
this.mapUrl = mapUrl;
43+
}
44+
45+
}
46+
47+
SuperMap.iPortalQueryResult = IPortalQueryResult;
48+
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/* Copyright© 2000 - 2019 SuperMap Software Co.Ltd. All rights reserved.
2+
* This program are made available under the terms of the Apache License, Version 2.0
3+
* which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
4+
import {SuperMap} from '../SuperMap';
5+
import {Util} from '../commontypes/Util';
6+
import {IPortalServiceBase} from './iPortalServiceBase';
7+
8+
/**
9+
* @class SuperMap.IPortalResource
10+
* @classdesc iPortal 资源详情类。
11+
* @category iPortal/Online
12+
* @param {string} resourceUrl - 资源地址。
13+
* @param {Object} [resourceInfo] - 资源详情参数。
14+
* @extends {SuperMap.iPortalServiceBase}
15+
*
16+
*/
17+
export class IPortalResource extends IPortalServiceBase {
18+
constructor(mapUrl, resourceInfo) {
19+
super(mapUrl);
20+
resourceInfo = resourceInfo || {};
21+
this.authorizeSetting = [];
22+
this.center = "";
23+
this.controls = null;
24+
this.checkStatus = "";
25+
this.createTime = 0;
26+
this.description = "";
27+
this.epsgCode = 0;
28+
this.extent = "";
29+
this.id = 0;
30+
this.isDefaultBottomMap = false;
31+
this.layers = [];
32+
this.level = null;
33+
this.nickname = "";
34+
this.sourceType = "";
35+
this.status = null;
36+
this.tags = [];
37+
this.thumbnail = "";
38+
this.title = "";
39+
this.units = null;
40+
this.updateTime = 0;
41+
this.userName = "";
42+
this.visitCount = 0;
43+
Util.extend(this, resourceInfo);
44+
this.mapUrl = mapUrl;
45+
// if (this.id) {
46+
// this.mapUrl = mapUrl + "/" + this.id;
47+
// }
48+
}
49+
50+
/**
51+
* @function SuperMap.iPortalMap.prototype.load
52+
* @description 加载地图信息。
53+
* @returns {Promise} 返回 Promise 对象。如果成功,Promise 没有返回值,请求返回结果自动填充到该类的属性中;如果失败,Promise 返回值包含错误信息。
54+
*/
55+
load() {
56+
var me = this;
57+
return me.request("GET", me.mapUrl + ".json")
58+
.then(function (mapInfo) {
59+
if (mapInfo.error) {
60+
return mapInfo;
61+
}
62+
for (var key in mapInfo) {
63+
me[key] = mapInfo[key];
64+
}
65+
});
66+
}
67+
68+
/**
69+
* @function SuperMap.iPortalMap.prototype.update
70+
* @description 更新地图参数。
71+
* @returns {Promise} 返回包含更新操作状态的 Promise 对象。
72+
*/
73+
update() {
74+
var mapUpdateParam = {
75+
units: this.units,
76+
level: this.level,
77+
center: this.center,
78+
controls: this.controls,
79+
description: this.description,
80+
epsgCode: this.epsgCode,
81+
extent: this.extent,
82+
status: this.status,
83+
tags: this.tags,
84+
layers: this.layers,
85+
title: this.title,
86+
thumbnail: this.thumbnail,
87+
sourceType: this.sourceType,
88+
authorizeSetting: this.authorizeSetting
89+
};
90+
var options = {
91+
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
92+
};
93+
return this.request("PUT", this.mapUrl, JSON.stringify(mapUpdateParam), options);
94+
}
95+
96+
}
97+
98+
SuperMap.iPortalMap = IPortalMap;
99+

0 commit comments

Comments
 (0)