import Zondy from '../../Zondy'
import { defaultValue, toJSON } from '../../../util'
import { AnchorType, Symbol3DLayerType } from '../../enum'
import { ColorMaterial, IconResource } from '../support'
import Symbol3DLayer from './Symbol3DLayer'
import { Point } from '../../geometry'
import { Color } from '../../../base'
/**
* 三维体对象符号图层,使用三维体符号来绘制一个点几何要素<br/>
* 通过设置resource的primitive属性来设置符号形状,支持如下形状:<br/>
* sphere、cylinder、cube、cone、inverted-cone、diamond、tetrahedron<br/>
* 也可通过设置resource中的href属性,来加载gltf数据<br/>
* 同时通过设置material属性来设置符号的外观<br/>
* 示例如下:<br/>
* <a href='#ObjectSymbol3DLayer-href'>[1、使用网络资源创建一个三维体对象符号图层对象]</a><br/>
* <a href='#ObjectSymbol3DLayer-primitive'>[2、使用系统自带资源创建一个三维体对象符号图层对象]</a><br/>
*
* @class ObjectSymbol3DLayer
* @moduleEX SymbolModule
* @extends Symbol3DLayer
* @param {Object} options 构造参数
* @param {IconResource} [options.resource = new IconResource()] 图标的资源,如果设置了href则表明使用网络gltf资源,如果设置了primitive则表明使用系统自带的资源<br/>
* 系统自带资源类型:'sphere'|'cylinder'|'cube'|'cone'|'inverted-cone'|'diamond'|'tetrahedron'
* @param {ColorMaterial} [options.material = new ColorMaterial() ] 符号材质,目前支持的材质有:<br/>
* ColorMaterial: 纯色材质,当图标的资源是网络gltf资源时,指的是模型的覆盖物颜色,通过覆盖物颜色的透明度可以来更改图标的透明度;当图标的资源是是系统自带的图标时,指的是几何体填充颜色
* @param {Number} [options.height = 10] 符号高度,当资源类型是gltf时,表明模型平面高度,当资源类型是系统自带类型时,表明几何体平面高度
* @param {Number} [options.width = 10] 符号宽度,当资源类型是gltf时,表明模型宽平面度,当资源类型是系统自带类型时,表明几何体平面宽度
* @param {Number} [options.depth = 10] 符号深度,当资源类型是gltf时,表明模型深度,当资源类型是系统自带类型时,表明几何体深度
* @param {Boolean} [options.castShadows = true] 是否显示阴影
* @param {Number} [options.heading = 0] 物体水平方向的旋转角度,z轴
* @param {Number} [options.roll = 0] 物体横向垂直面方向的旋转角度,y轴
* @param {Number} [options.tilt = 0] 物体纵向垂直面方向的旋转角度,x轴
* @param {AnchorType} [options.anchor = AnchorType.center] 锚点,指的图标相对于原始坐标点的位置,支持"center"|"top"|"bottom"|"origin"|"relative"
* @param {Point} [options.anchorPosition = new Point({coordinates: [0, 0]})] 锚点相对偏移量
*
* @summary <h5>支持如下方法:</h5>
* <a href='#fromJSON'>[1、通过json数据构造一个ObjectSymbol3DLayer对象]</a><br/>
* <a href='#toJSON'>[2、导出为JSON对象]</a><br/>
* <a href='#clone'>[3、克隆并返回一个新的ObjectSymbol3DLayer对象]</a><br/>
*
* @example <caption><h7 id='ObjectSymbol3DLayer-href'>使用网络资源创建一个三维体对象符号图层对象</h7></caption>
* // ES5引入方式
* const { Color } = Zondy
* const { ObjectSymbol3DLayer, IconResource, ColorMaterial } = Zondy.Symbol
* // ES6引入方式
* import { ObjectSymbol3DLayer, IconResource, ColorMaterial, Color } from "@mapgis/webclient-common"
*
* // 创建一个三维体对象符号图层对象
* const symbol = new ObjectSymbol3DLayer({
* // 网络资源
* resource: new IconResource({
* href: 'gltf网络资源'
* }),
* // 模型覆盖物颜色
* material: new ColorMaterial({
* color: new Color(255, 1, 1, 1)
* }),
* // 模型高度
* height: 1000,
* // 模型宽度
* width: 1000,
* // 模型深度
* depth: 1000
* })
*
* @example <caption><h7 id='ObjectSymbol3DLayer-primitive'>使用系统自带资源创建一个三维体对象符号图层对象</h7></caption>
* // ES5引入方式
* const { Color } = Zondy
* const { ObjectSymbol3DLayer, IconResource, ColorMaterial } = Zondy.Symbol
* // ES6引入方式
* import { ObjectSymbol3DLayer, IconResource, ColorMaterial, Color } from "@mapgis/webclient-common"
*
* // 创建一个三维体对象符号图层对象
* const symbol = new ObjectSymbol3DLayer({
* // 自带资源
* resource: new IconResource({
* // 创建一个椭球
* primitive: 'sphere'
* }),
* // 覆盖物颜色
* material: new ColorMaterial({
* color: new Color(255, 1, 1, 1)
* }),
* // 椭球半径
* height: 1000,
* // 椭球半径
* width: 1000,
* // 椭球半径
* depth: 1000
* })
* */
class ObjectSymbol3DLayer extends Symbol3DLayer {
constructor(options) {
super(options)
options = defaultValue(options, {})
/**
* 类型
* @member {Symbol3DLayerType} ObjectSymbol3DLayer.prototype.type
*/
this.type = Symbol3DLayerType.object
/**
* 锚点,指的图标相对于原始坐标点的位置,支持"center"|"top"|"bottom"|"origin"|"relative"
* @member {AnchorType} ObjectSymbol3DLayer.prototype.anchor
*/
this.anchor = defaultValue(options.anchor, AnchorType.center)
/**
* 锚点相对偏移量
* @member {Point} ObjectSymbol3DLayer.prototype.anchorPosition
*/
this.anchorPosition = options.anchorPosition
? Point.fromJSON(options.anchorPosition)
: new Point({
coordinates: [0, 0]
})
/**
* 是否显示阴影
* @member {Boolean} ObjectSymbol3DLayer.prototype.castShadows
*/
this.castShadows = defaultValue(options.castShadows, true)
/**
* 符号深度
* @member {Number} ObjectSymbol3DLayer.prototype.depth
*/
this.depth = defaultValue(options.depth, 10)
/**
* 物体水平方向的旋转角度,z轴
* @member {Number} ObjectSymbol3DLayer.prototype.heading
*/
this.heading = defaultValue(options.heading, 0)
/**
* 符号高度
* @member {Number} ObjectSymbol3DLayer.prototype.height
*/
this.height = defaultValue(options.height, 10)
/**
* 符号材质
* @member {Object} ObjectSymbol3DLayer.prototype.material
*/
this.material = options.material
? ColorMaterial.fromJSON(options.material)
: new ColorMaterial({
color: new Color(255, 255, 255, 1)
})
/**
* 图标的资源,如果没有设置图标资源,则使用系统自带的图标
* @member {IconResource} ObjectSymbol3DLayer.prototype.resource
*/
this.resource = options.resource
? IconResource.fromJSON(options.resource)
: new IconResource()
/**
* 物体横向垂直面方向的旋转角度,y轴
* @member {Number} ObjectSymbol3DLayer.prototype.roll
*/
this.roll = defaultValue(options.roll, 0)
/**
* 物体纵向垂直面方向的旋转角度,x轴
* @member {Number} ObjectSymbol3DLayer.prototype.tilt
*/
this.tilt = defaultValue(options.tilt, 0)
/**
* 符号宽度
* @member {Number} ObjectSymbol3DLayer.prototype.width
*/
this.width = defaultValue(options.width, 10)
}
/**
* <a id='fromJSON'/>
* 通过json数据构造一个ObjectSymbol3DLayer对象
* @param {Object} json json数据
* @return {ObjectSymbol3DLayer} 新的ObjectSymbol3DLayer对象
* */
static fromJSON(json) {
return new ObjectSymbol3DLayer(json)
}
/**
* <a id='toJSON'></a>
* 导出为JSON对象
* @return {Object} JSON对像
*/
toJSON() {
return {
type: this.type,
anchor: this.anchor,
anchorPosition: toJSON(this.anchorPosition, Point),
castShadows: this.castShadows,
depth: this.depth,
heading: this.heading,
height: this.height,
material: toJSON(this.material, ColorMaterial),
resource: toJSON(this.resource, IconResource),
roll: this.roll,
tilt: this.tilt,
width: this.width
}
}
/**
* <a id='clone'/>
* 克隆并返回一个新的ObjectSymbol3DLayer对象
* @return {ObjectSymbol3DLayer} 新的ObjectSymbol3DLayer对象
* */
clone() {
return new ObjectSymbol3DLayer(this.toJSON())
}
}
Zondy.Symbol.ObjectSymbol3DLayer = ObjectSymbol3DLayer
export default ObjectSymbol3DLayer