File

projects/angular-cesium/src/lib/angular-cesium/services/cesium/cesium.service.ts

Description

Service that initialize cesium viewer and expose cesium viewer and scene.

Index

Properties
Methods

Constructor

constructor(ngZone: NgZone, viewerFactory: ViewerFactory, viewerConfiguration: ViewerConfiguration)
Parameters :
Name Type Optional
ngZone NgZone No
viewerFactory ViewerFactory No
viewerConfiguration ViewerConfiguration No

Methods

getCanvas
getCanvas()
Returns : HTMLCanvasElement

cesium canvas

getMap
getMap()
Returns : AcMapComponent
getScene
getScene()
Returns : any

cesium scene

getViewer
getViewer()
Returns : any

cesiumViewer

init
init(mapContainer: HTMLElement, map: AcMapComponent)
Parameters :
Name Type Optional
mapContainer HTMLElement No
map AcMapComponent No
Returns : void

Properties

Private cesiumViewer
cesiumViewer: any
Type : any
Private map
map: AcMapComponent
Type : AcMapComponent
import { Injectable, NgZone, Optional } from '@angular/core';
import { ViewerFactory } from '../viewer-factory/viewer-factory.service';
import { ViewerConfiguration } from '../viewer-configuration/viewer-configuration.service';
import { AcMapComponent } from '../../components/ac-map/ac-map.component';

/**
 *  Service that initialize cesium viewer and expose cesium viewer and scene.
 */
@Injectable()
export class CesiumService {
  private cesiumViewer: any;
  private map: AcMapComponent;

  constructor(private ngZone: NgZone, private viewerFactory: ViewerFactory, @Optional() private viewerConfiguration: ViewerConfiguration) {
  }

  init(mapContainer: HTMLElement, map: AcMapComponent) {
    this.map = map;
    this.ngZone.runOutsideAngular(() => {
      const options = this.viewerConfiguration ? this.viewerConfiguration.getNextViewerOptions() : undefined;
      this.cesiumViewer = this.viewerFactory.createViewer(mapContainer, options);

      const viewerModifier = this.viewerConfiguration && this.viewerConfiguration.getNextViewerModifier();
      if (typeof viewerModifier === 'function') {
        viewerModifier(this.cesiumViewer);
      }
    });
  }

  /**
   * For more information see https://cesiumjs.org/Cesium/Build/Documentation/Viewer.html?classFilter=viewe
   * @returns cesiumViewer
   */
  getViewer() {
    return this.cesiumViewer;
  }

  /**
   * For more information see https://cesiumjs.org/Cesium/Build/Documentation/Scene.html?classFilter=scene
   * @returns cesium scene
   */
  getScene() {
    return this.cesiumViewer.scene;
  }

  /**
   * For more information see https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API
   * @returns cesium canvas
   */
  getCanvas(): HTMLCanvasElement {
    return this.cesiumViewer.canvas as HTMLCanvasElement;
  }

  getMap(): AcMapComponent {
    return this.map;
  }
}

result-matching ""

    No results matching ""