import { Zondy } from '../../base'
import { Layer } from './baseLayer'
import { defaultValue } from '../../util'
import { LayerType, LoadStatus } from '../../base/enum'
import { M3DServer } from '../../service'
import { jsonClone } from '../../util/Utils'
/**
* M3D缓存图层
* @class M3DModelCacheLayer
* @moduleEX LayerModule
* @extends Layer
* @param {Object} options 构造参数
* @param {String} [options.url] 服务基地址
* @param {Object} [options.extendOptions] 初始化场景图层的额外参数,三维引擎专有的初始化参数请传入此对象
* @param {Object} [options.extendProps] 存储额外参数的属性
*/
class M3DModelCacheLayer extends Layer {
constructor(options) {
super(options)
options = defaultValue(options, {})
/**
* 服务基地址
* @member {String} M3DModelCacheLayer.prototype.url
*/
this.url = defaultValue(options.url, '')
/**
* 图层类型
* @member {String} M3DModelCacheLayer.prototype.type
*/
this.type = LayerType.m3dCache
/**
* 服务版本号
* @member {String} M3DModelCacheLayer.prototype.version
*/
this.version = undefined
/**
* 模型外包盒
* @member {Object} M3DModelCacheLayer.prototype.boundingVolume
*/
this.boundingVolume = undefined
/**
* 服务名
* @member {String} M3DModelCacheLayer.prototype.sceneName
*/
this.sceneName = undefined
/**
* 服务包含的表字段数组
* @member {String} M3DModelCacheLayer.prototype.fieldInfo
*/
this.fieldInfo = undefined
/**
* 模型位置
* @member {Object} M3DModelCacheLayer.prototype.position
*/
this.position = undefined
/**
* 模型坐标系
* @member {Object} M3DModelCacheLayer.prototype.spatialReference
*/
this.spatialReference = undefined
/**
* 描述信息
* @member {String} M3DModelCacheLayer.prototype.description
*/
this.description = 'M3D图层'
/**
* 初始化图层的额外参数,三维引擎专有的初始化参数请传入此对象
* @member {Object} M3DModelCacheLayer.prototype.extendOptions
*/
this.extendOptions = defaultValue(options.extendOptions, {})
this._m3dServer = new M3DServer({
url: this.url
})
}
/**
* 查询图层信息
* */
load() {
return super.load()
}
/**
* 子类加载服务端元信息的方法
* @private
* */
_load() {
const self = this
return new Promise((resolve) => {
self.loadStatus = LoadStatus.loaded
self.loaded = true
resolve(self)
})
}
/**
* 将图层转为json对象
* @return {Object} josn对象
* */
toJSON() {
const _json = super.toJSON()
_json.url = this.url
_json.type = this.type
_json.version = this.version
_json.boundingVolume = this.boundingVolume
_json.sceneName = this.sceneName
_json.fieldInfo = this.fieldInfo
_json.position = this.position
_json.spatialReference = this.spatialReference
_json.description = this.description
_json.extendOptions = this.extendOptions
return _json
}
static fromJSON(json) {
json = jsonClone(json)
const _layer = new M3DModelCacheLayer(json)
_layer._isFromJSON = true
return _layer
}
/**
* 克隆图层对象
* @return {M3DModelCacheLayer} 克隆后的图层对象
*/
clone() {
return new M3DModelCacheLayer(this.toJSON())
}
}
/**
* 通过url创建图层对象
* @param {String} url 服务基地址
* @return {IGSMapImageLayer} 新的图层对象
* */
M3DModelCacheLayer.fromServerUrl = function (url) {
return new M3DModelCacheLayer({
url
})
}
Zondy.Layer.M3DModelCacheLayer = M3DModelCacheLayer
export default M3DModelCacheLayer