类名 common/base/symbol/MapGISTextSymbol.js
import Zondy from '../Zondy'
import { defaultValue } from '../../util'
import { SymbolType } from '../enum'
import Color from '../Color'
import TextSymbol from './TextSymbol'

/**
 * 文本符号,支持点几何对象,参考示例:<a href='#new-MapGISTextSymbol'>[创建文本样式]</a>
 * <br><br>[ES5引入方式]:<br/>
 * Zondy.Symbol.MapGISTextSymbol() <br/>
 * [ES6引入方式]:<br/>
 * import { MapGISTextSymbol } from "@mapgis/webclient-common" <br/>
 * <br/>
 * @class MapGISTextSymbol
 * @moduleEX SymbolModule
 * @extends Symbol
 * @param {Object} options 构造参数
 * @param {Array<Number>} [options.backgroundPadding = [5,5]] 背景内边距
 * @param {Image|Fuction} [options.backgroundImage] 背景图片样式,设置时会覆盖backgroundColor
 * @param {String} [options.textDecorationUnderlineColor] 文字下划线颜色
 * @param {Number} [options.textDecorationUnderlineWidth] 文字下划线宽度
 * @param {String} [options.textDecorationThroughlineColor] 文字删除线颜色
 * @param {Number} [options.textDecorationThroughlineWidth] 文字删除线宽度
 * @param {Number} [options.textShadowOffsetX = 0] 文字阴影横轴偏移
 * @param {Number} [options.textShadowOffsetY = 0] 文字阴影纵轴偏移
 * @param {Number} [options.textShadowBlur = 1] 文字阴影模糊度
 * @param {String} [options.textShadowColor] 文字阴影颜色
 * @param {Number} [options.letterSpacing = 0] 文字间距
 * @param {Number} [options.lineMaxNum = 3] 文字最大行数
 * @param {Boolean} [options.textWraps = false] 是否换行
 * @param {Image} [options.textExtraIcon] 文字额外符号图标。测试接口,后续可能会改动。
 * @param {String} [options.textExtraIconAnchor = 'left'] 文字额外图标方位,可选"left" "right" "top" "bottom"。测试接口,后续可能会改动。
 * @param {Number} [options.textExtraIconSize = 14] 文字额外图标大小,单位像素。测试接口,后续可能会改动。
 * @summary <h5>支持如下方法:</h5>
 * <a href='#fromJSON'>[1、将JSON里的数据导入,并返回一个新的TextSymbol对象]</a><br/>
 * <a href='#toJSON'>[2、导出为JSON对象]</a><br/>
 * <a href='#clone'>[3、克隆并返回新的符号对象]</a><br/>
 *
 * @example <caption><h7 id='new-MapGISTextSymbol'>创建文本样式</h7></caption>
 * // ES5引入方式
 * const { MapGISTextSymbol } = Zondy.Symbol
 * const { MapGISTextSymbol, Color } = Zondy
 * // ES6引入方式
 * import { MapGISTextSymbol, Color } from "@mapgis/webclient-common"
 * const textSymbol = new MapGISTextSymbol({
 *   // 字体颜色
 *   color: new Color(252, 100, 22, 1),
 *   // 字体内容,如果是服务端数据,可不填
 *   text: "默认文字",
 *   // 字体样式
 *   font: {
 *     // 字体
 *     family: "微软雅黑",
 *     // 文字大小,单位像素
 *     size: 30,
 *     // 文字是否为斜体,正常模式
 *     style: "normal",
 *     // 文字粗细
 *     weight: "normal"
 *   }
 * })
 */
class MapGISTextSymbol extends TextSymbol {
  constructor(options) {
    super(options)
    options = defaultValue(options, {})
    /**
     * 符号类型
     * @member {String} MapGISTextSymbol.prototype.type
     */
    this.type = SymbolType.mapgisText
    /**
     * 文字背景内边距
     * @member {Array<Number>} MapGISTextSymbol.prototype.backgroundPadding
     */
    this.backgroundPadding = defaultValue(options.backgroundPadding, [5, 5])
    /**
     * 文字背景颜色
     * @member {Function|Image} MapGISTextSymbol.prototype.backgroundImage
     */
    this.backgroundImage = options.backgroundImage
    /**
     * 文字下划线颜色
     * @member {Color} MapGISTextSymbol.prototype.textDecorationUnderlineColor
     */
    this.textDecorationUnderlineColor = defaultValue(
      Color.fromColor(options.textDecorationUnderlineColor),
      undefined
    )
    /**
     * 文字下划线宽度
     * @member {Number} MapGISTextSymbol.prototype.textDecorationUnderlineWidth
     */
    this.textDecorationUnderlineWidth = defaultValue(
      options.textDecorationUnderlineWidth,
      0
    )
    /**
     * 文字删除线颜色
     * @member {Color} MapGISTextSymbol.prototype.textDecorationThroughlineColor
     */
    this.textDecorationThroughlineColor = defaultValue(
      Color.fromColor(options.textDecorationThroughlineColor),
      undefined
    )
    /**
     * 文字删除线宽度
     * @member {Number} MapGISTextSymbol.prototype.textDecorationThroughlineWidth
     */
    this.textDecorationThroughlineWidth = defaultValue(
      options.textDecorationThroughlineWidth,
      0
    )
    /**
     * 文字阴影横轴偏移
     * @member {Number} MapGISTextSymbol.prototype.textShadowOffsetX
     */
    this.textShadowOffsetX = defaultValue(options.textShadowOffsetX, 0)
    /**
     * 文字阴影纵轴偏移
     * @member {Number} MapGISTextSymbol.prototype.textShadowOffsetY
     */
    this.textShadowOffsetY = defaultValue(options.textShadowOffsetY, 0)
    /**
     * 文字阴影模糊度
     * @member {Number} MapGISTextSymbol.prototype.textShadowBlur
     */
    this.textShadowBlur = defaultValue(options.textShadowBlur, 1)
    /**
     * 文字阴影颜色
     * @member {Color} MapGISTextSymbol.prototype.textShadowColor
     */
    this.textShadowColor = defaultValue(
      Color.fromColor(options.textShadowColor),
      undefined
    )
    /**
     * 文字间距
     * @member {Number} MapGISTextSymbol.prototype.letterSpacing
     */
    this.letterSpacing = defaultValue(options.letterSpacing, 0)
    /**
     * 文字最大行数
     * @member {Number} MapGISTextSymbol.prototype.lineMaxNum
     */
    this.lineMaxNum = defaultValue(options.lineMaxNum, 3)
    /**
     * 是否换行
     * @member {Boolean} MapGISTextSymbol.prototype.textWraps
     */
    this.textWraps = defaultValue(options.textWraps, false)
    /**
     * 注记额外符号
     * @member {Image} MapGISTextSymbol.prototype.textExtraIcon
     */
    this.textExtraIcon = options.textExtraIcon
    /**
     * 图标方位 "left" "right" "top" "bottom"
     * @member {String} MapGISTextSymbol.prototype.textExtraIconAnchor
     */
    this.textExtraIconAnchor = defaultValue(options.textExtraIconAnchor, 'top')
    /**
     * 图标大小
     * @member {Number} MapGISTextSymbol.prototype.textExtraIconSize
     */
    this.textExtraIconSize = defaultValue(options.textExtraIconSize, 14)
  }

  /**
   * <a id='fromJSON'/>
   * 将JSON里的数据导入,并返回一个新的TextSymbol对象<a id='fromJSON'></a>
   * @param {Object} json 新的TextSymbol对象
   * @return {MapGISTextSymbol} 新的TextSymbol对象
   */
  static fromJSON(json) {
    json = defaultValue(json, {})
    return new MapGISTextSymbol(json)
  }

  /**
   * <a id='clone'/>
   * 克隆并返回新的符号对象
   * @return {MapGISTextSymbol} 克隆后的新符号对象
   */
  clone() {
    return new MapGISTextSymbol(this.toJSON())
  }

  /**
   * <a id='toJSON'/>
   * 导出为JSON对象
   * @return {Object} JSON对像
   */
  toJSON() {
    const json = super.toJSON()
    json.backgroundPadding = this.backgroundPadding
    json.textDecorationUnderlineColor = Color.fromColor(
      this.textDecorationUnderlineColor
    ).toJSON()
    json.textDecorationUnderlineWidth = this.textDecorationUnderlineWidth
    json.textDecorationThroughlineColor = Color.fromColor(
      this.textDecorationThroughlineColor
    ).toJSON()
    json.textDecorationThroughlineWidth = this.textDecorationThroughlineWidth
    json.textShadowOffsetX = this.textShadowOffsetX
    json.textShadowOffsetY = this.textShadowOffsetY
    json.textShadowBlur = this.textShadowBlur
    json.textShadowColor = Color.fromColor(this.textShadowColor).toJSON()
    json.letterSpacing = this.letterSpacing
    json.lineMaxNum = this.lineMaxNum
    json.textWraps = this.textWraps
    // 暂不处理textExtraIcon、backgroundImage等系列接口
    return json
  }
}
Zondy.Symbol.MapGISTextSymbol = MapGISTextSymbol
export default MapGISTextSymbol
构造函数
成员变量
方法
事件