未显示的Mapbox地图截图
Screenshot of Mapbox map without displaying it
我需要在同一屏幕上显示地图上的几个地址预览。为此,我将使用位图显示 ImageViews
,而不是制作 MapView
的多个实例。但是为此我需要找到一种方法来捕获这些位图。
我在 MapboxMap (https://github.com/mapbox/mapbox-gl-native/issues/6062) 中找到了 snapshot
函数,但它需要显示地图。
val position = CameraPosition.Builder()
.target(addressLatLng)
.zoom(zoom)
.build()
mapboxMap.cameraPosition = position
mapboxMap.snapshot { bitmap: Bitmap ->
imageView.setImageBitmap(bitmap)
}
那么,我可以拍一张地图而不显示在屏幕上吗?
我终于找到了解决办法!我需要使用的 class 是 MapSnapshotter.
val width = imageView.width
val height = imageView.height
val location = CameraPosition.Builder()
.target(LatLng(55.7558, 37.6173))
.zoom(16.0)
.build()
val options = MapSnapshotter.Options(width, height)
.withCameraPosition(location)
MapSnapshotter(context, options).start { snapshot ->
imageView.setImageBitmap(snapshot.bitmap)
}
我需要在同一屏幕上显示地图上的几个地址预览。为此,我将使用位图显示 ImageViews
,而不是制作 MapView
的多个实例。但是为此我需要找到一种方法来捕获这些位图。
我在 MapboxMap (https://github.com/mapbox/mapbox-gl-native/issues/6062) 中找到了 snapshot
函数,但它需要显示地图。
val position = CameraPosition.Builder()
.target(addressLatLng)
.zoom(zoom)
.build()
mapboxMap.cameraPosition = position
mapboxMap.snapshot { bitmap: Bitmap ->
imageView.setImageBitmap(bitmap)
}
那么,我可以拍一张地图而不显示在屏幕上吗?
我终于找到了解决办法!我需要使用的 class 是 MapSnapshotter.
val width = imageView.width
val height = imageView.height
val location = CameraPosition.Builder()
.target(LatLng(55.7558, 37.6173))
.zoom(16.0)
.build()
val options = MapSnapshotter.Options(width, height)
.withCameraPosition(location)
MapSnapshotter(context, options).start { snapshot ->
imageView.setImageBitmap(snapshot.bitmap)
}