Class: Screenshot

Screenshot

new Screenshot(options)

view/utils/Screenshot.js, line 2

MapboxGL 视图截图工具。

该工具基于 MapboxGL 画布导出能力,为 MapView 提供屏幕截图和局部裁剪能力, 适用于导出当前地图画面或裁剪指定矩形区域的图片结果。

Name Type Default Description
options Object {} 可选

构造参数。

Name Type Default Description
view MapView 可选

承载截图能力的视图对象。

format PictureFormat | String PictureFormat.PNG 可选

输出图片格式,支持 png、jpeg 和 svg。

filename String 'screenshotFile' 可选

浏览器下载时使用的文件名。

width Number 可选

输出图片宽度;未设置时使用原始画布宽度。

height Number 可选

输出图片高度;未设置时使用原始画布高度。

x Number 0 可选

裁剪区域左上角的横向像素偏移。

y Number 0 可选

裁剪区域左上角的纵向像素偏移。

isDownload Boolean true 可选

是否在生成图片后直接触发浏览器下载。

Example

初始化视图截图工具

// ES5 引入方式
const { Map } = zondy
const { MapView } = zondy.mapboxgl
const { Screenshot } = zondy.mapboxgl.tool

// ES6 引入方式
import { Map } from '@mapgis/webclient-common'
import { MapView, Screenshot } from '@mapgis/webclient-mapboxgl-plugin'

const map = new Map()
const mapView = new MapView({
  viewId: 'viewer-id',
  map
})

const screenshot = new Screenshot({
  view: mapView,
  isDownload: false
})

screenshot._addView().then((result) => {
  console.log(result.dataUrl)
})

Members

filenameString

浏览器下载文件名。

formatPictureFormat String

输出图片格式。

heightNumber undefined

输出图片高度。

isDownloadBoolean

是否直接下载图片。

viewMapView null

当前绑定的视图对象。

widthNumber undefined

输出图片宽度。

xNumber

裁剪起始横向像素偏移。

yNumber

裁剪起始纵向像素偏移。