Source: objects/Points.js

import { Utils } from '../common/Utils'
import { BasePoints } from './BasePoints';

/**
 * @class Points
 * The points object.
 * @memberof THING
 * @extends THING.BasePoints
 * @public
 */
class Points extends BasePoints {

	_imageRatio = 1;
	_size = 1;
	_sizeAttenuation = false;
	_pickedIds = [];

	/**
	 * The points object in scene.
	 * @param {Object} param The initial parameters.
	 */
	constructor(param = {}) {
		super(param);

		this._syncOptions(param);
	}

	// #region Private Functions

	_syncOptions(param) {
		super.onSyncOptions(param);

		Utils.syncOptions(this, [
			'size',
			'imageRatio',
			'pickedIds'
		], param, param['extras'] || param['external']);
	}

	// #endregion

	// #region Overrides

	onBeforeSetup(param) {
		param['renderableNode'] = param['renderableNode'] || Utils.createObject('Points');

		super.onBeforeSetup(param);
	}

	onAfterSetup(param) {
		super.onAfterSetup(param);
	}

	onSetupStyle(param) {
		let style = param['style'];
		if (style) {
			// Enable transparent mode as default
			if (style.transparent === undefined) {
				style.transparent = true;
			}
		}
		else {
			param['style'] = {
				transparent: true
			}
		}

		super.onSetupStyle(param);
	}

	onRefreshPoints() {
		super.onRefreshPoints();

		let bodyNode = this.bodyNode;
		bodyNode.setSize(this._size);
		bodyNode.setSizeAttenuation(this._sizeAttenuation);
	}

	onImportExternalData(external, options) {
		super.onImportExternalData(external, options);
		if (external) {
			this._syncOptions(external);
		}
	}

	onExportExternalData() {
		let external = Object.assign({}, super.onExportExternalData());
		Utils.setAttributeIfExist(external, 'size', this);
		Utils.setAttributeIfExist(external, 'imageRatio', this);
		Utils.setAttributeIfExist(external, 'pickedIds', this);
		return external;
	}

	// #endregion

	// #region Accessor

	/**
	 * Get/Set the size.
	 * @type {Number}
	 * @public
	 */
	get size() {
		return this._size;
	}
	set size(value) {
		this._size = value;

		this.bodyNode.setSize(value);
	}

	/**
	 * Get/Set the image ratio.
	 * @type {Number}
	 * @public
	 */
	get imageRatio() {
		return this._imageRatio;
	}
	set imageRatio(value) {
		this._imageRatio = value;

		this.bodyNode.setImageRatio(value);
	}

	/**
	 * Enable/Disable the size attenuation.
	 * @type {Boolean}
	 * @public
	 */
	get sizeAttenuation() {
		return this._sizeAttenuation;
	}
	set sizeAttenuation(value) {
		this._sizeAttenuation = value;

		this.bodyNode.setSizeAttenuation(value);
	}

	/**
	 * Get/Set the picked Ids.
	 * @type {Array<Number>}
	 * @public
	 */
	get pickedIds() {
		return this._pickedIds;
	}
	set pickedIds(value) {
		if (value) {
			this._pickedIds = value.slice(0);
		}
		else {
			this._pickedIds.length = 0;
		}

		this.bodyNode.setPickedIds(this._pickedIds);
	}

	// #endregion

	get isPoints() {
		return true;
	}

}

export { Points }