File

projects/angular-cesium/src/lib/angular-cesium/services/drawers/entities-drawer/optimized-entity-collection.ts

Index

Properties
Methods
Accessors

Constructor

constructor(entityCollection: any, collectionSize, updateRate)
Parameters :
Name Type Optional
entityCollection any No
collectionSize No
updateRate No

Properties

Private _collectionSize
_collectionSize: number
Type : number
Private _isHardSuspend
_isHardSuspend:
Default value : false
Private _isSuspended
_isSuspended:
Default value : false
Private _onEventResumeCallback
_onEventResumeCallback: literal type
Type : literal type
Private _onEventSuspensionCallback
_onEventSuspensionCallback: literal type
Type : literal type
Private _suspensionTimeout
_suspensionTimeout: any
Type : any
Private _updateRate
_updateRate: number
Type : number

Methods

add
add(entity: any)
Parameters :
Name Type Optional
entity any No
Returns : any
collection
collection()
Returns : any
Public hardResume
hardResume()
Returns : void
Public hardSuspend
hardSuspend()
Returns : void
isFree
isFree()
Returns : boolean
onEventResume
onEventResume(callback: Function, once)
Parameters :
Name Type Optional Default value
callback Function No
once No false
Returns : Function
onEventSuspension
onEventSuspension(callback: Function, once)
Parameters :
Name Type Optional Default value
callback Function No
once No false
Returns : Function
remove
remove(entity: any)
Parameters :
Name Type Optional
entity any No
Returns : any
removeAll
removeAll()
Returns : void
removeNoSuspend
removeNoSuspend(entity: any)
Parameters :
Name Type Optional
entity any No
Returns : void
setShow
setShow(show: boolean)
Parameters :
Name Type Optional
show boolean No
Returns : void
Public suspend
suspend()
Returns : void
triggerEventResume
triggerEventResume()
Returns : void
triggerEventSuspension
triggerEventSuspension()
Returns : void

Accessors

isSuspended
getisSuspended()
updateRate
getupdateRate()
setupdateRate(value: number)
Parameters :
Name Type Optional
value number No
Returns : void
collectionSize
getcollectionSize()
setcollectionSize(value: number)
Parameters :
Name Type Optional
value number No
Returns : void
export class OptimizedEntityCollection {
  private _updateRate: number;
  private _collectionSize: number;
  private _isSuspended = false;
  private _isHardSuspend = false;
  private _suspensionTimeout: any;
  private _onEventSuspensionCallback: { once: boolean, callback: Function };
  private _onEventResumeCallback: { once: boolean, callback: Function };

  constructor(private entityCollection: any, collectionSize = -1, updateRate = -1) {
    this._updateRate = updateRate;
    this._collectionSize = collectionSize;

  }

  setShow(show: boolean) {
    this.entityCollection.show = show;
  }

  get isSuspended(): boolean {
    return this._isSuspended;
  }

  get updateRate(): number {
    return this._updateRate;
  }

  set updateRate(value: number) {
    this._updateRate = value;
  }

  get collectionSize(): number {
    return this._collectionSize;
  }

  set collectionSize(value: number) {
    this._collectionSize = value;
  }

  collection() {
    return this.entityCollection;
  }

  isFree(): boolean {
    return this._collectionSize < 1 || this.entityCollection.values.length < this._collectionSize;
  }

  add(entity: any) {
    this.suspend();
    return this.entityCollection.add(entity);
  }

  remove(entity: any) {
    this.suspend();
    return this.entityCollection.remove(entity);
  }

  removeNoSuspend(entity: any) {
    this.entityCollection.remove(entity);
  }

  removeAll() {
    this.suspend();
    this.entityCollection.removeAll();
  }

  onEventSuspension(callback: Function, once = false): Function {
    this._onEventSuspensionCallback = {callback, once};
    return () => {
      this._onEventSuspensionCallback = undefined;
    };
  }

  onEventResume(callback: Function, once = false): Function {
    this._onEventResumeCallback = {callback, once};
    if (!this._isSuspended) {
      this.triggerEventResume();
    }
    return () => {
      this._onEventResumeCallback = undefined;
    };
  }

  triggerEventSuspension() {
    if (this._onEventSuspensionCallback !== undefined) {
      const callback = this._onEventSuspensionCallback.callback;
      if (this._onEventSuspensionCallback.once) {
        this._onEventSuspensionCallback = undefined;
      }
      callback();
    }
  }

  triggerEventResume() {
    if (this._onEventResumeCallback !== undefined) {
      const callback = this._onEventResumeCallback.callback;
      if (this._onEventResumeCallback.once) {
        this._onEventResumeCallback = undefined;
      }
      callback();
    }
  }

  public suspend() {
    if (this._updateRate < 0) {
      return;
    }
    if (this._isHardSuspend) {
      return;
    }
    if (!this._isSuspended) {
      this._isSuspended = true;
      this.entityCollection.suspendEvents();
      this.triggerEventSuspension();
      this._suspensionTimeout = setTimeout(() => {
        this.entityCollection.resumeEvents();
        this.triggerEventResume();
        this._isSuspended = false;
        this._suspensionTimeout = undefined;
      }, this._updateRate);
    }
  }

  public hardSuspend() {
    this.entityCollection.suspendEvents();
    this._isHardSuspend = true;
  }

  public hardResume() {
    this.entityCollection.resumeEvents();
    this._isHardSuspend = false;
  }

}

result-matching ""

    No results matching ""