File

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

Description

Take screenshot of your cesium globe.

usage:

 * // get base 64 data url
 * const dataUrl = screenshotService.getMapScreenshotDataUrl();
 *
 * // or download as png
 * screenshotService.downloadMapScreenshot('my-map.png');
 *
 *

Index

Methods

Constructor

constructor(cesiumService: CesiumService)
Parameters :
Name Type Optional
cesiumService CesiumService No

Methods

downloadMapScreenshot
downloadMapScreenshot(filename: string)
Parameters :
Name Type Optional Default value
filename string No 'map.png'
Returns : void
Private downloadURI
downloadURI(uri: string, name: string)
Parameters :
Name Type Optional
uri string No
name string No
Returns : void
getMapScreenshotDataUrlBase64
getMapScreenshotDataUrlBase64()
Returns : any
import { Injectable } from '@angular/core';
import { CesiumService } from '../cesium/cesium.service';

/**
 * Take screenshot of your cesium globe.
 *
 * usage:
 * ```typescript
 * // get base 64 data url
 * const dataUrl = screenshotService.getMapScreenshotDataUrl();
 *
 * // or download as png
 * screenshotService.downloadMapScreenshot('my-map.png');
 *
 * ```
 *
 */
@Injectable()
export class ScreenshotService {
  constructor(private cesiumService: CesiumService) {
  }

  getMapScreenshotDataUrlBase64() {
    const canvas = this.cesiumService.getCanvas();
    return canvas.toDataURL();
  }


  downloadMapScreenshot(filename = 'map.png') {
    const dataUrl = this.getMapScreenshotDataUrlBase64();
    this.downloadURI(dataUrl, filename);
  }

  private downloadURI(uri: string, name: string) {
    const link = document.createElement('a');
    link.download = name;
    link.href = uri;
    document.body.appendChild(link);
    link.click();
    document.body.removeChild(link);
  }
}

result-matching ""

    No results matching ""