projects/angular-cesium/src/lib/angular-cesium-widgets/models/editable-point.ts
Properties |
|
Methods |
|
Accessors |
constructor(id: string, pointLayer: AcLayerComponent, coordinateConverter: CoordinateConverter, editOptions: PointEditOptions, position?: Cartesian3)
|
||||||||||||||||||
Parameters :
|
Private _enableEdit |
_enableEdit:
|
Default value : true
|
Private _labels |
_labels:
|
Type : LabelProps[]
|
Default value : []
|
Private _props |
_props:
|
Type : PointProps
|
Private point |
point:
|
Type : EditPoint
|
addLastPoint | ||||||
addLastPoint(position: Cartesian3)
|
||||||
Parameters :
Returns :
void
|
Private createFromExisting | ||||||
createFromExisting(position: Cartesian3)
|
||||||
Parameters :
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 :
Returns :
PositionWithPointProps
|
movePoint | ||||||
movePoint(toPosition: Cartesian3)
|
||||||
Parameters :
Returns :
void
|
setManually | |||||||||
setManually(point: PositionWithPointProps | Cartesian3, props?: PointProps)
|
|||||||||
Parameters :
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 :
Returns :
any
entity as AcEntity |
labels | ||||||
getlabels()
|
||||||
setlabels(labels: [])
|
||||||
Parameters :
Returns :
void
|
props | ||||
getprops()
|
||||
setprops(value)
|
||||
Parameters :
Returns :
void
|
enableEdit | ||||||
getenableEdit()
|
||||||
setenableEdit(value: boolean)
|
||||||
Parameters :
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;
}
}