|
| 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