File

projects/angular-cesium/src/lib/angular-cesium-widgets/models/editable-point.ts

Extends

AcEntity

Index

Properties
Methods
Accessors

Constructor

constructor(id: string, pointLayer: AcLayerComponent, coordinateConverter: CoordinateConverter, editOptions: PointEditOptions, position?: Cartesian3)
Parameters :
Name Type Optional
id string No
pointLayer AcLayerComponent No
coordinateConverter CoordinateConverter No
editOptions PointEditOptions No
position Cartesian3 Yes

Properties

Private _enableEdit
_enableEdit:
Default value : true
Private _labels
_labels: LabelProps[]
Type : LabelProps[]
Default value : []
Private _props
_props: PointProps
Type : PointProps
Private point
point: EditPoint
Type : EditPoint

Methods

addLastPoint
addLastPoint(position: Cartesian3)
Parameters :
Name Type Optional
position Cartesian3 No
Returns : void
Private createFromExisting
createFromExisting(position: Cartesian3)
Parameters :
Name Type Optional
position Cartesian3 No
Returns : void
dispose
dispose()
Returns : void
getCurrentPoint
getCurrentPoint()
Returns : EditPoint
getId
getId()
Returns : string
getPosition
getPosition()
Returns : Cartesian3
getPositionCallbackProperty
getPositionCallbackProperty()
Returns : Cartesian3
Private hasPosition
hasPosition(point: PositionWithPointProps | Cartesian3)
Parameters :
Name Type Optional
point PositionWithPointProps | Cartesian3 No
movePoint
movePoint(toPosition: Cartesian3)
Parameters :
Name Type Optional
toPosition Cartesian3 No
Returns : void
setManually
setManually(point: PositionWithPointProps | Cartesian3, props?: PointProps)
Parameters :
Name Type Optional
point PositionWithPointProps | Cartesian3 No
props PointProps Yes
Returns : void
update
update()
Returns : void
Private updatePointLayer
updatePointLayer()
Returns : void
Static create
create(json?: any)
Inherited from AcEntity
Defined in AcEntity:18

Creates entity from a json

Parameters :
Name Type Optional Description
json any Yes

entity object

Returns : any

entity as AcEntity

Accessors

labels
getlabels()
setlabels(labels: [])
Parameters :
Name Type Optional
labels [] No
Returns : void
props
getprops()
setprops(value)
Parameters :
Name Optional
value No
Returns : void
enableEdit
getenableEdit()
setenableEdit(value: boolean)
Parameters :
Name Type Optional
value boolean No
Returns : void
import { AcLayerComponent } from '../../angular-cesium/components/ac-layer/ac-layer.component';
import { AcEntity } from '../../angular-cesium/models/ac-entity';
import { Cartesian3 } from '../../angular-cesium/models/cartesian3';
import { CoordinateConverter } from '../../angular-cesium/services/coordinate-converter/coordinate-converter.service';
import { EditPoint } from './edit-point';
import { defaultLabelProps, LabelProps } from './label-props';
import { PointEditOptions, PointProps } from './point-edit-options';

interface PositionWithPointProps {
  position: Cartesian3;
  pointProp?: PointProps;
}

export class EditablePoint extends AcEntity {
  private point: EditPoint;
  private _enableEdit = true;
  private _props: PointProps;
  private _labels: LabelProps[] = [];

  constructor(private id: string,
              private pointLayer: AcLayerComponent,
              private coordinateConverter: CoordinateConverter,
              private editOptions: PointEditOptions,
              position?: Cartesian3) {
    super();
    this._props = {...editOptions.pointProps};
    if (position) {
      this.createFromExisting(position);
    }
  }

  get labels(): LabelProps[] {
    return this._labels;
  }

  set labels(labels: LabelProps[]) {
    if (!labels) {
      return;
    }
    const position = this.point.getPosition();
    this._labels = labels.map((label, index) => {
      if (!label.position) {
        label.position = position;
      }
      return Object.assign({}, defaultLabelProps, label);
    });
  }

  get props(): PointProps {
    return this._props;
  }

  set props(value: PointProps) {
    this._props = value;
  }

  get enableEdit() {
    return this._enableEdit;
  }

  set enableEdit(value: boolean) {
    this._enableEdit = value;
    if (value) {
      this.point.props.color = Cesium.Color.WHITE;
    } else {
      this.point.props.color = Cesium.Color.DIMGREY;
      this.point.props.pixelSize = 10;
    }
    this.updatePointLayer();
  }

  private createFromExisting(position: Cartesian3) {
    this.point = new EditPoint(this.id, position, this._props);
    this.updatePointLayer();
  }

  private hasPosition(point: PositionWithPointProps | Cartesian3): point is PositionWithPointProps {
    if ((point as PositionWithPointProps).position) {
      return true;
    }
    return false;
  }

  setManually(point: PositionWithPointProps | Cartesian3, props?: PointProps) {
    if (!this.enableEdit) {
      throw new Error('Update manually only in edit mode, after point is created');
    }
    let newProps = props;
    if (this.hasPosition(point)) {
      newProps = point.pointProp ? point.pointProp : props;
      this.point.setPosition(point.position);
    } else {
      this.point.setPosition(point);
    }
    this.point.props = newProps;
    this.updatePointLayer();
  }

  addLastPoint(position: Cartesian3) {
    this.point.setPosition(position);
    this.updatePointLayer();
  }

  movePoint(toPosition: Cartesian3) {
    if (!this.point) {
      this.point = new EditPoint(this.id, toPosition, this._props);
    } else {
      this.point.setPosition(toPosition);
    }
    this.updatePointLayer();
  }

  getCurrentPoint(): EditPoint {
    return this.point;
  }

  getPosition(): Cartesian3 {
    return this.point.getPosition();
  }

  getPositionCallbackProperty(): Cartesian3 {
    return new Cesium.CallbackProperty(this.getPosition.bind(this), false);
  }

  private updatePointLayer() {
    this.pointLayer.update(this.point, this.point.getId());
  }

  update() {
    this.updatePointLayer();
  }

  dispose() {
    this.pointLayer.remove(this.point.getId());
  }

  getId() {
    return this.id;
  }
}

result-matching ""

    No results matching ""