import Zondy from '../../Zondy'
import { defaultValue } from '../../../util'
import { AnchorType, Symbol3DLayerType } from '../../enum'
import { ColorMaterial, IconResource, PointSymbol3DOutline } from '../support'
import { Color } from '../../index'
import { Point } from '../../geometry'
/**
* 三维图标符号图层,用来在三维场景中绘制图标,不支持二维地图视图<br/>
* 支持使用网络图片资源或者使用系统自带的图标资源<br/>
* 是一个始终朝向屏幕,并且立起来的图标<br/>
* 示例如下:<br/>
* <a href='#IconSymbol3DLayer-href'>[1、使用网络资源创建一个三维图标图层对象]</a><br/>
* <a href='#IconSymbol3DLayer-primitive'>[2、使用系统自带资源创建一个三维图标图层对象]</a><br/>
*
* @class IconSymbol3DLayer
* @moduleEX SymbolModule
* @extends Symbol3DLayer
* @param {Object} options 构造参数
* @param {IconResource} [options.resource = new IconResource()] 图标的资源,如果没有设置图标资源,则使用系统自带的图标;<br/>
* 系统支持的图标类型有:'circle'|'square'|'cross'|'x'|'kite'|'triangle'
* @param {Number} [options.size = 1] 图标的大小,单位像素
* @param {ColorMaterial} [options.material = new ColorMaterial()] 材质,目前支持的材质有:<br/>
* ColorMaterial: 纯色材质,当图标的资源是网络图片时,指的是图标的覆盖物颜色,通过覆盖物颜色的透明度可以来更改图标的透明度;当图标的资源是是系统自带的图标时,指的是填充颜色
* @param {PointSymbol3DOutline} [options.outline = new PointSymbol3DOutline()] 外边线样式,仅当图标的资源是系统自带的图标时有效
* @param {AnchorType} [options.anchor = AnchorType.center] 锚点,指的图标相对于原始坐标点的位置
* @param {Point} [options.anchorPosition = new Point({coordinates: [0, 0]})] 锚点相对偏移量,即屏幕像素偏移
*
* @summary <h5>支持如下方法:</h5>
* <a href='#fromJSON'>[1、通过json数据构造一个IconSymbol3DLayer对象]</a><br/>
* <a href='#toJSON'>[2、导出为json数据]</a><br/>
* <a href='#clone'>[3、克隆并返回一个新的IconSymbol3DLayer对象]</a><br/>
*
* @example <caption><h7 id='IconSymbol3DLayer-href'>使用网络资源创建一个三维图标图层对象</h7></caption>
* // ES5引入方式
* const { Color } = Zondy
* const { IconSymbol3DLayer, IconResource } = Zondy.Symbol
* // ES6引入方式
* import { IconSymbol3DLayer, IconResource, Color } from "@mapgis/webclient-common"
*
* // 创建三维图标符号图层
* const iconSymbol3DLayer = new IconSymbol3DLayer({
* // 设置资源地址
* resource: new IconResource({
* href: '图片的网络资源'
* }),
* // 设置图标大小,单位像素
* size: 50
* })
*
* @example <caption><h7 id='IconSymbol3DLayer-primitive'>使用系统自带资源创建一个三维图标图层对象</h7></caption>
* // ES5引入方式
* const { Color } = Zondy
* const { IconSymbol3DLayer, IconResource } = Zondy.Symbol
* // ES6引入方式
* import { IconSymbol3DLayer, IconResource, Color } from "@mapgis/webclient-common"
*
* // 创建三维图标符号图层
* const iconSymbol3DLayer = new IconSymbol3DLayer({
* // 设置资源地址
* resource: new IconResource({
* // 创建一个圆形图标
* primitive: 'circle'
* }),
* // 设置图标大小,单位像素
* size: 50
* })
* */
class IconSymbol3DLayer {
constructor(options) {
options = defaultValue(options, {})
/**
* 三维符号图层类型
* @member {Symbol3DLayerType} IconSymbol3DLayer.prototype.type
*/
this.type = Symbol3DLayerType.icon
/**
* 锚点,指的图标相对于原始坐标点的位置
* @member {AnchorType} IconSymbol3DLayer.prototype.anchor
*/
this.anchor = defaultValue(options.anchor, AnchorType.center)
/**
* 锚点相对偏移量,即屏幕像素偏移
* @member {Point} IconSymbol3DLayer.prototype.anchorPosition
*/
this.anchorPosition = options.anchorPosition
? Point.fromJSON(options.anchorPosition)
: new Point({
coordinates: [0, 0]
})
/**
* 材质
* @member {ColorMaterial} IconSymbol3DLayer.prototype.material
*/
this.material = options.material
? ColorMaterial.fromJSON(options.material)
: new ColorMaterial({
color: new Color(255, 255, 255, 1)
})
/**
* 外边线样式
* @member {PointSymbol3DOutline} IconSymbol3DLayer.prototype.outline
*/
this.outline = options.outline
? PointSymbol3DOutline.fromJSON(options.outline)
: new PointSymbol3DOutline()
/**
* 图标的资源,如果没有设置图标资源,则使用系统自带的图标
* @member {IconResource} IconSymbol3DLayer.prototype.resource
*/
this.resource = options.resource
? IconResource.fromJSON(options.resource)
: new IconResource()
/**
* 图标的大小,单位像素
* @member {Number} IconSymbol3DLayer.prototype.size
*/
this.size = defaultValue(options.size, 12)
}
/**
* <a id='fromJSON'/>
* 通过json数据构造一个IconSymbol3DLayer对象
* @param {Object} json json数据
* @return {LineCallout3D} 新的IconSymbol3DLayer对象
* */
static fromJSON(json) {
return new IconSymbol3DLayer(json)
}
/**
* <a id='toJSON'/>
* 导出为json数据
* @return {Object} 导出的json数据
* */
toJSON() {
return {
type: this.type,
anchor: this.anchor,
anchorPosition: JSON.parse(JSON.stringify(this.anchorPosition)),
material: this.material,
outline: this.outline.toJSON(),
resource: this.resource.toJSON(),
size: this.size
}
}
/**
* <a id='clone'/>
* 克隆并返回一个新的IconSymbol3DLayer对象
* @return {IconSymbol3DLayer} 新的IconSymbol3DLayer对象
* */
clone() {
return new IconSymbol3DLayer(this.toJSON())
}
}
Zondy.Symbol.IconSymbol3DLayer = IconSymbol3DLayer
export default IconSymbol3DLayer