projects/angular-cesium/src/lib/angular-cesium/services/drawers/entities-drawer/entities-drawer.service.ts
General primitives drawer responsible of drawing Cesium primitives. Drawers the handle Cesium primitives extend it.
Properties |
|
Methods |
|
constructor(cesiumService: CesiumService, graphicsType: GraphicsType, defaultOptions: EntitiesDrawerOptions)
|
||||||||||||
Parameters :
|
Private entityCollections |
entityCollections:
|
Default value : new Map<any, OptimizedEntityCollection>()
|
Private graphicsTypeName |
graphicsTypeName:
|
Type : string
|
Protected _propsAssigner |
_propsAssigner:
|
Type : Function
|
Inherited from
BasicDrawerService
|
Defined in BasicDrawerService:6
|
add | ||||||
add(cesiumProps: any)
|
||||||
Parameters :
Returns :
any
|
Private getFreeEntitiesCollection |
getFreeEntitiesCollection()
|
Returns :
OptimizedEntityCollection
|
init | ||||||
init(options?: EntitiesDrawerOptions)
|
||||||
Parameters :
Returns :
{}
|
remove | ||||||
remove(entity: any)
|
||||||
Parameters :
Returns :
void
|
removeAll |
removeAll()
|
Returns :
void
|
setShow | ||||||
setShow(showValue: boolean)
|
||||||
Parameters :
Returns :
void
|
Private suspendEntityCollection | ||||||
suspendEntityCollection(entity: any)
|
||||||
Parameters :
Returns :
void
|
update |
update(entity: any, cesiumProps: any)
|
Returns :
void
|
Abstract add | |||||||||
add(cesiumProps: any, ...args: any[])
|
|||||||||
Inherited from
BasicDrawerService
|
|||||||||
Defined in BasicDrawerService:11
|
|||||||||
Parameters :
Returns :
any
|
Abstract init | ||||||
init(options?: any)
|
||||||
Inherited from
BasicDrawerService
|
||||||
Defined in BasicDrawerService:21
|
||||||
Parameters :
Returns :
any
|
Abstract remove | ||||||
remove(primitive: any)
|
||||||
Inherited from
BasicDrawerService
|
||||||
Defined in BasicDrawerService:15
|
||||||
Parameters :
Returns :
void
|
Abstract removeAll |
removeAll()
|
Inherited from
BasicDrawerService
|
Defined in BasicDrawerService:17
|
Returns :
void
|
setPropsAssigner | ||||||
setPropsAssigner(assigner: Function)
|
||||||
Inherited from
BasicDrawerService
|
||||||
Defined in BasicDrawerService:23
|
||||||
Parameters :
Returns :
void
|
Abstract setShow | ||||||
setShow(showValue: boolean)
|
||||||
Inherited from
BasicDrawerService
|
||||||
Defined in BasicDrawerService:19
|
||||||
Parameters :
Returns :
void
|
Abstract update |
update(primitive: any, cesiumProps: any, ...args: any[])
|
Inherited from
BasicDrawerService
|
Defined in BasicDrawerService:13
|
Returns :
void
|
import { BasicDrawerService } from '../basic-drawer/basic-drawer.service';
import { CesiumService } from '../../cesium/cesium.service';
import { GraphicsType } from './enums/graphics-type.enum';
import { EntitiesDrawerOptions } from '../../../models/entities-drawer-options';
import { OptimizedEntityCollection } from './optimized-entity-collection';
/**
* General primitives drawer responsible of drawing Cesium primitives.
* Drawers the handle Cesium primitives extend it.
*/
export class EntitiesDrawerService extends BasicDrawerService {
private entityCollections = new Map<any, OptimizedEntityCollection>();
private graphicsTypeName: string;
constructor(
private cesiumService: CesiumService,
private graphicsType: GraphicsType,
private defaultOptions: EntitiesDrawerOptions = {
collectionMaxSize: -1,
collectionSuspensionTime: -1,
collectionsNumber: 1,
},
) {
super();
this.graphicsTypeName = GraphicsType[this.graphicsType];
// Fix bad enum compilation
for (const i in GraphicsType) {
if (GraphicsType[i] as any === this.graphicsType) {
this.graphicsTypeName = i;
}
}
}
private getFreeEntitiesCollection(): OptimizedEntityCollection {
let freeEntityCollection = null;
this.entityCollections.forEach(entityCollection => {
if (entityCollection.isFree()) {
freeEntityCollection = entityCollection;
}
});
return freeEntityCollection;
}
init(options?: EntitiesDrawerOptions) {
const finalOptions = options || this.defaultOptions;
const dataSources = [];
for (let i = 0; i < finalOptions.collectionsNumber; i++) {
const dataSource = new Cesium.CustomDataSource(this.graphicsTypeName);
dataSources.push(dataSource);
this.cesiumService.getViewer().dataSources.add(dataSource);
this.entityCollections.set(
dataSource.entities,
new OptimizedEntityCollection(dataSource.entities, finalOptions.collectionMaxSize, finalOptions.collectionSuspensionTime),
);
}
return dataSources;
}
add(cesiumProps: any): any {
const optimizedEntityCollection = this.getFreeEntitiesCollection();
if (optimizedEntityCollection === null) {
throw new Error('No more free entity collections');
}
const entityObject = {
position: cesiumProps.position !== undefined ? cesiumProps.position : undefined,
description: cesiumProps.description !== undefined ? cesiumProps.description : undefined,
orientation: cesiumProps.orientation !== undefined ? cesiumProps.orientation : undefined,
viewFrom: cesiumProps.viewFrom !== undefined ? cesiumProps.viewFrom : undefined,
[this.graphicsTypeName]: cesiumProps,
};
if (cesiumProps.name !== undefined) {
entityObject.name = cesiumProps.name;
}
if (cesiumProps.availability !== undefined) {
entityObject.availability = cesiumProps.availability;
}
return optimizedEntityCollection.add(entityObject);
}
update(entity: any, cesiumProps: any) {
this.suspendEntityCollection(entity);
if (entity.position instanceof Cesium.CallbackProperty) {
if (entity.position._isConstant) {
entity.position = cesiumProps.position;
}
}
entity.position = cesiumProps.position !== undefined ? cesiumProps.position : undefined;
entity.name = cesiumProps.name !== undefined ? cesiumProps.name : entity.name;
entity.description = cesiumProps.description !== undefined ? cesiumProps.description : entity.description;
entity.orientation = cesiumProps.orientation !== undefined ? cesiumProps.orientation : entity.orientation;
entity.viewFrom = cesiumProps.viewFrom !== undefined ? cesiumProps.viewFrom : entity.viewFrom;
entity.availability = cesiumProps.availability !== undefined ? cesiumProps.availability : cesiumProps.availability;
if (this._propsAssigner) {
this._propsAssigner(entity[this.graphicsTypeName], cesiumProps);
} else {
Object.assign(entity[this.graphicsTypeName], cesiumProps);
}
}
remove(entity: any) {
const optimizedEntityCollection = this.entityCollections.get(entity.entityCollection);
optimizedEntityCollection.remove(entity);
}
removeAll() {
this.entityCollections.forEach(entityCollection => {
entityCollection.removeAll();
});
}
setShow(showValue: boolean) {
this.entityCollections.forEach(entityCollection => {
entityCollection.setShow(showValue);
});
}
private suspendEntityCollection(entity: any) {
const id = entity.entityCollection;
if (!this.entityCollections.has(id)) {
throw new Error('No EntityCollection for entity.entityCollection');
}
const entityCollection = this.entityCollections.get(id);
entityCollection.suspend();
}
}