类名 common/document/renderer/visualVariable/SizeVariable.js
import VisualVariable from './VisualVariable'
import { defaultValue } from '../../../util'
import VisualVariableType from '../../../base/enum/VisualVariableType'
import SizeStop from './support/SizeStop'
import { Zondy } from '../../../base'
/**
 * size视觉变量
 * @class SizeVariable
 * @moduleEX RendererModule
 * @param {Object} options 初始化参数
 * @param {Number} [options.maxDataValue] 最大数据值,超过这个数值以最大size显示
 * @param {Number} [options.maxSize] 符号最大size
 * @param {Number} [options.minDataValue] 最小数据值,小于这个数值以最小size显示
 * @param {Number} [options.minSize] 符号最小size
 * @param {Array<SizeStop>} [options.stops] 颜色分段数组
 * @example 
 * // 获取layer上renderer对象
 *  const renderer = layer.renderer
 * // 根据FID取值设置符号大小
 * // FID取值小于0时,设置符号大小为5
 * // FID取值大于300时 ,设置符号大小为20
 * // FID取值在0-300之间时,显示符号大小过渡值
 * // 设置size视觉变量方法一
 *  renderer.visualVariables = [{
          type: "size",
          field: "FID",
          minDataValue:0,
          maxDataValue:300,
          minSize:5,
          maxSize:20,
    }]
   // 设置size视觉变量方法二
  *  renderer.visualVariables = [
     {
          type: "size",
          valueExpression: "$feature.FID",
          stops:[
            {
              size:5,
              value:0
            },
            {
              size:20,
              value:300
            }
          ]
     }
  ]  
 */
class SizeVariable extends VisualVariable {
  constructor(options) {
    super(options)
    options = defaultValue(options, {})
    this.type = VisualVariableType.size
    /**
     * 最大数据值
     * @member {Number} SizeVariable.prototype.maxDataValue
     */
    this.maxDataValue = options.maxDataValue
    /**
     * 符号最大size
     * @member {Number} SizeVariable.prototype.maxSize
     */
    this.maxSize = options.maxSize
    /**
     * 最小数据值
     * @member {Number} SizeVariable.prototype.minDataValue
     */
    this.minDataValue = options.minDataValue
    /**
     * 符号最小size
     * @member {Number} SizeVariable.prototype.minSize
     */

    this.minSize = options.minSize
    /**
     * size分段数组
     * @member {Array<SizeStop>} SizeVariable.prototype.stops
     */
    this.stops = defaultValue(options.stops, [])
    this.stops = this.stops.map((v) => SizeStop.fromJSON(v))
  }

  /**
   * 通过json构造SizeVariable对象
   * @return {SizeVariable} json对象
   * */
  static fromJSON(json) {
    return new SizeVariable(json)
  }

  /**
   * 导出为json对象
   * @return {Object} json对象
   * */
  toJSON() {
    const json = super.toJSON()
    json.type = this.type
    json.minSize = this.minSize
    json.maxSize = this.maxSize
    json.minDataValue = this.minDataValue
    json.maxDataValue = this.maxDataValue
    json.normalizationField = this.normalizationField
    json.stops = this.stops.map((v) => v.toJSON())
    return json
  }

  /**
   * 克隆对象
   * @return {SizeVariable} 克隆后的SizeVariable对象
   */
  clone() {
    return new SizeVariable(this.toJSON())
  }
}

Zondy.Renderer.VisualVariable.SizeVariable = SizeVariable
export default SizeVariable
构造函数
成员变量
方法
事件