import FillSymbol from './FillSymbol'
import { SymbolType } from '../enum'
import { defaultValue } from '../../util'
import Zondy from '../Zondy'
/**
* 图片填充符号
* @class PictureFillSymbol
* @extends FillSymbol
* @moduleEX SymbolModule
* @param {options} options 构造参数
* @param {String} [options.url] 图片请求地址,支持baseUrl
* @param {Number} [options.width = 12] 简单填充符号宽度,默认为12,单位像素
* @param {Number} [options.height = 12] 简单填充符号高度,默认为12,单位像素
* @param {Number} [options.xoffset = 0] x方向偏移,默认为0,单位像素
* @param {Number} [options.yoffset = 0] y方向偏移,默认为0,单位像素
* @param {Number} [options.xscale = 1] x方向拉伸,取值在0-1之间
* @param {Number} [options.yscale = 1] y方向拉伸,取值在0-1之间
*
* @summary <h5>支持如下方法:</h5>
* <a href='#fromJSON'>[1、将JSON格式的符号转换为JS对象]</a><br/>
* <a href='#toJSON'>[2、将JS对象转换为JSON格式]</a><br/>
* <a href='#clone'>[3、克隆并返回新的符号对象]</a>
*
* @example <caption><h7 id='new-PictureMarkerSymbol'>创建图片填充符号对象</h7></caption>
* // ES5引入方式
* const { PictureFillSymbol } = Zondy.Symbol
* // ES6引入方式
* import { PictureFillSymbol } from "@mapgis/webclient-common"
* const pictureFillSymbol = new PictureFillSymbol({
* // 图片请求地址
* url: '图片请求地址',
* // 简单填充符号宽度,默认为12,单位像素
* width: 12,
* // 简单填充符号高度,默认为12,单位像素
* height: 12,
* // x方向偏移,默认为0,单位像素
* xoffset: 0,
* // y方向偏移,默认为0,单位像素
* yoffset: 0,
* // x方向拉伸,取值在0-1之间
* xscale: 1,
* // y方向拉伸,取值在0-1之间
* yscale: 1
* });
*/
class PictureFillSymbol extends FillSymbol {
constructor(options) {
super(options)
options = defaultValue(options, {})
/**
* 符号类型
* @member {String} PictureFillSymbol.prototype.type
*/
this.type = SymbolType.pictureFill
/**
* 简单填充符号高度,默认为12,单位像素
* @member {Number} PictureFillSymbol.prototype.height
*/
this.height = defaultValue(options.height, 12)
/**
* 图片请求地址
* @member {String} PictureFillSymbol.prototype.url
*/
this.url = defaultValue(options.url, '')
/**
* 简单填充符号宽度,默认为12,单位像素
* @member {Number} PictureFillSymbol.prototype.width
*/
this.width = defaultValue(options.width, 12)
/**
* x方向偏移,默认为0,单位像素
* @member {Number} PictureFillSymbol.prototype.xoffset
*/
this.xoffset = defaultValue(options.xoffset, 0)
/**
* x方向拉伸,取值在0-1之间
* @member {Number} PictureFillSymbol.prototype.xscale
*/
this.xscale = defaultValue(options.xscale, 1)
/**
* y方向偏移,默认为0,单位像素
* @member {Number} PictureFillSymbol.prototype.yoffset
*/
this.yoffset = defaultValue(options.yoffset, 0)
/**
* y方向拉伸,取值在0-1之间
* @member {String} PictureFillSymbol.prototype.yscale
*/
this.yscale = defaultValue(options.yscale, 1)
}
/**
* <a id="fromJSON"/>
* 将JSON格式的符号转换为JS对象
* @param {Object} json 符号的实例化对象
*/
static fromJSON(json) {
json = defaultValue(json, {})
return new PictureFillSymbol(json)
}
/**
* <a id="fromJSON"/>
* 将JS对象转换为JSON格式
* @returns {Object} 符号的实例化JSON
*/
toJSON() {
return {
type: this.type,
height: this.height,
outline: this.outline.toJSON(),
url: this.url,
width: this.width,
xoffset: this.xoffset,
xscale: this.xscale,
yoffset: this.yoffset,
yscale: this.yscale
}
}
/**
* <a id="clone"/>
* 克隆并返回新的符号对象
* @return {PictureFillSymbol} 克隆后的新符号对象
*/
clone() {
return new PictureFillSymbol(this.toJSON())
}
}
Zondy.Symbol.PictureFillSymbol = PictureFillSymbol
export default PictureFillSymbol